home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / turtle.h < prev    next >
C/C++ Source or Header  |  1992-10-25  |  4KB  |  197 lines

  1. /*
  2.  * Turtle.h - class definition for 3D turtle manipulations.
  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 Turtle_H
  19. # define Turtle_H
  20.  
  21. #include "Vector.h"
  22. #include "BoundingBox.h"
  23. #include "list.h"
  24. #include "Color.h"
  25. #include "Hull.h"
  26.  
  27. //___________________________________________________________ Tropism
  28.  
  29. struct Tropism 
  30. {
  31.   Tropism(real, real, real, real);
  32.  
  33.   Vector F;    // force vector of tropism
  34.   real weight; // weight factor
  35.   int apply;   // 0 = don't apply, 1 = apply
  36. };
  37.  
  38. //___________________________________________________________ Turtle
  39.  
  40. class Turtle 
  41. {
  42. public:
  43.   Turtle();
  44.   ~Turtle();
  45.  
  46.   int forward(real);
  47.   void pitch(real);
  48.   void turn(real);
  49.   void roll(real);
  50.   void reverse();
  51.   void rotate_vertical(); 
  52.  
  53.   const Vector& pos() const;     // get current position of turtle
  54.   const Vector& lastPos() const; // get last position of turtle
  55.  
  56.   const Vector& vecH() const;    // heading of turtle
  57.   const Vector& vecL() const;    // left directin of turtle
  58.   const Vector& vecU() const;    // up directin of turtle
  59.  
  60.   void setWidth(real);           // set line width
  61.   real getWidth() const;
  62.   void setLastWidth(real);
  63.   real getLastWidth() const;
  64.  
  65.   void setColor(const Color&); 
  66.   const Color& getColor() const;
  67.   const Color& getLastColor() const;
  68.  
  69.   void setTexture(const rcString&);
  70.   const rcString& getTexture() const;
  71.   const rcString& getLastTexture() const;
  72.  
  73.   void setTropism(real, real, real); 
  74.   void setWeight(real);
  75.  
  76.   void setHull(Hull*, real);
  77.   void unsetHull();
  78.   void setStopOnHit();          // stop turtle interpretation when hit 
  79.                                 //  a hull primitive
  80.   void unsetStopOnHit();
  81.  
  82.   void expandBBoxBy(const BoundingBox&);
  83.   const BoundingBox& bbox() const;
  84.   friend ostream& operator<<(ostream&, const Turtle&);
  85.  
  86. private:
  87.   int forwardWithRespectToHull(real);
  88.   void bounce();
  89.   void applyTropism();
  90.  
  91. private:
  92.   BoundingBox b;
  93.  
  94.   Vector P, lastP;
  95.   Vector H, L, U;
  96.   real width, lastWidth;
  97.   Tropism tropism;
  98.   Color color, lastColor;
  99.   rcString texture, lastTexture;
  100.  
  101.   int hullActivated;
  102.   int stopOnHit;
  103.   Hull* hull;
  104.   real reflectanceFactor;
  105.   GeoObject* closestObject;
  106.   real distanceToClosestObject;
  107. };
  108.  
  109. inline const Vector& Turtle::pos() const { 
  110.   return P; 
  111. }
  112.  
  113. inline const Vector& Turtle::lastPos() const { 
  114.   return lastP; 
  115. }
  116.  
  117. inline const Vector& Turtle::vecH() const { 
  118.   return H; 
  119. }
  120.  
  121. inline const Vector& Turtle::vecL() const { 
  122.   return L; 
  123. }
  124.  
  125. inline const Vector& Turtle::vecU() const { 
  126.   return U; 
  127. }
  128.  
  129. inline void Turtle::setWidth(real wi) { 
  130.   width = wi; 
  131. }
  132.  
  133. inline real Turtle::getWidth() const { 
  134.   return width; 
  135. }
  136.  
  137. inline real Turtle::getLastWidth() const { 
  138.   return lastWidth; 
  139. }
  140.  
  141. inline void Turtle::setLastWidth(real wi) { 
  142.   lastWidth = wi; 
  143. }
  144.  
  145. inline void Turtle::setColor(const Color& c) { 
  146.   color = c; 
  147. }
  148.  
  149. inline const Color& Turtle::getColor() const { 
  150.   return color; 
  151. }
  152.  
  153. inline const Color& Turtle::getLastColor() const { 
  154.   return lastColor; 
  155. }
  156.  
  157. inline void Turtle::setTexture(const rcString& t) {
  158.   texture = t;
  159. }
  160.  
  161. inline const rcString& Turtle::getTexture() const {
  162.   return texture;
  163. }
  164.  
  165. inline const rcString& Turtle::getLastTexture() const {
  166.   return lastTexture;
  167. }
  168.  
  169. inline void Turtle::expandBBoxBy(const BoundingBox& bb) { 
  170.   b.expand(bb); 
  171. }
  172.  
  173. inline const BoundingBox& Turtle::bbox() const { 
  174.   return b; 
  175. }
  176.  
  177. inline void Turtle::setHull(Hull* h, real reflect) {
  178.   hullActivated = h->numPrimitives() > 0;
  179.   hull = h;
  180.   reflectanceFactor = (reflect < 0 || reflect > 1) ? 1 : reflect;
  181. }
  182.  
  183. inline void Turtle::unsetHull() {
  184.   hullActivated = 0;
  185.   hull = NULL;
  186. }
  187.  
  188. inline void Turtle::setStopOnHit() {
  189.   stopOnHit = 1;
  190. }
  191.  
  192. inline void Turtle::unsetStopOnHit() {
  193.   stopOnHit = 0;
  194. }
  195.  
  196. #endif // Turtle_H
  197.