Author Topic: What am I doing wrong?  (Read 2439 times)

Offline Disastorm

  • long
  • ***
  • Posts: 161
    • View Profile
What am I doing wrong?
« 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?
« Last Edit: June 27, 2012, 11:58:07 am by Disastorm »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: What am I doing wrong?
« Reply #1 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());
« Last Edit: June 27, 2012, 01:51:46 pm by EgonOlsen »

Offline Disastorm

  • long
  • ***
  • Posts: 161
    • View Profile
Re: What am I doing wrong?
« Reply #2 on: June 27, 2012, 08:01:57 pm »
Thanks that worked.