Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

Cocos MVP 疑惑

$
0
0

@tianxiawuzhei 写道:

//渲染
void Scene::render(Renderer* renderer)
{
    auto director = Director::getInstance();
    Camera* defaultCamera = nullptr;
    const auto& transform = getNodeToParentTransform();

	//遍历所有相机
    for (const auto& camera : getCameras())
    {
        if (!camera->isVisible())
            continue;
        
        Camera::_visitingCamera = camera;
        if (Camera::_visitingCamera->getCameraFlag() == CameraFlag::DEFAULT)
        {
            defaultCamera = Camera::_visitingCamera;
        }
        
        //这里有个疑惑,getViewProjectionMatrix这个函数明明获取的是
        //试图投影矩阵即视图矩阵和投影矩阵的乘积,名字确实投影矩阵
        // /**get view projection matrix*/
    		// const Mat4& getViewProjectionMatrix() const;
        director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
        director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix());
        camera->apply();
        //clear background with max depth
        camera->clearBackground();
        
        //visit the scene
        //添加渲染命令
        visit(renderer, transform, 0);
        
        //真正的渲染
        renderer->render();
        
        director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
    }
    
    Camera::_visitingCamera = nullptr;
    experimental::FrameBuffer::applyDefaultFBO();
}

2、
渲染命令
void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags)
这里会获取模型变化,我的理解这里获取的是模型变化,并没有视图变换,名字为什么是modelView,我不是很理解。。。
if(flags & FLAGS_DIRTY_MASK)
_modelViewTransform = this->transform(parentTransform);

3、
void Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
trianglesCommand.init(globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, _polyInfo.triangles, transform, flags);
renderer->addCommand(&_trianglesCommand);
精灵的绘制命令
初始化方法:const Mat4& mv这里也是上面疑惑的地方
void TrianglesCommand::init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, const Triangles& triangles,const Mat4& mv, uint32_t flags)

疑问:cocos中的MVP矩阵如何计算的?

帖子: 1

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>