home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / graphics / graphtal.lha / Graphtal / Turtle.h < prev    next >
C/C++ Source or Header  |  1992-11-17  |  4KB  |  199 lines

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