I am trying to move my camera with my mouse, I can translate it juste by changing the current position of my camera, but when I want to move my forward vector and my up vector of my camera it doesnt work very well, the camera seem to move whereas it's not the case...
void Camera::moveCameraRotateUpdtade(GLFWwindow * window)
{
//curseur mvt ...
double xpos, ypos;
Vec3f new_front;
std::cout << "front = " << CameraFront << std::endl;
glfwGetCursorPos(window, &xpos, &ypos);
if(!(xpos > _width-1 || xpos < 0) && !(ypos > _height-1 || ypos < 0))
{
float x = (2.0f * xpos) / _width - 1.0f;
float y = 1.0f - (2.0f * ypos) / _height;
horizontalAngle += mouseSpeed * float(x) ;
verticalAngle -= mouseSpeed * float(y) ;
std::cout << "x y = " << x << " " << y << std::endl;
std::cout << "horizontalAngle verticalAngle = " << horizontalAngle << " " << verticalAngle << std::endl;
new_front = Vec3f(cos(verticalAngle) * sin(horizontalAngle),sin(verticalAngle),cos(verticalAngle) * cos(horizontalAngle));
Vec3f right = Vec3f(sin(horizontalAngle - M_PI/2.0f),0.0,cos(horizontalAngle - M_PI/2.0f));
CameraUp = right.cross(new_front);
CameraUp = CameraUp.normalize();
CameraFront = new_front.normalize();
std::cout << "CameraFront = " << CameraFront;
std::cout << "CameraUp = " << CameraUp;
std::cout << "position = " << _positionCam;
LookAt( _positionCam + CameraFront,_positionCam, CameraUp);
}
}
Here my lookAt function :
Mat4f Camera::LookAt(Vec3f target, Vec3f position,Vec3f CameraUp)
{
//ce dont j'ai besoin pour calculer les parametre de ma camera...
Vec3f f = (target - position).normalize();
Vec3f u = CameraUp.normalize();
Vec3f s = f.cross(u).normalize();
u = s.cross(f);
Mat4f R;
R.setCol(0,s);
R.setCol(1,u);
Vec3f f_tmp = f*-1.0 ;
R.setCol(2,f_tmp);
R.setElement(0,3,-1.0f * s.dot(position));
R.setElement(1,3,-1.0f * u.dot(position));
R.setElement(2,3,f.dot(position));
_LookAt = R.transpose();
return _LookAt;
}
Here a video showing my problem :