Author Topic: Parenting the camera to an object  (Read 4317 times)

Albareth

  • Guest
Parenting the camera to an object
« on: January 09, 2004, 04:05:17 pm »
I'm trying to attach the camera to the rear of an object, kind of like a Tomb Raider (TM) style follow camera.  How would I parent the camera to the object?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Parenting the camera to an object
« Reply #1 on: January 09, 2004, 04:17:27 pm »
We've covered something like this before in this thread:

http://www.jpct.net/forum/viewtopic.php?t=67

Could be bit messy to dig through it, because we had some problems with it in that version of jPCT. However, i've posted a little code-snippet at the end of the thread on how to setup that thing. Combine that with something like the code below

// Move the camera back to the cameraHolder and look at the player

from the initial posting (just using "dummy" instead of "cameraHolder" should work) and you should get what you want. If not, maybe JonnyDee is willing to help and post his solution?!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Parenting the camera to an object
« Reply #2 on: January 09, 2004, 04:33:17 pm »
Another possible solution is to place the camera behind the object by getting the object's transformed center and translate it somehow (i.e. as needed in your case) by evaluating the results from the get?Axis()-methods of the object. Somehow like:

Code: [Select]

SimpleVector tc=object.getTransformedCenter();
SimpleVector pos=new SimpleVector(tc);
SimpleVector zAxis=object.getZAxis();
SimpleVector yAxis=object.getYAxis();
zAxis.scalarMul(5f);
yAxis.scalarMul(2f);
pos.add(zAxis);
pos.add(yAxis);
theWorld.getCamera().setPosition(pos);
theWorld.getCamera().lookAt(tc);


Please note that i haven't tested this and typed it out of my head, so i could be totally wrong here...