Hi all,
I found over the web the code below to pick up 3D Objects. I actually have a 3D model with spheres that is renderized at the centre of the screen and I should be able to pick up a single sphere and change his texture. The problem is that it doesn't work very well, I have a lot of false positive. For example, sometimes I click out of the sphere and I have a positive hit. Why? Could it be a 3D model problem?
I'm not sure but wouldn't you just want to be applying the inverse world matrix to your ray data and not the inverse of a combined world-view matrix? The mesh data shouldn't be in view space at this point as far as I know.
You may want to compare your calcs for rayOrigin and rayDirection with what you get from D3DXVec3Unproject. It appears the results you're getting are due to not accounting for the mouse position in the rayOrigin calculation. I.e., rayOrigin is independent of the mouse position.
You say you found the code somewhere. Are you sure the code you posted is intended to give you the results you're expecting?
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.
I changed the code to use GetCursorPos and not the lParam of the WndProc message and it seems to work better, the precision is not really 100% but it's near the perfect... still working on it, anyway that was the problem
I changed the code to use GetCursorPos and not the lParam of the WndProc message and it seems to work better, the precision is not really 100% but it's near the perfect... still working on it, anyway that was the problem
lParam is simply used to pass extra data with messages. Do you know what the data was? That could help you figure things out.
They hated on Jeezus, so you think I give a f***?!
lParam is simply used to pass extra data with messages. Do you know what the data was? That could help you figure things out.
I was using the WM_LBUTTONUP message to find the mouse coordinates. This is what was on MSDN about the lParam argument:
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.[/quote]
Do you transform your mouse coordinates from screen to client? If you don't, this might cause a small offset.
now I'm doing it and the offset is really small, If i click out ot fhe sphere the hit isn't detected, if I hit the sphere the hit is detected and If I hit inside the sphere but really near the border the hit isn't detected. Anyway a big steep away from before