In a planetary gravity environment objects are represented in the following way:
struct object {
struct quaternion quat; // quaternion to represent the rotation between the object and the center of the planet
float dist; // distance from the center of the planet
};
Here are the steps at which I position my player:
// start at center of the planet
applyQuaternion(&object.quat);
glTranslatef(0.0f, object.dist, 0.0f);
drawObject(&object);
Step 1, translate to center of planet:
Step 2, apply quaternion:
Step 3, translate outwards by distance value:
I am also able to get the current position of the player or enemy by using this code:
struct matrix initialMatrix, resultantMatrix;
glPushMatrix();
getPositionMatrix(&initialMatrix);
applyQuaternion(&player.quat);
glTranslatef32(0, player.dist, 0);
getPositionMatrix(&resultantMatrix);
playerPosition = matrixTranslationToVector(initialMatrix, resultantMatrix);
glPopMatrix();
Given two objects:
struct object player;
struct object enemy;
How can I get the enemy to face in the direction of the player, whilst always standing upright on the planet, using quaternions?
I want the enemy to go from this:
To this:
His feet always on the planet, and head always away from planet.
I'm able to rotate on the axis which doesn't affect the position (from first enemy diagram to second enemy diagram like so):
// Rotate right
Quaternion_multiply(&player.quat, Quaternion_fromAxisAngle(vect(0.0f, 0.0f, 1.0f), degreesToAngle(2)));
// Rotate left
Quaternion_multiply(&player.quat, Quaternion_fromAxisAngle(vect(0.0f, 0.0f, 1.0f), degreesToAngle(-2)));
So I'm unsure as to why I'd need a local orientation in addition to the quaternion I already have.
How can I get the enemy to face in the direction of the player
doesn't make much sense. \$\endgroup\$ – concept3d Oct 30 '14 at 8:45