Updated copyright
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / math / Orientation.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2019, 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
11 package eu.svjatoslav.sixth.e3d.math;
12
13 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
14
15 public class Orientation implements Cloneable {
16
17     private double s1, c1, s2, c2;
18
19     private double angleXZ = 0;
20     private double angleYZ = 0;
21
22     public Orientation() {
23         computeMultipliers();
24     }
25
26     public Orientation(final double angleXZ, final double angleYZ) {
27         this.angleXZ = angleXZ;
28         this.angleYZ = angleYZ;
29         computeMultipliers();
30     }
31
32     @Override
33     public Orientation clone() {
34         return new Orientation(angleXZ, angleYZ);
35     }
36
37     private void computeMultipliers() {
38         s1 = Math.sin(angleXZ);
39         c1 = Math.cos(angleXZ);
40
41         s2 = Math.sin(angleYZ);
42         c2 = Math.cos(angleYZ);
43     }
44
45     public void rotate(final Point3D point3d) {
46         final double z1 = (point3d.z * c1) - (point3d.x * s1);
47         point3d.x = (point3d.z * s1) + (point3d.x * c1);
48
49         point3d.z = (z1 * c2) - (point3d.y * s2);
50         point3d.y = (z1 * s2) + (point3d.y * c2);
51     }
52
53     public void rotate(final double angleXZ, final double angleYZ) {
54         this.angleXZ += angleXZ;
55         this.angleYZ += angleYZ;
56         computeMultipliers();
57     }
58
59 }