0

I update my question asked yesterday,and hope someone to clarify this question !

When applying pitch-yaw-roll(assume we choose this order) angles to implement a air camera,I think we can compute the view matrix like this :

view matrix

And there are sites support this viewpoint such as Using a camera and simple user input and OpenGL Transformation,their code style like this :

// First, transform the camera (viewing matrix) from world space to eye space
// Notice all values are negated, because we move the whole scene with the
// inverse of camera transform
glRotatef(-roll, 0, 0, 1); // roll
glRotatef(-yaw, 0, 1, 0); //yaw
glRotatef(-pitch, 1, 0, 0); // pitch
glTranslatef(-cameraPosition[0], -cameraPosition[1], -cameraPosition[2]);

I do believe this is right.

while Red book pilotView(7th edition), A C++ Camera Class for Simple OpenGL FPS Controls , First Person Camera Control with LWJGL, Modern OpenGL 04 - Cameras, Vectors & Input code like this style :

glRotatef(roll, 0, 0, 1); // roll
glRotatef(yaw, 0, 1, 0); //yaw
glRotatef(pitch, 1, 0, 0); // pitch
glTranslatef(-cameraPosition[0], -cameraPosition[1], -cameraPosition[2]);

It will work,and not influence much on user interaction,But from math's viewpoint ,it is not that right.

Why books and others choose the second code style? Please Help clarify this question !

wangdq
  • 1,874
  • 17
  • 26

2 Answers2

0

I would suggest that it's a matter of convention. Eg, is the pitch angle positive when you nose-up or positive when you nose-down? Both approaches work fine, you may just need to negate the angles depending on your chosen convention. In the real world I have arguments about what "dip" and "azimuth" mean with geologists all the time and it seems that there is no set convention in geological circles.

It seems that your Lloyd Goodall reference does not negate the camera position in the glTranslatef() call. Yet another convention?

To answer the question of why they choose that code style... I think it somewhat arbitrary and so authors will simply do it one way or the other.

Daniel Paull
  • 6,797
  • 3
  • 32
  • 41
  • Thank you for taking time to investigate my reference pages and relieving my beginner's puzzle .Lloyd Goodall 's code glTranslatef is unusually from others,but he also did something different in walkForward/walkBackwards methods to compute camera position to make it work.I prefer to choose the first coding style. – wangdq Oct 08 '14 at 06:30
0

In OpenGL Camera matrix is part of ModelView matrix

  • Model matrix represents actually rendered object coordinate system
  • View (Camera) matrix represents observer coordinate system

To form correct ModelView matrix you need:

ModelView = Model * Inverse(View)
  • when you multiply this matrix by vector it converts it from object space to camera space
  • the way you generate the View part is matter of your convention (as Daniel Paull pointed out)
  • but the resultant matrix is the inverse of coordinate system you are looking from.
  • For more info look here: transform matrix anatomy
Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380