Author
Topic: Camera matching Object3d Z Axis (Read 7018 times)

I've tried playing around with some of the axis, vectors, alligning.... but I can't seem to figure out how to make it work.

I'm trying to get the camera Z roation(ie looking at it from a 2d perspective) to rotate with the target object. So if I flip the target object upside down through rotation. I want the camera to match. So it seems like the object always is upright.

That's because lookAt() replaces the camera's rotation matrix that align() has already set...the two methods can't be combined in that way, because both of them create a new matrix. Isn't the align sufficient? Where's the point in aligning the camera and doing a lookAt right afterwards

I am also having a little difficulty visualizing what you are attempting to do here (perhaps a simple picture might help). Are you trying to keep the camera's up-direction matching the target's up-direction while at the same time having the camera always point toward the target.

Some of this is Egon's. It's for my Rogue Squadron program. The camera is always behind the ship, wherever it goes or turns. Since I also don't know exactly what you want, I'm not sure if it will, but does that help?

hmm, I thought I was clear, but clearly what I'm thinking needs to be relayed better since I don't need to fill in the blanks. Since I know what I'm thinking about

ok let's say I have my 2d Mario jump into the air. The camera moves up with Mario keeping Mario at the center of the screen. 2d Mario is rotated say 90 degress. So his head is now "east/right". What i'm trying to figure is how to keep the camera looking at mario, but rotate the camera so that 2d mario "appears" to be upright.

cameraPivot.translate( someSimpleVector );resetCameraPosition();When rotating Mario around the X-axis or Z-axis (or whatever axis you want only Mario but not the cameraSatelite to rotate around), call rotate methods for marioObject3D:

SimpleVector direction = cameraPivot.getTransformedCenter().calcSub( cameraSatelite.getTransformedCenter() ).normalize();direction.scalarMul( someValue ); // how 'fast' to zoom (negative to "zoom out")cameraSatelite.translate( direction );Oh, and one more thing, if you also want to be able to rotate the camera seperately from Mario, you could create a "masterPivot", which both the cameraPivot and marioObject3D are a child of. That way translating/rotating masterPivot affects both Mario and the Camera, while translating/rotating cameraPivot only affects the Camera.

Though one thing I noticed. The marioObject in question is prone to the physics engine alot. So I don't actually know how much I move objects. So I tend to use .setOrigin() base on the current position the object is in the physics world.

Though one thing I noticed. The marioObject in question is prone to the physics engine alot. So I don't actually know how much I move objects. So I tend to use .setOrigin() base on the current position the object is in the physics world.

But the origin isn't taken into account when calculating parent-child-translations. You can switch to

One potential issue I thought of -- you will definitely need the camera alignment to take into account any parent rotations, so if you use the "masterPivot" idea that I mentioned above, you should use the code from AGP's 'follow' method, changing method 'resetCameraPosition' to something like this (I am unable to test this at the moment):