Archived

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

Guest Anonymous Poster

PR equivilant to D3D 'LookAt' ??

Recommended Posts

Hi,

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;
PR_Normalize(&k);

// 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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thankyou my mathematically inclined friend... I probably shouldn't be a programmer since i can't figure stuff like that out on my own, but hey... i'm trying !

It worked beautifully.

Share this post


Link to post
Share on other sites
SteveB:

No problem, glad to hear it worked for ya... it took a while to get working properly. I have more routines for rotation and many other things I have discovered working on my game and using PR. Let me know.

Jarrod

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well... i'm too dumb to figure this out. Can someone out there help me ? I need a PR 2.6 equivilant to D3DRM 'LookAt' function. You pass it two entity pointers and it makes the first entity 'look at' the second entity. It should be very simple, but I can't figure it out for the life of me. God I must have stunted math genes.

Share this post


Link to post
Share on other sites