Author Topic: Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.  (Read 3575 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
In my car-racing game, I need calc the distance between "rear\front" and road. But the result seems incorrect.

The car and road:

 -------
 |       |
 --------------------
|                        |
--------------------
rear               front
----------------------------------------  road

code:
Code: [Select]
    mCar.Translate(0, 50, 0); // move up
    SimpleVector d = new SimpleVector(0, -1, 0);
    float frontHeight = mRoad.calcMinDistance(front, d, 4 * 30);
    float rearHeight = mRoad.calcMinDistance(rear, d, 4 * 30);
    WLog.d("front: " + front);
    WLog.d("rear: " + rear);
    WLog.d("frontHeight: " + frontHeight);
    WLog.d("rearHeight: " + rearHeight);

log:

Code: [Select]
09-15 16:30:56.680: D/Woo3d(4707): frontHeight: 50.03162
09-15 16:30:56.680: D/Woo3d(4707): rearHeight: 1.0E12
09-15 16:30:56.690: D/Woo3d(4707): front: (-2172.8433,50.031296,-1480.5132)
09-15 16:30:56.690: D/Woo3d(4707): rear: (-2172.3599,50.031296,-1543.8423)
09-15 16:30:56.690: D/Woo3d(4707): frontHeight: 50.03162
09-15 16:30:56.690: D/Woo3d(4707): rearHeight: 1.0E12
09-15 16:30:56.710: D/Woo3d(4707): front: (-2172.8623,50.031296,-1477.4586)
09-15 16:30:56.710: D/Woo3d(4707): rear: (-2172.379,50.031296,-1540.7877)
09-15 16:30:56.710: D/Woo3d(4707): frontHeight: 50.03162
09-15 16:30:56.710: D/Woo3d(4707): rearHeight: 50.03162


But there shouldn't be the result of COLLISION_NONE(1.0E12).  What's the possible reason?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.
« Reply #2 on: October 10, 2013, 02:34:54 pm »
I have tried to increase this value(to a rather large value),  but seems useless. :(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.
« Reply #3 on: October 10, 2013, 09:21:42 pm »
Hmm...have you tried to increase the 4 * 30 value to maybe 40*30 (just to see if it helps)?

Offline wylng

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.
« Reply #4 on: October 12, 2013, 04:30:06 am »
I increased this value to 100 * 30, but that won't help.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.
« Reply #5 on: October 12, 2013, 08:40:58 am »
I have only two ideas left than: You aren't doing these calculations in the render thread or your road has culling disbabled and you are trying to calculate the distance to back faces....?

Offline wylng

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.
« Reply #6 on: October 12, 2013, 09:34:12 am »
I do it in render thread, and I calculate the distance to its face.

Object3D.calcMinDistance() only returns COLLISION_NONE occasionally, it return the right value most the time, and my car go straight on the road, I want to calculate the right Y coordinate and rotateX to place my car on the road.

Does the model affect the calculate?  Is there any restrictions on the model? 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.
« Reply #7 on: October 12, 2013, 01:40:54 pm »
You can be pretty sure that the calcMinDistance-method is flawless. I wouldn't say this if i weren't 110% sure that it is. If all happens in the same thread and the offset/distance settings don't help and you are always testing against the front faces of the road, then it has to have something to do with your road mesh itself. Maybe it has some very tiny gaps in the geometry between the triangles? They don't even have to be visible but thy might the distance calculation to fail. I suggest to take location where it fails and move away from it in very very subtle steps to see how it behaves. If nothing else helps, just ignore the COLLISION_NONE values and use the last correct value instead...

Edit: What irritates me in your code snippet is that your y-axis seems to go up for positive y values. Have you turned the camera 180° around Z or why is that? By default, it's this way: http://www.jpct.net/wiki/index.php/Coordinate_system...but that doesn't match your code.
« Last Edit: October 12, 2013, 01:44:15 pm by EgonOlsen »

Offline wylng

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.
« Reply #8 on: October 14, 2013, 07:08:20 am »
yes, I rotate camera 180.
maya's coordinate system is diffent from jpct


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.
« Reply #9 on: October 14, 2013, 08:17:21 pm »
Anyway...i still see tiny gaps in the geometry as the only reason how this can happen. I would just ignore these results and carry on.