# Object Location...

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

## 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 on other sites
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

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

See told ya it was easy!

Yratelev

##### Share on other sites
Wow that was easy.. thanks. I'll give it a try in the morrow.

DaveC

##### 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 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

1. 1
2. 2
JoeJ
20
3. 3
frob
20
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632212
• Total Posts
3004819

×