Gizmo3D

materialDemo.cpp

Material and light example application. This example illustrates how material and lights cooperate. Keys are used to interact with the application and change material and light properties.
The source code can also be found in the examples directory of the Gizmo3D distribution.

00001 // *****************************************************************************
00002 // File         : materialDemo.cpp
00003 // Module       : 
00004 // Description  : Interactive material/light editor example
00005 // Author       : Lisa Johansson
00006 // Product      : Gizmo3D 2.1.1
00007 //              
00008 // Copyright © 2003- Saab Training Systems AB, Sweden
00009 //                      
00010 // NOTE:    Gizmo3D is a high performance 3D Scene Graph and effect visualisation 
00011 //          C++ toolkit for Linux, Mac OS X, Windows (Win32) and IRIX® for  
00012 //          usage in Game or VisSim development.
00013 //
00014 //
00015 // Revision History...                                                  
00016 //                                                                      
00017 // Who  Date    Description                                             
00018 //                                                                      
00019 // LJH  040505  Created file    
00020 //
00021 // ******************************************************************************
00022 
00023 #include "gzGizmo3DLibrary.h"   // Use this to include all Gizmo3D functionality
00024 
00025 // Let the class be a subclass to gzApplication
00026 // Gets an application with window management etc
00027 class myTestApp: public gzApplication, public gzInputInterface
00028 {
00029 public:
00030     //Routes operators new and delete to gzApplication class.
00031 
00032     myTestApp();
00033     virtual ~myTestApp();
00034     gzVoid Create();
00035     gzVoid onIdle();
00036     virtual gzBool onKey (gzKeyValue key, gzKeyState keystate, const gzLongXY &mousePos, const gzLongXY &centerMousePos);
00037 
00038 private:
00039     // Uses a smart pointer which automatically makes delete when necessary
00040     gzRefPointer<gzWindow> myWin;
00041     gzRefPointer<gzMaterial> myMat;
00042     gzFloat shininess;
00043 
00044     gzRefPointer<gzText>    myText;
00045     gzRefPointer<gzState>   myMaterialState;
00046     gzRefPointer<gzLight>   myLight;
00047 
00048     gzString mode;
00049     gzVec4 matAmb;
00050     gzVec4 matDif;
00051     gzVec4 matSpe;
00052     gzVec4 matEmi;
00053     gzVec4 ligAmb;
00054     gzVec4 ligDif;
00055     gzVec4 ligSpe;
00056 };
00057 
00058 myTestApp::myTestApp()      // Setup the initial values
00059 {
00060     shininess = 16.0f;
00061     mode = "Ambient material";
00062 
00063     matAmb.set(0.16f , 0.16f, 0.16f , 0.5f);
00064     matDif.set(0.8f, 0.1f, 0.1f, 0.5f);
00065     matSpe.set(1.0f, 1.0f, 1.0f,1.0f);
00066     matEmi.set(0 , 0, 0, 0.5);
00067 
00068     ligAmb.set(0.0f, 0.0f, 0.0f, 1.0f);
00069     ligDif.set(1.0f, 1.0f, 1.0f, 1.0f); 
00070     ligSpe.set(1.0f, 1.0f, 1.0f, 1.0f); 
00071 }
00072 
00073 myTestApp::~myTestApp()     // Since we use gzRefPointer we don't need to destroy the pointers
00074 {
00075 
00076 }
00077 
00078 // Creates the application
00079 gzVoid myTestApp::Create()
00080 {
00081     // necessary to get the debug output
00082     gzMessage::setMessageLevel(GZ_MESSAGE_DEBUG);
00083 
00084     // loads a model and saves is as a node
00085     gzNode *myModel = gzDbManager::loadDB("torus2.3DS");
00086     
00087     // cast the model to a transform
00088     gzTransform * myTrans = gzDynamic_Cast<gzTransform>(myModel);
00089     
00090     // if there is a transform it can be modified with scaling, rotation and translation
00091     if(myTrans)
00092     {
00093         myTrans -> unitScale();
00094         myTrans -> rotate(gzVec3(0, 0, 1), 75);
00095         myTrans -> rotate(gzVec3(0, 1, 0), 15);
00096         myTrans -> scale((gzReal)(10),(gzReal)(10),(gzReal)(10));
00097     }
00098 
00099     // creates a material. The effect is only visible when a light source is added
00100     myMat = new gzMaterial;
00101     myMat->setAmbient(matAmb);
00102     myMat->setSpecular(matSpe);
00103     myMat->setDiffuse(matDif);
00104     myMat->setEmission(matEmi);
00105     myMat->setShininess(shininess);
00106 
00107     // creates a state with material mode enabled
00108     myMaterialState = new gzState;
00109     myMaterialState -> setMode(GZ_STATE_MATERIAL, GZ_STATE_ON );
00110     myMaterialState -> setOverride(GZ_STATE_MATERIAL, GZ_STATE_ON); // Used to override model definitions of material
00111     myMaterialState -> setMaterial(myMat);
00112 
00113     // creates a transform with rotation and translation. Adds a child and sets a state
00114     myTrans -> setState(myMaterialState);
00115 
00116     // The scene needs some light
00117     myLight = new gzLight;
00118     myLight -> setPosition(10.0, 3.0, 50.0);
00119 
00120     // creates an environment which makes it possible to add lighting to the scene
00121     gzEnvironment *myEnv = new gzEnvironment;
00122     myEnv -> addLight(myLight);
00123     myEnv -> addNode(myTrans);
00124 
00125     gzScene *myScene = new gzScene;
00126     myScene -> addNode(myEnv);
00127 
00128     myText=new gzText("Screen Text");       // Handle to text used to write messages to window
00129     myText->setColor(gzVec4(1,1,0,0.5));
00130     myText->use2DPosition(TRUE);
00131     myText->set2DPosition(10, -10);
00132 
00133     myScene -> addNode(myText);
00134 
00135     // adding a camera with perspective projection. The position is set, the viewing direction is
00136     // against the lookAt-point. The camera is connected to a scene.
00137     gzCamera *myCam = new gzPerspCamera;
00138     myCam -> setPosition(0.0, 0.0, 100.0);
00139     myCam -> lookAt(0, 0, 0);
00140     myCam -> setScene(myScene);
00141 
00142     // a window is created which shows the image (from the camera) on the screen.
00143     myWin = new gzWindow ("Material Demo");
00144     myWin->setCamera(myCam);
00145 
00146     // add some basic user interaction to the scene
00147     gzSimpleMouseViewControl * input = new gzSimpleMouseViewControl( myCam );
00148     myWin -> addInputInterface( input );
00149 
00150     // add our own keyboard input manager
00151     myWin -> addInputInterface( this );
00152 
00153     // adds a logger which collects information
00154     gzLogger logger("material_debug.log");
00155 
00156     // print the scene information into a the "material_debug.log" file
00157     myScene -> debug();
00158 }
00159 
00160 // function that updates for every frame
00161 gzVoid myTestApp::onIdle()
00162 {
00163     gzString outputString;
00164 
00165     outputString = mode + gzString("\n\n");
00166     
00167     outputString += gzString("Material properties \n");
00168     outputString += gzString("Shininess: ") + gzString(shininess) + gzString("\n");
00169     outputString += gzString("Ambient reflection: ") + gzString(matAmb.v1, "%.2f") + gzString(", ") + gzString(matAmb.v2, "%.2f") + gzString(", ") + gzString(matAmb.v3, "%.2f") + gzString(", ") + gzString(matAmb.v4, "%.2f") + gzString("\n");
00170     outputString += gzString("Diffuse reflection: ") + gzString(matDif.v1, "%.2f") + gzString(", ") + gzString(matDif.v2, "%.2f") + gzString(", ") + gzString(matDif.v3, "%.2f") + gzString(", ") + gzString(matDif.v4, "%.2f") + gzString("\n");
00171     outputString += gzString("Specular reflection: ") + gzString(matSpe.v1, "%.2f") + gzString(", ") + gzString(matSpe.v2, "%.2f") + gzString(", ") + gzString(matSpe.v3, "%.2f") + gzString(", ") + gzString(matSpe.v4, "%.2f") + gzString("\n");
00172     outputString += gzString("Emission: ") + gzString(matEmi.v1, "%.2f") + gzString(", ") + gzString(matEmi.v2, "%.2f") + gzString(", ") + gzString(matEmi.v3, "%.2f") + gzString(", ") + gzString(matEmi.v4, "%.2f") + gzString("\n\n");
00173         
00174     outputString += gzString("Light properties \n");
00175     outputString += gzString("Ambient color: ") + gzString(ligAmb.v1, "%.2f") + gzString(", ") + gzString(ligAmb.v2, "%.2f") + gzString(", ") + gzString(ligAmb.v3, "%.2f") + gzString(", ") + gzString(ligAmb.v4, "%.2f") + gzString("\n");
00176     outputString += gzString("Diffuse color: ")+ gzString(ligDif.v1, "%.2f") + gzString(", ") + gzString(ligDif.v2, "%.2f") + gzString(", ") + gzString(ligDif.v3, "%.2f") + gzString(", ") + gzString(ligDif.v4, "%.2f") + gzString("\n");
00177     outputString += gzString("Specular color: ") + gzString(ligSpe.v1, "%.2f") + gzString(", ") + gzString(ligSpe.v2, "%.2f") + gzString(", ") + gzString(ligSpe.v3, "%.2f") + gzString(", ") + gzString(ligSpe.v4, "%.2f") + gzString("\n");
00178     
00179     myText -> setText(outputString);
00180 
00181     // Checks if any button is pressed
00182     myWin -> triggerKeyEvaluation();
00183 
00184     // updates the window
00185     myWin -> refreshWindow();
00186 }
00187 
00188 gzBool myTestApp::onKey(gzKeyValue key, gzKeyState keystate, const gzLongXY &mousePos, const gzLongXY &centerMousePos)
00189 {
00190     switch(key)
00191     {
00192         case GZ_KEY_ADD :
00193         {
00194             if (shininess < 128)
00195             {
00196                 shininess += 0.5f;
00197                 myMat->setShininess(shininess);
00198             }
00199         }
00200         break;
00201         
00202         case GZ_KEY_SUBTRACT :
00203         {
00204             if (shininess > 0)
00205             {
00206                 shininess-=0.5f;
00207                 myMat->setShininess(shininess);
00208             }
00209         }
00210         break;
00211         case ' ':   // Space pressed (Show graphics in wireframe mode)
00212         {
00213             if(keystate == GZ_KEY_STATE_PRESSED)
00214             {
00215                 gzState *state=new gzState;
00216 
00217                 state->setFrontPolygonMode(GZ_POLYGON_MODE_LINE);
00218                 state->setBackPolygonMode(GZ_POLYGON_MODE_LINE);
00219                 state->setMode(GZ_STATE_POLYGON_MODE,GZ_STATE_ON);
00220                 state->setOverride(GZ_STATE_POLYGON_MODE,GZ_STATE_ON);
00221                 state->setOverride(GZ_STATE_TEXTURE,GZ_STATE_OFF);
00222                 state->setMode(GZ_STATE_GENERATE_DEBUG_INFO,GZ_STATE_ON);
00223                 state->setDebugMode((gzStateDebugMode)(GZ_STATE_DEBUG_COLLECT_STATS));
00224                     
00225                 state->disableAllNonEnabledModes();
00226 
00227                 gzState::setGlobalState(myWin->getContext(),state);
00228             }
00229             if(keystate == GZ_KEY_STATE_RELEASED)
00230             {
00231                 gzState::setGlobalState(myWin->getContext(),myMaterialState);
00232             }
00233             break;
00234         }
00235         case 'c':   // c key pressed (toggle between modes)
00236         {
00237             if(keystate == GZ_KEY_STATE_PRESSED)
00238             {
00239                 if (mode=="Ambient material")
00240                     mode = "Diffuse material";
00241                 else if (mode=="Diffuse material")
00242                     mode = "Specular material";
00243                 else if (mode=="Specular material")
00244                     mode = "Material emission";
00245                 else if (mode=="Material emission")
00246                     mode = "Ambient light";
00247                 else if (mode=="Ambient light")
00248                     mode = "Diffuse light";
00249                 else if (mode=="Diffuse light")
00250                     mode = "Specular light";
00251                 else if (mode=="Specular light")
00252                     mode = "Ambient material";
00253                 }
00254             break;
00255         }
00256         case 'e':   // e key pressed. The red component is increased
00257         {
00258             if (mode=="Ambient material" && matAmb.v1 < 1)
00259             {
00260                 matAmb.v1+=0.01f;
00261 
00262                 myMat->setAmbient(matAmb.v1, matAmb.v2, matAmb.v3, matAmb.v4);
00263             }
00264             else if (mode=="Diffuse material" && matDif.v1 < 1)
00265             {
00266                 matDif.v1+=0.01f;
00267 
00268                 myMat->setDiffuse(matDif.v1, matDif.v2, matDif.v3, matDif.v4);
00269             }
00270             else if (mode=="Specular material" && matSpe.v1 < 1)
00271             {
00272                 matSpe.v1+=0.01f;
00273 
00274                 myMat->setSpecular(matSpe.v1, matSpe.v2, matSpe.v3, matSpe.v4);
00275             }
00276             else if (mode=="Material emission" && matEmi.v1 < 1)
00277             {
00278                 matEmi.v1+=0.01f;
00279 
00280                 myMat->setEmission(matEmi.v1, matEmi.v2, matEmi.v3, matEmi.v4);
00281             }
00282             else if (mode=="Ambient light" && ligAmb.v1 < 1)
00283             {
00284                 ligAmb.v1+=0.01f;
00285 
00286                 myLight->setAmbientColor(ligAmb.v1, ligAmb.v2, ligAmb.v3, ligAmb.v4);
00287             }
00288             else if (mode=="Diffuse light" && ligDif.v1 < 1)
00289             {
00290                 ligDif.v1+=0.01f;
00291 
00292                 myLight->setDiffuseColor(ligDif.v1, ligDif.v2, ligDif.v3, ligDif.v4);
00293             }
00294             else if (mode=="Specular light" && ligSpe.v1 < 1)
00295             {
00296                 ligSpe.v1+=0.01f;
00297 
00298                 myLight->setSpecularColor(ligSpe.v1, ligSpe.v2, ligSpe.v3, ligSpe.v4);
00299             }       
00300             break;
00301         }
00302         case 'd':   // d key pressed. The red component is decreased
00303         {
00304             if (mode=="Ambient material" && matAmb.v1 > 0)
00305             {
00306                 matAmb.v1-=0.01f;
00307 
00308                 myMat->setAmbient(matAmb.v1, matAmb.v2, matAmb.v3, matAmb.v4);
00309             }
00310             else if (mode=="Diffuse material" && matDif.v1 > 0)
00311             {
00312                 matDif.v1-=0.01f;
00313 
00314                 myMat->setDiffuse(matDif.v1, matDif.v2, matDif.v3, matDif.v4);
00315             }
00316             else if (mode=="Specular material" && matSpe.v1 > 0)
00317             {
00318                 matSpe.v1-=0.01f;
00319 
00320                 myMat->setSpecular(matSpe.v1, matSpe.v2, matSpe.v3, matSpe.v4);
00321             }
00322             else if (mode=="Material emission" && matEmi.v1 > 0)
00323             {
00324                 matEmi.v1-=0.01f;
00325 
00326                 myMat->setEmission(matEmi.v1, matEmi.v2, matEmi.v3, matEmi.v4);
00327             }
00328             else if (mode=="Ambient light" && ligAmb.v1 > 0)
00329             {
00330                 ligAmb.v1-=0.01f;
00331 
00332                 myLight->setAmbientColor(ligAmb.v1, ligAmb.v2, ligAmb.v3, ligAmb.v4);
00333             }
00334             else if (mode=="Diffuse light" && ligDif.v1 > 0)
00335             {
00336                 ligDif.v1-=0.01f;
00337 
00338                 myLight->setDiffuseColor(ligDif.v1, ligDif.v2, ligDif.v3, ligDif.v4);
00339             }
00340             else if (mode=="Specular light" && ligSpe.v1 > 0)
00341             {
00342                 ligSpe.v1-=0.01f;
00343 
00344                 myLight->setSpecularColor(ligSpe.v1, ligSpe.v2, ligSpe.v3, ligSpe.v4);
00345             }
00346             
00347             break;
00348         }
00349         case 'r':   // increases the green component
00350         {
00351             if (mode=="Ambient material" && matAmb.v2 < 1)
00352             {
00353                 matAmb.v2+=0.01f;
00354 
00355                 myMat->setAmbient(matAmb.v1, matAmb.v2, matAmb.v3, matAmb.v4);
00356             }
00357             else if (mode=="Diffuse material" && matDif.v2 < 1)
00358             {
00359                 matDif.v2+=0.01f;
00360 
00361                 myMat->setDiffuse(matDif.v1, matDif.v2, matDif.v3, matDif.v4);
00362             }
00363             else if (mode=="Specular material" && matSpe.v2 < 1)
00364             {
00365                 matSpe.v2+=0.01f;
00366 
00367                 myMat->setSpecular(matSpe.v1, matSpe.v2, matSpe.v3, matSpe.v4);
00368             }
00369             else if (mode=="Material emission" && matEmi.v2 < 1)
00370             {
00371                 matEmi.v2+=0.01f;
00372 
00373                 myMat->setEmission(matEmi.v1, matEmi.v2, matEmi.v3, matEmi.v4);
00374             }
00375             else if (mode=="Ambient light" && ligAmb.v2 < 1)
00376             {
00377                 ligAmb.v2+=0.01f;
00378 
00379                 myLight->setAmbientColor(ligAmb.v1, ligAmb.v2, ligAmb.v3, ligAmb.v4);
00380             }
00381             else if (mode=="Diffuse light" && ligDif.v2 < 1)
00382             {
00383                 ligDif.v2+=0.01f;
00384 
00385                 myLight->setDiffuseColor(ligDif.v1, ligDif.v2, ligDif.v3, ligDif.v4);
00386             }
00387             else if (mode=="Specular light" && ligSpe.v2 < 1)
00388             {
00389                 ligSpe.v2+=0.01f;
00390 
00391                 myLight->setSpecularColor(ligSpe.v1, ligSpe.v2, ligSpe.v3, ligSpe.v4);
00392             }       
00393             break;
00394         }
00395 
00396         case 'f':   // decreases the green component
00397         {
00398             if (mode=="Ambient material" && matAmb.v2 > 0)
00399             {
00400                 matAmb.v2-=0.01f;
00401 
00402                 myMat->setAmbient(matAmb.v1, matAmb.v2, matAmb.v3, matAmb.v4);
00403             }
00404             else if (mode=="Diffuse material" && matDif.v2 > 0)
00405             {
00406                 matDif.v2-=0.01f;
00407 
00408                 myMat->setDiffuse(matDif.v1, matDif.v2, matDif.v3, matDif.v4);
00409             }
00410             else if (mode=="Specular material" && matSpe.v2 > 0)
00411             {
00412                 matSpe.v2-=0.01f;
00413 
00414                 myMat->setSpecular(matSpe.v1, matSpe.v2, matSpe.v3, matSpe.v4);
00415             }
00416             else if (mode=="Material emission" && matEmi.v2 > 0)
00417             {
00418                 matEmi.v2-=0.01f;
00419 
00420                 myMat->setEmission(matEmi.v1, matEmi.v2, matEmi.v3, matEmi.v4);
00421             }
00422             else if (mode=="Ambient light" && ligAmb.v2 > 0)
00423             {
00424                 ligAmb.v2-=0.01f;
00425 
00426                 myLight->setAmbientColor(ligAmb.v1, ligAmb.v2, ligAmb.v3, ligAmb.v4);
00427             }
00428             else if (mode=="Diffuse light" && ligDif.v2 > 0)
00429             {
00430                 ligDif.v2-=0.01f;
00431 
00432                 myLight->setDiffuseColor(ligDif.v1, ligDif.v2, ligDif.v3, ligDif.v4);
00433             }
00434             else if (mode=="Specular light" && ligSpe.v2 > 0)
00435             {
00436                 ligSpe.v2-=0.01f;
00437 
00438                 myLight->setSpecularColor(ligSpe.v1, ligSpe.v2, ligSpe.v3, ligSpe.v4);
00439             }
00440             
00441             break;
00442         }
00443         case 't':   // Increases the blue component
00444         {
00445             if (mode=="Ambient material" && matAmb.v3 < 1)
00446             {
00447                 matAmb.v3+=0.01f;
00448 
00449                 myMat->setAmbient(matAmb.v1, matAmb.v2, matAmb.v3, matAmb.v4);
00450             }
00451             else if (mode=="Diffuse material" && matDif.v3 < 1)
00452             {
00453                 matDif.v3+=0.01f;
00454 
00455                 myMat->setDiffuse(matDif.v1, matDif.v2, matDif.v3, matDif.v4);
00456             }
00457             else if (mode=="Specular material" && matSpe.v3 < 1)
00458             {
00459                 matSpe.v3+=0.01f;
00460 
00461                 myMat->setSpecular(matSpe.v1, matSpe.v2, matSpe.v3, matSpe.v4);
00462             }
00463             else if (mode=="Material emission" && matEmi.v3 < 1)
00464             {
00465                 matEmi.v3+=0.01f;
00466 
00467                 myMat->setEmission(matEmi.v1, matEmi.v2, matEmi.v3, matEmi.v4);
00468             }
00469             else if (mode=="Ambient light" && ligAmb.v3 < 1)
00470             {
00471                 ligAmb.v3+=0.01f;
00472 
00473                 myLight->setAmbientColor(ligAmb.v1, ligAmb.v2, ligAmb.v3, ligAmb.v4);
00474             }
00475             else if (mode=="Diffuse light" && ligDif.v3 < 1)
00476             {
00477                 ligDif.v3+=0.01f;
00478 
00479                 myLight->setDiffuseColor(ligDif.v1, ligDif.v2, ligDif.v3, ligDif.v4);
00480             }
00481             else if (mode=="Specular light" && ligSpe.v3 < 1)
00482             {
00483                 ligSpe.v3+=0.01f;
00484 
00485                 myLight->setSpecularColor(ligSpe.v1, ligSpe.v2, ligSpe.v3, ligSpe.v4);
00486             }       
00487             break;
00488         }
00489         case 'g':   // decreases the blue component
00490         {
00491             if (mode=="Ambient material" && matAmb.v3 > 0)
00492             {
00493                 matAmb.v3-=0.01f;
00494 
00495                 myMat->setAmbient(matAmb.v1, matAmb.v2, matAmb.v3, matAmb.v4);
00496             }
00497             else if (mode=="Diffuse material" && matDif.v3 > 0)
00498             {
00499                 matDif.v3-=0.01f;
00500 
00501                 myMat->setDiffuse(matDif.v1, matDif.v2, matDif.v3, matDif.v4);
00502             }
00503             else if (mode=="Specular material" && matSpe.v3 > 0)
00504             {
00505                 matSpe.v3-=0.01f;
00506 
00507                 myMat->setSpecular(matSpe.v1, matSpe.v2, matSpe.v3, matSpe.v4);
00508             }
00509             else if (mode=="Material emission" && matEmi.v3 > 0)
00510             {
00511                 matEmi.v3-=0.01f;
00512 
00513                 myMat->setEmission(matEmi.v1, matEmi.v2, matEmi.v3, matEmi.v4);
00514             }
00515             else if (mode=="Ambient light" && ligAmb.v3 > 0)
00516             {
00517                 ligAmb.v3-=0.01f;
00518 
00519                 myLight->setAmbientColor(ligAmb.v1, ligAmb.v2, ligAmb.v3, ligAmb.v4);
00520             }
00521             else if (mode=="Diffuse light" && ligDif.v3 > 0)
00522             {
00523                 ligDif.v3-=0.01f;
00524 
00525                 myLight->setDiffuseColor(ligDif.v1, ligDif.v2, ligDif.v3, ligDif.v4);
00526             }
00527             else if (mode=="Specular light" && ligSpe.v3 > 0)
00528             {
00529                 ligSpe.v3-=0.01f;
00530 
00531                 myLight->setSpecularColor(ligSpe.v1, ligSpe.v2, ligSpe.v3, ligSpe.v4);
00532             }
00533             
00534             break;
00535         }
00536         case 'y':   // increases the alpha component
00537         {
00538             if (mode=="Ambient material" && matAmb.v4 < 1)
00539             {
00540                 matAmb.v4+=0.01f;
00541 
00542                 myMat->setAmbient(matAmb.v1, matAmb.v2, matAmb.v3, matAmb.v4);
00543             }
00544             else if (mode=="Diffuse material" && matDif.v4 < 1)
00545             {
00546                 matDif.v4+=0.01f;
00547 
00548                 myMat->setDiffuse(matDif.v1, matDif.v2, matDif.v3, matDif.v4);
00549             }
00550             else if (mode=="Specular material" && matSpe.v4 < 1)
00551             {
00552                 matSpe.v4+=0.01f;
00553 
00554                 myMat->setSpecular(matSpe.v1, matSpe.v2, matSpe.v3, matSpe.v4);
00555             }
00556             else if (mode=="Material emission" && matEmi.v4 < 1)
00557             {
00558                 matEmi.v4+=0.01f;
00559 
00560                 myMat->setEmission(matEmi.v1, matEmi.v2, matEmi.v3, matEmi.v4);
00561             }
00562             else if (mode=="Ambient light" && ligAmb.v4 < 1)
00563             {
00564                 ligAmb.v4+=0.01f;
00565 
00566                 myLight->setAmbientColor(ligAmb.v1, ligAmb.v2, ligAmb.v3, ligAmb.v4);
00567             }
00568             else if (mode=="Diffuse light" && ligDif.v4 < 1)
00569             {
00570                 ligDif.v4+=0.01f;
00571 
00572                 myLight->setDiffuseColor(ligDif.v1, ligDif.v2, ligDif.v3, ligDif.v4);
00573             }
00574             else if (mode=="Specular light" && ligSpe.v4 < 1)
00575             {
00576                 ligSpe.v4+=0.01f;
00577 
00578                 myLight->setSpecularColor(ligSpe.v1, ligSpe.v2, ligSpe.v3, ligSpe.v4);
00579             }       
00580             break;
00581         }
00582         case 'h':   // decreases the alpha component
00583         {
00584             if (mode=="Ambient material" && matAmb.v3 > 0)
00585             {
00586                 matAmb.v3-=0.01f;
00587 
00588                 myMat->setAmbient(matAmb.v1, matAmb.v2, matAmb.v3, matAmb.v4);
00589             }
00590             else if (mode=="Diffuse material" && matDif.v4 > 0)
00591             {
00592                 matDif.v4-=0.01f;
00593 
00594                 myMat->setDiffuse(matDif.v1, matDif.v2, matDif.v3, matDif.v4);
00595             }
00596             else if (mode=="Specular material" && matSpe.v4 > 0)
00597             {
00598                 matSpe.v4-=0.01f;
00599 
00600                 myMat->setSpecular(matSpe.v1, matSpe.v2, matSpe.v3, matSpe.v4);
00601             }
00602             else if (mode=="Material emission" && matEmi.v4 > 0)
00603             {
00604                 matEmi.v4-=0.01f;
00605 
00606                 myMat->setEmission(matEmi.v1, matEmi.v2, matEmi.v3, matEmi.v4);
00607             }
00608             else if (mode=="Ambient light" && ligAmb.v4 > 0)
00609             {
00610                 ligAmb.v4-=0.01f;
00611 
00612                 myLight->setAmbientColor(ligAmb.v1, ligAmb.v2, ligAmb.v3, ligAmb.v4);
00613             }
00614             else if (mode=="Diffuse light" && ligDif.v4 > 0)
00615             {
00616                 ligDif.v4-=0.01f;
00617 
00618                 myLight->setDiffuseColor(ligDif.v1, ligDif.v2, ligDif.v3, ligDif.v4);
00619             }
00620             else if (mode=="Specular light" && ligSpe.v4 > 0)
00621             {
00622                 ligSpe.v4-=0.01f;
00623 
00624                 myLight->setSpecularColor(ligSpe.v1, ligSpe.v2, ligSpe.v3, ligSpe.v4);
00625             }
00626             
00627             break;  
00628         }
00629     
00630     }
00631     return TRUE;
00632 }
00633 
00634 int main(int argc, char *argv[])
00635 {
00636     gzStartUpGizmo();   // Needed for some systems to install external graphics engines
00637 
00638     // the try statement runs the program. If an exception is thrown this is caught
00639     // and reported by the catch statement. 
00640     try
00641     {
00642         // specifies graphics engine
00643         gzGraphicsEngine::useEngine(GZ_ENGINE_OPENGL);
00644 
00645         // makes it possible to load images with common formats
00646         gzInitializeDbManagers();
00647     
00648         myTestApp app;
00649 
00650         app.Create();
00651 
00652         app.run();
00653     }
00654 
00655     catch(gzBaseError &error)       // In case we get some exceptions
00656     {
00657         error.reportError();
00658     }
00659 
00660     gzShutDownGizmo();
00661 
00662     return 0;
00663 }
00664 

Documentation for Gizmo3D generated at Wed Feb 20 11:54:02 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond