Improved code readability.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / math / TransformsPipeline.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.math;
6
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8
9 public class TransformsPipeline {
10
11
12     private Transform[] transforms = new Transform[100];
13
14     /**
15      * The number of transforms in the pipeline.
16      */
17     private int transformsCount = 0;
18
19     /**
20      * Adds a transform to the pipeline.
21      *
22      * @param transform
23      *            The transform to add.
24      */
25     public void addTransform(final Transform transform) {
26         transforms[transformsCount] = transform;
27         transformsCount++;
28     }
29
30     /**
31      * Clears the pipeline.
32      */
33     public void clear() {
34         transformsCount = 0;
35     }
36
37     /**
38      * Drops the last transform from the pipeline.
39      */
40     public void dropTransform() {
41         transformsCount--;
42     }
43
44     /**
45      * Transforms a point.
46      *
47      * @param orinigalPoint
48      *            Original point to transform. Original point is not modified.
49      * @param transformedPoint
50      *            Transformed point.
51      */
52     public void transform(final Point3D orinigalPoint, final Point3D transformedPoint) {
53
54         transformedPoint.clone(orinigalPoint);
55
56         // apply transforms in reverse order
57         for (int i = transformsCount - 1; i >= 0; i--)
58             transforms[i].transform(transformedPoint);
59     }
60 }