Picking problem

Started by
2 comments, last by Kaloux 16 years, 1 month ago
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 ?
Advertisement
Nobody ?
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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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 ;)

This topic is closed to new replies.

Advertisement