- void glCamera::SetPerspective(float Height, float Width)
- {
- GLfloat Matrix[16];
- glQuaternion q;
- //adjust the projection Matrix with gluPerspective
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glViewport(0, 0, Width,Height);
- //Get new values from the LUT Table
- //float FOV = cameraEncoder-> getFieldOfView(ZoomEncoder, FocusEncoder);
- //float NPS = cameraEncoder-> getNodalPointShift(ZoomEncoder, FocusEncoder);
- float FOV = 60.0;
- float NPS = 0.00;
- //Now set the new Field of View to the Viewport
- gluPerspective(FOV, Width/Height, 0.01f, 1000.0f);
- // Create a rotation matrix based on the recorded quaternion
- q = m_qPitch;
- q.CreateMatrix(Matrix);
- //Z-Vector
- glVector Vector_Z;
- Vector_Z.i = 0;
- Vector_Z.j = 0;
- Vector_Z.k = 1;
- Vector_Z.l = 1;
- //Y-Vector
- glVector Vector_Y;
- Vector_Y.i = 0;
- Vector_Y.j = 1;
- Vector_Y.k = 0;
- Vector_Y.l = 1;
- //Calculates the Vector through the camera = Matrix * (0/0/1)
- m_DirectionVector.i = Matrix[0]*Vector_Z.i + Matrix[4]*Vector_Z.j + Matrix[8]*Vector_Z.k + Matrix[12]*Vector_Z.l;
- m_DirectionVector.j = Matrix[1]*Vector_Z.i + Matrix[5]*Vector_Z.j + Matrix[9]*Vector_Z.k + Matrix[13]*Vector_Z.l;
- m_DirectionVector.k = Matrix[2]*Vector_Z.i + Matrix[6]*Vector_Z.j + Matrix[10]*Vector_Z.k + Matrix[14]*Vector_Z.l;
- m_DirectionVector.l = Matrix[3]*Vector_Z.i + Matrix[7]*Vector_Z.j + Matrix[11]*Vector_Z.k + Matrix[15]*Vector_Z.l;
- //Point of interest
- m_Center.x = m_DirectionVector.i + m_Position.x;
- m_Center.y = m_DirectionVector.j + m_Position.y;
- m_Center.z = m_DirectionVector.k + m_Position.z;
- //Calculates the Up-Vector = Matrix * (0/1/0)
- m_UpVector.i = Matrix[0]*Vector_Y.i + Matrix[4]*Vector_Y.j + Matrix[8]*Vector_Y.k + Matrix[12]*Vector_Y.l;
- m_UpVector.j = Matrix[1]*Vector_Y.i + Matrix[5]*Vector_Y.j + Matrix[9]*Vector_Y.k + Matrix[13]*Vector_Y.l;
- m_UpVector.k = Matrix[2]*Vector_Y.i + Matrix[6]*Vector_Y.j + Matrix[10]*Vector_Y.k + Matrix[14]*Vector_Y.l;
- m_UpVector.l = Matrix[3]*Vector_Y.i + Matrix[7]*Vector_Y.j + Matrix[11]*Vector_Y.k + Matrix[15]*Vector_Y.l;
- //NodalPointShift shifts the camera position on the z-axis
- m_DirectionVector *= 1/m_DirectionVector.l;
- m_DirectionVector *= 1/sqrt(m_UpVector.i*m_UpVector.i+ m_UpVector.j*m_UpVector.j+m_UpVector.k*m_UpVector.k);
- m_DirectionVector *= NPS;
- m_Position.x = m_Position.x + m_DirectionVector.i;
- m_Position.y = m_Position.y + m_DirectionVector.j;
- m_Position.z = m_Position.z + m_DirectionVector.k;
- // calculate the point above the camera
- glPoint m_UpPoint;
- m_UpPoint.x = m_Position.x + m_UpVector.i;
- m_UpPoint.y = m_Position.y + m_UpVector.j;
- m_UpPoint.z = m_Position.z + m_UpVector.k;
- //CLear frame buffer and depth buffer
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- glEnable(GL_DEPTH_TEST);
- //adjust the modelview matrix with gluLookAt
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- gluLookAt(m_Position.x, m_Position.y, m_Position.z, m_Center.x, m_Center.z, m_Center.z, m_UpVector.i, m_UpVector.j, m_UpVector.k);
- // set up coordinate system
- glBegin(GL_LINES);
- glColor3f(1,0,0); glVertex3f(-4.659 ,0.726 ,3.831 ); glVertex3f(0,0.726 ,3.831);
- glColor3f(0,1,0); glVertex3f(-4.659 ,0.726 ,3.831); glVertex3f(-4.659 ,12,3.831);
- glColor3f(0,0,1); glVertex3f(-4.659 ,0.726 ,3.831); glVertex3f(-4.659 ,0.726 ,0);
- glEnd();
- }