View Full Version : projecting a ray from mouse position
03-26-2001, 09:07 AM
I'm sure this is been done already in some tutorial if so please let me know.
I'm trying to project a ray from the camera to wherever the mouse points to.
any pointers will be appreciated.
what do you mean? An african or a european ray?
if you think about it, then the *projection* of a ray through the optical centre and the mouse's coordinates is just the mouse coordinates. In other words, what you're asking is actually a trivial problem. (Think about it... the projection of any point on the retina plane is just the coordinates of that point!! there IS no depth to change its 2d position).
do you mean, perhaps, constructing a ray through a point? or something??
03-27-2001, 05:32 AM
What I ment was constructing a ray from the camera position to where the mouse points to, the problem is that I'm not sure how to calculate the vector in relation to the nearZ plane of the fustrum.
I tried to caculate the angle of projection like this:
projScale = (viewRight-viewLeft) / tan (hViewAngle );
so I can set a point on the nearZ plane to later be transformed by the camera forward vector.
p = (x,y,0) * projScale;
mouseVec = camera.forwardVec * p;
So I'm not trying to project a point along the forward vector, but rather through the mouse position.
How do I get (X,Y) coordinates normalized to the nearZ plane of the frustum?
03-27-2001, 06:25 AM
use gluUnProject with winz=0, that gives you the mouse position on the near Clipping plane in GL coordinates
03-28-2001, 01:38 PM
DaViper Thank you so much.
It works just fine!! http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.