00001 /* 00002 File: TestScene.cc 00003 00004 Function: See header file 00005 00006 Author(s): Andrew Willmott 00007 00008 Copyright: (c) 1997-2000, Andrew Willmott 00009 00010 Notes: 00011 00012 */ 00013 00014 #include "TestScene.h" 00015 00016 #include "gcl/SceneLang.h" 00017 #include "gcl/Avars.h" 00018 #include "gcl/Writers.h" 00019 00020 //#define RAD_TEX_HACK 00021 00022 Void SaveTestModels(FileName &name) 00023 { 00024 name.SetFile("box"); 00025 SceneWriter::Save(BoxScene(), name); 00026 name.SetFile("box-tetra"); 00027 SceneWriter::Save(BoxScene(1), name); 00028 name.SetFile("parallel"); 00029 SceneWriter::Save(ParallelScene(), name); 00030 name.SetFile("blocker"); 00031 SceneWriter::Save(BlockerScene(), name); 00032 // ... 00033 } 00034 00035 Int gQuadType = 0; 00036 00037 static Void SideWall() 00038 { 00039 slPointList(); 00040 slPoint(Point(-1, -1, -1)); 00041 slPoint(Point( 1, -1, -1)); 00042 slPoint(Point( 1, -1, 1)); 00043 slPoint(Point(-1, -1, 1)); 00044 } 00045 00046 static Void CreateMyCube() 00047 { 00048 if (slObjectExists("myCube")) return; 00049 slAddToLibrary(slBeginObject("myCube")); 00050 00051 SideWall(); 00052 slPoly(); 00053 00054 SideWall(); 00055 slApply(Rotation(vl_z, -vl_halfPi)); 00056 slPoly(); 00057 00058 SideWall(); 00059 slApply(Rotation(vl_z, vl_halfPi)); 00060 slPoly(); 00061 00062 SideWall(); 00063 slApply(Rotation(vl_z, vl_pi)); 00064 slPoly(); 00065 00066 SideWall(); 00067 slApply(Rotation(vl_x, -vl_halfPi)); 00068 slPoly(); 00069 00070 SideWall(); 00071 slApply(Rotation(vl_x, vl_halfPi)); 00072 slPoly(); 00073 00074 slEndObject(); 00075 } 00076 00077 static Void Table() 00078 { 00079 scPrimitive *leg; 00080 00081 if (slObjectExists("table")) return; 00082 00083 CreateMyCube(); 00084 slAddToLibrary(slBeginObject("table")); 00085 00086 slObject("myCube"); 00087 slApply(Scale(Vector(1, 0.05, 1))); 00088 slApply(Shift(Vector(0, 1.95, 0))); 00089 00090 leg = slObject("myCube"); 00091 slApply(Scale(Vector(0.15, 0.95, 0.15))); 00092 slApply(Shift(Vector(0.85, 0.95, 0.85))); 00093 00094 slObject(Clone(leg)); 00095 slApply(Rotation(vl_y, vl_halfPi)); 00096 00097 slObject(Clone(leg)); 00098 slApply(Rotation(vl_y, 2 * vl_halfPi)); 00099 00100 slObject(Clone(leg)); 00101 slApply(Rotation(vl_y, 3 * vl_halfPi)); 00102 00103 slEndObject(); 00104 } 00105 00106 static Void CreateWall() 00107 { 00108 // A 2x2 square centered in the x-z plane, at y=-1. 00109 if (slObjectExists("wall")) return; 00110 00111 slAddToLibrary(slBeginObject("wall")); 00112 slPointList(); 00113 slPoint(Point(-1, -1, 1)); 00114 slPoint(Point( 1, -1, 1)); 00115 slPoint(Point( 1, -1, -1)); 00116 slPoint(Point(-1, -1, -1)); 00117 if (gQuadType == 2) 00118 slPoint(Point(0, -1, 0)); 00119 00120 switch (gQuadType) 00121 { 00122 case 0: 00123 slPoly(); 00124 break; 00125 case 1: 00126 slPointIndexes(Indexes(0, 1, 2, IDX_END)); 00127 slPoly(); 00128 slPointIndexes(Indexes(2, 3, 0, IDX_END)); 00129 slPoly(); 00130 break; 00131 case 2: 00132 slPointIndexes(Indexes(0, 1, 4, IDX_END)); 00133 slPoly(); 00134 slPointIndexes(Indexes(1, 2, 4, IDX_END)); 00135 slPoly(); 00136 slPointIndexes(Indexes(2, 3, 4, IDX_END)); 00137 slPoly(); 00138 slPointIndexes(Indexes(3, 0, 4, IDX_END)); 00139 slPoly(); 00140 } 00141 00142 slEndObject(); 00143 } 00144 00145 scScenePtr BoxScene(Int centrepiece) 00146 { 00147 scScenePtr result; 00148 00149 CreateWall(); 00150 result = slBeginObject("box"); 00151 slBeginObject("light"); 00152 slColour(cBlack); 00153 00154 slAttribute(new scAvarEmittance(Avar("light", 20, 5, 50), cWhite)); 00155 slAttribute(new scAvarShift(Avar("height", -0.1, 0.5, -1.9), vl_y)); 00156 slAttribute(new scAvarShift(Avar("shift", 0, -1, 1), vl_z)); 00157 slAttribute(new scAvarRotation(Avar("rotate", 0.0, -1, 1), vl_x)); 00158 slAttribute(new scAvarRotation(Avar("roll", 0.0, -1, 1), vl_z)); 00159 slAttribute(new scAvarScale(Avar("size", 1, 0.1, 2), Vector(0.3, 0, 0.3))); 00160 slTransform(Rotation(vl_x, vl_pi)); 00161 slObject("wall"); 00162 slEndObject(); 00163 00164 #ifdef RAD_TEX_HACK 00165 slCoord(Coord(0, 1)); 00166 slCoord(Coord(0, 0)); 00167 slCoord(Coord(1, 0)); 00168 slCoord(Coord(1, 1)); 00169 slTexture("$TEXTURES/grey.tif"); 00170 #endif 00171 00172 slAttribute(new scAvarColour(Avar("floor", 0.8, 0.0, 1.0), cWhite)); 00173 slObject("wall"); 00174 00175 slAttribute(new scAvarColour(Avar("rwall", 0.8, 0.0, 1.0), 00176 RGBCol(1.0, 0.2, 0.2))); 00177 slObject("wall"); 00178 slApply(Rotation(vl_z, -vl_halfPi)); 00179 00180 #ifdef RAD_TEX_HACK 00181 slTexture("$TEXTURES/curves.tif"); 00182 #endif 00183 00184 slAttribute(new scAvarColour(Avar("bwall", 0.8, 0.0, 1), 00185 RGBCol(0.2, 0.2, 1.0))); 00186 slObject("wall"); 00187 slApply(Rotation(vl_z, vl_halfPi)); 00188 00189 slAttribute(new scAvarColour(Avar("wwall", 0.8, 0.0, 1), 00190 cWhite)); 00191 slObject("wall"); 00192 slApply(Rotation(vl_x, vl_halfPi)); 00193 00194 if (centrepiece == 1) 00195 { 00196 slAttribute(new scAvarRotation(Avar("tetra_rotate_y", 0.0, -1, 1), vl_y)); 00197 slAttribute(new scAvarRotation(Avar("tetra_rotate_z", 0.0, -1, 1), vl_z)); 00198 slColour(HSVCol(200, 0.5, 1)); 00199 slObject("tetrahedron"); 00200 slApply(Rotation(vl_y, (35.0 / 180.0) * vl_pi)); 00201 slApply(Shift(Vector(0, -0.5, 0))); 00202 } 00203 00204 if (centrepiece == 2) 00205 { 00206 slBeginObject("tri"); 00207 slColour(HSVCol(300, 0.5, 0.6)); 00208 slAttribute(new scAvarShift(Avar("tri_height", 1, 0, 2), vl_y)); 00209 slPointList(); 00210 slPoint(Point(-1, -1, 1)); 00211 slPoint(Point( 1, -1, 1)); 00212 slPoint(Point( 1, -1, -1)); 00213 slPoly(); 00214 slEndObject(); 00215 slApply(Rotation(vl_y, (35.0 / 180.0) * vl_pi)); 00216 slApply(Scale(Vector(0.3, 1, 0.3))); 00217 } 00218 00219 slEndObject(); 00220 00221 return(result); 00222 } 00223 00224 scScenePtr ParallelScene() 00225 // Parallel 00226 { 00227 scScenePtr result; 00228 00229 CreateWall(); 00230 result = slBeginObject("parallel"); 00231 slBeginObject("light"); 00232 slColour(cBlack); 00233 00234 slAttribute(new scAvarEmittance(Avar("light", 20, 5, 50), cWhite)); 00235 slAttribute(new scAvarShift(Avar("height", 0.0, 0.0, -2.0), vl_y)); 00236 slAttribute(new scAvarShift(Avar("shift", 0, -1, 1), vl_z)); 00237 slAttribute(new scAvarRotation(Avar("rotate", 0.0, -1, 1), vl_x)); 00238 slAttribute(new scAvarRotation(Avar("roll", 0.0, -1, 1), vl_z)); 00239 slAttribute(new scAvarScale(Avar("size", 1, 0.1, 2), Vector(0.3, 0, 0.3))); 00240 00241 slTransform(Rotation(vl_x, vl_pi)); 00242 slObject("wall"); 00243 slEndObject(); 00244 00245 slColour(0.5 * HSVCol(0, 0, 0.8)); 00246 slObject("wall"); 00247 slEndObject(); 00248 00249 return(result); 00250 } 00251 00252 scScenePtr SidelightScene() 00253 { 00254 scScenePtr result; 00255 00256 CreateWall(); 00257 result = slBeginObject("sidelight"); 00258 slBeginObject("light"); 00259 slColour(cBlack); 00260 00261 slAttribute(new scAvarEmittance(Avar("light", 20, 5, 50), cWhite)); 00262 slAttribute(new scAvarShift(Avar("height", -0.5, 1.5, -0.5), vl_y)); 00263 slAttribute(new scAvarShift(Avar("shift", 0, -1, 1), vl_z)); 00264 slAttribute(new scAvarRotation(Avar("rotate", 0.0, -1, 1), vl_x)); 00265 slAttribute(new scAvarRotation(Avar("roll", 0.0, -1, 1), vl_z)); 00266 slAttribute(new scAvarScale(Avar("size", 1, 0.1, 2), 00267 Vector(1.0, 1.0, 0.0))); 00268 00269 slObject("wall"); 00270 slApply(Rotation(vl_x, vl_pi / 2)); 00271 slApply(Scale(0.5, 0.5, 1.0)); 00272 slEndObject(); 00273 00274 #ifdef RAD_TEX_HACK 00275 slCoord(Coord(0, 1)); 00276 slCoord(Coord(0, 0)); 00277 slCoord(Coord(1, 0)); 00278 slCoord(Coord(1, 1)); 00279 slTexture("$TEXTURES/grey.tif"); 00280 #endif 00281 00282 slColour(0.5 * HSVCol(0, 0, 0.8)); 00283 slObject("wall"); 00284 slEndObject(); 00285 00286 return(result); 00287 } 00288 00289 scScenePtr BlockerScene() 00290 { 00291 scScenePtr result; 00292 00293 CreateWall(); 00294 result = slBeginObject("blocker"); 00295 slBeginObject("light"); 00296 slColour(cBlack); 00297 00298 slAttribute(new scAvarEmittance(Avar("light_strength", 20, 5, 50), 00299 cWhite)); 00300 slAttribute(new scAvarShift(Avar("light_height", 0.0, 1.5, -0.9), vl_y)); 00301 slAttribute(new scAvarShift(Avar("light_z", 0, -1, 1), vl_z)); 00302 slAttribute(new scAvarScale(Avar("light_size", 1, 0.1, 2), 00303 Vector(0.3, 0, 0.3))); 00304 00305 slAttribute(new scAvarRotation(Avar("light_spin", 0.0, -1, 1), vl_y)); 00306 slTransform(Rotation(vl_x, vl_pi)); 00307 slObject("wall"); 00308 slEndObject(); 00309 00310 slColour(HSVCol(0, 0, 0.5)); 00311 slObject("wall"); 00312 00313 slAttribute(new scAvarRotation(Avar("blocker_spin", 0.0, -1, 1), vl_y)); 00314 slAttribute(new scAvarShift(Avar("blocker_height", 1, 0, 2), vl_y)); 00315 slAttribute(new scAvarScale(Avar("blocker_size", 1, 0.1, 2), 00316 Vector(0.2, 0, 0.2))); 00317 00318 slColour(HSVCol(0, 0.5, 0.5)); 00319 slObject("wall"); 00320 slEndObject(); 00321 00322 return(result); 00323 } 00324 00325 scScenePtr AbuttingScene() 00326 { 00327 scScenePtr result; 00328 00329 result = slBeginObject("abutting"); 00330 00331 slBeginObject("light"); 00332 slColour(cBlack); 00333 00334 slAttribute(new scAvarEmittance(Avar("light", 20, 5, 50), cWhite)); 00335 00336 slAttribute(new scAvarShift(Avar("height", 0.9, 1.5, -0.9), vl_y)); 00337 slAttribute(new scAvarShift(Avar("shift", 0, -1, 1), vl_z)); 00338 slAttribute(new scAvarRotation(Avar("rotate", 0.0, -1, 1), vl_x)); 00339 slAttribute(new scAvarRotation(Avar("roll", 0.0, -1, 1), vl_z)); 00340 slAttribute(new scAvarScale(Avar("size", 1, 0.1, 2), Vector(0.3, 0, 0.3))); 00341 00342 slTransform(Rotation(vl_x, vl_pi)); 00343 slPointList(); 00344 slPoint(Point(-1, 0, 1)); 00345 slPoint(Point( 1, 0, 1)); 00346 slPoint(Point( 1, 0, -1)); 00347 slPoint(Point(-1, 0, -1)); 00348 00349 slPoly(); 00350 slEndObject(); 00351 00352 slAttribute(new scAvarColour(Avar("wall_refl", 0.9, 0.0, 1), cWhite)); 00353 slObject("wall"); 00354 slObject("wall"); 00355 slApply(Rotation(vl_x, vl_halfPi)); 00356 00357 slEndObject(); 00358 00359 return(result); 00360 } 00361 00362 scScenePtr TableScene() 00363 { 00364 scScenePtr result; 00365 00366 Table(); 00367 result = slBeginObject("table_scene"); 00368 slBeginObject("light"); 00369 slColour(cBlack); 00370 00371 slAttribute(new scAvarEmittance(Avar("lights", 20, 5, 50), cWhite)); 00372 00373 // three lights in a row 00374 slTransform(Shift(0.0, 0.0, -0.6)); 00375 slTransform(Scale(Vector(0.2, 1.0, 0.2))); 00376 slTransform(Rotation(vl_x, vl_pi)); 00377 slObject("wall"); 00378 slObject("wall"); 00379 slApply(Shift(Vector(-6.0, 0.0, 0.0))); 00380 slObject("wall"); 00381 slApply(Shift(Vector(6.0, 0.0, 0.0))); 00382 slEndObject(); 00383 00384 // floor 00385 slColour(0.8 * cWhite); 00386 slObject("wall"); 00387 slApply(Scale(2.0, 1.0, 1.0)); 00388 00389 slColour(cBlue * 0.8); 00390 slObject("wall"); 00391 slApply(Rotation(vl_z, -vl_halfPi)); 00392 slApply(Shift(Vector(-1.0, 0.0, 0.0))); 00393 00394 slColour(cYellow * 0.8); 00395 slObject("wall"); 00396 slApply(Scale(2.0, 1.0, 1.0)); 00397 slApply(Rotation(vl_x, vl_halfPi)); 00398 00399 slBeginObject("scene table"); 00400 slAttribute(new scAvarShift(Avar("shift_table", 0.8, -1, 1), 00401 Vector(-0.5, 0.0, -0.5))); 00402 slAttribute(new scAvarRotation(Avar("rotate_table", 0.2), vl_y)); 00403 slAttribute(new scAvarScale(Avar("scale_table", 0.5), Vector(2, 0, 2))); 00404 slColour(HSVCol(100, 0.5, 0.5)); 00405 slObject("table"); 00406 slApply(Scalef(0.25)); 00407 slApply(Shift(Vector(0, -1.0, 0))); 00408 slEndObject(); 00409 00410 slEndObject(); 00411 00412 return(result); 00413 } 00414 00415 scScenePtr SimpleTriScene() 00416 { 00417 scScenePtr result; 00418 00419 slAddToLibrary(slBeginObject("tri")); 00420 slPointList(); 00421 slPoint(Point(-1, -1, 1)); 00422 slPoint(Point( 1, -1, 1)); 00423 slPoint(Point( 1, -1, -1)); 00424 slPoly(); 00425 slEndObject(); 00426 00427 result = slBeginObject("simple_tri"); 00428 00429 slBeginObject("light"); 00430 slColour(cBlack); 00431 00432 slAttribute(new scAvarEmittance(Avar("light", 20, 5, 50), cWhite)); 00433 00434 slAttribute(new scAvarShift(Avar("height", 0.9, 1.5, -0.9), vl_y)); 00435 slAttribute(new scAvarShift(Avar("shift", 0, -1, 1), vl_z)); 00436 slAttribute(new scAvarRotation(Avar("rotate", 0.0, -1, 1), vl_x)); 00437 slAttribute(new scAvarRotation(Avar("roll", 0.0, -1, 1), vl_z)); 00438 slAttribute(new scAvarScale(Avar("size", 1, 0.1, 2), Vector(0.3, 0, 0.3))); 00439 00440 slTransform(Rotation(vl_x, vl_pi)); 00441 slPointList(); 00442 slPoint(Point(-1, 0, 1)); 00443 slPoint(Point( 1, 0, 1)); 00444 slPoint(Point( 1, 0, -1)); 00445 slPoint(Point(-1, 0, -1)); 00446 00447 slPoly(); 00448 slEndObject(); 00449 00450 slColour(0.5 * HSVCol(0, 0, 0.8)); 00451 slObject("tri"); 00452 00453 slEndObject(); 00454 00455 return(result); 00456 }