obj.translate not moving object

Started by AugTech, January 30, 2013, 07:40:59 PM

Previous topic - Next topic

AugTech

Hi,
Can anyone tell me what I'm doing wrong here...
I'm trying to get an object to automatically place itself on the ground (a plane). I've read several posts on 'gravity' and collision detection, but nothing I do is actually moving the object.

I have an object 2m above a plane (manually created). The plane is set to plane.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
and the 'floating' object is also set to Object3D.COLLISION_CHECK_OTHERS.
The objects are added to the world at runtime as follows

public void addObjectsToWorld(A_Object3D[] objects) {
if (objects==null) return;

for (A_Object3D obj : objects) {
if (obj.requiresOrientation==false || sceneOrientation==null) continue;

// Align and rotate to our scene
tmpDirVector.x = sceneOrientation.front.x;
tmpDirVector.y = sceneOrientation.front.y;
tmpDirVector.z = sceneOrientation.front.z;
tmpUpVector.x = sceneOrientation.up.x;
tmpUpVector.y = sceneOrientation.up.y;
tmpUpVector.z = sceneOrientation.up.z;

obj.setOrientation(tmpDirVector, tmpUpVector);

obj.applyStyleRotations();// X,Y,Z rotation done here so angles are correct for scene

}

// Add...
theWorld.addObjects(objects);
theWorld.buildAllObjects();


Immediately afterwards I've tried two methods to move the object as follows

for (A_Object3D obj : objects) {
if (!obj.clampToGround) continue;

// SimpleVector dir = obj.getYAxis();
// SimpleVector tmp = new SimpleVector(dir);
// obj.checkForCollisionEllipsoid(dir, ellipsoid, 1);
// if (!dir.equals(tmp)) {
// Log.i(LOG_TAG, "Obj collided "+dir.toString());
// obj.translate(dir);
// }
SimpleVector dir = obj.getYAxis();
float dist = theWorld.calcMinDistance(
obj.getOrigin(),
dir,
50f);
Log.i(LOG_TAG, "Dist="+dist);
if (dist!=Object3D.COLLISION_NONE) {
obj.translate(dir.x*dist, dir.y*dist, dir.z*dist);
}

}

The distance is logging as 3.7001638m, which isn't far out as the object is 1m square, although I think it should be more like 2.5m to the centre...
Anyway, the object does not move with the translate, even if I try 50f. I also tried to put the translate code into the onDrawFrame(), but still nothing :(

Could this be related to the objects all being cloned from an original?

EgonOlsen

Quote from: AugTech on January 30, 2013, 07:40:59 PM
Could this be related to the objects all being cloned from an original?
No. But maybe you've called enableLazyTransformations() on them?

AugTech