//Portal 03may07 GF 06jun07 add dawn and 11jun07 in szg-1.1 //szgLorenz... by Kurtis Blank, Geronimo Caldwell //and Stan Blank Wayne City High School February 2003 //Based on szgDemos avn, atlantis, etc. //With special thanks to Ben Schaeffer and //George Francis for their suggestions and //inspiration. //Instructions: //From keyboard mode 5 in wandsimserver // 1) Left mouse button... rotations // 2) Middle mouse button... change number of spheres // 3) Right mouse button... Toggle trails and trail width // 4) Left and Middle buttons... Toggle between Lorenz and modified Lorenz // 5) Left and Right buttons... Reset the simulation // 6) Middle and Right buttons... toggle the sim speed through 2-3 presets //questions: sblank@accessus.net // precompiled header include MUST appear as the first non-comment line #include "arPrecompiled.h" #include "arMasterSlaveFramework.h" #include //gkf 11jun07 #include "dawn.c" arMasterSlaveFramework* framework; arMatrix4 worldMatrix; //initial number of spheres = minspheres //30 is a good number. Maxspheres is the maximum //number of spheres. How fast is your machine? GLuint maxspheres = 120; GLuint minspheres = 30; //Array initialization should be 3 x maxspheres GLint colors[360]; //the first parameter/3 = number of spheres //the second parameter = number of trail segments GLfloat trails[360][120]; GLuint flag; GLuint theCount; //numdots = number of trail segments GLuint numdots = 120; GLfloat wid = 0.5; GLuint howmany = maxspheres*3; GLuint displayhowmany = minspheres*3; GLuint n; GLuint lorenz = 1 ; GLint addtrails = 1; GLint but1, but2, but3; //Time increment... make larger on slower machines GLfloat dt = .004; GLfloat dtemp = dt; // (a,b,c) = center of sphere in Cartesian space GLfloat a; GLfloat b; GLfloat c; //for trails GLfloat ta; GLfloat tb; GLfloat tc; //Lighting stuff GLfloat whiteLight[] = {0.5f, 0.5f, 0.5f, 1.0f}; GLfloat sourceLight[]= {0.8f, 0.8f, 0.8f, 1.0f}; GLfloat lightPos[] = {1.0f, 1.0f, 1.0f, 0.0f}; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 128.0 }; GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; void SetupLorenz() { GLuint i,n; GLfloat zpos = 23.999f; GLfloat coordinat; GLint red = 255; GLint green = 0; GLint blue = 0; //Sets up howmany/3 spheres, slightly //varying the z position of each sphere n=0; for(i=0;i trails[i][0]=coordinat; } //Very kludgy but workable way to vary //sphere colors to approximate a visible spectrum //Will automatically adjust with the "howmany" variable for(i=0;ihowmany/10&&i<=2*(howmany/10)){ red=255; green=128; blue=0; } else if(2*(howmany/10)&&i<=3*(howmany/10)){ red=255; green=255; blue=0;} else if(3*(howmany/10)&&i<=4*(howmany/10)){ red=128; green=255; blue=0;} else if(4*(howmany/10)&&i<=5*(howmany/10)){ red=0; green=255; blue=0;} else if(5*(howmany/10)&&i<=6*(howmany/10)){ red=0; green=255; blue= 128;} else if(6*(howmany/10)&&i<=7*(howmany/10)){ red=0; green=128; blue=255;} else if(7*(howmany/10)&&i<=8*(howmany/10)){ red=0; green=0; blue=255;} else if(8*(howmany/10)&&i<=9*(howmany/10)){ red=128; green=0; blue=255;} else{ red=255; green=0; blue=255;} //assign colors to proper location in colors array colors[i] = red; colors[i+1] = green; colors[i+2] = blue; } } void draw(){ //Let's calculate the Lorenz thingy for(n=0;n numdots-1) flag = numdots-1; } else{ flag = 0; } } //Important variables and arrays to transfer //to the other workstations bool init(arMasterSlaveFramework&, arSZGClient&){ ar_setNavMatrix(ar_translationMatrix(0,0,60)); framework->addTransferField("worldRotation",worldMatrix.v,AR_FLOAT,16); framework->addTransferField("colors",colors,AR_INT,maxspheres*3); framework->addTransferField("trails",trails,AR_FLOAT,maxspheres*3*numdots); framework->addTransferField("displayhowmany",&displayhowmany,AR_INT,1); framework->addTransferField("dt",&dt,AR_FLOAT,1); framework->addTransferField("addtrails",&addtrails,AR_INT,1); framework->addTransferField("wid",&wid,AR_FLOAT,1); framework->addTransferField("flag",&flag,AR_INT,1); framework->addTransferField("lorenz",&lorenz,AR_INT,1); return true; } //Common syzygy stuff void preExchange(arMasterSlaveFramework&){ if (!framework->getMaster()) return; double timeDelta = framework->getLastFrameTime()/1000.0; arMatrix4 wandMatrix = framework->getMatrix(1); arVector3 wandDirection = ar_vectorToNavCoords( ar_extractRotationMatrix(framework->getMatrix(1)) * arVector3(0,0,-1)); if (framework->getAxis(1) > 0.5) wandDirection *= 10. * timeDelta; else if (framework->getAxis(1) < -0.5) wandDirection *= -10. * timeDelta; else wandDirection *= 0.; ar_navTranslate(wandDirection); //get the buttons! //This works in mode 4 and 5 (4 or 5 on keyboard) //in wandsimserver but1 = framework -> getButton(0); but2 = framework -> getButton(1); but3 = framework -> getButton(2); static bool grabState = false; static arMatrix4 grabMatrix; static bool trailstatus = false; static bool attractor = false; static bool twobuttons = false; static bool resetlorenz = false; static bool changenum = false; //speed up routine using buttons 1 and 3 if(but2 && but3 && !twobuttons){ twobuttons = true; } if(!but2 && !but3 && twobuttons){ twobuttons = false; dt*=1.8; if(dt>.018) dt=dtemp; dt*=1.8; if(dt>.018) dt=dtemp; } //Reset the attractor if(but1 && but3 && !resetlorenz){ resetlorenz = true; } if(!but1 && !but3 && resetlorenz){ resetlorenz = false; flag=0; SetupLorenz(); } //change attractors using buttons 1 and 2 if(but1 && but2 && !attractor){ attractor = true; } if(!but1 && !but2 && attractor) { attractor = false; lorenz = -1*lorenz; } //Rotate the attractor using mode 5 and button 1 if(but1 && !grabState){ grabState = true; grabMatrix = !worldMatrix * ar_extractRotationMatrix(wandMatrix); } else if (but1 && grabState) { worldMatrix = ar_extractRotationMatrix(wandMatrix) * !grabMatrix; } else if (!but1 && grabState){ grabState = false; } //increment the number of spheres using button 2 //by 30 each time to a max of howmany/3 if(but2 && !changenum && !attractor && !twobuttons){ changenum = true; } if(!but2 && changenum){ changenum = false; flag = 0; displayhowmany += minspheres*3; dt*=1.2; if(displayhowmany>maxspheres*3){ displayhowmany=minspheres*3; dt=dtemp; } printf ("# spheres = %d\n",displayhowmany/3); } //Toggle the trails on and off and //change the trail line width with button 3 if(but3 && !trailstatus && !twobuttons && !resetlorenz){ trailstatus = true; } if(!but3 && trailstatus){ trailstatus = false; addtrails = -1 * addtrails; if(addtrails==-1){ dt = dt/1.5;} else{ dt*=1.5;} if(addtrails==1){ wid+=1;} if(wid>3){ wid=0.5;} } //calculate positions for(n=0;ninit(argc, argv)) return 1; // framework->setInitCallback(init); framework->setStartCallback(init); framework->setPreExchangeCallback(preExchange); framework->setDrawCallback(drawCallback); framework->setPostExchangeCallback(postExchange); return framework->start() ? 0 : 1; }