Jump to content


How to identify 3D scene objects with mouse clicks?


5 replies to this topic

#1 Weng

    New Member

  • Members
  • PipPip
  • 16 posts

Posted 20 November 2008 - 02:36 AM

I am developing a multiplayer point and click game.
How do I correctly identify the scene object which is being clicked on?

Currently, I use ray picking to identify the object being clicked. The first object which is intersected by the picking ray is taken to be the object which is clicked.

However, the problem is that if there is a player character standing in front of that object, the result will be inaccurate as the ray intersects the character first even if the object is clicked.

Since the picking ray could intersect through several scene objects, how do I identify which is the actual scene object which is being clicked?

Or is there another method of identifying clicked objects? :huh:

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 20 November 2008 - 03:06 AM

You could just ignore player characters in your ray intersection routine. Return the first intersection that isn't a player character.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Kochol

    New Member

  • Members
  • PipPip
  • 22 posts

Posted 20 November 2008 - 06:32 AM

Hi
Yes there is another way to find out which object was clicked but it needs shaders.
If you use opengl, it has built in function to do it for you. You set an object id to your objects and opengl will tell you witch object is clicked. If you want a tutorial then search google.

But if you use direct3d you need shaders, RTT(Render To Texture) and MRT(Multi Rendering Targets).
1. Add an object id parameter to your objects
2. In your shader code draw your scene to the screen and draw objectid as color to your texture. You can pass the object id as a variable to your shader code.
3. When user clicks somewhere get the color (Object ID) in rendered texture from specific coordinate (x,y that user clicked)

This picking method also can support masking

#4 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 143 posts

Posted 20 November 2008 - 09:32 AM

why dont you just check the player postion to see if its the same on the y axis but diferent on the z axis

#5 Kochol

    New Member

  • Members
  • PipPip
  • 22 posts

Posted 21 November 2008 - 05:44 AM

He want to select objects with mouse clicks

#6 deks

    New Member

  • Members
  • Pip
  • 3 posts

Posted 27 November 2008 - 02:16 PM

I implemented the same thing with occlusion queries in my engine - everytime you render a "clickable" object, use an occlusion query. At the end of the frame, go through all your queries, and if any pixels passed the z-test, the object is potentially under the cursor. I say potentially because if you don't use a z-prepass, *all* the objects under the mouse will be returned as "clicked", and you'd have to sort them out to know the nearest one.

Good luck!
JF





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users