Parenting the camera to an object

Started by Albareth, January 09, 2004, 04:05:17 PM

Previous topic - Next topic

Albareth

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?

EgonOlsen

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?!

EgonOlsen

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:


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...