Camera.CAMERA_MOVEUP, Camera.CAMERA_MOVEDOWN - bug?

Started by gabriel_mb1, December 31, 2006, 01:42:55 AM

Previous topic - Next topic

gabriel_mb1

Hi Egon, I'm new here and playing around Java and jPCT for a few weeks.

I was playing with the camera and found something like a bug or
at least a different behavior on the Camera.CAMERA_MOVERIGHT, Camera.CAMERA_MOVELEFT X
Camera.CAMERA_MOVEUP, Camera.CAMERA_MOVEDOWN


I used this code to rotate the camera around the center of the World:


               if (rotleft) {
                   theWorld.getCamera().moveCamera(Camera.CAMERA_MOVERIGHT, zoomSpeed);
                   theWorld.getCamera().lookAt(SimpleVector.ORIGIN);
               }
               if (rotright) {
                   theWorld.getCamera().moveCamera(Camera.CAMERA_MOVELEFT, zoomSpeed);
                   theWorld.getCamera().lookAt(SimpleVector.ORIGIN);
               }
               if (rotup) {
                   theWorld.getCamera().moveCamera(Camera.CAMERA_MOVEUP, zoomSpeed);
                   theWorld.getCamera().lookAt(SimpleVector.ORIGIN);
               }
               if (rotdown) {
                   theWorld.getCamera().moveCamera(Camera.CAMERA_MOVEDOWN, zoomSpeed);
                   theWorld.getCamera().lookAt(SimpleVector.ORIGIN);
               }

It's not a beautiful code but I'm still learning how the engine works.

and what I got is that when I rotate right or left, it's ok, but
when I rotate up or down, there is a jump when the camera is crossing the Y axis. (Or the XY plane of the world)

Seems that the code behavior of MOVEUP, MOVEDOWN is different from MOVELEFT and MOVERIGHT.

Congratulations for your engine, it looks fantastic!

Thanks, and Happy hollidays!

Gabriel

EgonOlsen

But moveCamera translates the camera, it doesn't rotate it. Are you sure that this is, what you intended? About the "jump"...that's most likely caused by the lookAt(). They are multiple possibilities to look from one point in space to another. The used algorithm chooses one of them, which may cause such a jump or twist under some circumstances. It's difficult to explain...maybe you should check first if moveCamera is really what you wanted to do.

gabriel_mb1

Yes I know that this code is bad for the intention. What I want is an OrbitCameraAroundPivot thing. I'm working on it. The basic code I wrote doesn't really orbit, because the camera will be far and far from the pivot at every single movement, but it was simple and as I'm learning jPCT and Java, better do simple things first.

What I wanted with this thread is to tell you about this apparently inconsistent behavior, because it works fine in all directions but when it crosses the Y axis (it apparently twists the camera 180 degrees).

Is this lookAt() behavior particular to cameras or it will do this with object3D too? Is this related to that the rotation of a camera actually rotates the world, not the camera? Is this related only with the Y axis or it can occur in other circumstances? Is there another way to look at something don't using lookAt()? So many questions, sorry.

I saw the code in Car example and it has another aproach to do the orbit, I'm working on it to do some more generic orbit "function" (I told I'm new on Java, ok - method?). I'm also working with the mirror thing that athanazio wrote in another thread. Cameras, cameras and more cameras. The mirror works fine at the moment but needs work on the reflection angle, for now it does only perpendicular reflection. It's hard to work with cameras as we can't parent them, we can't rotate them along a given pivot, or can we and I didn't find it?

Thanks for this great API and support,

Gabriel

EgonOlsen

The "problem" with lookAt is, that is has to choose one axis to start with and depending on which one that is, you are getting this "flipping" under some circumstances. lookAt() ensures, that the vector in question (in this the camera's view direction) is facing the object to look at. It doesn't make any assumptions about orientation.
Here's a thread that covers the camera-around-an-object-topic. Maybe it can help: http://www.jpct.net/forum/viewtopic.php?t=641

Melssj5

Which car code are you looking, the on ethat came with the engine or the one you can download made by thirds. On the second one I did a very simple way to do a camera orbitation. just move the camera to the center of the object, rotate it and move it back again!
Nada por ahora

gabriel_mb1

Thanks Egon,
understood!

I'll try to do the camera follow a dummy rotating object as Sebastian did and I'll also try as Melssj5 did, rotate the camera around a dummy object. Both should work fine. (I'll use a dummy object because the pivot I want is not necessarily in any object of the world).

Thanks Egon, Melssj5 and Sebastian.

Gabriel