@@ -57,11 +57,11 @@ public Transform() {
5757 * @param g The graphics context to which this transformation is applied.
5858 */
5959 public void apply (Graphics g ) {
60- g .translate ( position .x , position .y , position .z );
61- g .rotateX (rotation .x );
60+ g .scale ( scale .x , scale .y , scale .z ); // Scale first
61+ g .rotateX (rotation .x ); // Then rotate
6262 g .rotateY (rotation .y );
6363 g .rotateZ (rotation .z );
64- g .scale ( scale .x , scale .y , scale .z );
64+ g .translate ( position .x , position .y , position .z ); // Translate last
6565 }
6666
6767 /**
@@ -88,6 +88,17 @@ public void rotate(Vector3f delta) {
8888 this .rotation .addLocal (delta );
8989 }
9090
91+ /**
92+ * Rotates this transformation by the given delta values for each axis (in radians).
93+ *
94+ * @param x The change in rotation around the X-axis (in radians).
95+ * @param y The change in rotation around the Y-axis (in radians).
96+ * @param z The change in rotation around the Z-axis (in radians).
97+ */
98+ public void rotate (float x , float y , float z ) {
99+ this .rotation .addLocal (x , y , z );
100+ }
101+
91102 /**
92103 * Scales this transformation by the provided scaling factors.
93104 *
@@ -208,6 +219,38 @@ public void setScale(float sx, float sy, float sz) {
208219 this .scale .set (sx , sy , sz );
209220 }
210221
222+ /**
223+ * Retrieves the forward direction of the transform, based on its current rotation.
224+ *
225+ * <p>The forward direction is calculated using the rotation values and represents the vector that
226+ * points in the direction the object is facing.
227+ *
228+ * @return A normalized {@link Vector3f} representing the forward direction of the object.
229+ */
230+ public Vector3f getForward () {
231+ float cosY = (float ) Math .cos (rotation .y );
232+ float sinY = (float ) Math .sin (rotation .y );
233+ float cosX = (float ) Math .cos (rotation .x );
234+ float sinX = (float ) Math .sin (rotation .x );
235+
236+ return new Vector3f (cosY * cosX , sinX , sinY * cosX ).normalizeLocal ();
237+ }
238+
239+ /**
240+ * Retrieves the right direction of the transform, based on its current rotation.
241+ *
242+ * <p>The right direction is calculated using the rotation values and represents the vector that
243+ * points to the right of the object.
244+ *
245+ * @return A normalized {@link Vector3f} representing the right direction of the object.
246+ */
247+ public Vector3f getRight () {
248+ float cosY = (float ) Math .cos (rotation .y );
249+ float sinY = (float ) Math .sin (rotation .y );
250+
251+ return new Vector3f (-sinY , 0 , cosY ).normalizeLocal ();
252+ }
253+
211254 @ Override
212255 public void update (float tpf ) {}
213256
0 commit comments