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?
new
Vectors being built and it saves one method call, which might make a difference on mobile devices. – noone