MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / GameCamera

Class GameCamera

CodenameOne/src/com/codename1/gaming/GameCamera.java:54–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52/// pixels -- use `Sprite#setSize(float, float)` or `Sprite#setScale(float)` to pick a
53/// world-space size.
54public class GameCamera {
55 /// Orthographic, pixel-space 2D rendering (the default).
56 public static final int MODE_ORTHO_2D = 0;
57 /// Perspective 3D rendering with billboarded sprites.
58 public static final int MODE_PERSPECTIVE = 1;
59
60 private int mode = MODE_ORTHO_2D;
61
62 private float fov = 60f;
63 private float near = 0.1f;
64 private float far = 1000f;
65
66 private float eyeX;
67 private float eyeY;
68 private float eyeZ = 10f;
69 private float targetX;
70 private float targetY;
71 private float targetZ;
72 private float upX;
73 private float upY = 1f;
74 private float upZ;
75
76 // billboard basis, recomputed by #updateBasis(); columns right | up | toCamera
77 private final float[] basis = new float[16];
78
79 public int getMode() {
80 return mode;
81 }
82
83 /// Switches to perspective 3D rendering and sets the lens.
84 ///
85 /// #### Parameters
86 ///
87 /// - `fovYDegrees`: vertical field of view in degrees (e.g. 60)
88 ///
89 /// - `near`: near clip distance (> 0)
90 ///
91 /// - `far`: far clip distance
92 public GameCamera setPerspective(float fovYDegrees, float near, float far) {
93 this.mode = MODE_PERSPECTIVE;
94 this.fov = fovYDegrees;
95 this.near = near;
96 this.far = far;
97 return this;
98 }
99
100 /// Switches back to the default orthographic 2D mode.
101 public GameCamera setOrthographic2D() {
102 this.mode = MODE_ORTHO_2D;
103 return this;
104 }
105
106 /// The eye position in world space (perspective mode).
107 public GameCamera setPosition(float x, float y, float z) {
108 eyeX = x;
109 eyeY = y;
110 eyeZ = z;
111 return this;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected