View Full Version : Looking at a point

Orzech

01-08-2004, 11:21 AM

Hello!

I know I could post this topic in mathematic's section as well (meaby in the end this post will be moved there http://www.opengl.org/discussion_boards/ubb/wink.gif ). 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! http://www.opengl.org/discussion_boards/ubb/smile.gif

See ya'

Orzech

01-09-2004, 11:02 AM

Is it really that no one knows the answer? http://www.opengl.org/discussion_boards/ubb/frown.gif It is important for me!

Thanks

fuxiulian

01-09-2004, 12:20 PM

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.

Orzech

01-10-2004, 06:24 AM

Originally posted by fuxiulian:

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.

Thanks! It seems to be simple. http://www.opengl.org/discussion_boards/ubb/smile.gif

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.

Orzech

01-12-2004, 07:58 AM

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. http://www.opengl.org/discussion_boards/ubb/smile.gif I'd be grateful if you could a bit of explanation about it. http://www.opengl.org/discussion_boards/ubb/smile.gif

Thanx

Sure! By module of an (x,y,z) vector I mean its length, given by m = sqrt ( x*x + y*y + z*z ). 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

Orzech

01-13-2004, 01:37 AM

Hello again!

Originally posted by Ob1:

Sure! By module of an (x,y,z) vector I mean its length, given by m = sqrt ( x*x + y*y + 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. http://www.opengl.org/discussion_boards/ubb/smile.gif 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! http://www.opengl.org/discussion_boards/ubb/smile.gif 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 http://www.opengl.org/discussion_boards/ubb/smile.gif))

Any ideaz (maybe code sample)?

See ya...

Orzech

01-14-2004, 01:49 AM

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. http://www.opengl.org/discussion_boards/ubb/wink.gif 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! http://www.opengl.org/discussion_boards/ubb/smile.gif

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.