Updated readability of the code.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / math / Transform.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko.
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.math;
6
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8
9 /**
10  * Used to represent transformation in a 3D space.
11  * Transformations are represented as a translation and an orientation.
12  */
13 public class Transform implements Cloneable {
14
15     private final Point3D translation;
16     private final Orientation orientation;
17
18     public Transform() {
19         translation = new Point3D();
20         orientation = new Orientation();
21     }
22
23     /**
24      * Creates a new transform with the specified translation.
25      *
26      * @param translation the translation
27      */
28     public Transform(final Point3D translation) {
29         this.translation = translation;
30         orientation = new Orientation();
31     }
32
33     /**
34      * Creates a new transform with the specified translation and orientation.
35      *
36      * @param translation the translation
37      * @param angleXZ     the angle around the XZ axis
38      * @param angleYZ     the angle around the YZ axis
39      */
40     public Transform(final Point3D translation, final double angleXZ,
41                      final double angleYZ) {
42
43         this.translation = translation;
44         orientation = new Orientation(angleXZ, angleYZ);
45     }
46
47     /**
48      * Creates a new transform with the specified translation and orientation.
49      *
50      * @param translation the translation
51      * @param orientation the orientation
52      */
53     public Transform(final Point3D translation, final Orientation orientation) {
54         this.translation = translation;
55         this.orientation = orientation;
56     }
57
58     @Override
59     public Transform clone() {
60         return new Transform(translation, orientation);
61     }
62
63     public Orientation getOrientation() {
64         return orientation;
65     }
66
67     public Point3D getTranslation() {
68         return translation;
69     }
70
71     public void transform(final Point3D point) {
72         orientation.rotate(point);
73         point.add(translation);
74     }
75
76 }