00001 /* 00002 File: Avars.cc 00003 00004 Function: See header file 00005 00006 Author(s): Andrew Willmott 00007 00008 Copyright: (c) 1995-2000, Andrew Willmott 00009 00010 Notes: 'Avar' is defined in Scene.cc 00011 00012 */ 00013 00014 #include "gcl/Avars.h" 00015 #include "cl/CLConfig.h" 00016 00034 Void ReadAvar(Avar &a, istream &s); 00035 00036 00037 // --- Transformation avars --------------------------------------------------- 00038 00039 scAvarTransform::scAvarTransform(const Avar &avar, Vector vector) : 00040 scTransform(), 00041 avar(avar), 00042 listSlot(-1), 00043 vector(vector) 00044 { 00045 Recalc(); 00046 }; 00047 00048 Bool scAvarTransform::HasAvar(Avar &setAvar, Int slot) 00049 { 00050 setAvar = avar; 00051 listSlot = slot; 00052 00053 return(true); 00054 } 00055 00056 #ifdef UNFINISHED 00057 Bool scAvarTransform::HasAvar(Avar &setAvar, Int slot) 00058 { 00059 setAvar = avar; 00060 listSlot = slot; 00061 00062 return(true); 00063 } 00064 #endif 00065 00066 Void scAvarTransform::AddToContext(SLContext *context) 00067 { 00068 AvarList *avarList; 00069 GCLReal newValue; 00070 00071 if (avarList = SC_GET(AvarList)) 00072 { 00073 newValue = (*avarList)[listSlot].value; 00074 00075 if (newValue != avar.value) 00076 { 00077 avar.value = newValue; 00078 Recalc(); 00079 } 00080 } 00081 00082 scTransform::AddToContext(context); 00083 } 00084 00085 Void scAvarShift::Recalc() 00086 { 00087 (Transform &) SELF = Shift(vector * avar.value); 00088 } 00089 00090 Void scAvarShift::Print(ostream &s) const 00091 { 00092 s << "avar shift " << avar << " " << vector; 00093 } 00094 00095 Void ReadAvar(Avar &a, istream &s) 00096 { 00097 String *str = new String; 00098 Vector v; 00099 00100 str->ReadWord(s); 00101 a.name = str->Ref(); 00102 s >> v; 00103 a.lowerBound = v[0]; 00104 a.value = v[1]; 00105 a.upperBound = v[2]; 00106 } 00107 00108 Void scAvarShift::Parse(istream &s) 00109 { 00110 ReadAvar(avar, s); 00111 s >> vector; 00112 Recalc(); 00113 } 00114 00115 Void scAvarRotation::Recalc() 00116 { 00117 (scTransform &) SELF = Rotation(vector, avar.value * vl_pi); 00118 } 00119 00120 Void scAvarRotation::Print(ostream &s) const 00121 { 00122 s << "avar rotate " << avar << " " << vector; 00123 } 00124 00125 Void scAvarRotation::Parse(istream &s) 00126 { 00127 ReadAvar(avar, s); 00128 s >> vector; 00129 Recalc(); 00130 } 00131 00132 Void scAvarScale::Recalc() 00133 { 00134 Vector scale(vector); 00135 Int i; 00136 00137 for (i = 0; i < 3; i++) 00138 if (scale[i] == 0) 00139 scale[i] = 1; 00140 else 00141 scale[i] *= avar.value; 00142 00143 (Transform &) SELF = Scale(scale); 00144 } 00145 00146 Void scAvarScale::Print(ostream &s) const 00147 { 00148 s << "avar scale " << avar << " " << vector; 00149 } 00150 00151 Void scAvarScale::Parse(istream &s) 00152 { 00153 ReadAvar(avar, s); 00154 s >> vector; 00155 Recalc(); 00156 } 00157 00158 scAvarScalef::scAvarScalef(const Avar &avar) : 00159 scTransform(), 00160 avar(avar), 00161 listSlot(-1) 00162 { 00163 } 00164 00165 Void scAvarScalef::Recalc() 00166 { 00167 (Transform &) SELF = Scalef(avar.value); 00168 } 00169 00170 Bool scAvarScalef::HasAvar(Avar &setAvar, Int slot) 00171 { 00172 setAvar = avar; 00173 00174 listSlot = slot; 00175 00176 return(true); 00177 } 00178 00179 Void scAvarScalef::AddToContext(SLContext *context) 00180 { 00181 AvarList *avarList; 00182 00183 if (avarList = SC_GET(AvarList)) 00184 avar.value = (*avarList)[listSlot].value; 00185 00186 Recalc(); 00187 00188 scTransform::AddToContext(context); 00189 } 00190 00191 Void scAvarScalef::Print(ostream &s) const 00192 { 00193 s << "avar scalef " << avar; 00194 } 00195 00196 Void scAvarScalef::Parse(istream &s) 00197 { 00198 ReadAvar(avar, s); 00199 Recalc(); 00200 } 00201 00202 00203 // --- Colour avar ------------------------------------------------------------ 00204 00205 00206 scAvarColour::scAvarColour(const Avar &avar, Colour colour) : 00207 scColour(), 00208 avar(avar), 00209 listSlot(-1), 00210 colour(colour) 00211 { 00212 } 00213 00214 Void scAvarColour::Recalc() 00215 { 00216 (Colour &) SELF = colour * avar.value; 00217 } 00218 00219 Bool scAvarColour::HasAvar(Avar &setAvar, Int slot) 00220 { 00221 setAvar = avar; 00222 00223 listSlot = slot; 00224 00225 return(true); 00226 } 00227 00228 Void scAvarColour::AddToContext(SLContext *context) 00229 { 00230 AvarList *avarList; 00231 00232 if (avarList = SC_GET(AvarList)) 00233 avar.value = (*avarList)[listSlot].value; 00234 00235 Recalc(); 00236 00237 scColour::AddToContext(context); 00238 } 00239 00240 Void scAvarColour::Print(ostream &s) const 00241 { 00242 s << "avar colour " << avar << " " << colour; 00243 } 00244 00245 Void scAvarColour::Parse(istream &s) 00246 { 00247 ReadAvar(avar, s); 00248 s >> colour; 00249 Recalc(); 00250 } 00251 00252 00253 // --- Emittance avar --------------------------------------------------------- 00254 00255 00256 scAvarEmittance::scAvarEmittance(const Avar &avar, Colour colour) : 00257 scEmittance(), 00258 avar(avar), 00259 listSlot(-1), 00260 colour(colour) 00261 { 00262 } 00263 00264 Void scAvarEmittance::Recalc() 00265 { 00266 (Colour &) SELF = colour * avar.value; 00267 } 00268 00269 Bool scAvarEmittance::HasAvar(Avar &setAvar, Int slot) 00270 { 00271 setAvar = avar; 00272 00273 listSlot = slot; 00274 00275 return(true); 00276 } 00277 00278 Void scAvarEmittance::AddToContext(SLContext *context) 00279 { 00280 AvarList *avarList; 00281 00282 if (avarList = SC_GET(AvarList)) 00283 avar.value = (*avarList)[listSlot].value; 00284 00285 Recalc(); 00286 00287 scEmittance::AddToContext(context); 00288 } 00289 00290 Void scAvarEmittance::Print(ostream &s) const 00291 { 00292 s << "avar emittance " << avar << " " << colour; 00293 } 00294 00295 Void scAvarEmittance::Parse(istream &s) 00296 { 00297 ReadAvar(avar, s); 00298 s >> colour; 00299 Recalc(); 00300 } 00301 00302 00303 // --- Emittance avar --------------------------------------------------------- 00304 00305 00306 scAvarSwitch::scAvarSwitch(const Avar &avar) : 00307 scAttribute(aObjHide), 00308 avar(avar), 00309 listSlot(-1) 00310 { 00311 } 00312 00313 Bool scAvarSwitch::HasAvar(Avar &setAvar, Int slot) 00314 { 00315 setAvar = avar; 00316 00317 listSlot = slot; 00318 00319 return(true); 00320 } 00321 00322 Void scAvarSwitch::AddToContext(SLContext *context) 00323 { 00324 AvarList *avarList; 00325 00326 if (avarList = SC_GET(AvarList)) 00327 avar.value = (*avarList)[listSlot].value; 00328 00329 if (avar.value < 0.5) 00330 scAttribute::AddToContext(context); 00331 } 00332 00333 Void scAvarSwitch::Print(ostream &s) const 00334 { 00335 s << "avar switch " << avar; 00336 } 00337 00338 Void scAvarSwitch::Parse(istream &s) 00339 { 00340 ReadAvar(avar, s); 00341 } 00342 00343 00344 // --- scAvarList -------------------------------------------- 00345 00346 Void scAvarList::Print(ostream &s) const 00347 { 00348 // XXX 00349 // s << "avarList " << (AvarList &) SELF; 00350 } 00351 00352 Bool scAvarList::SetAvar(StrConst name, GCLReal value) 00353 { 00354 Int i; 00355 00356 for (i = 0; i < NumItems(); i++) 00357 if (Item(i).name == name) 00358 { 00359 Item(i).value = value; 00360 return(true); 00361 } 00362 return(false); 00363 } 00364 00365 #ifdef UNFINISHED 00366 Int scAvarList::AddAvar(StrConst name, Int numElts) 00367 { 00368 00369 } 00370 #endif 00371 00372 00373 // --- Action to build avar list ---------------------------------------------- 00374 00375 00376 Void CreateAvarList::Start() 00377 { 00378 scSceneAction::Start(); 00379 delete avarList; 00380 avarList = new scAvarList; 00381 } 00382 00383 Void CreateAvarList::Attribute(scAttribute *sa) 00384 { 00385 scSceneAction::Attribute(sa); 00386 if (sa->HasAvar(newAvar, avarList->NumItems())) 00387 avarList->Append(newAvar); 00388 } 00389 00390 #ifdef CL_TMPL_INST 00391 template class Array<Avar>; 00392 #endif