Author Topic: obj.translate not moving object  (Read 2011 times)

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
obj.translate not moving object
« on: January 30, 2013, 07:40:59 pm »
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
Code: [Select]
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
Code: [Select]
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
Code: [Select]
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: obj.translate not moving object
« Reply #1 on: January 30, 2013, 07:44:36 pm »
Could this be related to the objects all being cloned from an original?
No. But maybe you've called enableLazyTransformations() on them?

Offline AugTech

  • int
  • **
  • Posts: 64
    • View Profile
    • Augmented Technologies
Re: obj.translate not moving object
« Reply #2 on: January 31, 2013, 09:44:32 am »
Indeed I have :) 

Thanks Egon