www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Disastorm on June 27, 2012, 11:12:46 am

Title: What am I doing wrong?
Post by: Disastorm on June 27, 2012, 11:12:46 am
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.

Code: [Select]
                                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?
Title: Re: What am I doing wrong?
Post by: EgonOlsen on June 27, 2012, 01:49:10 pm
This should work as long as the parent has no rotation.

If it is, try to add this:

Code: [Select]
dest.rotate(parent.getRotationMatrix().invert3x3());
Title: Re: What am I doing wrong?
Post by: Disastorm on June 27, 2012, 08:01:57 pm
Thanks that worked.