Camera lookat not working correctly - rotation values not resetting

Rtech1's icon

I noticed that changing the camera position with lookat enabled gets incorrect rotation values. This seems to happen after changing position in x, y, and z values.

That patch below shows this after clicking through the different views a few times. The perspective view is the one that usually skews the rotation. The top view also doesn't orient in the right direction after going to side view.

Also in the patch is the older way of controlling the camera directly using sendrender. Using sendrender works correctly for all views. But there's a black spot between 0.7 and -0.7 when changing camera position on the z-axis.

On the other hand, the camera object method moves smoothly through this z-range but only auto-rotates correctly if the y-position equals 0. Anything greater in y position and the camera flips upside down when viewing the object from the back.

It looks like there could be a few things going on here. Everything should be easy to see in the patch. If possible, I'd like to use the camera object rather than the sendrender message. Is there a setting that will fix this or is it a bug?

camera problem.maxpat
Max Patch

Matteo Marson's icon

Hi,
You can set jit.gl.camera @tripod 1 to keep the camera rotation parallel to the XZ plane

Rtech1's icon

That won't help here since it doesn't allow movement in all three directions.

It looks like the camera position system is broken when lookat is enabled. Moving the camera on the z-axis causes errors in rotation values.

Rob Ramirez's icon

if you don't want to use tripod (which can be selectively enabled depending on mode), then simply zero out your rotation values when switching from perspective.

Alternatively have a single camera per view, and use enable to toggle.

I'm not sure what you think is broken, but I'll need some steps to reproduce.

Rtech1's icon

I've updated the patch to show things more clearly. The steps are to move through the views in method 1 until the camera view tilts. Then switch on method 2 on the right and move through the views. This patch was made just to test and show the camera issues.

I tried zeroing out rotation values and that didn't work. Single camera would work for the test patch but it's a workaround that doesn't address the issue. Tripod same thing.


From the test patch, it seems like when two axis values are changed , only one axis gets reset. So the view eventually tilts in some direction. On the right side of the patch, the same positions are sent with the sendrender message and work correctly.

The patch also includes triggers for the camera to move through the z axis. This is another discrepancy between the two methods. At y=0, both methods rotate the camera correctly when passing through x,z = 0,0. However, when Y=1, only the sendrender camera method keeps the scene upright. The camera object method flips the world upside down once the z-position becomes negative. I don't know which way is correct but keeping everything upright seems more useful.

Using the sendrender method however makes the world disappears when z position is between -0.7 and 0.7. This is easy to see in the patch too.

So neither method works perfectly. Hopefully there's a setting somewhere that fixes the rotation problems.

camera problem 2.maxpat
Max Patch

Rob Ramirez's icon

there is no setting that gives you exactly what you want, you need to build your own logic. the jit.gl.camera object is far more flexible than the legacy jit.gl.render camera messages, so parity is not guaranteed, though with proper patching logic, can be achieved as already suggested above.

moving along Z can be "fixed" with the tripod enabled. AFAICT from your patch the only time you want tripod disabled is for your top view. I don't see any bugs here and I think you will be better off working with the object's current behavior rather than insisting it should behave like the legacy jit.gl.render camera.