PDA

View Full Version : Matrix Refresher and books



jeckil
04-23-2010, 02:59 PM
Hey guys im stuck real bad on something and I need help!!!

Say I have a 3d object at a point, looking towards an arbitrary point, say (-10,10,0) how would I change it so the its looking elsewhere without changing the position.


Matrix Model; <- the model matrix

I can, transform the model by translating and rotating discretely but im stuck at modifying the matrix so that the look at vector is moved

I need to just change the look at without changing the position..

Help??

I am trying to move objects in 3d space.
Thanks a lot !


P.S. Can you suggest a good book on these kinds of topics that is easy to comprehend? (large pictures ^_^)

jmfairlie
04-24-2010, 03:23 PM
Not sure if this is going to be of any help, if you are seeing 3D/GL for the first time but well...

Rotate first the object (which should be centered in object space), then apply the translation.



//translate the object to your desired destination
glTranslate(your point)
//whatever combination of rotations
//that leaves the object in your desired orientation
glRotate(..)*
glBegin()
...
glEnd()


As for the book, you could start by reading chapter 3 of the Red Book (OpenGL programming Guide 7h ed)

P.D: Be aware that the code is written in reverse order of how the transformations are being applied to the objects, so in the code above glRotate will be applied first then the glTranslate. Yes It's confusing.

jeckil
04-26-2010, 02:31 PM
Whoot I got it now, but im still stuck at extracting the data directly from the already constructed matrix;

can't i just do?

vector3 vectorLookAt;
vectorTo.x = mymatrix[12];
vectorTo.y = mymatrix[13];
vectorTo.z = mymatrix[14];

to extract the data? Are these the correct indices? :P

Thanks in advance everybody :)