f7f64db7d8609f193b89dd594d5a8fe318f4828b
[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
27      *            the translation
28      */
29     public Transform(final Point3D translation) {
30         this.translation = translation;
31         orientation = new Orientation();
32     }
33
34     /**
35      * Creates a new transform with the specified translation and orientation.
36      *
37      * @param translation
38      *            the translation
39      * @param angleXZ
40      *            the angle around the XZ axis
41      * @param angleYZ
42      *            the angle around the YZ axis
43      */
44     public Transform(final Point3D translation, final double angleXZ,
45                      final double angleYZ) {
46
47         this.translation = translation;
48         orientation = new Orientation(angleXZ, angleYZ);
49     }
50
51     /**
52      * Creates a new transform with the specified translation and orientation.
53      *
54      * @param translation
55      *            the translation
56      * @param orientation
57      *            the orientation
58      */
59     public Transform(final Point3D translation, final Orientation orientation) {
60         this.translation = translation;
61         this.orientation = orientation;
62     }
63
64     @Override
65     public Transform clone() {
66         return new Transform(translation, orientation);
67     }
68
69     public Orientation getOrientation() {
70         return orientation;
71     }
72
73     public Point3D getTranslation() {
74         return translation;
75     }
76
77     public void transform(final Point3D point) {
78         orientation.rotate(point);
79         point.add(translation);
80     }
81
82 }