What am I doing wrong?

Started by Disastorm, June 27, 2012, 11:12:46 AM

Previous topic - Next topic

Disastorm

Hello, I am trying to make an object move toward the camera. I was having some problems so i commented out the normalize call and tried to see if i could just make the object translate to the camera, but I couldn't do it.  This is the code I am using.


                                Object3D obj = data.getObject();
Camera cam = visualWorld.getCamera();
SimpleVector desti = new SimpleVector(cam.getPosition());
SimpleVector objCenter = obj.getTransformedCenter();
SimpleVector dest = desti.calcSub(objCenter);

System.out.println(objCenter.x + " " + desti.x + " " + objCenter.y + " " + desti.y);
//dest=dest.normalize();
// dest.scalarMul(0.05f);
obj.translate(dest);
objCenter = obj.getTransformedCenter();
System.out.println(objCenter.x + " " + desti.x + " " + objCenter.y + " " + desti.y);



Output:
973.6122 921.0 -13.489336 -21.0
2551.978 921.0 -483.8615 -21.0

Can you tell me what I am doing wrong?

Thanks.

*edit it looks like it has something to do with me setting a parent object.  When I remove the parent object it translates as it should. Do you know why this is? Could it be related to scaling on the parent?

EgonOlsen

#1
This should work as long as the parent has no rotation.

If it is, try to add this:


dest.rotate(parent.getRotationMatrix().invert3x3());

Disastorm