I am rotating a world like a FPS and need a sphere to move opposite to the camera so that the effect is it stays put. Here is the ball moving wrongly with the rotation:
https://www.youtube.com/watch?v=ksNt3W_p5u8
and here is the function that changes the camera vectors with my try that didn't work:
void Camera::updateCameraVectors(void)
{
// Calculate the new Front vector
glm::vec3 front;
front.x = cos(glm::radians(this->yaw)) * cos(glm::radians(this->pitch));
front.y = sin(glm::radians(this->pitch));
front.z = sin(glm::radians(this->yaw)) * cos(glm::radians(this->pitch));
glm::vec3 temp = this->front;
this->front = glm::normalize(front);
// Also re-calculate the Right and Up vector
this->right = glm::normalize(glm::cross(this->front, this->worldUp)); // Normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement.
this->up = glm::normalize(glm::cross(this->right, this->front));
//this didn't work:
//ball.xadj = ball.xadj + front.x;
//ball.zadj = ball.zadj - front.z;
}
and this is for changing the world with the mouse:
void Camera::ProcessMouseMovement(GLfloat xOffset, GLfloat yOffset, GLboolean constrainPitch)
{
xOffset *= this->mouseSensitivity;
yOffset *= this->mouseSensitivity;
this->yaw += xOffset;
this->pitch += yOffset;
// Make sure that when pitch is out of bounds, screen doesn't get flipped
if (constrainPitch)
{
if (this->pitch > 89.0f)
{
this->pitch = 89.0f;
}
if (this->pitch < -89.0f)
{
this->pitch = -89.0f;
}
}
// Update Front, Right and Up Vectors using the updated Eular angles
this->updateCameraVectors();
}
and to get the view matrix:
glm::mat4 Camera::GetViewMatrix(void)
{
return glm::lookAt(this->position, this->position + this->front, this->up);
}
lastly, the translate:
ball = glm::translate(ball, glm::vec3(c_mycamera.ball.xadj, 0.0f, c_mycamera.ball.zadj));
So, how do I get the exactly correct amount for translating the sphere over and over again as the world rotates?
This has been my ongoing project for some time (thanks,)
Josheir