I have a perspective camera with Obs and VRP and Up vector.
I want to implement turning around to act like an observer inside my scene. I have already implemented forward and backward as it is only adding same amount to z coordinate to Obs and VRP (both are vec3). The problem comes when I try to implement rotate, is there any way to do it with matrix product? I've tried that:
x = R * cos angle
z = R * sin angle
where R is the magnitude of vector (VRP - Obs) but it doesn't work
Edit: i apply view and projection matrix here:
void MyGLWidget::projTransform(){
//fov window, ra window (anchura / altura), near, far
glm::mat4 Proj = glm::perspective(M_PI/1.3, 1.0, 0.2, 3000.0);
glUniformMatrix4fv(projLoc,1,GL_FALSE, &Proj[0][0]);
}
void MyGLWidget::viewTransform(){
//lookAt(OBS,VRP;UP)
//glm::mat4 View = glm::lookAt(glm::vec3(0,0,10),glm::vec3(0,0,-2), glm::vec3(0,1,0));
glm::mat4 View = glm::lookAt(glm::vec3(xObs,yObs,zObs),glm::vec3(xVRP,yVRP,zVRP), glm::vec3(0,1,0));
glUniformMatrix4fv(viewLoc,1,GL_FALSE, &View[0][0]);
}
Assuming the Obs is the camera position and VRP is the look-at position:
r = ||VRP - Obs||
r * cos(angle)
VRP_new = Obs + [ 0 ]
r * sin(angle)
Since you might want to have a second rotation axis later on, I would suggest to have this parameters for the camera: A position vector t and two angles describing rotations around x and y axis [rx, ry]. One can combine them in every frame to get Obs and VRP, but this is not really necessary, since the view matrix can directly be derived from this parameters:
V = T(t) * R_y(ry) * R_x(rx),
where T is a translation matrix and R_x, R_y are rotation matrices. Depending on your notation, the view matrix might have to be inverted.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.