00001
00008 #include "camera.h"
00009
00014 TCamera::TCamera()
00015 {
00016 pos.LoadIdentity();
00017 rot.LoadIdentity();
00018 }
00019
00027 TMatrix TCamera::Rotate(GLfloat angle, GLint axis)
00028 {
00029 switch(axis)
00030 {
00031 case A_X: rot.x += angle;
00032 break;
00033 case A_Y: rot.y += angle;
00034 break;
00035 case A_Z: rot.z += angle;
00036 break;
00037 default:
00038 break;
00039 }
00040 UpdateMatrix();
00041 return transform;
00042 }
00043
00051 TMatrix TCamera::RotateAbs(GLfloat angle, GLint axis)
00052 {
00053 switch(axis)
00054 {
00055 case A_X: rot.x = angle;
00056 break;
00057 case A_Y: rot.y = angle;
00058 break;
00059 case A_Z: rot.z = angle;
00060 break;
00061 default:
00062 break;
00063 }
00064 UpdateMatrix();
00065 return transform;
00066 }
00067
00076 TMatrix TCamera::Move(GLfloat wx, GLfloat wy, GLfloat wz)
00077 {
00078 pos.x += wx;
00079 pos.y += wy;
00080 pos.z += wz;
00081 UpdateMatrix();
00082 return transform;
00083 }
00084
00093 TMatrix TCamera::MoveAbs(GLfloat wx, GLfloat wy, GLfloat wz)
00094 {
00095 pos.x = wx;
00096 pos.y = wy;
00097 pos.z = wz;
00098 UpdateMatrix();
00099 return transform;
00100 }
00101
00110 TMatrix TCamera::LookAt(GLfloat wx, GLfloat wy, GLfloat wz)
00111 {
00112 look.x = wx;
00113 look.y = wy;
00114 look.z = wz;
00115 UpdateMatrix();
00116 return transform;
00117 }
00118
00119
00124 void TCamera::UpdateMatrix()
00125 {
00126 glLoadIdentity();
00127
00128 if(look.IsEmpty())
00129 {
00130 glTranslatef(pos.x,pos.y,pos.z);
00131 glRotatef(rot.x,1.0f,0.0f,0.0f);
00132 glRotatef(rot.y,0.0f,1.0f,0.0f);
00133 }
00134
00135 else
00136 {
00137 gluLookAt(pos.x, pos.y, pos.z,
00138 look.x, look.y, look.z,
00139 0.0, 1.0, 0.0);
00140 }
00141 glGetFloatv(GL_MODELVIEW_MATRIX, transform);
00142 }