int main(int argc, char *argv[]) { srand ( time(NULL) ); int running = GL_TRUE; int mousebtn, lastmousebtn; //Did the init not succeed? if(!SceneHandler::Init()) { //quit. return 0; } Light *moon = SceneHandler::CreateLight(); moon->setPosition(-2000.0,0.0,1000.0); moon->setDiffuse(0.3,0.3,0.4); moon->setAmbient(0.2,0.2,0.3); moon->setSpecular(1.0,1.0,1.0); moon->setRadius(20000.0); int numLights=4; Light *lights[numLights]; ParticleSystem *ps[numLights]; ps[0] = SceneHandler::CreateParticleSystem(); ps[0]->SetPosition(-307.0,-10.0,90.0); ps[0]->scale = 2.0; lights[0] = SceneHandler::CreateLight(); lights[0]->setPosition(-307.0,-10.0,90.0); lights[0]->setDiffuse(1.0,1.0,0.8); lights[0]->setAmbient(0.1,0.1,0.1); lights[0]->setSpecular(1.0,1.0,1.0); lights[0]->setRadius(200.0); ps[1] = SceneHandler::CreateParticleSystem(); ps[1]->SetPosition(-307.0,-188.0,90.0); ps[1]->scale = 2.0; lights[1] = SceneHandler::CreateLight(); lights[1]->setPosition(-307.0,-188.0,90.0); lights[1]->setDiffuse(1.0,1.0,0.8); lights[1]->setAmbient(0.1,0.1,0.1); lights[1]->setSpecular(1.0,1.0,1.0); lights[1]->setRadius(200.0); ps[2] = SceneHandler::CreateParticleSystem(); ps[2]->SetPosition(178.0,-45.0,64.0); ps[2]->scale = 2.0; lights[2] = SceneHandler::CreateLight(); lights[2]->setPosition(178.0,-45.0,64.0); lights[2]->setDiffuse(1.0,1.0,0.8); lights[2]->setAmbient(0.1,0.1,0.1); lights[2]->setSpecular(1.0,1.0,1.0); lights[2]->setRadius(200.0); ps[3] = SceneHandler::CreateParticleSystem(); ps[3]->SetPosition(178.0,-131.0,64.0); ps[3]->scale = 2.0; lights[3] = SceneHandler::CreateLight(); lights[3]->setPosition(178.0,-131.0,64.0); lights[3]->setDiffuse(1.0,1.0,0.8); lights[3]->setAmbient(0.1,0.1,0.1); lights[3]->setSpecular(1.0,1.0,1.0); lights[3]->setRadius(200.0); mousebtn = lastmousebtn = GLFW_RELEASE; Camera camera; camera.setDirection(90.0,0.0,0.0); camera.setPosition(0.0,0.0,100.0); PlayerEntity *player; player = SceneHandler::CreatePlayerEntity(); player->SetPosition(-400.0,-100.0,50.0); player->minBox=glm::vec4(-12.0,-12.0,-30.0,1.0f); player->maxBox=glm::vec4(12.0,12.0,30.0,1.0f); player->eyeHeight=25.0; PlayerEntity::SetCamera(&camera); StaticEntity *scene; StaticEntity *beast; StaticEntity *box; scene = SceneHandler::CreateStaticEntity("media/ny.ase",1.0); beast = SceneHandler::CreateStaticEntity("media/beast/beast1.ase",0.5); box = SceneHandler::CreateStaticEntity("media/box/box.ase",1.0); MD5Model *bob; bob = SceneHandler::CreateMD5Entity("models/monsters/hellknight/hellknight.md5mesh","models/monsters/hellknight/idle2.md5anim"); bob->scale=0.7; bob->SetPosition(300.0,100.0,0.0); bob->SetRotation(0.0,0.0,-90.0); beast->SetPosition(0.0,100.0,50.0); beast->SetRotation(90.0,0.0,0.0); scene->SetPosition(500.0,200.0,0.0); scene->SetRotation(0.0,0.0,0.0); box->SetPosition(100.0,100.0,150.0); box->SetRotation(0.0,0.0,-20.0); SceneHandler::CreateBBoxCollision(box,10.0); SceneHandler::CreateBBoxCollision(beast,10.0); SceneHandler::CreateMeshCollision(scene); SceneHandler::CreatePlayerCollision(player); GLint tex_units; glGetIntegerv(GL_MAX_TEXTURE_UNITS, &tex_units); cout<<"Max Texture units: "<<tex_units<<endl; glfwSwapInterval(0); // Do not wait for screen refresh between frames GLuint errorID = glGetError(); if(errorID != GL_NO_ERROR) { printf("\nOpenGL error: %s\n", gluErrorString(errorID)); printf("Attempting to proceed anyway. Expect rendering errors or a crash.\n"); } // Main loop while(running) { mousebtn=glfwGetMouseButton( GLFW_MOUSE_BUTTON_1 ); if(mousebtn == GLFW_PRESS) { glfwDisable( GLFW_MOUSE_CURSOR ); PlayerEntity::followMouse=true; } mousebtn=glfwGetMouseButton( GLFW_MOUSE_BUTTON_2 ); if(mousebtn == GLFW_PRESS) { glfwEnable( GLFW_MOUSE_CURSOR ); PlayerEntity::followMouse=false; } // Update the scene. SceneHandler::Update(); // glm::vec3 minBBoxPoint = box->ClosestMeshBBoxPoint(0); // glm::vec3 dist = minBBoxPoint - Camera::getActiveCamera()->pos; // std::cout<<std::sqrt(glm::dot(dist,dist))<<std::endl; //bob.Update(SceneHandler::g_dt); camera.setUp(); // Finally, draw the scene. SceneHandler::Render(); //bob.Render(); // Swap buffers, i.e. display the image and prepare for next frame. glfwSwapBuffers(); // Check if the ESC key was pressed or the window was closed. if(glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED)) running = GL_FALSE; } // Free the allocated resources SceneHandler::Destroy(); return(0); }
void Dragon_Dogs_ParticleSystem::Init(Scene * scene) { StaticEntityPtr skyPtr = scene->AddStaticEntity("assets/sphere.smodel", "sky"); StaticEntity * sky = skyPtr.Get(); sky->Illuminate(false); sky->SetScale(10000, 10000, 10000); Material * m = sky->GetMaterial(0); m->SetDiffuseMap("assets/risinger.jpg"); m->UseDiffuseMap(true); psPtr = scene->AddParticleSystem(); ParticleSystem * ps = psPtr.Get(); ps->SetColorTexture("assets/fire.png"); ps->SetEmmiterPosition(Vector3(45.0f, 0.0f, 0.0f)); ps->SetMinSpawnPosition(Vector3(-1.0f, 0.0f, 0.0f)); ps->SetMaxSpawnPosition(Vector3(1.0f, 0.0f, 0.0f)); ps->SetMaxLifeTime(70); ps->SetMinLifeTime(50); ps->SetMaxParticles(70); ps->SetSpawnTime(4.0); ps->SetMinSize(10); ps->SetMaxSize(14); ////entitiy->SetPosition(10.0f,0.0f,0.0f); drPtr = scene->AddParticleSystem(); ps = drPtr.Get(); ps->SetColorTexture("assets/fire.png"); ps->SetEmmiterPosition(Vector3(-30.0f, 150.0, 10.0f)); ps->SetMinSpawnPosition(Vector3(-0.2f, 0.3f, 0.0f)); ps->SetMaxSpawnPosition(Vector3(0.2f, -0.3f, 0.0f)); ps->SetMinSpawnVelocity(Vector3(-1.0f, -2.0f, -1.8f)); ps->SetMaxSpawnVelocity(Vector3(1.0f, -2.0f, -1.0f)); ps->SetMaxLifeTime(30); ps->SetMinLifeTime(45); ps->SetMaxParticles(70); ps->SetSpawnTime(4.0); ps->SetMinSize(10); ps->SetMaxSize(14); ps->AllowParticleAdd(false); plDragon = scene->AddPointLight(); PointLight * plD = plDragon.Get(); plD->SetDiffuse(1.0f, 0.4f, 0.0f, 1.0f); plD->SetRange(1.0f); plD->SetPosition(-30.0f, 150.0, 10.0f); dragonTime = 0; dragonOn = false; enPtr = scene->AddAnimatedEntity("assets/ninja.model", "ninja"); AnimatedEntity * en = enPtr.Get(); en->SetPosition(0.0f, 0.0f, 0.0f); en->Illuminate(true); en->SetScale(10.0f, 10.0f, 10.0f); en->SetPosZ(-100); //en->SetRotationY(90.0f); Material * mat = en->GetMaterial(0); mat->UseDiffuseMap(true); mat->SetDiffuseColor(Color::White()); mat->SetDiffuseMap("assets/nskin.jpg"); mat->SetEmmisivePower(1); mat->SetSpecularPower(0); mat->SetSpecularIntesity(0); mat = en->GetMaterial(1); mat->UseDiffuseMap(false); mat->SetEmmisivePower(1); mat->SetSpecularIntesity(0); mat->SetSpecularPower(0); mat->SetDiffuseColor(Color(0.3f, 0.3f, 0.3f, 1.0f)); pointLight = scene->AddPointLight(); PointLight * p = pointLight.Get(); p->SetDiffuse(1.0f, 0.4f, 0.0f, 1.0f); p->SetRange(500.0f); p->SetPosition(45.0f, 4.0f, 0.0f); planePtr = scene->AddStaticEntity("assets/plane.model", "plane"); StaticEntity * plane = planePtr.Get(); plane->Illuminate(true); plane->SetScale(500.0f, 1.0f, 500.0f); Material * pMat = plane->GetMaterial(0); pMat->UseDiffuseMap(false); pMat->SetDiffuseColor(Color(0.3f, 0.3f, 0.3f, 1.0f)); pMat->SetEmmisivePower(1); pMat->SetSpecularPower(0); pMat->SetSpecularIntesity(0); plane->SetPosition(0.0f, -7.0f, 0.0f); dogPtr = scene->AddStaticEntity("assets/dog.smodel", "dog"); StaticEntity * dog = dogPtr.Get(); dog->Illuminate(true); dog->SetPosition(80.0f, 10.0, 60.0f); dog->SetScale(400.0f, 400.0f, 400.0f); dog->SetRotation(0.0f, 60.0f, 180.0f); dog->SetRotationY(45.0f); pMat = dog->GetMaterial(0); pMat->SetDiffuseColor(Color(0.2f, 0.2f, 0.2f, 1.0f)); dogPtr2 = scene->AddStaticEntity("assets/dog.smodel", "dog"); dog = dogPtr2.Get(); dog->Illuminate(true); dog->SetPosition(-100.0f, 10.0, 60.0f); dog->SetScale(400.0f, 400.0f, 400.0f); dog->SetRotation(0.0f, -60.0f, 180.0f); //dog->SetRotationY(45.0f); pMat = dog->GetMaterial(0); pMat->SetDiffuseColor(Color(0.2f, 0.0f, 0.0f, 1.0f)); lightChangeTime = 0.0f; powerMin = 0.6f; powerMax = 1.0f; animContr = enPtr.Get()->LoadAnimationFromFile("assets/ninja.anim", "animPack"); enPtr.Get()->SetCurrentAnimationController(animContr); animContr->AddAnimationState(0, 14, LOOP, "idle"); animContr->SetCurrentAnimationState("idle"); torchPtr = scene->AddStaticEntity("assets/smaug.smodel", "m24"); StaticEntity * torch = torchPtr.Get(); torch->SetPosition(-30.0f, 100.0, 70.0f); torch->SetScale(3.0f, 3.0f, 3.0f); torch->Illuminate(true); mat = torch->GetMaterial(0); mat->SetEmmisivePower(1); mat->SetSpecularPower(1); treePtr = scene->AddStaticEntity("assets/tree.smodel", "tree"); StaticEntity * tree = treePtr.Get(); tree->SetPosition(150.0f, 23.0f, 0.0f); tree->SetScale(10.0f, 10.0f, 10.0f); tree->Illuminate(true); mat = tree->GetMaterial(0); mat->UseDiffuseMap(true); mat->SetDiffuseMap("assets/w3.jpg"); swordPtr = scene->AddStaticEntity("assets/sword.smodel", "sword"); StaticEntity * sword = swordPtr.Get(); sword->SetPosition(150.0f, 80.0f, 0.0f); sword->Illuminate(false); sword->SetScale(2.0f, 2.0f, 2.0f); sword->SetRotationZ(180.0f); mat = sword->GetMaterial(0); mat->UseDiffuseMap(false); mat->SetDiffuseColor(Color::White()); mat->SetEmmisivePower(20); }