On 11/30/2011 1:37 PM, Jean-Sébastien Guay wrote:
Distance from one object to the other? Simply subtract the translation of each
matrix, which gives you the vector from one to the other. Then take the length
of that. In OSG, you would do:
osg::Vec3 o1_to_o2 = o1Matrix.getTrans() - o2Matrix.getTrans();
double distance = o1_to_o2.length();
That works when there's no scaling, and that appears to be the case in the OP's
matrices.
When scaling is used, it's possible for the translation values to be scaled
(depending on order of matrix concatenation). One way to account for that would
be to multiply the same vector by both matrices, subtract one result from the
other, then get the length of the difference vector.
But it really depends on what the OP wants. Does he want the distance from the
transformed model origin of the two objects? Does he want the distance from the
exterior of one bounding sphere to another? Does he want an exact closest
distance accounting for possibly concave objects? Just a few different ways to
interpret "I need to compute a distance", in increasing order of complexity. :-)
-Paul
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org