Fixed git clone URL
[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 {@link Orientation}.
12  */
13 public class Transform implements Cloneable {
14
15     /**
16      * The translation is applied after the orientation.
17      */
18     private final Point3D translation;
19
20     /**
21      * The orientation is applied before the translation.
22      */
23     private final Orientation orientation;
24
25     public Transform() {
26         translation = new Point3D();
27         orientation = new Orientation();
28     }
29
30     /**
31      * Creates a new transform with the specified translation.
32      *
33      * @param translation the translation
34      */
35     public Transform(final Point3D translation) {
36         this.translation = translation;
37         orientation = new Orientation();
38     }
39
40     /**
41      * Creates a new transform with the specified translation and orientation.
42      *
43      * @param translation the translation
44      * @param angleXZ     the angle around the XZ axis
45      * @param angleYZ     the angle around the YZ axis
46      */
47     public Transform(final Point3D translation, final double angleXZ,
48                      final double angleYZ) {
49
50         this.translation = translation;
51         orientation = new Orientation(angleXZ, angleYZ);
52     }
53
54     /**
55      * Creates a new transform with the specified translation and orientation.
56      *
57      * @param translation the translation
58      * @param orientation the orientation
59      */
60     public Transform(final Point3D translation, final Orientation orientation) {
61         this.translation = translation;
62         this.orientation = orientation;
63     }
64
65     @Override
66     public Transform clone() {
67         return new Transform(translation, orientation);
68     }
69
70     public Orientation getOrientation() {
71         return orientation;
72     }
73
74     public Point3D getTranslation() {
75         return translation;
76     }
77
78     /**
79      * Applies this transform to the specified point in a 3D space.
80      *
81      * @param point to apply this transform to
82      */
83     public void transform(final Point3D point) {
84         orientation.rotate(point);
85         point.add(translation);
86     }
87
88 }