Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Mouse input in 3D

This topic is 5397 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m just wondering in general how mouse clicks would be taken.. Lets say that your looking at a wall thats at a small angle to you.. and there are a bunch of buttons on that wall.. so you want your mouse cursor to be able to click on the screen where the buttons are How do you convert screen co-ords to where that is on the wall? I''m guessing 1 way would be to draw a line straight out from the point that was clicked to the point where it hits the wall.. then you can take that point to find what button If you wondering I''m thinking of making a 3D display for my current project which you can see in my sig.. so basically Imagine that the blocks are at a 30 degree angle from the screen and thats what this question is about.. how would I find what block they are trying to click.. Please visit Turt99 Productions
Email: admin@turt99.com

Share this post

Link to post
Share on other sites
The way I''ve done it is somewhat unortodox, but it works for my RTS at least. =)

I simply draw a mousepicture in 3d space (Depth testing disabled), and translating it according to the mousemovements... and use some "fancy" math to make sure it''s smooth all over the place...

for clicking, I check what the original MouseX,Y is when the 3Dcursor is where I wanna click. =)

"Game Maker For Life, probably never professional thou." =)

Share this post

Link to post
Share on other sites
I think the best way is as you said, draw a line from the view point along the cursor and find out where it intersects with that wall. What is going to realy mess with your brain is finding that intersection in O(1) time. Sure you could run a for loop taking realy small steps along that line untill the distances from the plane start getting larger instead of smaller, but that will slow your game down and no body wants that.

So here is some psudo code to find where in 3 space your line intersecs that wall:

// First what you will need to calculate this:

// The distance from the view point to any point on the wall
// use a corner since you already know where thay are

// The unit vector of the line you are using
// (these are lower case)
FLOAT x, y, z

// The Unit Normal Vector of the plane you are trying to hit

// The Location of your POV (Point Of View)

// Now we begin the calculations
// I have reduced a lot of redundant opperations out of the
// formulas I used to get this

TRAVEL_DIST = ( P*X + Q*Y + R*Z ) / ( P*x + Q*y + R*z )

// multiply your lines unit vector by the travel distance
// and add that to the POV''s position to get a point that is
// both in your line and in the plane.


I copied this out of an old test I took, but it should work. Good luck and happy programming.

Share this post

Link to post
Share on other sites
The way I did it was to transform every 3D click point to screen co-ords and pick the closest one to the mouse pointer. My math isn''t that strong so I found it to be the simplest solution.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!