059ba392a743469debbae97630d10ec8581488e8
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / math / Transform.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  *
8  */
9
10 package eu.svjatoslav.sixth.e3d.math;
11
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13
14 public class Transform implements Cloneable {
15
16     private final Point3D translation;
17     private final Orientation orientation;
18
19     public Transform() {
20         translation = new Point3D();
21         orientation = new Orientation();
22     }
23
24     public Transform(final Point3D translation) {
25         this.translation = translation;
26         orientation = new Orientation();
27     }
28
29     public Transform(final Point3D translation, final double angleXZ,
30                      final double angleYZ) {
31
32         this.translation = translation;
33         orientation = new Orientation(angleXZ, angleYZ);
34     }
35
36     public Transform(final Point3D translation, final Orientation orientation) {
37         this.translation = translation;
38         this.orientation = orientation;
39     }
40
41     @Override
42     public Transform clone() {
43         return new Transform(translation, orientation);
44     }
45
46     public Orientation getOrientation() {
47         return orientation;
48     }
49
50     public Point3D getTranslation() {
51         return translation;
52     }
53
54     public void transform(final Point3D point) {
55         orientation.rotate(point);
56         point.add(translation);
57     }
58
59 }