openGL(GLFW)-摄影机移动和视图方向向量 我用C++和GLFW库制作OpenGL游戏。 我让我的相机移动功能正常工作,下面是代码 void Player::mouse_callback(double xpos, double ypos) { static float lastX = 0.0; static float lastY = 0.0; GLfloat xoffset = xpos - lastX; GLfloat yoffset = lastY - ypos; lastX = xpos; lastY = ypos; GLfloat sensitivity = 0.1; xoffset *= sensitivity; yoffset *= sensitivity; yaw -= xoffset; pitch -= yoffset; if (pitch > 89.0f) pitch = 89.0f; if (pitch < -89.0f) pitch = -89.0f; glm::vec3 front; front.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); front.y = sin(glm::radians(pitch)); front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); this->viewDirection = glm::normalize(front); cout << "ViewDirection: " << viewDirection.x << " " << viewDirection.y << " " << viewDirection.z << endl; }

openGL(GLFW)-摄影机移动和视图方向向量 我用C++和GLFW库制作OpenGL游戏。 我让我的相机移动功能正常工作,下面是代码 void Player::mouse_callback(double xpos, double ypos) { static float lastX = 0.0; static float lastY = 0.0; GLfloat xoffset = xpos - lastX; GLfloat yoffset = lastY - ypos; lastX = xpos; lastY = ypos; GLfloat sensitivity = 0.1; xoffset *= sensitivity; yoffset *= sensitivity; yaw -= xoffset; pitch -= yoffset; if (pitch > 89.0f) pitch = 89.0f; if (pitch < -89.0f) pitch = -89.0f; glm::vec3 front; front.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); front.y = sin(glm::radians(pitch)); front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); this->viewDirection = glm::normalize(front); cout << "ViewDirection: " << viewDirection.x << " " << viewDirection.y << " " << viewDirection.z << endl; },c++,opengl,camera,trigonometry,C++,Opengl,Camera,Trigonometry,现在我认为viewDirection是一个向量,它指示我要去的方向。 我现在试着在我旁边放置一个标记,当我移动相机时,它总是在我前面,但它的位置不正确。这是marker类的draw函数的代码部分 this->setPosition(this->scene->getPov()->getPosition() + this->scene->getPov()->getViewDirection() * 4.0f ); (4x将放置在离我一定距离的位置) 你知道

现在我认为viewDirection是一个向量,它指示我要去的方向。 我现在试着在我旁边放置一个标记,当我移动相机时,它总是在我前面,但它的位置不正确。这是marker类的draw函数的代码部分

this->setPosition(this->scene->getPov()->getPosition() + this->scene->getPov()->getViewDirection() * 4.0f );
(4x将放置在离我一定距离的位置)


你知道我怎样才能使标记始终保持在我面前吗?

gluLookAt可以帮你找出这个“标记”是什么吗?就像十字线一样?标记是一个正方形,我想一直放在我面前只是为了测试你可以直接渲染到NDC,跳过所有的相机属性,通过加载你的矩阵和身份。然后,无论摄像机的方向和位置如何,标记都会定位在显示屏上。不确定你所说的“在我面前”是否就是这个意思。@ScazzoMatto:你的问题中没有提供enoguh的信息,所以我只能做出一些猜测:我认为你的转变是颠倒的。您似乎使用这两个
glRotate
调用来移动摄影机-但它不这样做,而是移动对象,这相当于反向移动虚拟摄影机。
this->setPosition(this->scene->getPov()->getPosition() + this->scene->getPov()->getViewDirection() * 4.0f );