Author Topic: distance from a point to an Object3D?  (Read 3337 times)

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
distance from a point to an Object3D?
« 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

Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: distance from a point to an Object3D?
« Reply #1 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.
« Last Edit: July 13, 2007, 06:44:37 pm by EgonOlsen »

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
Re: distance from a point to an Object3D?
« Reply #2 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: distance from a point to an Object3D?
« Reply #3 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.