我正在使用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;
}
(在另一个班级中也有一些glrotate)
glRotatef(this->pov->pitch, 1, 0, 0);
glRotatef(this->pov->yaw, 0, -1, 0);
现在我认为viewDirection是一个向量,指示我要去的方向。 我现在试着在我旁边放一个标记,当我移动相机时,它一直停留在我面前,但它的位置不正确。这是标记类
的绘制函数的代码部分this->setPosition(this->scene->getPov()->getPosition() + this->scene->getPov()->getViewDirection() * 4.0f );
(4x是将它放在离我一定距离的地方)
你是否知道如何让这个标记永远留在我面前?