# Looking at a point

Hello!

I know I could post this topic in mathematic’s section as well (meaby in the end this post will be moved there ). I decided to place it here beacuse potentially more people visit this forum.

Right to the point … Having a vector x,y,z describing a point in the world and having given camera’s position Cx, Cy, Cz how can I calculate Euler’s angles (yaw, pitch, roll) so that the camera looks exactly at the given point?

I would be thankful for your help! See ya’

Is it really that no one knows the answer? It is important for me!

Thanks

If all you want is to look at a point use
gluLookAt function

The angles you are looking for are the angles are the angles of the vector (x-cx, y-cy, z-cz) with the 0x, oy and oz axes, meaning the (1, 0, 0), (0, 1, 0) and (0, 0, 1) vectors
To compute the angles you’ll have to use the dotproduct. Search on the net how exactly you compute the angle between two vectors. I hope that helps.

Originally posted by fuxiulian:
[b]

The angles you are looking for are the angles are the angles of the vector (x-cx, y-cy, z-cz) with the 0x, oy and oz axes, meaning the (1, 0, 0), (0, 1, 0) and (0, 0, 1) vectors
To compute the angles you’ll have to use the dotproduct. Search on the net how exactly you compute the angle between two vectors. I hope that helps.[/b]

Thanks! It seems to be simple. I managed to implement something like this lately. I had a vector positioned in ( px, py, pz ) and pointing at an arbitrary ( x,y,z ) in space. I wanted to know how to rotate a vector with the same module and initially looking along the Z axis so that it became coincident with the given one.
Assuming to rotate it first on the X axis and then on the Y axis ( you can actually achieve any positiono this way ) you’ll get :

rotX = arcsin( (y - py)/m )
rotY = arcsin( (x - pz)/mXZ )

being rotX and rotY radiant angles, m the module of the given vector and mXY the module of its projection on the XZ plane.
Once you have the angles, you can use standard algebra or GL functions to rotate whatever you want towards your (x,y,z) point.

Hope it can help somehow for your problem. If you need i can post some code samples.

Hello!

Thanks for your anwser. I also tried to implement it but I got wrong results (as usuall). Looking at your solution I have a question. What do you mean by “m the module of the given vector”. I guess that I know what it is but I just can’t find anything corresponding to this term in my head. I’d be grateful if you could a bit of explanation about it. Thanx

Sure! By module of an (x,y,z) vector I mean its length, given by m = sqrt ( xx + yy + zz ). I’m sorry it wasn’t clear enough but i really don’t know the correct translation in english!
Of course as the vector we were taliking about is centered in ( px, py, pz ) you’ll have m = sqrt( (x-px)
(x-px) + (y-py)(y-py) + (z-pz)(z-pz) ) while it’s projection on XZ will lack the Y component and become mXZ = sqrt( (x-px)(x-px) + (z-pz)(z-pz) ).
With this you should be able to get a smooth rotation, in case it’s not in the direction you want, you’ll just have to check some sign and you’ll get what you want.
Hope it works! I’ll keep checking this topic in case you have any other question.
Byez =8)!
Ob1

Hello again!

Originally posted by Ob1:
Sure! By module of an (x,y,z) vector I mean its length, given by m = sqrt ( xx + yy + z*z ). I’m sorry it wasn’t clear enough but i really don’t know the correct translation in english!

I guess that your “modul” is just a vector’s length. Although, now everything seems clear to me.

Of course as the vector we were taliking about is centered in ( px, py, pz ) you’ll have m = sqrt( (x-px)(x-px) + (y-py)(y-py) + (z-pz)(z-pz) ) while it’s projection on XZ will lack the Y component and become mXZ = sqrt( (x-px)(x-px) + (z-pz)*(z-pz) ).
With this you should be able to get a smooth rotation, in case it’s not in the direction you want, you’ll just have to check some sign and you’ll get what you want.
Hope it works! I’ll keep checking this topic in case you have any other question.

Great thanks! Now I will surely make it work. I wish there were more such polite members on this forum.

Bye!

Well Orzech, quite good question…

I was wondering too, how can I write own implementations of functions such as gluLookAt(), gluProject() and gluUnProject().

Well, but it hasn’t been more than just wondering ))

Any ideaz (maybe code sample)?

See ya…

Originally posted by Nut Cr4ck3r:
I was wondering too, how can I write own implementations of functions such as gluLookAt(), gluProject() and gluUnProject().

Your question - as well as mine - treats about doing some 3d mathematics. Functions like gluLookAt(), gluProjects() just use OpenGL matrices to make some changes to then or to extract some values (like pixel position). It’s rather hard to remember it all - at least for me. I suggest you should look for some detailed explanation of this functions and after that you shouldn’t have any problems with making your own implementation of them. Try The Red Book.

Bye! 