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;
10 * Used to represent transformation in a 3D space.
12 public class Orientation implements Cloneable {
15 private double s1, c1, s2, c2;
18 * The angle of rotation around the XZ axis.
20 private double angleXZ = 0;
23 * The angle of rotation around the YZ axis.
25 private double angleYZ = 0;
27 public Orientation() {
31 public Orientation(final double angleXZ, final double angleYZ) {
32 this.angleXZ = angleXZ;
33 this.angleYZ = angleYZ;
38 public Orientation clone() {
39 return new Orientation(angleXZ, angleYZ);
43 * Computes the sine and cosine of the angles.
45 private void computeMultipliers() {
46 s1 = Math.sin(angleXZ);
47 c1 = Math.cos(angleXZ);
49 s2 = Math.sin(angleYZ);
50 c2 = Math.cos(angleYZ);
53 public void rotate(final Point3D point3d) {
54 final double z1 = (point3d.z * c1) - (point3d.x * s1);
55 point3d.x = (point3d.z * s1) + (point3d.x * c1);
57 point3d.z = (z1 * c2) - (point3d.y * s2);
58 point3d.y = (z1 * s2) + (point3d.y * c2);
61 public void rotate(final double angleXZ, final double angleYZ) {
62 this.angleXZ += angleXZ;
63 this.angleYZ += angleYZ;