Distance between two objects
Hi all...
In order to correctly perform picking, I need to know which of the objects of my scene are closer to the camera position. But, as there might be rotations I can't use the original position vector as it was transformed. So, the only thing left are position matrices (in my case D3DXMATRIX, Im working with DX 9.0c). Is there any way (mathematically or with DirectX) I can find out the distance between an object and the camera using only their position matrices?
Thanks...
Multiplying a transform matrix by a position vector will give you the composite transformation - i.e. where the position vector is now, based on the transform matrix. Pseudocodestyle:
That should do it. [smile]
-jouley
[Edit: Ver-ified.]
[Edited by - jouley on January 27, 2007 12:08:49 PM]
Vector vecNewPosition = matTransformMatrix * vecOldPosition;
Then, perform the usual distance test on vecNewPosition.That should do it. [smile]
-jouley
[Edit: Ver-ified.]
[Edited by - jouley on January 27, 2007 12:08:49 PM]
I'm not sure if you're already aware of this, but your post makes it a little unclear.
You should unproject (pick) the geometry with the same transformations applied as when it was rendered, so that all objects are in world space. So not only should you calculate vecNewPosition for the purposes of depth-testing, but also for picking.
Admiral
You should unproject (pick) the geometry with the same transformations applied as when it was rendered, so that all objects are in world space. So not only should you calculate vecNewPosition for the purposes of depth-testing, but also for picking.
Admiral
Hmm, I don't know if I totally understood what you meant. What I'm doing is trying to pick a cube between several of them. So, in order to perform picking, what I do is to create a local copy of a cube (sending it to a picking routine), using the same rotation, translation and scaling matrices I used to place that object on the scene to get the picking right. But, to check if I picked the right cube, before I pick anything, I calculate the distance of each cube to the camera, put them into an ordered vector and render them in that order. This way I can guarantee I'm picking the right cube (nearest to the camera).
Is this correct or am I doing something wrong in this process? =
Thanks once again... ;)
Quote:Original post by Sagito
Is this correct or am I doing something wrong in this process?
Does it work? [wink]
Quote:Original post by Sagito
Is this correct or am I doing something wrong in this process?
That sounds fine. I just misunderstood.
Admiral
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement