Hello everyone.
I have my camera in third person, as shown below.
As you can see, the player is in the center, covering the crosshairs and making it difficult.
How do I move the player to the side as shown in the image below (there I used a free camera to demonstrate), such as the GTA 5 camera.
if I add a value to the x axis of the player model it even works. But if I keep turning the mouse to look around, start and unconfigure the camera:
glm::vec3 pos = camera.Front;
pos.y = 0;
pos.x += -0.06f; //to keep left
model = glm::translate(model, pos);
My Front is Position + glm::vec3(0.0, 0.0, -0.36f); and viewMatrix is glm::lookAt(Position, Front, Up);
My mouse movement:
void updateCameraVectors()
{
POINT mousePos;
int mid_x = wndWidth >> 1;
int mid_y = wndHeight >> 1;
float angle_y = 0.0f;
float angle_z = 0.0f;
GetCursorPos(&mousePos); // Get the mouse cursor 2D x,y position
if ((mousePos.x == mid_x) && (mousePos.y == mid_y)) return;
SetCursorPos(mid_x, mid_y); // Set the mouse cursor in the center of the window
// Get the direction from the mouse cursor, set a resonable maneuvering speed
angle_y = (float)((mid_x - mousePos.x)) / 1000;
angle_z = (float)((mid_y - mousePos.y)) / 5000;
Front.y += angle_z * 2;
// limit o mouse olhando para cima e para baixo
if (Front.y > 0.26f) {
Front.y = 0.26f;
}
if (Front.y < -0.05f) {
Front.y = -0.05f;
}
glm::vec3 vVector = Position - Front;
float speed = angle_y;
playerYaw += speed;
if (rotateAround == 1) {
playerYaw = oldPlayerYaw;
}
else {
oldPlayerYaw = playerYaw;
}
Position.z = (float)(Front.z + sin(-speed)*vVector.x + cos(-speed)*vVector.z);
Position.x = (float)(Front.x + cos(-speed)*vVector.x - sin(-speed)*vVector.z);
}
can someone help me ?
Tank you