Improved code readability
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / math / TransformsPipeline.java
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/math/TransformsPipeline.java b/src/main/java/eu/svjatoslav/sixth/e3d/math/TransformsPipeline.java
new file mode 100644 (file)
index 0000000..4e9985f
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Sixth 3D engine. Author: Svjatoslav Agejenko. 
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.sixth.e3d.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+
+public class TransformsPipeline {
+
+
+    private Transform[] transforms = new Transform[100];
+
+    /**
+     * The number of transforms in the pipeline.
+     */
+    private int transformsCount = 0;
+
+    /**
+     * Adds a transform to the pipeline.
+     *
+     * @param transform
+     *            The transform to add.
+     */
+    public void addTransform(final Transform transform) {
+        transforms[transformsCount] = transform;
+        transformsCount++;
+    }
+
+    /**
+     * Clears the pipeline.
+     */
+    public void clear() {
+        transformsCount = 0;
+    }
+
+    /**
+     * Drops the last transform from the pipeline.
+     */
+    public void dropTransform() {
+        transformsCount--;
+    }
+
+    /**
+     * Transforms a point.
+     *
+     * @param orinigalPoint
+     *            Original point to transform. Original point is not modified.
+     * @param transformedPoint
+     *            Transformed point.
+     */
+    public void transform(final Point3D orinigalPoint, final Point3D transformedPoint) {
+
+        transformedPoint.clone(orinigalPoint);
+
+        // apply transforms in reverse order
+        for (int i = transformsCount - 1; i >= 0; i--)
+            transforms[i].transform(transformedPoint);
+    }
+}