home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
oct93
/
graphics
/
graphtal.lha
/
Graphtal
/
Turtle.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-17
|
4KB
|
199 lines
/*
* Turtle.h - class definition for 3D turtle manipulations.
*
* Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
* University of Berne, Switzerland
* All rights reserved.
*
* This software may be freely copied, modified, and redistributed
* provided that this copyright notice is preserved on all copies.
*
* You may not distribute this software, in whole or in part, as part of
* any commercial product without the express consent of the authors.
*
* There is no warranty or other guarantee of fitness of this software
* for any purpose. It is provided solely "as is".
*
*/
#ifndef Turtle_H
# define Turtle_H
#include "Vector.h"
#include "BoundingBox.h"
#include "list.h"
#include "Color.h"
#include "Hull.h"
//___________________________________________________________ Tropism
struct Tropism
{
Tropism(real, real, real, real);
Vector F; // force vector of tropism
real weight; // weight factor
int apply; // 0 = don't apply, 1 = apply
};
//___________________________________________________________ Turtle
class Turtle
{
public:
Turtle();
Turtle(const Turtle&);
~Turtle();
int forward(real);
void pitch(real);
void turn(real);
void roll(real);
void reverse();
void rotate_vertical();
const Vector& pos() const; // get current position of turtle
const Vector& lastPos() const; // get last position of turtle
const Vector& vecH() const; // heading of turtle
const Vector& vecL() const; // left directin of turtle
const Vector& vecU() const; // up directin of turtle
void setWidth(real); // set line width
real getWidth() const;
void setLastWidth(real);
real getLastWidth() const;
void setColor(const Color&);
const Color& getColor() const;
const Color& getLastColor() const;
void setTexture(const rcString&);
const rcString& getTexture() const;
const rcString& getLastTexture() const;
void setTropism(real, real, real);
void setWeight(real);
void setHull(Hull*, real);
void unsetHull();
void setStopOnHit(); // stop turtle interpretation when hit
// a hull primitive
void unsetStopOnHit();
void expandBBoxBy(const BoundingBox&);
const BoundingBox& bbox() const;
friend ostream& operator<<(ostream&, const Turtle&);
private:
int forwardWithRespectToHull(real);
void bounce();
void applyTropism();
private:
BoundingBox b;
Vector P, lastP;
Vector H, L, U;
real width, lastWidth;
Tropism tropism;
Color color, lastColor;
rcString texture, lastTexture;
int hullActivated;
int stopOnHit;
Hull* hull;
real reflectanceFactor;
GeoObject* closestObject;
real distanceToClosestObject;
};
inline const Vector& Turtle::pos() const {
return P;
}
inline const Vector& Turtle::lastPos() const {
return lastP;
}
inline const Vector& Turtle::vecH() const {
return H;
}
inline const Vector& Turtle::vecL() const {
return L;
}
inline const Vector& Turtle::vecU() const {
return U;
}
inline void Turtle::setWidth(real wi) {
width = wi;
}
inline real Turtle::getWidth() const {
return width;
}
inline real Turtle::getLastWidth() const {
return lastWidth;
}
inline void Turtle::setLastWidth(real wi) {
lastWidth = wi;
}
inline void Turtle::setColor(const Color& c) {
color = c;
}
inline const Color& Turtle::getColor() const {
return color;
}
inline const Color& Turtle::getLastColor() const {
return lastColor;
}
inline void Turtle::setTexture(const rcString& t) {
texture = t;
}
inline const rcString& Turtle::getTexture() const {
return texture;
}
inline const rcString& Turtle::getLastTexture() const {
return lastTexture;
}
inline void Turtle::expandBBoxBy(const BoundingBox& bb) {
b.expand(bb);
}
inline const BoundingBox& Turtle::bbox() const {
return b;
}
inline void Turtle::setHull(Hull* h, real reflect) {
hullActivated = h->numPrimitives() > 0;
hull = h;
reflectanceFactor = (reflect < 0 || reflect > 1) ? 1 : reflect;
}
inline void Turtle::unsetHull() {
hullActivated = 0;
hull = NULL;
}
inline void Turtle::setStopOnHit() {
stopOnHit = 1;
}
inline void Turtle::unsetStopOnHit() {
stopOnHit = 0;
}
#endif // Turtle_H