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

Started by
1 comment, last by matthughson 18 years, 5 months ago
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]
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Advertisement
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.
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]
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]

This topic is closed to new replies.

Advertisement