quaternions

Started by
36 comments, last by a2k 23 years, 11 months ago
err..

top = v_yaw * M;

should be:

top = top * M;
Advertisement
okay, i got the example to compile. i had to change my general settings to "using mfc" that library is an mfc library, so it has to be enabled.

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
WickedMystic,

The code "Anonymous Poster" posted is the exact same way implmented my demo. For every space ship, I added 3 points to the vertex list of the polygon model (0, 0, -1), (0, 1, 0) and (1, 0, 0). I use these 3 points as components for the 3 quarternions I use. So if I want to turn 5 degrees in the yaw turn I create a quatrnion using angle = 5 and the "yaw" point as the vector.

I probably haven''t looked deeply enough but I can''t find the problem Anonymous Poster" was having.

For the camera part. My camera has a view point and a x, y and z angle. To find the present viewpoint of a ship that I attached my camera to I wrote a function that gets the present x, y, z angles of the ship. To do that, I used the same "yaw," "pitch" and "roll" vectors. The first thing my function does make a copy of those vectors because I''m going to alter these vectors but I don''t want to change the points in my poly object''s vertex list. I then find the x angle by taking my pitch_copy angle, drop the x part of the vector and find the 2D angle between pitch_copy and (1,0) using the equation cos(angle) = (v1.v2)/(/v1//v2/). I then rotate the "yaw_copy" and "roll_copy" vectors buy 360 - xangle. I then take "yaw_copy" vector, drop the y part of the vector and get the 2D between the vector and (0, 1). I then take the y angle and rotate the "roll_copy" vector by 360 - yangle. I then take the "roll_copy" vector and drop the z part and find the angle between "roll_copy" and (0,1). Here''s the code for getting the present angles.

public void getPresentAngles(TrigLookupTable table, ArcCosLookup arcTable)
{
float temp_x, temp_y, temp_z;
Point3D forwardVector = Point3D.clone(_localVertices[_forwardVector]);
Point3D topVector = Point3D.clone(_localVertices[_topVector]);

_xAngle = get2DAngle(forwardVector._z, forwardVector._y, 1, 0, arcTable);
if(forwardVector._y > 0)
_xAngle = 360 - _xAngle;
float rotMat_0_0 = table._cos[360 - _xAngle];
float rotMat_0_1 = table._sin[360 - _xAngle];
float rotMat_1_0 = -(table._sin[360 - _xAngle]);
float rotMat_1_1 = table._cos[360 - _xAngle];
temp_y = forwardVector._y * rotMat_0_0 + forwardVector._z * rotMat_1_0;
temp_z = forwardVector._y * rotMat_0_1 + forwardVector._z * rotMat_1_1;
forwardVector._y = temp_y;
forwardVector._z = temp_z;
temp_y = topVector._y * rotMat_0_0 + topVector._z * rotMat_1_0;
temp_z = topVector._y * rotMat_0_1 + topVector._z * rotMat_1_1;
topVector._y = temp_y;
topVector._z = temp_z;

_yAngle = get2DAngle(forwardVector._x, forwardVector._z, 0, 1, arcTable);
if(forwardVector._x < 0)
_yAngle = 360 - _yAngle;
rotMat_0_0 = table._cos[360 - _yAngle];
rotMat_0_1 = -(table._sin[360 - _yAngle]);
rotMat_1_0 = table._sin[360 - _yAngle];
rotMat_1_1 = table._cos[360 - _yAngle];
temp_x = forwardVector._x * rotMat_0_0 + forwardVector._z * rotMat_1_0;
temp_z = forwardVector._x * rotMat_0_1 + forwardVector._z * rotMat_1_1;
forwardVector._x = temp_x;
forwardVector._z = temp_z;
temp_x = topVector._x * rotMat_0_0 + topVector._z * rotMat_1_0;
temp_z = topVector._x * rotMat_0_1 + topVector._z * rotMat_1_1;
topVector._x = temp_x;
topVector._z = temp_z;

_zAngle = get2DAngle(topVector._x, topVector._y, 0, 1, arcTable);
if(topVector._x > 0)
_zAngle = 360 - _zAngle;
}

public int get2DAngle(float a1, float b1, float a2, float b2, ArcCosLookup arcTable)
{

float dp = (a1 * a2 + b1 * b2);
return (int)arcTable.getArcCos((float) (dp/(Math.sqrt(a1 * a1 + b1 * b1) * Math.sqrt(a2 * a2 + b2 * b2))));
}


thanks a lot, guys. now i just gotta sit down and figure it all out. i''m learning slowly but surely. you''re ship thing is quite an inspiration, tc.

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Btw, TC, that Anonymous poster was me, hehe, still getting used to typing in my user name each time I post. Most MBs I use store the user name and pass in a cookie....

WickedMystic.
WickedMystic
Opps. LOL. I overlooked your name at the end. After work I''m usally brain dead from sleepyness.

a2k
Your welcome. I''m flattered that something I have done has insprired someone.

okay, maybe i''m just a little lazy, or maybe it really is tht hard, but how can i obtain a direction vector from using these quaternions? or is the only way using euler angles, and using sin, cos etc? (i hope there''s an easy way.)

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
oh yeah, and TC,
do you even use quaternions, or straight rotation matrices.

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
a2k

I use quaternions and the "quaternion to rotation matrix" function to turn my game objects. I attach my camera to a game object. When it is to for the camera to project a scene, I get the current eular angles that game object has. I then peform that well known world-to-camera projection using eular angels.

how do you guys obtain a direction vector from quaternions? (yeah, i posted that 3d direction vector topic) it tried to use axis/angle conversion, but unfortunately, that didn''t help much cuz the axis was pretty arbitrary. also, euler angles would lead me back to using sin/cos, which is what we''re trying to avoid with quaternions, isn''t it? or is sin/cos the only way to obtain a direction vector from euler angles?

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k

This topic is closed to new replies.

Advertisement