Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL Camera Rotation Not Working
    text
    copied!<p>I know this is a common question (as I have read many threads on here and other forums about it) but for the life of me I can not get the camera rotation that I desire. I want the camera to be able to 'look around' and not for it to 'orbit' around a point, this point being the OpenGL origin.</p> <p>I am aware that 'there is no camera in OpenGL', the terrain moves and not the viewpoint, etc. and all of those similar concepts but it has not helped me in solving this. </p> <p>Unfortunately I am stubborn and want to write my code with no deprecated features and so this eliminates 99% of the similar situations I have read about since most of those solutions were with gluLook and similar functions. </p> <p>The matrix class I am using is similar to the one that is used by the OpenGL SuperBible 5th Edition ( <a href="http://oglsuperbible5.googlecode.com/svn/trunk/Src/GLTools/" rel="nofollow">source</a>, GLFrame.h is the main file of interest) but have adapted it to use the <a href="http://glm.g-truc.net/" rel="nofollow">OpenGL Mathematics Library</a>.</p> <p>The typical response to this question is to translate to the origin, rotate, then translate back, but this does nothing for me.</p> <p>Some code:</p> <pre><code>void rotateLocalX( GLfloat p_Angle ) { if( ( m_Roll &lt; m_RollLimit ) &amp;&amp; ( m_Roll &gt; ( -m_RollLimit ) ) ) { //store away the current location so I can translate back to it glm::vec3 tempOrigin = getOrigin( ); m_Roll += p_Angle; // Go to the Origin //you can also subtract the current location to get to 0.f //also doing glm::translate( m_Matrix, -( tempOrigin ) ); -&gt; rotate -&gt; //glm::translate( m_Matrix, tempOrigin ) has the same result m_Matrix[ 3 ][ 0 ] = 0.f; m_Matrix[ 3 ][ 1 ] = 0.f; m_Matrix[ 3 ][ 2 ] = 0.f; m_Matrix[ 3 ][ 3 ] = 1.f; // Rotate the matrix m_Matrix = glm::rotate( m_Matrix, p_Angle, glm::vec3( 1.f, 0.f, 0.f ) ); // Go back to the original location m_Matrix[ 3 ][ 0 ] = tempOrigin.x; m_Matrix[ 3 ][ 1 ] = tempOrigin.y; m_Matrix[ 3 ][ 2 ] = tempOrigin.z; m_Matrix[ 3 ][ 3 ] = 1.f; normalize( ); } } </code></pre> <p>And if it is of any consequence, I am treating the camera matrix as the view matrix (with a separate model matrix [view*model=modelview] and a perspective projection matrix).</p> <p>Finally a typical frame goes like this: check for input (move/rotate camera as appropriate), render skybox (ignoring the origin/location column of the view/camera matrix), draw everything else (taking into account the entire view matrix).</p> <p>I apologize for asking such a common question but two days of searching and trying various different solutions has yielded no positive results.</p> <p>Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload