Jump to content
  • Advertisement
Sign in to follow this  
bobason456

Object Location...

This topic is 4843 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

I thought it would be convenient in my application to use gluLookAt to place my objects in my world, because each object has a position, a normalized heading vector, and it's own up vector. Any way gluLookAt gave me rather strange results.. So could some one please explain how I can construct my own matrix from position, heading and up vectors? I could then use push pop & glMultMatrixf. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Real easy - I use this all the time!

Right first let me define a Matrix as:

Xx Yx Zx Tx
Xy Yy Zy Ty
Xz Yz Zz Tz
Xw Yw Zw Tw

So that makes 4, 4D Vectors, X, Y, Z and T. (eg X = (Xx, Xy, Xz))
Stuff your position vector into T (the translation part of the matrix)
Stuff your Lookup vector into Y
Stuff your Heading Vector into Z

Now form the cross product of Y and Z (Y x Z for a left hand side coordinate system I think) and stuff that into X.

Set Xw = Yw = Zw = 0 and Tw = 1

and your done!

See told ya it was easy!

Yratelev

Share this post


Link to post
Share on other sites
Ok.. so I tryed it now.

It seems to work ok, not tested it much.. but it seems that I must pass normalized vertex data to LookUp and Heading. Somthing I did not need to do with GluLookAt.. does this mean your method is faster seeing as two out of my three vectors are normalized already.?

Also interested in what way around I need to do things for the other coordinate system (open GL) because things are streching a little.


DaveC

Share this post


Link to post
Share on other sites
So here is the code I wrote in my Matrix class.. I was wondering if you could have a look at it for me.


void CMatrix4x4::LookAt(global_struct_vertexA eye,global_struct_vertexA center,global_struct_vertexA up)
{
GLfloat mp[4][4];
global_struct_vertexA xProd;
mathsCrossProduct(xProd,up,center);

mp[0][0]=xProd.x; mp[0][1]=up.x; mp[0][2]=center.x; mp[0][3]=eye.x;
mp[1][0]=xProd.y; mp[1][1]=up.y; mp[1][2]=center.y; mp[1][3]=eye.y;
mp[2][0]=xProd.z; mp[2][1]=up.z; mp[2][2]=center.z; mp[2][3]=eye.z;
mp[3][0]=0; mp[3][1]=0; mp[3][2]=0; mp[3][3]=1.0;


Multiply(mp);
}



Thanks

DaveC

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!