Jump to content
  • Advertisement
Sign in to follow this  
Simplicity

MouseOver in 3D

This topic is 4863 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

In 2D, to test if the cursor is over an object you simply test to see if the hotspot is within and object's area ( point inside and area ). How is this done in a 3D environment. Obviously, the camera's view must be taken in consideration. How may object be projected so that the mouseover condition can be calculated?

Share this post


Link to post
Share on other sites
Advertisement
first you have to create a bounding object over your meshes for faster performance.
the easiest bounding object is sphere and AABB (axis aligned bounding box) , then you should cast e Ray from the center of the camera viewport , which is camera's position, to where the camera looks.
by intersecting the Ray with the bounding objects, you can determine if the mouse hits the object or not

if you want to know how to create this ray from the viewport, check out "Pick" example from D3D SDK.
and if you have problems with intersecting Ray with AABB or Sphere, tell me ,and I will post this routines for you.

Share this post


Link to post
Share on other sites
Thanks for the help guys. Why don't I have the pick example with the new DX SDK release. I do remember seeing it though. Do you know what version/release it was?

By the way, conceptually, what do you mean "e Ray" ?

Share this post


Link to post
Share on other sites
for opengl, you may use opengl up to ~64 objects with most cards with object names. draw your geometry wtih in pushname/popname blocks. this will make pixel-perfect selecting using another buffer for objects.. i think this method can be used with directx "manually" if not supporting. (like drawing another buffer with different colors(unique color id) of selectable objects, and read the pixel color under mouse, control it with selectable objects unique color id )
but it is not hard to use aabb s with raycasting. Introduction to 3D Game Programming with DirectX 9.0 has a great tut about this.

Share this post


Link to post
Share on other sites
ray is actually a line in 3d space, has a start point and an end point.
you can also define a ray as an endless line in one end.

p0------------------------->p1

p0 is the start point of the ray, and p1 is the end point of the ray.
and it is used in many cases in 3d graphics, such as collision detection and selecting in your case.

let's say you have a mouse position (mouseX, mouseY)
you can use D3DXVec3Unproject (see DX SDK help) , to convert mouseX,mouseY into 3d world space which will be 'sourcePt', and then you make a ray from sourcePt as start point and (sourcePt + 1000.0f * normalize(camLookAtVect) ) as end point.
after that you should test collision with AABB box of your object and see if it hits it.

there is a book on 3d graphics and basic math stuff called "3d math primer for graphics and game development - http://www.amazon.com/exec/obidos/tg/detail/-/1556229119/qid=1122751348/sr=8-1/ref=sr_8_xs_ap_i1_xgl14/104-0032809-6457541?v=glance&s=books&n=507846 " - I really recommend it, it clearly explains these stuff and much more

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!