Sign in to follow this  
Kaloux

Picking problem

Recommended Posts

Hi ! I'm trying to implement a basic picking system for my units and managed to do something that almost works. In fact, I'm using bounding boxes. The thing is, they seem two time bigger than they should be (I checked coordinates, they are good). So I printed the mouse's 3D coordinates and the direction vector in the log, then used 3ds max to check if these were good. And they aren't. I must be doing something bad when converting 2D to 3D. Well, I'll explain what I do. I render a model in a 256*256 render target in orthographic projection. This render target is then rendered on the screen at (xt, yt), the hot spot (~reference point) being its center : (128,128). So first I convert absolute mouse coordinates to relative ones : rmx = amx - xt + 128; rmy = amy - yt + 128; Here, if the mouse is at the top left corner of the render target, its coordinates are (0,0), as if this render target was the screen. Then I call my test function with these coordinates. Here is its content : Create a vector3(rmx, rmy, 0) : vMouse, Create another vector3(rmx, rmy, 1) : vDir, Build a D3DVIEWPORT9 struct : X = 0, Y = 0, Width = 256, Height = 256, MinZ = 0, MaxZ = 1 Unproject the two vectors using D3DXVec3Unproject with the proper matrices, (vDir -= vMouse ? It doesn't seem to change anything) Test intersection with the bouding box using D3DXBoxBoundProbe. Am I missing a step ?

Share this post


Link to post
Share on other sites
Perhaps if you describe more specifically what problem you're having. You haven't provided enough information.

It appears you want to pick something ( Units? Do you mean meshes? ) and it doesn't work. For someone to help you, you need to describe what you want to do (more than just 'implement a picking system'), the results you get (more than just 'the coordinates aren't good') and why the results aren't what you expect or what you want. You can perhaps even provide a specific instance of: where the mouse is, what you want as a result and what you actually get.

Perhaps, "I want to click the mouse on my screen and detect which mesh is underneath that point."

Go from there.

Share this post


Link to post
Share on other sites
Oh well, sorry I wasn't clear enough :)
Anyway, I've just noticed that my bones where scaling the whole model down (don't know why yet). Everything is fine with my bounding box and my picking function !

Thanks for your help anyway ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this