enjoycrf

04-06-2011, 04:26 PM

hi

didnt go dirtbiking today so...

i was trying to figure out how to upgrade my camera to quaternions, cawse they are the coolest

so i found some class from nehe tutorials but it didnt do what i wanted

and it was not meant for an fps style camera

and it was way too much code

so i had to totally tear it down like a 747 boeing

and after some trial and error because i dont know anything about quaternions

i was able to put this working example together

NOTE that i am still using glulookat() but using the quaternions to make my view vector for it

this way everyone is happy :D even Gadafi >:O

but now i wish i went dirtbiking cause it only took me 4 hours to figure this

anyways here is the coed, let me kno if u need the rest of the code for the quaternions and the header files, but i think you guys should have all that already

/*

* wow quaternions braw :eek:

* */

void glCamera::Look() {

GLfloat Matrix[16];

glQuaternion q;

// Make the Quaternions that will represent our rotations

m_qHeading.CreateFromAxisAngle(0.0f, 0.0f, 1.0f, m_HeadingDegrees);

m_qPitch.CreateFromAxisAngle(1.0f, 0.0f, 0.0f, m_PitchDegrees);

// Combine the pitch and heading rotations and store the results in q

q = m_qHeading * m_qPitch; //swapping these will inverse rotations

q.CreateMatrix(Matrix);

camera.view[0] = camera.pos[0] + Matrix[4]; //changing these to 8 9 10 will inverse rotations only if looking above horizon

camera.view[1] = camera.pos[1] + Matrix[5]; //just totally weird [censored] hamilton

camera.view[2] = camera.pos[2] + Matrix[6]; //were you drunk? aww f it

}

void glCamera::Move(GLfloat vel) {

GLfloat Matrix[16];

glQuaternion q;

// Make the Quaternions that will represent our rotations

m_qHeading.CreateFromAxisAngle(0.0f, 0.0f, 1.0f, m_HeadingDegrees);

m_qHeading.CreateMatrix(Matrix);

// Increment our position by the vector

camera.pos[0] += Matrix[4] * vel;

camera.pos[1] += Matrix[5] * vel;

}

void glCamera::Strafe(GLfloat vel) {

GLfloat Matrix[16];

glQuaternion q;

// Make the Quaternions that will represent our rotations

m_qHeading.CreateFromAxisAngle(0.0f, 0.0f, 1.0f, m_HeadingDegrees);

m_qHeading.CreateMatrix(Matrix);

// Increment our position by the vector

camera.pos[0] += Matrix[0] * vel;

camera.pos[1] += Matrix[1] * vel;

}

void glCamera::ChangePitch(GLfloat degrees) {

m_PitchDegrees += degrees * m_sens;

//lock it up

int lock = 89;

if (m_PitchDegrees < -lock) m_PitchDegrees = -lock;

if (m_PitchDegrees > lock) m_PitchDegrees = lock;

}

void glCamera::ChangeHeading(GLfloat degrees) {

//lock it up

int lock = 360;

if (m_HeadingDegrees < 0) m_HeadingDegrees += lock;

if (m_HeadingDegrees > lock) m_HeadingDegrees -= lock;

m_HeadingDegrees += degrees * m_sens;

}

//fing amazing

didnt go dirtbiking today so...

i was trying to figure out how to upgrade my camera to quaternions, cawse they are the coolest

so i found some class from nehe tutorials but it didnt do what i wanted

and it was not meant for an fps style camera

and it was way too much code

so i had to totally tear it down like a 747 boeing

and after some trial and error because i dont know anything about quaternions

i was able to put this working example together

NOTE that i am still using glulookat() but using the quaternions to make my view vector for it

this way everyone is happy :D even Gadafi >:O

but now i wish i went dirtbiking cause it only took me 4 hours to figure this

anyways here is the coed, let me kno if u need the rest of the code for the quaternions and the header files, but i think you guys should have all that already

/*

* wow quaternions braw :eek:

* */

void glCamera::Look() {

GLfloat Matrix[16];

glQuaternion q;

// Make the Quaternions that will represent our rotations

m_qHeading.CreateFromAxisAngle(0.0f, 0.0f, 1.0f, m_HeadingDegrees);

m_qPitch.CreateFromAxisAngle(1.0f, 0.0f, 0.0f, m_PitchDegrees);

// Combine the pitch and heading rotations and store the results in q

q = m_qHeading * m_qPitch; //swapping these will inverse rotations

q.CreateMatrix(Matrix);

camera.view[0] = camera.pos[0] + Matrix[4]; //changing these to 8 9 10 will inverse rotations only if looking above horizon

camera.view[1] = camera.pos[1] + Matrix[5]; //just totally weird [censored] hamilton

camera.view[2] = camera.pos[2] + Matrix[6]; //were you drunk? aww f it

}

void glCamera::Move(GLfloat vel) {

GLfloat Matrix[16];

glQuaternion q;

// Make the Quaternions that will represent our rotations

m_qHeading.CreateFromAxisAngle(0.0f, 0.0f, 1.0f, m_HeadingDegrees);

m_qHeading.CreateMatrix(Matrix);

// Increment our position by the vector

camera.pos[0] += Matrix[4] * vel;

camera.pos[1] += Matrix[5] * vel;

}

void glCamera::Strafe(GLfloat vel) {

GLfloat Matrix[16];

glQuaternion q;

// Make the Quaternions that will represent our rotations

m_qHeading.CreateFromAxisAngle(0.0f, 0.0f, 1.0f, m_HeadingDegrees);

m_qHeading.CreateMatrix(Matrix);

// Increment our position by the vector

camera.pos[0] += Matrix[0] * vel;

camera.pos[1] += Matrix[1] * vel;

}

void glCamera::ChangePitch(GLfloat degrees) {

m_PitchDegrees += degrees * m_sens;

//lock it up

int lock = 89;

if (m_PitchDegrees < -lock) m_PitchDegrees = -lock;

if (m_PitchDegrees > lock) m_PitchDegrees = lock;

}

void glCamera::ChangeHeading(GLfloat degrees) {

//lock it up

int lock = 360;

if (m_HeadingDegrees < 0) m_HeadingDegrees += lock;

if (m_HeadingDegrees > lock) m_HeadingDegrees -= lock;

m_HeadingDegrees += degrees * m_sens;

}

//fing amazing