相机围绕原点而不是自身旋转[关闭]

问题描述 投票:0回答:0

我试图在 openGL 中启动 3D,但我的相机总是围绕坐标原点旋转!这是我的代码:对于每个模型,我调用的每一帧:

models[i])->draw(currentShader, projectionMatrix * camera.getTransformation().mat()

然后在各个模型的draw函数中是:

shader.setUniform<Matrix4>(shader.getUniformLocation("MVP"), VP * transformation.mat());

现在对于 cursorPositionCallBack 函数,我这样做:

enviroment.camera.getTransformation().rotate(Transformation::Y, movedX);

所以它总是旋转给定的距离!

然而,世界各地起源。虽然我认为我会用这段代码解决它:(从“转换”类中截取:

Transformation & rotate(Axes axes, float angel, bool degree = true) {
    Vector3 curT = this->getTranslation();
    setTranslation({0, 0, 0});
    matrix = glm::rotate(matrix,
                         degree ? glm::radians(angel) : angel,
                         Vector3(axes == X ? 1 : 0, axes == Y ? 1 : 0, axes == Z ? 1 : 0));
    
    setTranslation(curT);
    return *this;
}

transformation & setTranslation(Vector3 values) {
    matrix[3][0] = values.x;
    matrix[3][1] = values.y;
    matrix[3][2] = values.z;
    return *this;
}

getTranslation 方法使用与 setTranslation 相同的字段。

在着色器中,它只是设置

gl_Position = MVP * vec4(position);
。我真的很难过。

我试着把它平移到原点,然后旋转它。只是没有做任何不同的事情。

c++ matrix opengl camera glm-math
© www.soinside.com 2019 - 2024. All rights reserved.