gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > DS OpenGL local rotations

#97580 - Rajveer - Thu Aug 10, 2006 4:46 pm

hi, im trying to rotate a 3d object by an arbitrary axis. i have stored the object's local axis as a 3x3 matrix starting off as the identity matrix, and pressing left/right will rotate the object on the y-vector (second column) in the matrix.

1 0 0
0 1 0
0 0 1
x y z (axis)

to modify the local axis when rotating, i thought i could multiply the rotation matrix created, by the 3x3 matrix. the reason why was because multiplying the rotation matrix by vertices at coordinates (1, 0, 0), (0, 1, 0) and (0, 0, 1) would rotate them correctly so it should do the same with these position vectors. to do this i store the rotation matrix in a temporary 3x3 matrix, call glLoad.. to load the axis and call glMult.. to multiply it by the rotation matrix.

my questions:

1) how would i now store these results in the original 3x3 axis matrix?

2) is this way of modifying axis ok? any tips?

cheers

#97728 - Rajveer - Fri Aug 11, 2006 9:30 am

anybody?

#97778 - dj-ceejay - Fri Aug 11, 2006 2:37 pm

Are you thinking about a quaternion. It's a custom rotation axis (qx,qy,qz) and an angle(qw) giving: (qx,qy,qz,qw).

To create the matrix:
Code:

1 - 2*qy^2 - 2*qz^2 ,, 2*qx*qy - 2*qz*qw ,, 2*qx*qz + 2*qy*qw
2*qx*qy + 2*qz*qw ,, 1 - 2*qx^2 - 2*qz^2 ,, 2*qy*qz - 2*qx*qw
2*qx*qz - 2*qy*qw ,, 2*qy*qz + 2*qx*qw ,,1 - 2*qx2 - 2*qy^2

(from euclideanspace)

Then load the created matrix in and draw your verts.

Is this what you mean Rajveer?
_________________
Fruit Machine Games:
http://www.fmsoftware.info/

#97786 - Rajveer - Fri Aug 11, 2006 3:11 pm

im thinkin about quaternions which ill convert to axis-angle for glRotate (or matrix, not really sure).

i think i need help with the bigger picture:

1) im trying to make a racing game. for collision, i have to calculate which polygon in the level the object is over, and then match the objects rotation to the plane of the polygon its over (so i have to change the objects axis according to the polygon). then i want to be able to rotate in the objects modified y-axis and move through the objects z-axis. so i was thinkin of storing a list of some sort for each polygon with details on its rotation and its boundaries that the object has to pass to be able to say "its over this polygon". would this be too complicated? any tips?

2) what would you say the best way of matching the objects rotation with the polygons rotation is? any tips?

cheers :)