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?
Have you tried to increase this value: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#collideOffset (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#collideOffset)?
I have tried to increase this value(to a rather large value), but seems useless. :(
Hmm...have you tried to increase the 4 * 30 value to maybe 40*30 (just to see if it helps)?
I increased this value to 100 * 30, but that won't help.
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....?
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?
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 (http://www.jpct.net/wiki/index.php/Coordinate_system)...but that doesn't match your code.
yes, I rotate camera 180.
maya's coordinate system is diffent from jpct
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.