0
\$\begingroup\$

I have done a scene in opengl where I'm using a third person camera (that I can control with the mouse). Then, inside it, it has the camera of the first view (that I called thirdpersonCamera, see the code above), drawing the camera, the frustum etc..

It looks like this picture:

enter image description here

and I've done with this code:

void GLView::drawSubThirdpersoncamera() { // set perspective viewing frustum in the 3rd person camera thirdpersonCamera.setFrustum(FOV_Y, (float)(W)/(H), NEAR, FAR); // use 3rd person camera projection matrix (the frustum, the perspective etcetera) // as the opengl camera glMatrixMode(GL_PROJECTION); glLoadMatrixf(thirdpersonCamera.projectionMatrix.getTranspose()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); { // First, transform the camera (viewing matrix) from world space to eye space glLoadMatrixf(thirdpersonCamera.viewMatrix.getTranspose()); // translate and rotate the mouse control // (keeping the camera fixed because // we want only the scene to rotate/translate) // for thinking about modern opengl: should be a matrix.. glTranslatef(mousePosition[0], mousePosition[1], mousePosition[2]); glRotatef(mouseAngle[0], 1, 0, 0); // pitch glRotatef(mouseAngle[1], 0, 1, 0); // heading glRotatef(mouseAngle[2], 0, 0, 1); // roll // now the draw the scene drawScene(); // draw the first person camera glPushMatrix(); { glMultMatrixf(physicalCamera.viewMatrix.getTranspose()); drawAxis(4); drawCamera(); drawFrustum(physicalCamera.fovy, physicalCamera.aspectRatio, physicalCamera.near, physicalCamera.far); } glPopMatrix(); } glPopMatrix(); } 

Now I want to switch to the eye of the camera I've drawn, with this code:

void GLView::drawSubPhysicalCamera() { // use physical camera projection matrix (the frustum, the perspective etcetera) // as the opengl camera glMatrixMode(GL_PROJECTION); glLoadMatrixf(physicalCamera.projectionMatrix.getTranspose()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); { // the view matrix: how the camera is positioned in the world space glLoadMatrixf(physicalCamera.viewMatrix.getTranspose()); drawScene(); } glPopMatrix(); } 

I think it should go because I'm using the same matrix once for translate the object in the screen, once for translate the camera but.. in the second view I don't see anything.. I don't find any error because the transformation in the space is the same but.. it doen't work..

Where am I wrong?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

As clearly explained in this article I have to take the inverse:

If you only have the view matrix and you need to find a camera transform that can be used to position a visual representation of the camera in the scene, you can simply take the inverse of the view matrix.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.