void DrawScene() { modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); // Transform the light position into eye coordinates M3DVector4f vLightPos = { LIGHT_POSITION[0], LIGHT_POSITION[1], LIGHT_POSITION[2], LIGHT_POSITION[3] }; M3DVector4f vLightEyePos; m3dTransformVector4(vLightEyePos, vLightPos, mCamera); /* ------------ */ /* FERRIS WHEEL */ modelViewMatrix.PushMatrix(); /* Position the ferris wheel appropriately. */ modelViewMatrix.Translate(FERRIS_WHEEL_POSITION[0], FERRIS_WHEEL_POSITION[1], FERRIS_WHEEL_POSITION[2]); /* Apply the Translation to this entire block of objects */ modelViewMatrix.PushMatrix(); //theWheel.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos, capTexture, wheelTexture, wallTexture, carTexture, currentTextureIndex); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); /* -------------- */ /* ROLLER COASTER */ modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0, 0.0, -10.0); //track.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); modelViewMatrix.PopMatrix(); /* -------- */ /* CAROUSEL */ modelViewMatrix.PushMatrix(); //modelViewMatrix.Translate(3.0f, 0.0f, -3.0f); modelViewMatrix.Translate(0.0f, 0.0f, -3.0f); //carousel.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); modelViewMatrix.PopMatrix(); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, 0.0f, -2.0f); //unicorn.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); //ostrich.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); turtle.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); }
int main() { Scene *scene = NULL; LSystems lsystems; Turtle turtle; SDL_Window*window = NULL; SDL_GLContext Context; //Use OpenGL 3.1 core SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); window = SDL_CreateWindow( "L-Systems", 200, 100, WINDOWWIDTH, WINDOWHEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); if( window == NULL ) { printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() ); return EXIT_FAILURE; } Context = SDL_GL_CreateContext( window ); scene = new Scene(); scene->init(); bool quit = false; SDL_Event event; SDL_TimerID Update = SDL_AddTimer(500,UpdateIteration,&lsystems); while(quit!=true) { while( SDL_PollEvent(&event) != 0) { if(event.type == SDL_QUIT) { quit=true; } //If esc pressed exit window if(event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_ESCAPE: { quit=true; break; } // if 1 is pressed draw 1st tree type case SDLK_1: { lsystems.selectTree(1);lsystems.m_iterations=0; break; } // if 2 is pressed draw 2ns tree type case SDLK_2: { lsystems.selectTree(2); lsystems.m_iterations=0 ; break; } // press up to increase angle case SDLK_UP: { turtle.m_angle+=5; break; } // press down to decrease angle case SDLK_DOWN: { turtle.m_angle -=5; break; } // if right pressed increase max increments (max growth) case SDLK_RIGHT: { lsystems.m_maxIterations+=1; lsystems.m_iterations=0; break; } // if left pressed decrease max increments (min graowth) case SDLK_LEFT: { lsystems.m_maxIterations-=1; lsystems.m_iterations=0; break; } default: { break; } } } } scene->drawScene(); //lsystems.createLeaf(); lsystems.setAxiom(); lsystems.setRule(); lsystems.setAlphabet(); lsystems.setAlphabetRule(); turtle.setAngle(turtle.m_angle); // number of iterations lsystems.productions(lsystems.m_iterations); lsystems.getDrawingRule(); // width and height. width increases with each iteration turtle.Draw(lsystems,lsystems.m_iterations*0.008,0.20); SDL_GL_SwapWindow( window); } // Delete our scene delete scene; //Destroy window SDL_DestroyWindow( window ); // Disable our timer SDL_RemoveTimer(Update); //Quit SDL subsystems SDL_Quit(); return EXIT_SUCCESS; }