Object3D.calcMinDistance() return COLLISION_NONE, but shouldn't happen.

Started by kiffa, September 14, 2013, 10:51:25 AM

Previous topic - Next topic

kiffa

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:
    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:


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?


kiffa

I have tried to increase this value(to a rather large value),  but seems useless. :(

EgonOlsen

Hmm...have you tried to increase the 4 * 30 value to maybe 40*30 (just to see if it helps)?

wylng


EgonOlsen

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....?

wylng

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? 

EgonOlsen

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.

wylng

yes, I rotate camera 180.
maya's coordinate system is diffent from jpct


EgonOlsen

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.