Sign in to follow this  
matthughson

This seems like it should be simple... [solved]

Recommended Posts

Hi All, So here's the deal: I'm making a 2.5D game (3D world and geometry, 2D gameplay). I need to place a mouse cursor in the game world. Everything in the game world is centered on the same point on the Z-Axis. I want the mouse cursor to also be centered at that same point. I have written a ray picking feature already, so I am able to convert the windows mouse position into screen coordinates, and then I am able to take the coordinate and convert it in a point and ray in the game world. But I can't not figure out a simple and elegant solution to placing the cursor on that ray with a z value of 0 (the position shared by all objects). Does anyone have a simple solution? And please let me know if you need any more information. Matt [Edited by - matthughson on November 12, 2005 1:07:11 AM]

Share this post


Link to post
Share on other sites
I may be totally misunderstanding what you're saying, but it sounds like you just want to intersect the ray with the plane z = 0:
t = -rayOrigin.z/rayDir.z;
point = rayOrigin+t*rayDir;
Which should always work given that the picking ray will not be parallel to the plane. If that's totally off base, perhaps you could clarify a bit what you're looking for.

Share this post


Link to post
Share on other sites
It sounds like you understood the question correctly, but the only problem with that is that the ray will not always be paralell to the X-Y plane. That's because it is based on the view frustum: ie. click on the left of the screen and the ray will shot slightly to the left.

I'm thinking something like get the distance from the rays origin to the target in the z (target.z - orig.z) and multiply the normalized ray vector by that scaler. But in my head that seems like it would create an arc, rather than locking to the x-y plane...


Sorry misread ur response! Thanks, I'll give her a shot!

Update: Works great! Thanks!

Matt

[Edited by - matthughson on November 12, 2005 1:52:54 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this