Initial revision
[lsystem3d.git] / lsystem3d / src / turtle.h
diff --git a/lsystem3d/src/turtle.h b/lsystem3d/src/turtle.h
new file mode 100644 (file)
index 0000000..d56c09a
--- /dev/null
@@ -0,0 +1,157 @@
+// Copyright (C) 2006 Erik Dahlberg
+// 
+// This file is part of LSystem3d.
+// 
+// LSystem3D is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+// 
+// LSystem3D is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with LSystem3D; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+
+
+
+#ifndef TURTLE_H
+#define TURTLE_H
+
+#include <stack>
+
+#include "coordinate.h"
+#include "model.h"
+#include "vector.h"
+
+using namespace std;
+
+
+
+/**
+ * The model renderer
+ */
+class Turtle
+{
+public:
+    /**
+     * Constructor
+     * @param model render this model
+     */
+    Turtle(Model *model);
+
+    /**
+     * Destructor
+     */
+    ~Turtle();
+    
+    /**
+     * Turn left
+     */
+    void turnLeft();
+    
+    /**
+     * Turn right
+     */
+    void turnRight();
+    
+    /**
+     * Pitch down
+     */
+    void pitchDown();
+    
+    /**
+     * Pitch up
+     */
+    void pitchUp();
+    
+    /**
+     * Roll left
+     */
+    void rollLeft();
+    
+    /**
+     * Roll right
+     */
+    void rollRight();
+    
+    /**
+     * Turn around
+     */
+    void turnAround();
+    
+    /**
+     * Walk forward
+     */
+    void walk();
+    
+    /**
+     * Save current state to stack
+     */
+    void push();
+    
+    /**
+     * Restore old state from stack
+     */
+    void pop();
+    
+    /**
+     * Reset to default state
+     */
+    void reset();
+    
+    /**
+     * Decrement diameter of segment
+     */
+    void decrementDiameter();
+    
+    /**
+     * Begin creation of a filled surface
+     */
+    void fenceInBegin();
+    
+    /**
+     * End creation of a filled surface
+     */
+    void fenceInEnd();
+    
+    /**
+     * Set turn/pitch/roll angle
+     * @param angle the angle, in radians
+     */
+    void setAngle(double radians);
+    
+    /**
+     * Get turn/pitch/roll angle
+     * @return the angle, in radians
+     */
+    double getAngle();
+    
+protected:
+    
+    Coordinate _position;       // current position
+    
+    Vector _heading;    // forward pointing vector
+    Vector _left;       // left pointing vector
+    Vector _up;         // up pointing vector
+    
+    double _angle;          // turn/pitch/roll angle
+    double _diameter;       // diameter of segment
+    bool _fenceMode;        // create filled surface?
+    
+    stack<Coordinate> _positionStack;       // positions in stack
+    stack<Vector> _headingStack;            // heading vectors in stack
+    stack<Vector> _leftStack;               // left vectors in stack
+    stack<Vector> _upStack;                 // up vectors in stack
+    stack<double> _diameterStack;           // diameters in stack
+    
+    Model *_model;    // the rendered model
+};
+
+
+
+#endif