94c359cf276b990396edcf370ac4c5f467e6b275
[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 public class Transform implements Cloneable {
10
11     private final Point3D translation;
12     private final Orientation orientation;
13
14     public Transform() {
15         translation = new Point3D();
16         orientation = new Orientation();
17     }
18
19     /**
20      * Creates a new transform with the specified translation.
21      *
22      * @param translation
23      *            the translation
24      */
25     public Transform(final Point3D translation) {
26         this.translation = translation;
27         orientation = new Orientation();
28     }
29
30     /**
31      * Creates a new transform with the specified translation and orientation.
32      *
33      * @param translation
34      *            the translation
35      * @param angleXZ
36      *            the angle around the XZ axis
37      * @param angleYZ
38      *            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
51      *            the translation
52      * @param orientation
53      *            the orientation
54      */
55     public Transform(final Point3D translation, final Orientation orientation) {
56         this.translation = translation;
57         this.orientation = orientation;
58     }
59
60     @Override
61     public Transform clone() {
62         return new Transform(translation, orientation);
63     }
64
65     public Orientation getOrientation() {
66         return orientation;
67     }
68
69     public Point3D getTranslation() {
70         return translation;
71     }
72
73     public void transform(final Point3D point) {
74         orientation.rotate(point);
75         point.add(translation);
76     }
77
78 }