Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Guest Anonymous Poster

Tracking Algorithim

This topic is 6954 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This should work for you:

// Vector Routines
void GV_VectorCrossProduct(PR_POINT *dest, PR_POINT *src1, PR_POINT *src2)
dest->x = src1->y * src2->z - src1->z * src2->y;
dest->y = src1->z * src2->x - src1->x * src2->z;
dest->z = src1->x * src2->y - src1->y * src2->x;

// Matrix Routines
void GV_RotateMatrixToPoint(PR_MATRIX mat, PR_POINT *src, PR_POINT *dest)
PR_POINT i, j, k;

// calc forward vector
k.x = dest->x - src->x;
k.y = dest->y - src->y;
k.z = dest->z - src->z;

// calc up vector
j.x = 0;
j.y = 1;
j.z = 0;

// calc right vector
GV_VectorCrossProduct(&i, &j, &k);

// calc new up vector
GV_VectorCrossProduct(&j, &i, &k);

// store in rotation matrix
mat[0] = i.x;
mat[1] = i.y;
mat[2] = i.z;
mat[3] = 0;
mat[4] = -j.x;
mat[5] = -j.y;
mat[6] = -j.z;
mat[7] = 0;
mat[8] = k.x;
mat[9] = k.y;
mat[10] = k.z;
mat[11] = 0;
//mat[12] = trans->x;
//mat[13] = trans->y;
//mat[14] = trans->z;
mat[15] = 1.0;

Just pass in the Entity->orientation.rot_mat, the source pos of the entity and the dest pos of where you what to look. Afterwords, the entity will be pointing at the dest. If you want a higher end function that will allow you to interporlate from any orientation to the dest point across N number of frames, e-mail me and I can send it to you. I am using this in my current game to make the enemy ships find there way to the player or any object, find powerups and so forth.

Jarrod Davis

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Please, could anyone help me out with a good tracking algorithim? I have two spaceships(in 3d space), and I would like for the nose of one to always point at the other. I know how to calculate the displacement vector(where T is the target and S is the ship) :
V = sqrt((Tx2 - Sx2) + (Ty2 - Sy2) + (Tz2 - Sz2))
which will get the ship to the other one, but not facing it. I get the feeling I should be able to derive rotational values
from this vector(maybe passed through the identity matrix?) but I guess I'm too stupid. If anyone is so kind as to help me out, please keep this in mind in your response.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!