00001 /* 00002 File: Avars.h 00003 00004 Function: Provides avar-controlled scene objects, and methods 00005 for extracting a list of avars from the current scene. 00006 00007 Author(s): Andrew Willmott 00008 00009 Copyright: (c) 1995-2000, Andrew Willmott 00010 */ 00011 00012 #ifndef __Avars__ 00013 #define __Avars__ 00014 00015 #include "gcl/SceneObjects.h" 00016 #include "cl/NArray.h" 00017 00018 // --- Avar class ------------------------------------------------------------- 00019 00020 class Avar 00021 { 00022 public: 00023 Avar() 00024 {}; 00025 Avar( 00026 StrConst name, 00027 GCLReal value = 0.0, 00028 GCLReal lowerBound = 0.0, 00029 GCLReal upperBound = 1.0 00030 ) : 00031 name(name), value(value), 00032 lowerBound(lowerBound), upperBound(upperBound) {}; 00033 00034 StrConst name; // Avar's name 00035 GCLReal value; // its value 00036 GCLReal lowerBound; // its range 00037 GCLReal upperBound; 00038 }; 00039 00040 ostream &operator << (ostream &s, const Avar &avar); 00041 00042 typedef NArray<Avar> AvarList; 00043 00044 class scAvarList : public scAttribute, public AvarList 00045 { 00046 public: 00047 scAvarList() : scAttribute(aAvarList), AvarList() {}; 00048 00049 Void Print(ostream &s) const; 00050 Object *Clone() const { return new scAvarList(SELF); }; 00051 00052 Bool SetAvar(StrConst name, GCLReal value); 00053 // Void AddAvar(StrConst name); 00054 00055 // IntHash avarNames; 00056 }; 00057 00058 class CreateAvarList: public scSceneAction 00059 { 00060 public: 00061 CreateAvarList() : scSceneAction(), avarList(0) {}; 00062 00063 Void Start(); 00064 Void Attribute(scAttribute *sa); 00065 00066 scAvarList *avarList; 00067 Avar newAvar; 00068 }; 00069 00070 // --- Avar-capable attributes ------------------------------------------------- 00071 00072 class scAvarColour : public scColour 00073 { 00074 public: 00075 scAvarColour(const Avar &avar, Colour colour); 00076 00077 Bool HasAvar(Avar &avar, Int slot); 00078 Void AddToContext(SLContext *context); 00079 Void Print(ostream &s) const; 00080 Void Parse(istream &s); 00081 00082 virtual Void Recalc(); 00083 Object *Clone() const { return new scAvarColour(SELF); }; 00084 00085 Avar avar; 00086 Colour colour; 00087 Int listSlot; 00088 }; 00089 00090 class scAvarEmittance : public scEmittance 00091 { 00092 public: 00093 scAvarEmittance(const Avar &avar, Colour colour); 00094 00095 Bool HasAvar(Avar &avar, Int slot); 00096 Void AddToContext(SLContext *context); 00097 Void Print(ostream &s) const; 00098 Void Parse(istream &s); 00099 00100 virtual Void Recalc(); 00101 Object *Clone() const { return new scAvarEmittance(SELF); }; 00102 00103 Avar avar; 00104 Colour colour; 00105 Int listSlot; 00106 }; 00107 00108 class scAvarScalef : public scTransform 00109 { 00110 public: 00111 scAvarScalef(const Avar &avar); 00112 00113 Bool HasAvar(Avar &avar, Int slot); 00114 Void AddToContext(SLContext *context); 00115 Void Print(ostream &s) const; 00116 Void Parse(istream &s); 00117 00118 virtual Void Recalc(); 00119 Object *Clone() const { return new scAvarScalef(SELF); }; 00120 00121 Avar avar; 00122 Int listSlot; 00123 }; 00124 00125 class scAvarTransform : public scTransform 00126 { 00127 public: 00128 scAvarTransform(const Avar &avar, Vector vector); 00129 00130 Bool HasAvar(Avar &avar, Int slot); 00131 Void AddToContext(SLContext *context); 00132 00133 virtual Void Recalc() {}; 00134 Object *Clone() const { return new scAvarTransform(SELF); }; 00135 00136 Avar avar; 00137 Vector vector; 00138 Int listSlot; 00139 }; 00140 00141 class scAvarShift : public scAvarTransform 00142 { 00143 public: 00144 scAvarShift(const Avar &avar, Vector vector) : scAvarTransform(avar, vector) { Recalc();}; 00145 Void Recalc(); 00146 Void Print(ostream &s) const; 00147 Void Parse(istream &s); 00148 Object *Clone() const { return new scAvarShift(SELF); }; 00149 }; 00150 00151 class scAvarRotation : public scAvarTransform 00152 { 00153 public: 00154 scAvarRotation(const Avar &avar, Vector vector) : scAvarTransform(avar, vector) { Recalc();}; 00155 Void Recalc(); 00156 Void Print(ostream &s) const; 00157 Void Parse(istream &s); 00158 Object *Clone() const { return new scAvarRotation(SELF); }; 00159 }; 00160 00161 class scAvarScale : public scAvarTransform 00162 { 00163 public: 00164 scAvarScale(const Avar &avar, Vector vector) : scAvarTransform(avar, vector) { Recalc();}; 00165 Void Recalc(); 00166 Void Print(ostream &s) const; 00167 Void Parse(istream &s); 00168 Object *Clone() const { return new scAvarScale(SELF); }; 00169 }; 00170 00171 class scAvarSwitch : public scAttribute 00172 { 00173 public: 00174 scAvarSwitch(const Avar &avar); 00175 00176 Bool HasAvar(Avar &avar, Int slot); 00177 Void AddToContext(SLContext *context); 00178 Void Print(ostream &s) const; 00179 Void Parse(istream &s); 00180 00181 Object *Clone() const { return new scAvarSwitch(SELF); }; 00182 00183 Avar avar; 00184 Int listSlot; 00185 }; 00186 00187 #endif