Good spot! Sometimes code just needs another pair of eyes to see the problem. I fixed that and managed to get much further, I almost have all of the maths I need to start work on my game!
I've attached my current status, in the demo, rotate with the D-Pad and press A to translate at the direction the teapot is rotated in (towards the handle). It kind of works, if you rotate only on one axis it always translates correctly, however if you rotate on both it starts to translate in the wrong direction.
Thanks once again!
Using quaternions
Re: Using quaternions
- Attachments
-
- Quaternions.zip
- (159.22 KiB) Downloaded 504 times
Re: Using quaternions
With help from IRC, I've rethought my approach and was able to get the model to translate in the direction it is rotated at.
My problem now however is that I cannot get the new position which the model has been translated at.
I first get the position matrix before movement has been applied:
Apply translation:
Get the position matrix again:
And then calculate the delta position based on the the difference between the matrices:
Unfortunately it isn't calculating the correct delta position.
I've attached my source:
My problem now however is that I cannot get the new position which the model has been translated at.
I first get the position matrix before movement has been applied:
Code: Select all
getPositionMatrix(&initialMatrix);
Code: Select all
glTranslatef32(0, 0, 1 << 12);
Code: Select all
getPositionMatrix(&resultantMatrix);
Code: Select all
#define MATRIX_X 12
#define MATRIX_Y 13
#define MATRIX_Z 14
deltaPosition.x = resultantMatrix.m[MATRIX_X] - initialMatrix.m[MATRIX_X];
deltaPosition.y = resultantMatrix.m[MATRIX_Y] - initialMatrix.m[MATRIX_Y];
deltaPosition.z = resultantMatrix.m[MATRIX_Z] - initialMatrix.m[MATRIX_Z];
I've attached my source:
- Attachments
-
- Quaternions.zip
- (173.64 KiB) Downloaded 484 times
Re: Using quaternions
Never mind, the delta position is calculated correctly. I just forgot to reverse the rotation before applying the inverse of delta position.
Re: Using quaternions
Just for the benefit of anyone who might find this useful, here's a complete demo of using quaternions with the camera following the model.
- Attachments
-
- Quaternions.zip
- (180.52 KiB) Downloaded 485 times
Re: Using quaternions
I'm not sure if this needs its own topic or not.
Using the D-Pad you can rotate the teapot to a direction. Using L you can reposition the camera to be facing the model.
I want the teapot to always face in the direction relative to the camera, not the world.
So for example, I want pressing up to always make the teapot face away from the camera. At the moment it always makes the teapot point North.
Using the D-Pad you can rotate the teapot to a direction. Using L you can reposition the camera to be facing the model.
I want the teapot to always face in the direction relative to the camera, not the world.
So for example, I want pressing up to always make the teapot face away from the camera. At the moment it always makes the teapot point North.
Re: Using quaternions
Sorry, the file didn't upload correctly. Here it is.
- Attachments
-
- Quaternions.zip
- (180.45 KiB) Downloaded 523 times
Who is online
Users browsing this forum: No registered users and 0 guests