Orthographic camera rotation

I can rotate the camera with this code

camera.zoom = 3//in constructor if(camera.zoom>1) { camera.zoom-=0.01f; camera.rotate(15); } 

this is done in rendering mode, now the zoom effect works correctly, but when the zoom completes, my screen remains rotated with the current angle. as shown below. enter image description here

I want my screen to stop after scaling 0 degrees.

+4
source share
4 answers

In code snippet

 **camera.zoom=3;** 

and at each iteration you scale the camera 0.01 to camera.zoom> 1 so you have a general iteration to scale

Then rotate with a power angle of 18 after iteration, it will rotate to a power of 360 .

+1
source

I wrote this method to calculate the current camera angle:

 public float getCameraCurrentXYAngle(Camera cam) { return (float)Math.atan2(cam.up.x, cam.up.y)*MathUtils.radiansToDegrees; } 

Then I call the rotate method as follows:

 camera.rotate(rotationAngle - getCameraCurrentXYAngle(camera)); 

This code works, but it will rotate immediately in one call. To rotate it at speed, you need to calculate the corresponding "rotationAngle" for each frame.

+1
source

Have you tried to rotate a multiple of 1.8 degrees with each iteration? Then you must complete the full number of revolutions after 200 iterations have passed.

0
source

attention, the computer cannot correctly represent most real numbers!

in binary format, 0.01 is a periodic number, so it will be truncated / rounded.

Substituting / adding floating-point numbers will add a rounding error a few hundred times and thus give you terribly wrong results.

(for example, after 200 tweaks, the value of your .zoom camera will be ~ 1.0000019 - NOT 1.0!)

why does your loop repeat 201 times, giving you a scaling value of 0.9900019 and a rotation of 361.7996 ~ 361.8 (when using 1.8, as in alex's answer).

you can use libGDX interpolation functions:

 time += Gdx.graphics.getDeltaTime(); //the rounding error is futile here, //because it'll increase the animation time by max. 1 frame camera.zoom = Interpolation.linear.apply(3, 1, Math.min(time, 1)); camera.rotate = Interpolation.linear.apply(0, 360, Math.min(time, 1)); 

this code will create an animation with a duration of one second from 3 to 1 and a rotation from 0 to 360 (just one whole rotation)

0
source

All Articles