From: spixx Date: Sun, 26 Nov 2006 14:22:06 +0000 (+0000) Subject: Minor cleanup. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=68a7b857d7778c1a7b33d916d062de317fdd5069;p=lsystem3d.git Minor cleanup. --- diff --git a/src/model.cpp b/src/model.cpp index 20dc567..8e3417b 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -59,6 +59,32 @@ Model::~Model() +/** + * Clear the model + */ +void Model::clear() +{ + glDeleteLists(_displayList, 1); + _displayList = glGenLists(1); + + setColorIndex(0); + + _diameter = 0.1; + _diameterFactor = 0.8; +} + + + +/** + * Render to screen + */ +void Model::draw() +{ + glCallList(_displayList); +} + + + /** * Create a segment * @param x1 x start point @@ -125,32 +151,6 @@ void Model::normal(double x, double y, double z) -/** - * Render to screen - */ -void Model::draw() -{ - glCallList(_displayList); -} - - - -/** - * Clear the model - */ -void Model::clear() -{ - glDeleteLists(_displayList, 1); - _displayList = glGenLists(1); - - setColorIndex(0); - - _diameter = 0.1; - _diameterFactor = 0.8; -} - - - /** * Begin a modelling session */ @@ -216,7 +216,7 @@ void Model::prevColor() /** - * Decrement diameter of segment + * Decrement segment diameter */ void Model::decrementDiameter() { @@ -260,7 +260,7 @@ void Model::setColorIndex(int index) /** - * Set current diameter of segment + * Set current segment diameter * @param diameter the diameter */ void Model::setDiameter(double diameter) @@ -271,7 +271,7 @@ void Model::setDiameter(double diameter) /** - * Set diameter factor + * Set segment diameter factor * @param diameter the diameter factor */ void Model::setDiameterFactor(double diameterFactor) @@ -293,10 +293,21 @@ int Model::getColorIndex() /** - * Get current diameter of segment - * @return diameter of segment + * Get current segment diameter + * @return the diameter */ double Model::getDiameter() { return _diameter; } + + + +/** + * Get segment diameter factor + * @return the diameter factor + */ +double Model::getDiameterFactor() +{ + return _diameterFactor; +} diff --git a/src/model.h b/src/model.h index 2e05697..138b801 100644 --- a/src/model.h +++ b/src/model.h @@ -38,6 +38,7 @@ using namespace std; class Model { public: + /** * Constructor */ @@ -48,6 +49,17 @@ public: */ ~Model(); + + /** + * Clear the model + */ + void clear(); + + /** + * Render to screen + */ + void draw(); + /** * Create a segment * @param x1 x start point @@ -75,16 +87,6 @@ public: */ void normal(double x, double y, double z); - /** - * Render to screen - */ - void draw(); - - /** - * Clear the model - */ - void clear(); - /** * Begin a modelling session */ @@ -116,10 +118,11 @@ public: void prevColor(); /** - * Decrement diameter of segment + * Decrement segment diameter */ void decrementDiameter(); + /** * Set current color index * @param index the color index @@ -127,17 +130,18 @@ public: void setColorIndex(int index); /** - * Set current diameter of segment + * Set current segment diameter * @param diameter the diameter */ void setDiameter(double diameter); /** - * Set diameter factor + * Set segment diameter factor * @param diameter the diameter factor */ void setDiameterFactor(double diameterFactor); + /** * Get current color index * @return color index @@ -145,18 +149,24 @@ public: int getColorIndex(); /** - * Get current diameter of segment - * @return diameter of segment + * Get current segment diameter + * @return the diameter */ double getDiameter(); + /** + * Get segment diameter factor + * @return the diameter factor + */ + double getDiameterFactor(); + protected: GLuint _displayList; // All drawing operations vector _colorTable; // Color table int _colorIndex; // Current index to color table - double _diameter; // Current diameter of segment + double _diameter; // Current segment diameter double _diameterFactor; // Diameter factor // TODO: "Diameter factor"? }; diff --git a/src/renderingsurface.h b/src/renderingsurface.h index fd9bbc6..1c7ebff 100644 --- a/src/renderingsurface.h +++ b/src/renderingsurface.h @@ -45,18 +45,24 @@ public: ID_CANVAS = FXMainWindow::ID_LAST, ID_LAST }; - + + /** * Constructor - * @param application the FOX application object - * @param lsystem the Lindenmayer-system + * @param application the application object */ - RenderingSurface(FXApp *application, LindenmayerSystem *lsystem); - + RenderingSurface(FXApp *application); + + /** + * Destructor + */ + virtual ~RenderingSurface(); + + /** * Create and initialize the window */ - void create(); + virtual void create(); /** * Initialize OpenGL @@ -68,6 +74,7 @@ public: */ void draw(); + /** * Called by the system when the left mouse button is pressed * @param sender the sender object @@ -139,6 +146,22 @@ public: * @return */ long onRepaint(FXObject *sender, FXSelector selector, void *data); + + /** + * Called by the system when the close button is pressed + * @param sender the sender object + * @param selector message type and id + * @param data event related data + * @return + */ + long onQuit(FXObject *sender, FXSelector selector, void *data); + + + /** + * Set current L-system generator + * @param lsystem the L-system generator + */ + void setLSystem(LindenmayerSystem *lsystem); protected: @@ -147,12 +170,12 @@ protected: */ RenderingSurface() {} -private: FXGLVisual *_visual; // Pixel format info FXGLCanvas *_canvas; // OpenGL-capable drawing area - LindenmayerSystem *_lsystem; // The Lindenmayer System + LindenmayerSystem *_lsystem; // The Lindenmayer system generator + // Model position double _modelX, diff --git a/src/rule.h b/src/rule.h index fcef31f..68d57be 100644 --- a/src/rule.h +++ b/src/rule.h @@ -59,6 +59,7 @@ public: */ ~Rule(); + /** * Clear rule */ @@ -76,6 +77,7 @@ public: */ string toString(); + /** * Set rule name * @param name the name @@ -94,6 +96,7 @@ public: */ void setProbability(double probability); + /** * Get rule name * @return the rule name diff --git a/src/ruleset.h b/src/ruleset.h index 63575a5..7945712 100644 --- a/src/ruleset.h +++ b/src/ruleset.h @@ -50,6 +50,7 @@ public: */ ~RuleSet(); + /** * Clear rule set */ @@ -68,6 +69,7 @@ public: */ Rule findRule(string ruleName); + /** * Get all rules * @return the rules diff --git a/src/turtle.cpp b/src/turtle.cpp index ae3e5f0..5ef84a5 100644 --- a/src/turtle.cpp +++ b/src/turtle.cpp @@ -58,6 +58,31 @@ Turtle::~Turtle() +/** + * Reset to default state + */ +void Turtle::reset() +{ + // put turtle at (0,0,0), head upwards, back towards camera + + _position.setXYZ(0.0, 0.0, 0.0); + + _heading.setXYZ(0.0, 1.0, 0.0); + _left.setXYZ(1.0, 0.0, 0.0); + _up.setXYZ(0.0, 0.0, 1.0); + + + // empty the stacks + _positionStack = stack(); + _headingStack = stack(); + _leftStack = stack(); + _upStack = stack(); + _diameterStack = stack(); + _colorIndexStack = stack(); +} + + + /** * Turn left */ @@ -238,31 +263,6 @@ void Turtle::pop() -/** - * Reset to default state - */ -void Turtle::reset() -{ - // put turtle at (0,0,0), head upwards, back towards camera - - _position.setXYZ(0.0, 0.0, 0.0); - - _heading.setXYZ(0.0, 1.0, 0.0); - _left.setXYZ(1.0, 0.0, 0.0); - _up.setXYZ(0.0, 0.0, 1.0); - - - // empty the stacks - _positionStack = stack(); - _headingStack = stack(); - _leftStack = stack(); - _upStack = stack(); - _diameterStack = stack(); - _colorIndexStack = stack(); -} - - - /** * Set turn/pitch/roll angle * @param angle the angle, in radians diff --git a/src/turtle.h b/src/turtle.h index 3d1ec3c..d28f75f 100644 --- a/src/turtle.h +++ b/src/turtle.h @@ -38,6 +38,7 @@ using namespace std; class Turtle { public: + /** * Constructor * @param model create this model @@ -49,6 +50,12 @@ public: */ ~Turtle(); + + /** + * Reset to default state + */ + void reset(); + /** * Turn left */ @@ -104,10 +111,6 @@ public: */ void pop(); - /** - * Reset to default state - */ - void reset(); /** * Set turn/pitch/roll angle @@ -115,6 +118,7 @@ public: */ void setAngle(double radians); + /** * Get turn/pitch/roll angle * @return the angle, in radians diff --git a/src/vector.cpp b/src/vector.cpp index 639d0b2..06ce40c 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -47,6 +47,23 @@ Vector::~Vector() +/** + * Normalize vector + */ +void Vector::normalize() +{ + double length = sqrt(_x * _x + _y * _y + _z * _z); + + if (length != 0) + { + _x /= length; + _y /= length; + _z /= length; + } +} + + + /** * Rotate around another vector * @param angle rotation angle @@ -82,23 +99,6 @@ void Vector::rotate(double angle, Vector vector) -/** - * Normalize vector - */ -void Vector::normalize() -{ - double length = sqrt(_x * _x + _y * _y + _z * _z); - - if (length != 0) - { - _x /= length; - _y /= length; - _z /= length; - } -} - - - /** * Get scalar product of two vectors * @param vector arbitrary vector diff --git a/src/vector.h b/src/vector.h index 056e22d..7d0bf77 100644 --- a/src/vector.h +++ b/src/vector.h @@ -32,6 +32,7 @@ class Vector : public Coordinate { public: + /** * Constructor * @param x the x-coordinate @@ -45,6 +46,12 @@ public: */ ~Vector(); + + /** + * Normalize vector + */ + void normalize(); + /** * Rotate around another vector * @param angle rotation angle @@ -52,10 +59,6 @@ public: */ void rotate(double angle, Vector vector); - /** - * Normalize vector - */ - void normalize(); /** * Get scalar product of two vectors diff --git a/src/xmlstructure.h b/src/xmlstructure.h index 0e5cd2a..c07dd2f 100644 --- a/src/xmlstructure.h +++ b/src/xmlstructure.h @@ -39,6 +39,7 @@ using namespace std; class XMLStructure { public: + /** * Constructor */ @@ -52,7 +53,6 @@ public: protected: // Saver - // ----- /** * Create new document with root node @@ -93,7 +93,6 @@ protected: // Loader - // ------ /** * Load document from file @@ -133,6 +132,14 @@ protected: */ string getAttribute(string name); + + /** + * Convert double to string + * @param doubleValue the double value + * @return the corresponding string + */ + string doubleToString(double doubleValue); + private: // Saver