Screen coordinates on an XY plane

Started by
2 comments, last by rk 19 years, 10 months ago
I am doing some 3-D programming and I need to determine what coordinate on the XY plane (Z = 0) my mouse cursor is over. I have designed my engine so that the camera will always "see" the XY plane. Neither will the camera be able to be perpendicular with Z, or go "under" the XY plane. Within these restrictions, the angle and position can be anything. I can't figure out how to do this on my own. I have given this some thought and I think I could do it if the camera was always parallel to the Z axis, but that's just not enough. If I didn't manage to ask my question in an understandable manner, please feel free to ask for further details. I will be happy to elaborate. rk Edited by - rk on January 9, 2002 5:30:13 PM
Advertisement
*bump*
I'm definately not a math nerd, but it would seems logical to use the pixel coordinates of the mouse in conjuction with the camera's field of view to create a line extending from the camera position. Then just determine where that line intersects the plane.

-edit- I'm not much of a 3d programmer yet, so there's almost certainly much better/faster ways of accomplishing this.

Edited by - B-Barlow on January 10, 2002 8:44:16 PM
I believe I know what you are asking here.

I am doing something similar. I didn''t want my "view" from the characters perspective to ever go below a specific Y point or above it for that matter( I wanted it to stay parallel) with the origin but with Y always being up.

I am currently using DirectInput to grab the Mouse and Keyboard input.

What I do is create a tmp variable set to store all my current vectors. I then apply my new vectors etc based on the movement from my directinput calls(mouse/keyboard). however before I apply them I check my positionVector.Y, positionvector.x and positionvector.z

If my positionvector.y is above or below say .1 then I reset it to .1 and go on to X and Z.

The reason I did this was two fold.

1. I didn''t want someone to use the keyboard to move "Up" straight, up the Y axis, so that was easy. Merely check if Y is greater then my starting point of .1

2. However since the person CAN change the angle they are looking at using the mouse I didn''t want them to look up or look down and then move forward and go through the floor or ceiling.
Since these are two distinct issues(although the resolution) is the same, it required me to do the same thing just a little different.

If I know for a fact they want to move straight up(not look up just go up) then I know what key they pressed and I merely check is currentpositionvector.y + upwardvelocity > maxYposition and if so then just ignore the movement totally.

If they are "looking" up or at angle angle that would increase or decrease Y, when they are moving forward or backward(or any direction) then I merely check the position.Y vector AFTEr all the calculations have been completed. I then reset it to Max/Min(which in my case are the same on purpose) and bingo it works great.

This allows the person to LOOK upward or downward at any angle and STILL move forward/backward without moving up or down.

The same works for x and z too. Merely check the values after calculation and reset them to something else that would stop them from breaking your rules of collision/movement.

You can also do the extreme and if they do something really wack, take your temp variables and use them to reset the right/up/look/position vectors back to what they were before they were newly calculated. Then they wont move at all.

This also requires though that you are not using the LookAt helper functions(for instance in DirectX) as you actually have to calculate all the information, just using the helper functions will only give you what you say you don''t want.

I hope that helps.

This topic is closed to new replies.

Advertisement