   help with camera math
  hi,i have a problem understanding how to make a basic opengl camera. i found a good tutorial athttp://www.swiftless.com/tutorials/opengl/camera.htmlbut some bits are still disturbing me.-------------------------------------------------------------------------------------------code snipet-------------------------------------------------------------------------------------------float   xpos, ypos, zpos;//x,y,z positions of the camerafloat xrot = 0, yrot = 0;//angle of rotation about x and y axesyrotrad = (yrot / 180 * 3.141592654f);//i think the angles are being converted to radiansxrotrad = (xrot / 180 * 3.141592654f);//for use in sin, cos,etcxpos -= float(sin(yrotrad));//this is the part i dont get.zpos += float(cos(yrotrad)) ;    //how does cos and sine come inypos += float(sin(xrotrad));//can someone explain the math to me?glRotatef(xrot,1.0,0.0,0.0);  //the values are used hereglRotatef(yrot,0.0,1.0,0.0);  glTranslated(-xpos,-ypos,-zpos); -------------------------------------------------------------------------------------------  Any help would be appreciated. am not a math wiz but i remember doing trigonometry and calculus at high school. thanks    
  Quite simply, the unit circle.Although I do believe the code should be:float yaw = TO_RAD( yrot );float pitch = TO_RAD( xrot );// Assuming://   +x is right //   +y is into the screen,//   +z is upfloat pcos = cos( pitch );x += cos( yaw ) * pcos;y += sin( yaw ) * pcos;z += sin( pitch );;  _fastcall is correct. The correct order of using cos and sin is always: cos, sin, sin - relative to x, y, z. Whether or not your Y or Z axis is the up axis.About cos() and sin() .. ermmm... enter it in a small program and see what happens :)If you enter an angle into cos() or sin(), they will both return a value. It's kinda like normalizing the rotation on a certain axis, between 0 and 90 degrees. I know its not a proper explanation, but check out wikipedia.However, I'd use Matrices or Quaternions to do your camera class though. Using Euler angles (what you're doing now) can cause weird side effects like "gimbal lock". This has to do with cos and sin, where 90 degrees can also equal 0 degrees, roughly put.   ;Quote:However, I'd use Matrices or Quaternions to do your camera class though. Using Euler angles (what you're doing now) can cause weird side effects like "gimbal lock".Keep in mind that for some types of motion gimbal lock isn't really issue; in these cases, Euler angles can be a perfectly acceptable way to represent an object's orientation.   ;Quote:Original post by jykQuote:However, I'd use Matrices or Quaternions to do your camera class though. Using Euler angles (what you're doing now) can cause weird side effects like "gimbal lock".Keep in mind that for some types of motion gimbal lock isn't really issue; in these cases, Euler angles can be a perfectly acceptable way to represent an object's orientation.It of course depends on what he wishes to accomplish with his camera. If it's only for a first person view, Euler is your man! If it's for a fully rotating camera, Euler needs to be ashamed of himself.   ;Quote:Original post by wiegje85Quote:Original post by jykQuote:However, I'd use Matrices or Quaternions to do your camera class though. Using Euler angles (what you're doing now) can cause weird side effects like "gimbal lock".Keep in mind that for some types of motion gimbal lock isn't really issue; in these cases, Euler angles can be a perfectly acceptable way to represent an object's orientation.It of course depends on what he wishes to accomplish with his camera. If it's only for a first person view, Euler is your man! If it's for a fully rotating camera, Euler needs to be ashamed of himself.thanks guys. i was trying to understand first person camera. i had noticed some queer problem with my camera class, at a certain angle, it became hard to rotate around,it was as if the camera was "locked!!". i think thats the gimbo lock thing. post me some links on implementing a camera class using matrices or quarternions.;  Do a google search. Toymaker has an example.   