2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.math;
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
9 public class Orientation implements Cloneable {
12 private double s1, c1, s2, c2;
15 * The angle of rotation around the XZ axis.
17 private double angleXZ = 0;
20 * The angle of rotation around the YZ axis.
22 private double angleYZ = 0;
24 public Orientation() {
28 public Orientation(final double angleXZ, final double angleYZ) {
29 this.angleXZ = angleXZ;
30 this.angleYZ = angleYZ;
35 public Orientation clone() {
36 return new Orientation(angleXZ, angleYZ);
40 * Computes the sine and cosine of the angles.
42 private void computeMultipliers() {
43 s1 = Math.sin(angleXZ);
44 c1 = Math.cos(angleXZ);
46 s2 = Math.sin(angleYZ);
47 c2 = Math.cos(angleYZ);
50 public void rotate(final Point3D point3d) {
51 final double z1 = (point3d.z * c1) - (point3d.x * s1);
52 point3d.x = (point3d.z * s1) + (point3d.x * c1);
54 point3d.z = (z1 * c2) - (point3d.y * s2);
55 point3d.y = (z1 * s2) + (point3d.y * c2);
58 public void rotate(final double angleXZ, final double angleYZ) {
59 this.angleXZ += angleXZ;
60 this.angleYZ += angleYZ;