www.jpct.net

General => Feedback => Topic started by: Melssj5 on July 13, 2007, 06:23:29 pm

Title: distance from a point to an Object3D?
Post by: Melssj5 on July 13, 2007, 06:23:29 pm
Can I get the distance from a point to an Object3D?, not just getting the difference from its centers, but calculating a perpendicular projection from a point to the body?. I will post images later

Title: Re: distance from a point to an Object3D?
Post by: EgonOlsen on July 13, 2007, 06:28:33 pm
You can iterate through all transformed vertices of the object by using the PolygonManager, calculate the euclidean distance from your point in world space by yourself and take the lowest value as the distance (which is not always the shortest distance because it ignores that a polygon's plane can have a shorter distance than it's points, but it may be good enough).

Edit: Or you can use the IVertexController to get the vertices in object space and do the check there, after transforming your point into object space using the object's inverse world transformation...should be more efficient.
Title: Re: distance from a point to an Object3D?
Post by: Mizuki Takase on August 10, 2007, 06:26:50 pm
That sounds painfully slow but then again, I cannot imagine any other way to do that... X_X
Title: Re: distance from a point to an Object3D?
Post by: EgonOlsen on August 10, 2007, 06:29:47 pm
For getting the smallest distance, it's not needed to really calculate it, so you can at least leave the square root out and calculate it once on the lowest found value. It should be fast enough. The collision detection methods are doing more work and a usually fast enough too.