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