Advertisement

mouse coordinates to 3D coordinates

Started by December 20, 2000 06:14 PM
6 comments, last by Possibility 24 years, 1 month ago
How do you take the x and y values of the mouse coordinates on the screen and get them to 3D world coordinates so I can figure out what i am clicking on (can of like shooting at stuff, but not just always shooting at whatever is in the exact center of the screen as in fps games). If anyone knows of a good way to do this, or even better a tutorial on it, I would be much thankfull. And I searched gamedev.net and didnt find any articles here on it Possibility
Its actually the same as raytracing. But you probably dont care about the colour of the pixel you hit. Also reflections & shadows dont matter, so when you are only using 1 ray - the popular term is ray-casting (I think).

Even more popular is the word "picking". Pick your object. Have you tried a search using these words?

Oh - you can do this in camera space, but its more intuitive to do it in world space. Watch out with this!

Advertisement
I wasnt able to find any specific topics on what I kind of want to do with a search for ray-casting. I have a GUI, and mouse pointer that can move to any pixel on the screen, and when I click the mouse, i need to know where that mouse is clicking on in the 3D world behind it. I actually saw a specific article on this many months ago but I dont know the link to it any more

Possibility
Rather than viewing the mouse as a point on the screen view it as a point on a line. Another point is the position of the camera. You want to find the first polygon within the limits of the view frustrum that the line intersects.
Keys to success: Ability, ambition and opportunity.
You need to get the screen coordinate, transform it BACK to camera-space (the inverse projection matrix will help you), and then cast a ray to the back of the scene and find the object which intersects that line and is the closest to the screen.


go to: mr.game-maker.com
I think thats the right URL, its something close to that. They have lots of tutorials on stuff that is - well - isn''t at gamedev.net!

------------------------------
BCB DX Library - RAD C++ Game development for BCB
Advertisement
to be correct - its http://www.mr-gamemaker.co.uk/
and I''ve just noticed the site got a facelift. A very nice facelift! looks cool now

------------------------------
BCB DX Library - RAD C++ Game development for BCB
Ah, thank you C++Freak, that site had the exact article I was looking for "Object Picking."
I had seen it once before but couldnt remember the web site. I didnt have www.mr-gamemaker.co.uk bookmarked.

Thanks
Possibility

This topic is closed to new replies.

Advertisement