Hi all !
I'm trying to implement two things at the moment, and after three days its still driving me nuts!

Firstly, and most importantly, I'm trying to automatically 'clamp' objects to the ground....yes that old chestnut! I've read many a post here, but I just can't get a catch all that works for .obj models and in-built primitives (like a cube, which I seem to have fixed now incidentally)
In the app I either create a primitive, such as a cube, or load an .obj model and then add it to the scene through the following method;
public void addObjectsToWorld(A_Object3D[] objects) {
if (objects==null || sceneOrientation==null) return;
SimpleVector frontAxis = sceneOrientation.front.normalize();
SimpleVector upAxis = sceneOrientation.up.normalize();
// Align our object axis to the ECEF axis
for (A_Object3D obj : objects) {
if (obj.requiresOrientation) {
obj.setOrientation(frontAxis, upAxis);
}
obj.applyStyleRotations();
obj.build();
}
// Add...
theWorld.addObjects(objects);
// Now clamp objects to the floor if flagged to do so...
SimpleVector trans = new SimpleVector();
for (A_Object3D obj : objects) {
if (!obj.clampToGround) continue;
float dist = plane.calcMinDistance( obj.getTransformedCenter(), upAxis );
// Move object above plane by 20m and try again
if (dist==Object3D.COLLISION_NONE) {
trans.set( upAxis );
trans.scalarMul( -20f );
obj.translate( trans );
dist = plane.calcMinDistance( obj.getTransformedCenter(), upAxis );
// Couldn't collide, move to original position
if (dist==Object3D.COLLISION_NONE) {
trans.set( upAxis );
trans.scalarMul( 20f );
obj.translate( trans );
}
}
// Do the clamping...
if (dist!=Object3D.COLLISION_NONE) {
float htAdjust = obj.isPlane ? 0f : -obj.getMesh().getBoundingBox()[3];
Log.i(LOG_TAG, "Obj: "+obj.getParentFeatureID()+" Dist: "+(dist+htAdjust));
trans.set( upAxis );
trans.scalarMul( dist-obj.heightOffset+htAdjust );
// (paulscode) Grab a handle to the Object3D's world transformation matrix:
Matrix m = new Matrix( obj.getWorldTransformation() );
// Turn that into a rotation matrix:
float[] dm = m.getDump();
for( int i = 12; i < 15; i++ ) dm[i] = 0;
dm[15] = 1;
m.setDump( dm );
// Apply this rotation matrix to the translation vector:
trans.matMul( m );
obj.translate( trans );
}
}
The plane object is a transparent plane sat 2m below the camera position.
Adding additional planes (map tiles) through the above method works; adding cubes works, but .obj models (and an arrow which I'll get to in the minute) does not. The links should hopefully illustrate;
Screen1: Primitive models sat on ground, but .obj model floating

Screen2: Model the same size and axis alignment, but sat below plane (the rotating arrow is sat below the overlay).

It should be noted that the models (not mine!) are exported from Sketch-up with the swap YZ axis option enabled. To then align the axis to jPCT I use the following;
if (shapeName.endsWith(".obj") || shapeName.endsWith(".3ds")) {
ret = getShapeFromAssets(shapeName);
/* jPCT axis are rotated 180 around X axis,
* contrary to most graphics systems, so we rotate and then
* replace the matrix so this rotation is ignored in later
* translations and rotations */
ret.obj.rotateZ(PI);// Why Z, not X ??? (Is Z so North is aligned)
ret.obj.rotateMesh();
ret.obj.setRotationMatrix( new Matrix() );
ret.obj.getMesh().setLocked(true);
}
I can seem to get a decent value from calcMinDistance, one model is 0.09m, whereas the other is 19.4m. ??
As a secondary issue, I'm trying display an arrow permanently in front of the camera, at a fixed distance, but also clamped to the ground. I suspect a
very similar problem as, again, the arrow is loaded from an .obj, added to as a child to a dummyObject at the camera position and then translated to be in front of the camera. With the arrow being 8m in front of the camera, calcMinDistance is returning 6.9 metres from the plane!!??
Many, many thanks to the person who tells me what stupid thing I'm doing!
[attachment deleted by admin]