home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / interprt.h < prev    next >
C/C++ Source or Header  |  1992-10-28  |  3KB  |  143 lines

  1. /*
  2.  * Interpreter.h - class definition for l-system interpreter.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #ifndef Interpreter_H
  19. # define Interpreter_H
  20.  
  21. #include "Globals.h"
  22. #include "Value.h"
  23. #include "Polygon.h"
  24. #include "DeviceDriver.h"
  25. #include "Module.h"
  26. #include "Turtle.h"
  27. #include "Hull.h"
  28. #include "Options.h"
  29.  
  30. //___________________________________________________________ Interpreter
  31.  
  32. class Interpreter;
  33. typedef void (Interpreter::*FP)(void);
  34. class TurtleStack;
  35.  
  36. class Interpreter
  37. {
  38. public: 
  39.   Interpreter(DeviceDriver*, Options*);
  40.   ~Interpreter();
  41.  
  42.   void interpret(ModuleList*);
  43.  
  44.   static Value* getTx();
  45.   static Value* getTy();
  46.   static Value* getTz();
  47.  
  48. private:
  49.   void forward();
  50.   void width();
  51.   void go();
  52.   void pitch();
  53.   void pitch_negativ();
  54.   void roll();
  55.   void roll_negativ();
  56.   void turn();
  57.   void turn_negativ();
  58.   void rotate_vertical();
  59.   void reverse();
  60.   void push();
  61.   void pop();
  62.   void startPolygon();
  63.   void saveVertex();
  64.   void endPolygon();
  65.   void tropism();
  66.   void weight();
  67.   void color();
  68.   void beginMacro();
  69.   void endMacro();
  70.   void executeMacro();
  71.   void libraryObject();
  72.   void sphere();
  73.   void triangle();
  74.   void polygon();
  75.   void activateHull();
  76.   void deactivateHull();
  77.   void cutBranchWhenHit();
  78.   void cutBranch();
  79.   void texture();
  80.  
  81.   void flush();
  82.   void createConeBetweenSpheres(const Vector&, real, const Vector&, real);
  83.   void computeTropism();
  84.  
  85. public:
  86.   struct InterpreterFunctions {
  87.     char* name;
  88.     FP function;
  89.     long  index;
  90.   };
  91.  
  92. private:
  93.   static InterpreterFunctions FuncTable[];
  94.   static FP* functable;
  95.   static Value turtleX; // position of turtle, for use in analytic
  96.   static Value turtleY; // tropism functions
  97.   static Value turtleZ;
  98.  
  99.   Expression* tropismX; // analytic tropism functions
  100.   Expression* tropismY;
  101.   Expression* tropismZ;
  102.   Expression* tropismWeight;
  103.   int tropismFunction; // analytic tropism functions set?
  104.   int weightFunction;  // analytic weight functions set?
  105.  
  106.   DeviceDriver* d;
  107.   Turtle* t;
  108.   HullSymtab* h;
  109.   Options* options;
  110.  
  111.   ModuleList* ml;
  112.   Module* m;           // current module
  113.   long currentModule;  // position of current module in the list
  114.  
  115.   PolygonList* polyStack;
  116.   TurtleStack* turtleStack;
  117.   Turtle* saveTurtle;
  118.  
  119.   int definingMacro;  // defining a macro?
  120.   int reflected;      // did we hit a hull primitive in the last move?
  121.   int deleteBranchWhenHit;
  122. };
  123.  
  124.  
  125. inline Value* Interpreter::getTx() {
  126.   return &turtleX;
  127. }
  128.  
  129. inline Value* Interpreter::getTy() {
  130.   return &turtleY;
  131. }
  132.  
  133. inline Value* Interpreter::getTz() {
  134.   return &turtleZ;
  135. }
  136.  
  137. #endif // Interpreter_H
  138.  
  139.  
  140.  
  141.  
  142.  
  143.