LibGDX - Orthographic camera translation and rotation - camera

I'm making a 2D top-down game in LibGDX, using orthographic camera. The camera is supposed to follow player, rotate with him etc. I'm also using Box2D, which means every sprite is updated by model coordinates and angle. And I want to make the same with the camera.
This code:
Vector3 v = new Vector3(playerModel.getPosition().x, playerModel.getPosition().y, 0);
camera.rotateAround(v, Vector3.Z, -playerModel.getAngle() * MathUtils.radiansToDegrees);
camera.translate(deltaMove);
camera.update();
gives me only relative translation and rotation - relative to current position and angle of the camera. And although this works I don't think It's the best, is it?:
Vector3 v = new Vector3(playerModel.getPosition().x, playerModel.getPosition().y, 0);
camera.up.x = (float) Math.cos(playerModel.getAngle());
camera.up.y = (float) Math.sin(playerModel.getAngle());
camera.position.x = v.x;
camera.position.y = v.y;
camera.update();
Is it possible to do it smoother way with orthographic camera or should I use a classis 3D camera?

You can remove the jerky movements of the camera by interpolating the current frame's camera properties between the last camera properties and the new camera properties. Camera movements are very jerky if you don't use some kind of interpolation.
I hope this helps, I would go into how to implement such such a change, but it seems a bit beyond the scope of this question.

Related

How to calculate Distance D to object from a tilted camera with known H?

Considering the camera is not tilted, it is easy to get the distance. However, can you refer a source where camera is tilted at some angle on y axis. By tilt i mean pitch. Also the camera is not looking directly at the object.

Rotate camera but render sprites so that they appear in their original world positions

TLDR: I want to rotate camera but render sprites in regards to their world position not camera position.
Howdy,
I'm currently using LibGDX and have come across an issue in regards to camera/object rotation.
Say I have my camera with a rotation of 0 and I have an object(sprite) to the left of the camera's center.
i.e.
Camera Normal (0 degrees rotation)
The sprite renders fine when given a standard world coordinate, however once I rotate my camera, that world coordinate differs from the camera's new (x, y) values.
If I then rotate my camera smoothly 90 degrees to the right(clockwise so that the up direction is facing to the right like the picture below), the object(sprite) that used to be on the left should have simulated a left rotation in regards to the camera (the rotation happens via the camera, the sprite just needs to update position) and now be below the camera's center point.
i.e.
Camera Rotated (90 degrees clockwise)
I'm confused as to how I would calculate the sprite's new locations/positions during the smooth rotation.
Cheers,
Solist.
After looking everywhere for a solution to this problem for 3 weeks it was merely a matter of me needing to call the method
batch.setProjectionMatrix(camera.combined);
in order to update the sprites to their new position in regards to the changing camera rotation.
This link here explains how the Projection Matrix works.

How to place the camera so that it shows a 2d area of variable size in full?

I'm making an application that generates a 2D area (you can think of it as a drawing), with a camera hovering over it. The size of said drawing isn't known in advance, and could change greatly. After the "drawing" is generated, I want to position the camera so that the whole drawing is in view.
My original idea was to calculate the points that are at the top, bottom, left, and right of the drawing and having the camera move back, "zooming out" until they are all in sight, but there has to be a better way, right?
Assuming you are working in 2D (thus orthographic camera mode), you can set the camera's orthographicSize:
Camera.main.orthographicSize = height / 2F; //half of the height of the area
Then, set the aspect ratio (width / height):
Camera.main.aspect = 1F; //for example, a square area

Optical Flow egomotion estimation

below you can see the result of the optical flow if a camera makes a translation movement. If the camera makes a roll rotation the result looks like the second picture. Is it possible to retrieve the yaw angle from a camera if its only rotation around the yaw axis?
I think in the optical flow you can recognize if the camera is rotating around the yaw axis (z-axis), but i don't know how to retrieve the information how much the cam has rotated.
I would be gradeful for any hints. Thanks
Translation:
Roll rotation:
Orientation of camera:
If you have a pure rotation of your cam then you can use findhomography. You need four point correspondence in your pictures. For a pure rotation the homography matrix is already a rotation matrix. Otherwise you need to decompose the homograohy matrix. For a camera movement off 6 dof you can use the function find essential matrix and decompose this to translation and rotation.

Three.js camera understanding

Here's the task:
We have an Mesh, drawn in position POS with rotation ROT
Also we have a camera Which position and rotation is relative to Mesh For example camera point is CPOS and camera rotation is CROT.
How to calculate resulting angle for camera? I was assuming that it something like:
camera.rotation.x = mesh.rotation.x + viewport.rotation.x
camera.rotation.y = mesh.rotation.y + viewport.rotation.y
camera.rotation.z = mesh.rotation.z + viewport.rotation.z
That worked strange and wrong.
Then I decided to read about it on docs and completely dissapointed.
There are several kind of rotation structures (Euler, Quaternion). But What a want is something different.
Imagine, like you are on spaceship. And it moves in space. You are sitting at starboard turret and looking at objects. They seems like passing by...
Then you want to turn your head - Angel of your head is known to you (in raw opengl, I'd just multiplied head rotation matrix on ship's rotation matrix and got my projection matrix).
In other words I want only x and y axis for camera rotations, combined in matrix. Then I want to multiply it with position-rotation matrix of an object. And this final matrix would be my projection matrix.
How could I do the same in THREE.js?
-----EDIT-----
Thank you for the answer.
Which coords should I give to a camera? It should be local, mesh relative coords, or something absolute?
I understand, that this questions are obvious, but there's no any description about relative objects in THREE.JS docs (besides api description). And the answer might be ambiguous.
Add the camera as a child of the mesh like so:
mesh.add( camera );
When the camera is a child of an object, the camera's position and orientation are specified relative to the parent object.
You can set the camera's orientation by setting either the camera's quaternion or Euler rotation -- your choice.
Please note that the renderer updates the object's matrix and matrixWorld for you. You do not need to do that manually.
three.js r.63