www.pudn.com > fi_treegen10.zip > Tree.h


//--------------------------------------------------------------------------- 
// Tree.h 
// by Alex ( alex@FusionIndustries.com ) 
// Created May 14, 2001 
// 
// This code may be freely used in any project, as long as credit 
// or greetz are given. Please also let me know if you use this 
// code, find it useful, or even if you don't like it. 
//--------------------------------------------------------------------------- 
#ifndef TREE_H_10101 
#define TREE_H_10101 
 
//--------------------------------------------------------------------------- 
#include "Global.h" 
#include  
 
//--------------------------------------------------------------------------- 
// Desc: Recursively draws a tree. Recurses currLevel levels deep and stops 
//       when currLevel == 0 
//--------------------------------------------------------------------------- 
class Tree 
{ 
  private: 
    GLuint        texId;            // id of the tree's texture 
    bool          currColorScheme;  // toggle between two schemes 
    float         currLOD;          // current Level of Detail between [1,10] 
    unsigned int  maxRecursionLevel; 
    unsigned int  branchesPerLevel; // how many branches to draw per recursion level 
    unsigned int  spread;           // an angle in degrees, relative to the y-axis 
    unsigned int  twist;            // an angle in degrees 
    unsigned int  treeBaseType;     // 0 == type0, 1 == type1 
    PrimitiveType currPrim; 
    GLUquadricObj *quadric;         // used for drawing some of the primitives (cylinder & sphere) 
    float line[3];        // vector representation; tail at (0,0,0); this defines the path the primitives follow 
    bool drawLeaves;      // if true we draw leaves 
    bool initialized;     // true if we're initialized 
 
    bool useDisplayList;  // if we want to use and generate a DL, set to true 
    bool treeGeomValid;   // false if any changes have been made, which means that we have to build a new display list for this tree 
    GLuint displayListId; // allows us to create and access the display list 
 
  public: 
    Tree(); 
    ~Tree() { shutdown(); } 
 
    void init(); // the Tree must be initialized before being used, or after calling shutdown() 
    void shutdown(); 
    void draw                ( unsigned int currLevel ); // a wrapper for the drawRecTree -- sets some params 
    void drawRecTree         ( unsigned int currLevel ); // recursively draws a tree 
    void setMaxRecursionLevel( unsigned int maxLevel ) { maxRecursionLevel = maxLevel; treeGeomValid = false; } 
    void setBranchesPerLevel ( unsigned int bpl )      { branchesPerLevel = bpl; treeGeomValid = false; } 
    void setLevelOfDetail    ( float lod ) { currLOD = lod; treeGeomValid = false; } // scales geom complexity (slices and stacks) [0,1] 
    void setPrimitiveType    ( PrimitiveType primitive ) { currPrim = primitive; treeGeomValid = false; } 
 
    void setSpread( unsigned int spreadAngle ){ spread = spreadAngle;             treeGeomValid = false; } // how spread out the branches are 
    void setTwist ( unsigned int twistAngle ) { twist = twistAngle;               treeGeomValid = false; } // how much each branch twists 
    void setColorScheme( bool scheme )        { currColorScheme = scheme;         treeGeomValid = false; } // toggle between 2 schemes [0,1] 
 
    void toggleLeaves()                       { drawLeaves = !drawLeaves;         treeGeomValid = false; } 
    void useLeaves( bool leafState )          { drawLeaves = leafState;           treeGeomValid = false; } 
 
    void toggleTreeBase()                     { treeBaseType = !treeBaseType;     treeGeomValid = false; } 
    void setTreeBase( unsigned int baseType ) { treeBaseType = baseType;          treeGeomValid = false; } 
 
    void toggleDisplayList()                  { useDisplayList = !useDisplayList; treeGeomValid = false; } 
    void setUseDisplayList( bool state )      { useDisplayList = state;           treeGeomValid = false; } 
 
    void drawLinePrim    ( float scale ); 
    void drawPlanePrim   ( float scale ); 
    void drawSpherePrim  ( float scale ); 
    void drawCylinderPrim( float scaleBase, float scaleTop ); 
}; 
 
//--------------------------------------------------------------------------- 
#endif