#include "glCamera.h"
glCamera::glCamera()
{
pDegrees = yDegrees = rDegrees = 0.0f;
Direction.i = 0.0f;
Direction.j = 0.0f;
Direction.k = -1.0f;
Up.i = 0.0f;
Up.j = 1.0f;
Up.k = 0.0f;
Right.i = 1.0f;
Right.j = 0.0f;
Right.k = 0.0f;
}
void glCamera::Render()
{
GLfloat m[16];
glQuaternion q;
qPitch.CreateFromAxisAngle(1.0f, 0.0f, 0.0f, pDegrees);
qYaw.CreateFromAxisAngle(0.0f, 1.0f, 0.0f, yDegrees);
qRoll.CreateFromAxisAngle(0.0f, 0.0f, 1.0f, rDegrees);
q = qRoll * qPitch * qYaw;
q.CreateMatrix(m);
glMultMatrixf(m);
q = q.Conjugate();
q.CreateMatrix(m);
Direction.i = -m[8];
Direction.j = -m[9];
Direction.k = -m[10];
Up.i = m[4];
Up.j = m[5];
Up.k = m[6];
Right.i = m[0];
Right.j = m[1];
Right.k = m[2];
glTranslatef(-Position.x, -Position.y, -Position.z);
}
void glCamera::ChangePosition(GLfloat x, GLfloat y, GLfloat z)
{
Position.x += (x * Right.i) + (y * Up.i) - (z * Direction.i);
Position.y += (x * Right.j) + (y * Up.j) - (z * Direction.j);
Position.z += (x * Right.k) + (y * Up.k) - (z * Direction.k);
}
void glCamera::ChangeOrientation(GLfloat pitch, GLfloat yaw, GLfloat roll)
{
pDegrees += pitch;
yDegrees += yaw;
rDegrees += roll;
if(pDegrees > 360.0f)
{
pDegrees -= 360.0f;
}
else if(pDegrees < -360.0f)
{
pDegrees += 360.0f;
}
if(yDegrees > 360.0f)
{
yDegrees -= 360.0f;
}
else if(yDegrees < -360.0f)
{
yDegrees += 360.0f;
}
if(rDegrees > 360.0f)
{
rDegrees -= 360.0f;
}
else if(rDegrees < -360.0f)
{
rDegrees += 360.0f;
}
}
#include "glCamera.h"
glCamera::glCamera()
{
Direction.i = 0.0f;
Direction.j = 0.0f;
Direction.k = -1.0f;
Up.i = 0.0f;
Up.j = 1.0f;
Up.k = 0.0f;
Right.i = 1.0f;
Right.j = 0.0f;
Right.k = 0.0f;
}
void glCamera::Render()
{
GLfloat m[16];
glQuaternion q;
qOrientation.CreateMatrix(m);
glMultMatrixf(m);
q = qOrientation.Conjugate();
q.CreateMatrix(m);
Direction.i = -m[8];
Direction.j = -m[9];
Direction.k = -m[10];
Up.i = m[4];
Up.j = m[5];
Up.k = m[6];
Right.i = m[0];
Right.j = m[1];
Right.k = m[2];
glTranslatef(-Position.x, -Position.y, -Position.z);
}
void glCamera::ChangePosition(GLfloat x, GLfloat y, GLfloat z)
{
Position.x += (x * Right.i) + (y * Up.i) - (z * Direction.i);
Position.y += (x * Right.j) + (y * Up.j) - (z * Direction.j);
Position.z += (x * Right.k) + (y * Up.k) - (z * Direction.k);
}
void glCamera::ChangePitch(GLfloat pitch)
{
qPitch.CreateFromAxisAngle(Right.i, Right.j, Right.k, pitch);
qOrientation = qOrientation * qPitch;
}
void glCamera::ChangeYaw(GLfloat yaw)
{
qYaw.CreateFromAxisAngle(Up.i, Up.j, Up.k, yaw);
qOrientation = qOrientation * qYaw;
}
void glCamera::ChangeRoll(GLfloat roll)
{
qRoll.CreateFromAxisAngle(Direction.i, Direction.j, Direction.k, roll);
qOrientation = qOrientation * qRoll;
}