void preprocess(const Scene *scene) { /* Create a sample generator for the preprocess step */ Sampler *sampler = static_cast<Sampler *>( NoriObjectFactory::createInstance("independent", PropertyList())); Emitter* distantsDisk = scene->getDistantEmitter(); if(distantsDisk != nullptr ) { float lngstDir = scene->getBoundingBox().getLongestDirection(); distantsDisk->setMaxRadius(lngstDir); } /* Allocate memory for the photon map */ m_photonMap = std::unique_ptr<PhotonMap>(new PhotonMap()); m_photonMap->reserve(m_photonCount); /* Estimate a default photon radius */ if (m_photonRadius == 0) m_photonRadius = scene->getBoundingBox().getExtents().norm() / 500.0f; int storedPhotons = 0; const std::vector<Emitter *> lights = scene->getEmitters(); int nLights = lights.size(); Color3f tp(1.0f, 1.0f, 1.0f); cout << "Starting to create "<< m_photonCount << " photons!" << endl; int percentDone= 0; int onePercent = int(floor(m_photonCount / 100.0)); // create the expected number of photons while(storedPhotons < m_photonCount) { //uniformly sample 1 light (assuming that we only have area lights) int var = int(std::min(sampler->next1D()*nLights, float(nLights) - 1.0f)); const areaLight* curLight = static_cast<const areaLight *> (lights[var]); //sample a photon Photon curPhoton; Vector3f unQuantDir(0.0f,0.0f,0.0f); curLight->samplePhoton(sampler, curPhoton, 1, nLights, unQuantDir); Color3f alpha = curPhoton.getPower(); Color3f tp(1.0f, 1.0f, 1.0f); //trace the photon Intersection its; Ray3f photonRay(curPhoton.getPosition(), unQuantDir); m_shootedRays++; if (scene->rayIntersect(photonRay, its)) { while(true) { const BSDF* curBSDF = its.mesh->getBSDF(); if (curBSDF->isDiffuse()) { //store the photon m_photonMap->push_back(Photon( its.p /* Position */, -photonRay.d /* Direction*/, tp * alpha /* Power */ )); storedPhotons++; } if(!(storedPhotons < m_photonCount)) break; BSDFQueryRecord query = BSDFQueryRecord(its.toLocal(-photonRay.d), Vector3f(0.0f), EMeasure::ESolidAngle); Color3f fi = curBSDF->sample(query, sampler->next2D()); if(fi.maxCoeff() == 0.0f) break; tp *= fi; Vector3f wo = its.toWorld(query.wo); photonRay = Ray3f(its.p, wo); //ray escapes the scene if (!scene->rayIntersect(photonRay, its)) break; //stop critirium russian roulette float q = tp.maxCoeff(); if(q < sampler->next1D()) break; tp /= q; } } if(onePercent != 0) { if(storedPhotons % onePercent == 0){ int percent = int(floor(storedPhotons / onePercent)); if(percent % 10 == 0 && percentDone != percent){ percentDone = percent; cout << percent << "%" << endl; } } } } /* Build the photon map */ m_photonMap->build(); }
int main() { glfwInit(); ////our window //GLFWwindow* window; //window = glfwCreateWindow(800, 600, "ParticleSystemXML", NULL, NULL); //glfwMakeContextCurrent(window); // ////CAM //cam.setKeySpeed(4.0); //iH.setAllInputMaps(cam); //glfwSetKeyCallback(window, key_callback); //cam.setFOV(50); //cam.setNearFar(1, 100); Window testWindow(500, 50, 800, 600, "testWindow"); glfwMakeContextCurrent(testWindow.getWindow()); // Callback glfwSetKeyCallback(testWindow.getWindow(), key_callback); cam.setKeySpeed(4.0); cam.setNearFar(0.1, 100); glewInit(); //our renderer OpenGL3Context context; Renderer *renderer; renderer = new Renderer(context); //////////////////////Textures////////////////////// Texture* fireTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/Fire2_M.png"); Texture* fireTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire1_M.png"); Texture* fireTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire3_M.png"); Texture* fireTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/flame02_L.png"); //Texture* fireFlickering1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire_flickering_1.png"); //Texture* fireFlickering2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire_flickering_2.png"); //Texture* fireFlickering3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire_flickering_3.png"); //Texture* fireFlickering4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fire_flickering_4.png"); Texture* fireSparkleTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fireSparkle1_S.png"); Texture* fireSparkleTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/fireSparkle2.png"); Texture* texFireworkBlue = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_blue.png"); Texture* texFireworkRed = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_red.png"); Texture* texFireworkGreen = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_green.png"); Texture* texFireworkGold = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_gold.png"); Texture* texFireworkTail = new Texture((char*)RESOURCES_PATH "/ParticleSystem/firework/firework_tail.png"); Texture* smokeWhiteTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeWhite/smokeWhite01.png"); Texture* smokeWhiteTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeWhite/smokeWhite02.png"); Texture* smokeBlack1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeBlack/smokeBlack01.png"); Texture* smokeBlack2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeBlack/smokeBlack02.png"); //////////////////////Emitter////////////////////// //Emitter explosion sparkle Emitter* explosionSparkle = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 0.25, 0.01, 80, 1.25, true); explosionSparkle->setVelocity(5); //explosionSparkle->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 0.3), 3.0f); explosionSparkle->usePhysicPointGravity(glm::vec3(0.0, 0.0, 0.0), 0.6, 10.0, 2, 4.0f, true); explosionSparkle->addTexture(fireSparkleTex1, 1.0); explosionSparkle->defineLook(true, 0.01, 0.0, 0.1); //Emitter explosion fire //TODO //Emitter fire smoke Emitter* fire = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 0.0, 0.2, 2, 5.0, true); fire->setVelocity(5); fire->usePhysicDirectionGravity(glm::vec4(0.0, 1.0, 0.0, 5.0), 0.5f); fire->addTexture(fireTex1, 1.0); fire->addTexture(fireTex2, 0.7); fire->addTexture(smokeBlack2, 0.1); //fire->addTexture(smokeBlack2, 0.1); //fire->addTexture(smokeWhiteTex2, 0.25); std::vector<float> sizeF{ 0.05f, 0.5f, 0.75f, 1.0f }; std::vector<float> timeF{ 0.0f, 0.4f, 0.75f, 1.0f }; fire->defineLook(true, sizeF, timeF, 0.5, 4.0, 3.0, true, 0.3); fire->switchToGeometryShader(); //Emitter fire flickering Emitter* fireFlickering = new Emitter(0, glm::vec3(0.0, 0.1, 0.0), 0.0, 0.2, 1, 2.0, true); fireFlickering->setVelocity(5); fireFlickering->usePhysicDirectionGravity(glm::vec4(0.0, 1.0, 0.0, 0.5), 0.3f); /*fireFlickering->addTexture(fireFlickering1, 1.0); fireFlickering->addTexture(fireFlickering2, 0.7); fireFlickering->addTexture(fireFlickering3, 0.5); fireFlickering->addTexture(fireFlickering4, 0.3);*/ fireFlickering->defineLook(true, 0.1, 0.5, 1.0, 0.5, true, 0.3); fireFlickering->switchToGeometryShader(); Emitter* fireSparkle = new Emitter(0, glm::vec3(0.0, 0.1, 0.0), 0.0, 0.05, 3, 2.5, true); fireSparkle->setVelocity(5); fireSparkle->usePhysicDirectionGravity(glm::vec4(0.0, 1.0, 0.0, 0.8), 0.5f); fireSparkle->addTexture(fireSparkleTex1, 1.0); fireSparkle->defineLook(true, 0.05, 0.5, 0.5); //Emitter firework explosion Emitter* fireworkExplosion = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 0.1, 0.01, 80, 2.0, true); fireworkExplosion->setVelocity(6); //fireworkExplosion->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 0.6), 3.0f); fireworkExplosion->usePhysicPointGravity(glm::vec3(0.0, -2.0, 0.0), 0.9, 5.0, 2, 2.0f, true); fireworkExplosion->addTexture(texFireworkRed, 1.0); fireworkExplosion->defineLook(true, 0.04, 0.0, 0.5); fireworkExplosion->setStartTime(2.0); //Emitter firework tail Emitter* fireworkTail = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 2.0, 0.01, 20, 0.5, true); fireworkTail->setVelocity(5); //fireworkTail->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 2.9), 0.2f); fireworkTail->usePhysicPointGravity(glm::vec3(0.0, -4.0, 0.0), 30.6, 10.0, 2, 0.2f, true); fireworkTail->addTexture(texFireworkTail, 1.0); fireworkTail->defineLook(true, 0.001, 0.0, 0.1); //FINAL EMITTER WHITE SMOKE Emitter* smokeWhite = new Emitter(0, glm::vec3(0.0, 0.0, 0.0), 0.0, 0.4, 1, 8.0, true); smokeWhite->setVelocity(2); smokeWhite->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.8), 0.3f); smokeWhite->addTexture(smokeWhiteTex1, 1.0); smokeWhite->addTexture(smokeWhiteTex2, 0.25); std::vector<float> smokeWhiteSize{ 0.05f, 0.5f, 0.75f, 1.0f }; std::vector<float> smokeWhiteTime{ 0.0f, 0.4f, 0.75f, 1.0f }; smokeWhite->defineLook(true, smokeWhiteSize, smokeWhiteTime, 1.0, 2.0, 1.0, false, 0.3); smokeWhite->switchToGeometryShader(); //////////////////////Effect////////////////////// Effect* efExplosion = new Effect(); efExplosion->addEmitter(explosionSparkle); Effect* efFire = new Effect(); efFire->addEmitter(fire); //efFire->addEmitter(fireFlickering); efFire->addEmitter(fireSparkle); efFire->saveEffect(RESOURCES_PATH "/XML/Effect_Fire.xml"); Effect* efFirework = new Effect(); efFirework->addEmitter(fireworkTail); efFirework->addEmitter(fireworkExplosion); //efFirework->saveEffect(RESOURCES_PATH "/XML/Effect_Firework.xml"); Effect* efFireworkTail = new Effect(); efFireworkTail->addEmitter(fireworkTail); Effect* efFireworkExplosion = new Effect(); efFireworkExplosion->addEmitter(fireworkExplosion); Effect* efSmWhi = new Effect(); efSmWhi->addEmitter(smokeWhite); efSmWhi->saveEffect(RESOURCES_PATH "/XML/Effect_SmokeWhite.xml"); //////////////////////ParticleSystem////////////////////// //ParticleSystem* psExplosion = new ParticleSystem(glm::vec3(0, -1, 0), efExplosion); //ParticleSystem* psFire = new ParticleSystem(glm::vec3(-2, 0, 3), efFire); ParticleSystem* psFire = new ParticleSystem(glm::vec3(-2, 0, 3), RESOURCES_PATH "/XML/Effect_Fire.xml"); ParticleSystem* psFirework = new ParticleSystem(glm::vec3(0, 0, 5), efFirework); ParticleSystem* psFireworkTail = new ParticleSystem(glm::vec3(0, 0, 5), efFireworkTail); ParticleSystem* psFireworkExplosion = new ParticleSystem(glm::vec3(0, 2, 5), efFireworkExplosion); ParticleSystem* psSmokeWhite = new ParticleSystem(glm::vec3(2, 0, 3), efSmWhi); //ParticleSystem* psSmokeWhite = new ParticleSystem(glm::vec3(2, 0, 3), RESOURCES_PATH "/XML/Effect_SmokeWhite.xml"); ParticleSystem* psFireworkRed = new ParticleSystem(glm::vec3(-3, -1, 5), RESOURCES_PATH "/XML/Effect_FireworkRed.xml"); ParticleSystem* psFireworkBlue = new ParticleSystem(glm::vec3(-1, -1, 5), RESOURCES_PATH "/XML/Effect_FireworkBlue.xml"); ParticleSystem* psFireworkGreen = new ParticleSystem(glm::vec3(1, -1, 5), RESOURCES_PATH "/XML/Effect_FireworkGreen.xml"); ParticleSystem* psFireworkGold = new ParticleSystem(glm::vec3(3, -1, 5), RESOURCES_PATH "/XML/Effect_FireworkGold.xml"); //////////////////////Node////////////////////// //Node nodeExplosion("nodeExplosion"); //nodeExplosion.setCamera(&cam); //nodeExplosion.addParticleSystem(psExplosion); //nodeExplosion.setParticleActive(true); // //Node fireNode("fireNode"); //fireNode.setCamera(&cam); //fireNode.addParticleSystem(psFire); //fireNode.setParticleActive(true); // //Node nodeFirework("fireworkNode"); //nodeFirework.setCamera(&cam); //nodeFirework.addParticleSystem(psFirework); //nodeFirework.setParticleActive(true); // //Node whiteSmokeNode("whiteSmokeNode"); //whiteSmokeNode.setCamera(&cam); //whiteSmokeNode.addParticleSystem(psSmokeWhite); //whiteSmokeNode.setParticleActive(true); ////Firework //Node nodeFireworkRed("fireworkRedNode"); //nodeFireworkRed.setCamera(&cam); //nodeFireworkRed.addParticleSystem(psFireworkRed); //nodeFireworkRed.setParticleActive(true); //Node nodeFireworkBlue("fireworBlueNode"); //nodeFireworkBlue.setCamera(&cam); //nodeFireworkBlue.addParticleSystem(psFireworkBlue); //nodeFireworkBlue.setParticleActive(true); //Node nodeFireworkGreen("fireworkGreenNode"); //nodeFireworkGreen.setCamera(&cam); //nodeFireworkGreen.addParticleSystem(psFireworkGreen); //nodeFireworkGreen.setParticleActive(true); //Node nodeFireworkGold("fireworkGoldNode"); //nodeFireworkGold.setCamera(&cam); //nodeFireworkGold.addParticleSystem(psFireworkGold); //nodeFireworkGold.setParticleActive(true); // Shader VertexShader vs(loadShaderSource(SHADERS_PATH + std::string("/ColorShader3D/ColorShader3D.vert"))); FragmentShader fs(loadShaderSource(SHADERS_PATH + std::string("/ColorShader3D/ColorShader3D.frag"))); ShaderProgram shader(vs, fs); //need scene here mainly because of input Level testLevel("testLevel"); Scene testScene("testScene"); testLevel.addScene(&testScene); testLevel.changeScene("testScene"); //Add Camera to Scene testScene.getScenegraph()->addCamera(&cam); testScene.getScenegraph()->setActiveCamera("Pilotview"); //Set Input-Maps and activate one iH.setAllInputMaps(*(testScene.getScenegraph()->getActiveCamera())); iH.changeActiveInputMap(MapType::CAMPILOTVIEW); iH.getActiveInputMap()->update(cam); //Object Cube cube; Texture bricks((char*)RESOURCES_PATH "/Wall/bricks_diffuse.png"); Node cube1("cube"); cube1.addGeometry(&cube); cube1.addTexture(&bricks); cube1.setModelMatrix(glm::translate(cube1.getModelMatrix(), glm::vec3(0.0, 0.0, 0.0))); //cube1.setModelMatrix(glm::scale(cube1.getModelMatrix(), glm::vec3(0.5, 0.5, 0.5))); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube1); //add nodes to the scenegraph //testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeExplosion); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&fireNode); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&whiteSmokeNode); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFirework); /*testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFireworkRed); testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFireworkBlue); testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFireworkGreen); testScene.getScenegraph()->getRootNode()->addChildrenNode(&nodeFireworkGold);*/ //using this, the ParticleSystems get rendered in order of their distance to the camera testScene.getScenegraph()->addParticleSystem(psFire); testScene.getScenegraph()->addParticleSystem(psSmokeWhite); testScene.getScenegraph()->addParticleSystem(psFireworkBlue); testScene.getScenegraph()->addParticleSystem(psFireworkRed); testScene.getScenegraph()->addParticleSystem(psFireworkGreen); testScene.getScenegraph()->addParticleSystem(psFireworkGold); //TEST /*ParticleSystem* psComicCloud = new ParticleSystem(glm::vec3(0, -1, 4), RESOURCES_PATH "/XML/ComicCloudEffect - Kopie.xml"); testScene.getScenegraph()->addParticleSystem(psComicCloud); psComicCloud->start();*/ //start the ParticleSystems psFire->start(); psSmokeWhite->start(); //psExplosion->start(); //psFirework->start(); psFireworkRed->start(); psFireworkBlue->start(); psFireworkGreen->start(); psFireworkGold->start(); double startTime = glfwGetTime(); double lastTime = glfwGetTime(); int nbFrames = 0; while (!glfwWindowShouldClose(testWindow.getWindow())) { // Measure speed double currentTime = glfwGetTime(); nbFrames++; if (currentTime - lastTime >= 1.0){ // If last prinf() was more than 1 sec ago // printf and reset timer //printf("%f ms/frame\n", 1000.0 / double(nbFrames)); nbFrames = 0; lastTime += 1.0; } cam.setSensitivity(glfwGetTime() - startTime); startTime = glfwGetTime(); /*glEnable(GL_DEPTH); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shader.bind(); shader.sendMat4("viewMatrix", cam.getViewMatrix()); shader.sendMat4("projectionMatrix", cam.getProjectionMatrix()); testScene.render(shader); testScene.renderParticleSystems(); shader.unbind();*/ //renderer->useBloom(true); renderer->renderScene(testScene, testWindow); //update Positions of firework ParticleSystems glm::vec3 pos = psFireworkRed->getPosition(); psFireworkRed->setPosition(glm::vec3(pos.x, pos.y + (glfwGetTime() - startTime), pos.z)); pos = psFireworkBlue->getPosition(); psFireworkBlue->setPosition(glm::vec3(pos.x, pos.y + (glfwGetTime() - startTime), pos.z)); pos = psFireworkGreen->getPosition(); psFireworkGreen->setPosition(glm::vec3(pos.x, pos.y + (glfwGetTime() - startTime), pos.z)); pos = psFireworkGold->getPosition(); psFireworkGold->setPosition(glm::vec3(pos.x, pos.y + (glfwGetTime() - startTime), pos.z)); /*glfwSwapBuffers(testWindow.getWindow()); glfwPollEvents();*/ } glfwDestroyWindow(testWindow.getWindow()); glfwTerminate(); return 0; }
std::string Dump(const Node& node) { Emitter emitter; emitter << node; return emitter.c_str(); }
bool Enemy::update(Game* _game) { if(mHealth <= 0) { Emitter* newEmitter = new Emitter(sf::Vector2f(mX, mY), sf::Vector2f(.0f, -1.f), EMITTERTYPE_Directional, false); newEmitter->parseParticleFile("Resources/Particles/plus10.particle"); _game->addEmitter(newEmitter); Random* random = Random::get_singleton(); int rand = (int)random->rand_range(1, 250); Timer* t = NULL; for(auto& i: _game->getObjects()) if(i->getUniqueType() == "spawnTimer") t = static_cast<Timer*>(i); if(rand >= 190 && rand <= 219) { WeaponPickup* pickup = new WeaponPickup(14, mX, mY, mReloadVisual); _game->pushObject(pickup); } else if(rand >= 220 && rand <= 240) { WeaponPickup* pickup = new WeaponPickup(15, mX, mY, mReloadVisual); _game->pushObject(pickup); } else if(rand >= 241 && t->getRound() > 40) { WeaponPickup* pickup = new WeaponPickup(13, mX, mY, mReloadVisual); _game->pushObject(pickup); } HealthPickup* pickup = new HealthPickup(19, mX, mY); _game->pushObject(pickup); int coinRand = (int)random->rand_range(1, 4); for(int i = 0; i < coinRand; i++) { CoinPickup* pickup = new CoinPickup(20, mX, mY + (45 * i)); _game->pushObject(pickup); } // Score Player* player = static_cast<Player*>(_game->getPlayer()); sf::Vector2f playerPositon = _game->getPlayer()->getPosition(); double distance = sqrt((playerPositon.x - mX) * (playerPositon.x - mX) + (playerPositon.y - mY) * (playerPositon.y - mY)); float scoreRand = random->rand_range(0.3f, 0.7f); player->addScore((int)(1000 - distance * scoreRand), _game); // Destroy destroy(); } if(mAIState == AISTATE_Pursue) { sf::Vector2f direction; direction.x = _game->getPlayer()->getPosition().x - mX /** 0.8f*/; direction.y = _game->getPlayer()->getPosition().y - mY /** 0.8f*/; float normal = sqrt(direction.x * direction.x + direction.y * direction.y); direction.x /= normal; direction.y /= normal; mVelocityX = (direction.x * _game->getDelta() * 10.f) * .6f; mVelocityY = (direction.y * _game->getDelta() * 10.f) * .6f; Random* random = Random::get_singleton(); mVelocityX += random->rand_range(-.5f, .5f); mVelocityY += random->rand_range(-.5f, .5f); sf::Vector2f distance; distance.x = _game->getPlayer()->getPosition().x - mX; distance.y = _game->getPlayer()->getPosition().y - mY; if(abs(distance.x) < 25.f && abs(distance.y) < 25.f) mAIState = AISTATE_Attack; } else if(mAIState == AISTATE_Attack) { mVelocityX = 0.f; mVelocityY = 0.f; sf::Vector2f distance; Player* player = static_cast<Player*>(_game->getPlayer()); distance.x = (player->getPosition().x + player->getAABB().width) - (mX + mAABB.width); distance.y = (player->getPosition().y + player->getAABB().height) - (mY + mAABB.height); player->damage(1); if(abs(distance.x) > 25.f && abs(distance.y) > 25.f) mAIState = AISTATE_Pursue; } Animation::update(_game); addPosition(mVelocityX * (_game->getDelta() * 1000.f), mVelocityY * (_game->getDelta() * 1000.f)); Object::update(_game); return true; }
bool DrawGame(void) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //glTranslatef(0.0f,0.0f,-8.0f); gluLookAt(0.0f,0.0f,18.0,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f); glPushAttrib(GL_CURRENT_BIT); glBegin(GL_LINES); Matrix2 orientation(gameShip.m_orientation); #ifdef _DEBUG if(debugDraw) { glColor3f(1.0f,0.0f,0.0f); glVertex2f(0.0f,0.0f); glVertex2f(1.0f,0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex2f(0.0f,0.0f); glVertex2f(0.0f,1.0f); } #endif glColor3f(0.0f,0.0f,1.0f); if(debugSpring1) { glVertex2fv(gameSpring1); glVertex2fv(gameShip.m_position + orientation * gameAnchor1); } if(debugSpring2) { glVertex2fv(gameSpring2); glVertex2fv(gameShip.m_position + orientation * gameAnchor2); } for(unsigned long i = 0; i < gameMissles.GetSize(); ++i) { if(gameMissles[i]->m_spring) { glVertex2fv(*gameMissles[i]->m_spring); glVertex2fv(gameMissles[i]->m_position); } } glEnd(); glPopAttrib(); gameShip.DrawShip(); gameEmitter.DrawParticles(); for(unsigned long i = 0; i < gameMissles.GetSize(); ++i) gameMissles[i]->DrawMissle(); return true; }
//------------------------------------------------------------------------------ // Class: System // Method: initFromFile // Description: load the emitter from an xml file //------------------------------------------------------------------------------ bool System::initFromFile(std::string theFilename) { tinyxml2::XMLDocument aFile; if (tinyxml2::XML_NO_ERROR != aFile.LoadFile(theFilename.c_str())) { return false; } tinyxml2::XMLElement* aEmittersNode {aFile.FirstChildElement("emitters")}; if(!aEmittersNode) { return false; } tinyxml2::XMLElement* aEmitterNode {aEmittersNode->FirstChildElement("emitter")}; while(aEmitterNode) { Emitter aEmitter {aEmitterNode->Attribute("id")}; std::string aShape {aEmitterNode->Attribute("shape")}; if(aShape == "CIRCLE") { aEmitter.setShape(Emitter::CIRCLE); } else if (aShape == "RECTANGLE") { aEmitter.setShape(Emitter::RECTANGLE); } std::string aDispersion {aEmitterNode->Attribute("dispersion")}; if(aDispersion == "LINEAR") { aEmitter.setDispersion(Emitter::LINEAR); } else if(aDispersion == "RADIAL") { aEmitter.setDispersion(Emitter::RADIAL); } else if(aDispersion == "REFLECT") { aEmitter.setDispersion(Emitter::REFLECT); } else if(aDispersion == "RANDOM") { aEmitter.setDispersion(Emitter::RANDOM); } else if(aDispersion == "STATIC") { aEmitter.setDispersion(Emitter::STATIC); } tinyxml2::XMLElement* aTextRectNode {aEmitterNode->FirstChildElement("textRect")}; if(!aTextRectNode) { return false; } aEmitter.setTextRect(TextRect {aTextRectNode->IntAttribute("x"), aTextRectNode->IntAttribute("y"), aTextRectNode->IntAttribute("width"), aTextRectNode->IntAttribute("height") }); tinyxml2::XMLElement* aGeneratorNode {aEmitterNode->FirstChildElement("ranges")}; if(!aGeneratorNode) { return false; } tinyxml2::XMLElement* aNode {aGeneratorNode->FirstChildElement("focusTOL")}; if(!aNode) { return false; } aEmitter.setGeneratorFocusTOL(aNode->FloatAttribute("min"), aNode->FloatAttribute("max")); aNode = aGeneratorNode->FirstChildElement("focusWidth"); if(!aNode) { return false; } //float aFloat{aNode->FloatAttribute("min")}; //float aFloat1{aNode->FloatAttribute("max")}; aEmitter.setGeneratorFocusWidth(aNode->FloatAttribute("min"), aNode->FloatAttribute("max")); aNode = aGeneratorNode->FirstChildElement("focusHeight"); if(!aNode) { return false; } aEmitter.setGeneratorFocusHeight(aNode->FloatAttribute("min"), aNode->FloatAttribute("max")); aNode = aGeneratorNode->FirstChildElement("focusNP"); if(!aNode) { return false; } aEmitter.setGeneratorFocusNP(aNode->IntAttribute("min"), aNode->IntAttribute("max")); aNode = aGeneratorNode->FirstChildElement("focusPPS"); if(!aNode) { return false; } aEmitter.setGeneratorFocusPPS(aNode->FloatAttribute("min"), aNode->FloatAttribute("max")); aNode = aGeneratorNode->FirstChildElement("particleTOL") ; if(!aNode) { return false; } aEmitter.setGeneratorParticleTOL(aNode->FloatAttribute("min"), aNode->FloatAttribute("max")); aNode = aGeneratorNode->FirstChildElement("particleSize") ; if(!aNode) { return false; } aEmitter.setGeneratorParticleSize(aNode->FloatAttribute("min"), aNode->FloatAttribute("max")); aNode = aGeneratorNode->FirstChildElement("particleAngle") ; if(!aNode) { return false; } aEmitter.setGeneratorParticleAngle(aNode->FloatAttribute("min"), aNode->FloatAttribute("max")); aNode = aGeneratorNode->FirstChildElement("particleLV") ; if(!aNode) { return false; } aEmitter.setGeneratorParticleLV(aNode->FloatAttribute("min"), aNode->FloatAttribute("max")); aNode = aGeneratorNode->FirstChildElement("particleAV") ; if(!aNode) { return false; } aEmitter.setGeneratorParticleAV(aNode->FloatAttribute("min"), aNode->FloatAttribute("max")); addEmitter(aEmitter); aEmitterNode = aEmitterNode->NextSiblingElement("emitter"); } return true; }
int main() { //////////////////////////////////////////BASICS/////////////////////////////////////////// srand(time(NULL)); glfwInit(); //WINDOW Window window(50, 50, 800, 600, "ParticleSystem"); glfwMakeContextCurrent(window.getWindow()); //CAM cam.setPosition(glm::vec4(-15.0, 0.0, 7.0, 1.0)); cam.setNearFar(0.1f, 100.0f); cam.setLookAt(glm::vec3(cam.getPosition().x, cam.getPosition().y, cam.getPosition().z - 1.0)); cam.setKeySpeed(8.0); iH.setAllInputMaps(cam); iH.changeActiveInputMap("Pilotview"); //Callback glfwSetKeyCallback(window.getWindow(), key_callback); //More then just 60 fps, vsync off glfwSwapInterval(0); glewInit(); //SHADER VertexShader vsSkybox(loadShaderSource(SHADERS_PATH + std::string("/SkyboxShader/SkyboxShader.vert"))); FragmentShader fsSkybox(loadShaderSource(SHADERS_PATH + std::string("/SkyboxShader/SkyboxShader.frag"))); ShaderProgram shaderSkybox(vsSkybox, fsSkybox); VertexShader vsObject(loadShaderSource(SHADERS_PATH + std::string("/TextureShader3D/TextureShader3D.vert"))); FragmentShader fsObject(loadShaderSource(SHADERS_PATH + std::string("/TextureShader3D/TextureShader3D.frag"))); ShaderProgram shaderObject(vsObject, fsObject); /////////////////////////////////////////TEXTURES////////////////////////////////////////// //COMIC CLOUD Texture* comicBalloonTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/balloon01.png"); Texture* comicBalloonTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/balloon02.png"); Texture* comicBalloonTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/balloon03.png"); Texture* comicBalloonTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/balloon04.png"); Texture* comicCloudTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/cloud01.png"); Texture* comicCloudTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/cloud02.png"); Texture* comicCloudTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/cloud03.png"); Texture* comicCloudTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/cloud04.png"); Texture* comicExclamationMarkTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/exclamationMark01.png"); Texture* comicExclamationMarkTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/exclamationMark02.png"); Texture* comicExclamationMarkTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/exclamationMark03.png"); Texture* comicExclamationMarkTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/exclamationMark04.png"); Texture* comicLightningTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/lightning01.png"); Texture* comicLightningTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/lightning02.png"); Texture* comicLightningTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/lightning03.png"); Texture* comicLightningTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/lightning04.png"); Texture* comicSpiralTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral01.png"); Texture* comicSpiralTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral02.png"); Texture* comicSpiralTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral03.png"); Texture* comicSpiralTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral04.png"); Texture* comicSpiralTex5 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral05.png"); Texture* comicSpiralTex6 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/spiral06.png"); Texture* comicStarTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/star01.png"); Texture* comicStarTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/comicCloud/star02.png"); //FIRE Texture* fireTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/flame01_L.png"); Texture* fireTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/flame02_L.png"); Texture* fireTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/fire/flame03_L.png"); //PARTICLE Texture* particleBlackTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/virus.png"); Texture* particleWhiteTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/particle.png"); Texture* snowTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/snowflake.png"); //TODO better Resolution Texture* glowwormTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/glowworm.png"); Texture* energyTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/energy.png"); Texture* fireflyTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/firefly.png"); Texture* fireSparkTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/sparkOrange.png"); Texture* fireSparkTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/particle/sparkRed.png"); //RAIN Texture* rainTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/rain/rain.png"); //TODO darker //SMOKE Texture* drawSmokeTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeDraw/smoke01_L.png"); Texture* drawSmokeTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeDraw/smoke02_L.png"); Texture* drawSmokeTex3 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeDraw/smoke03_L.png"); Texture* drawSmokeTex4 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeDraw/smoke04_L.png"); Texture* smokeWhiteTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeWhite/smokeWhite01.png"); Texture* smokeWhiteTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeWhite/smokeWhite02.png"); Texture* smokeBlackTex1 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeBlack/smokeBlack01.png"); Texture* smokeBlackTex2 = new Texture((char*)RESOURCES_PATH "/ParticleSystem/smoke/smokeBlack/smokeBlack02.png"); //STAR Texture* fireWorkYellowTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starYellow.png"); //TODO Work? Texture* fireWorkOrangeTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starPink.png"); //TODO Work? Texture* fireWorkRedTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starRed.png"); //TODO Work? Texture* fireWorkBlueTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starBlue.png"); //TODO Work? Texture* fireWorkGreenTex = new Texture((char*)RESOURCES_PATH "/ParticleSystem/star/starGreen.png"); //TODO Work? ///////////////////////////////////////FINAL EMITTER/////////////////////////////////////// //FINAL EMITTER SNOW Emitter* snow = new Emitter(0, glm::vec3(0.0, 5.0, 0.0), 0.0, 0.166, 100, 30.0, true); snow->setVelocity(0); snow->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 1.0), 0.5f); snow->setAreaEmitting(false,true, 10.0, 10000); snow->addTexture(snowTex, 0.0); snow->defineLook(true, 0.04, 2.0); particleCount += (100 * 30 / 0.166); //FINAL EMITTER STRONG SNOW Emitter* snowStrong = new Emitter(0, glm::vec3(-3.5, 4.0, 0.0), 0.0, 0.166, 100, 15.0, true); snowStrong->setVelocity(2); snowStrong->usePhysicDirectionGravity(glm::vec4(0.6, -1.5, 0.0, 1.0), 2.6f); snowStrong->setAreaEmitting(false, true, 8.0, 10000); snowStrong->addTexture(snowTex, 0.0); snowStrong->defineLook(true, 0.03, 1.0, 3.0); particleCount += (100 * 15.0 / 0.166); //FINAL EMITTER WHITE SMOKE Emitter* smokeWhite = new Emitter(0, glm::vec3(3.0, -1.0, 1.0), 0.0, 0.4, 1, 8.0, true); smokeWhite->setVelocity(2); smokeWhite->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.8), 0.3f); smokeWhite->addTexture(smokeWhiteTex1, 1.0); smokeWhite->addTexture(smokeWhiteTex2, 0.25); std::vector<float> smokeWhiteSize{ 0.05f, 0.5f, 0.75f, 1.2f }; std::vector<float> smokeWhiteTime{ 0.0f, 0.4f, 0.75f, 1.0f }; smokeWhite->defineLook(true, smokeWhiteSize, smokeWhiteTime, 1.0, 4.0, 3.0, false, 0.3); smokeWhite->switchToGeometryShader(); particleCount += (1 * 8.0 / 0.4); //FINAL EMITTER BLACK SMOKE Emitter* smokeBlack = new Emitter(0, glm::vec3(6.0, -1.0, 1.0), 0.0, 0.6, 1, 8.0, true); smokeBlack->setVelocity(2); smokeBlack->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.8), 0.3f); smokeBlack->addTexture(smokeBlackTex1, 1.0); smokeBlack->addTexture(smokeBlackTex2, 0.2); std::vector<float> smokeBlackSize{ 0.1f, 0.4f, 0.8f, 1.2f }; std::vector<float> smokeBlackTime{ 0.0f, 0.2f, 0.75f, 1.0f }; smokeBlack->defineLook(true, smokeBlackSize, smokeBlackTime, 1.0, 5.0, 3.0, false, 0.3); smokeBlack->switchToGeometryShader(); particleCount += (1 * 8 / 0.4); //FINAL EMITTER CLOUD SMOKE Emitter* smokeCloud = new Emitter(0, glm::vec3(15.0, -1.0, 1.0), 0.0, 0.3, 1, 10.0, true); smokeCloud->setVelocity(3); smokeCloud->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.1), 0.15f); smokeCloud->addTexture(smokeWhiteTex1, 1.0); smokeCloud->addTexture(smokeWhiteTex2, 0.08); std::vector<float> smokeCloudSize{ 0.1f, 0.4f, 0.8f, 1.2f }; std::vector<float> smokeCloudTime{ 0.0f, 0.2f, 0.75f, 1.0f }; smokeCloud->defineLook(true, smokeBlackSize, smokeBlackTime, 1.0, 2.0, 4.0, false, 0.3); smokeCloud->switchToGeometryShader(); particleCount += (1 * 10.0 / 0.3); //FINAL EMITTER RAIN Emitter* rain = new Emitter(0, glm::vec3(0.0, 3.0, 0.0), 0.0, 0.02, 50, 5.0, true); rain->setVelocity(0); rain->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 1.0), 5.0f); rain->setAreaEmitting(false, true, 8.0, 10000); rain->addTexture(rainTex, 0.0); rain->defineLook(true, 0.03, 1.0, 0.0); particleCount += (50 * 5.0 / 0.02); //FINAL EMITTER FONTAINE Emitter* fontaine = new Emitter(0, glm::vec3(-15.0,-1.0, 1.0), 0.0, 0.05, 5, 2.0, true); fontaine->setVelocity(0); fontaine->usePhysicTrajectory(glm::vec4(0.0, 0.0, 0.0, 1.0), 1.0); //fontaine->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.0), 0.7f); fontaine->defineLook(false, 0.3, 0.0, 0.5, 0.0, true, 1.0); particleCount += (3 * 2.0 / 0.05); //FINAL EMITTER CIRCLE Emitter* circle = new Emitter(0, glm::vec3(-18.0, 0.0, 1.0), 0.0, 0.2, 50, 4.0, true); circle->setVelocity(4); circle->addTexture(fireSparkTex1, 1.0); circle->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.0), 0.3f); circle->addTexture(fireSparkTex2 ,0.1); circle->defineLook(true, 0.03, 0.0, 2.0, 1.0, true, 0.0); circle->switchToGeometryShader(); particleCount += (50 * 4.0 / 0.4); //FINAL EMITTER QUAD Emitter* quad = new Emitter(0, glm::vec3(-21.0, 0.0, 1.0), 0.0, 1.0, 100, 1.0, true); quad->setVelocity(0); quad->setAreaEmitting(true, true, 0.5, 1); quad->defineLook(false, 0.1, 0.0, 0.0, 0.0, false, 0.0); particleCount += (50 * 1.0 / 1.0); //FINAL EMITTER FRUITFLIES Emitter* fruitFlies = new Emitter(0, glm::vec3(11.5, 0.0, 1.0), 0.0, 0.166, 2, 10.0, true); fruitFlies->setVelocity(0); fruitFlies->usePhysicSwarmCircleMotion(true, true, true, 3.0); fruitFlies->setAreaEmitting(true, true, 0.5, 100); fruitFlies->addTexture(particleBlackTex, 0.0); fruitFlies->defineLook(true, 0.012, 3.0, 3.0, 0.0, true, 1.0); fruitFlies->switchToGeometryShader(); particleCount += (2 * 10.0 / 0.166); //FINAL SCREEN EMITTER FRUITFLIES Emitter* screenFruitFlies = new Emitter(0, glm::vec3(-0.2, 0.2, 7.0), 0.0, 0.1, 2, 10.0, true); screenFruitFlies->setVelocity(0); screenFruitFlies->usePhysicSwarmCircleMotion(true, true, true, 3.0); screenFruitFlies->setAreaEmitting(true, false, 2.5, 1000); screenFruitFlies->addTexture(particleBlackTex, 0.0); screenFruitFlies->defineLook(true, 0.02, 1.0, 3.0, 0.0, true, 1.0); screenFruitFlies->switchToGeometryShader(); particleCount += (3 * 10.0 / 0.166); //FINAL EMITTER GLOWWORM Emitter* glowworm = new Emitter(0, glm::vec3(-3.0, 0.0, 1.0), 0.0, 0.2, 1, 10.0, true); glowworm->setVelocity(0); glowworm->usePhysicSwarmCircleMotion(true, true, true, 3.0); glowworm->setAreaEmitting(true, false, 0.4, 1000); glowworm->addTexture(glowwormTex, 0.0); glowworm->defineLook(true, 0.1, 1.0, 1.5); particleCount += (1 * 10.0 / 0.2); //FINAL EMITTER ENERGYBALL Emitter* energyBall = new Emitter(0, glm::vec3(-12.0, -1.0, 1.0), 0.0, 0.01, 5, 15.0, true); energyBall->setVelocity(5); energyBall->usePhysicPointGravity(glm::vec4(-10.0, 1.0, 1.0, 3.0), 8.0, 2, 1.8); energyBall->addTexture(energyTex, 1.0); energyBall->defineLook(true, 0.04); particleCount += (5 * 15.0 / 0.01); //FINAL EMITTER COMIC CLOUD Emitter* cloud01 = new Emitter(0, glm::vec3(-6.0, 0.5, 1.0), 0.0, 1.6, 1, 10.0, true); cloud01->setVelocity(4); cloud01->usePhysicPointGravity(glm::vec4(0.0, -1.0, 0.0, -0.0), 0.0, 0, 0.72); cloud01->addTexture(comicCloudTex1, 0.0); std::vector<float> cloudSize1{ 0.8f, 1.6f }; std::vector<float> cloudTime1{ 0.0f, 1.0f }; cloud01->defineLook(true, cloudSize1, cloudTime1, 0.4, 4.0, 0.0, false, 0.3); cloud01->switchToGeometryShader(); particleCount += (1 * 1.5 / 10.0); Emitter* cloud02 = new Emitter(0, glm::vec3(-6.0, 0.5, 1.0), 0.0, 2.3, 1, 10.0, true); cloud02->setVelocity(4); cloud02->usePhysicPointGravity(glm::vec4(0.0, -1.0, 0.0, -0.0), 0.0, 0, 0.6); cloud02->addTexture(comicCloudTex3, 0.0); std::vector<float> cloudSize2{ 0.8f, 1.6f }; std::vector<float> cloudTime2{ 0.0f, 1.0f }; cloud02->defineLook(true, cloudSize2, cloudTime2, 0.4, 4.0, 0.0, false, 0.3); cloud02->switchToGeometryShader(); particleCount += (1 * 2.1 / 10.0); Emitter* cloud03 = new Emitter(0, glm::vec3(-7.0, 1.0, 1.0), 0.0, 0.0, 1, 0.0, false); cloud03->setVelocity(0); cloud03->addTexture(comicBalloonTex4, 1.0); cloud03->defineLook(true, 0.8, 2.0); cloud03->switchToGeometryShader(); particleCount += 1; Emitter* cloud04 = new Emitter(0, glm::vec3(-4.8, 2.0, 1.0), 0.0, 0.0, 1, 0.0, false); cloud04->setVelocity(0); cloud04->addTexture(comicStarTex2, 1.0); cloud04->defineLook(true, 0.3, 2.0, 0.0, 0.0, false, 0.6); cloud04->switchToGeometryShader(); particleCount += 1; Emitter* cloud05 = new Emitter(0, glm::vec3(-7.0, -1.0, 1.0), 0.0, 0.0, 1, 0.0, false); cloud05->setVelocity(0); cloud05->addTexture(comicStarTex2, 1.0); cloud05->defineLook(true, 0.5, 2.0, 0.0, 0.0, true, 0.4); cloud05->switchToGeometryShader(); particleCount += 1; Emitter* cloud06 = new Emitter(0, glm::vec3(-4.3, 0.2, 1.0), 0.0, 0.0, 1, 0.0, false); cloud06->setVelocity(0); cloud06->addTexture(comicSpiralTex5, 1.0); cloud06->defineLook(true, 0.3, 2.0); cloud06->switchToGeometryShader(); particleCount += 1; Emitter* cloud07 = new Emitter(0, glm::vec3(-8.0, 0.7, 1.0), 0.0, 0.0, 1, 0.0, false); cloud07->setVelocity(0); cloud07->addTexture(comicSpiralTex3, 1.0); cloud07->defineLook(true, 0.3, 2.0); cloud07->switchToGeometryShader(); particleCount += 1; Emitter* cloud08 = new Emitter(0, glm::vec3(-7.9, 2.1, 1.0), 0.0, 0.0, 1, 0.0, false); cloud08->setVelocity(0); cloud08->addTexture(comicLightningTex1, 1.0); cloud08->defineLook(true, 0.6, 2.0); cloud08->switchToGeometryShader(); particleCount += 1; Emitter* cloud09 = new Emitter(0, glm::vec3(-4.0, 1.4, 1.0), 0.0, 0.0, 1, 0.0, false); cloud09->setVelocity(0); cloud09->addTexture(comicLightningTex4, 1.0); cloud09->defineLook(true, 0.5, 2.0); cloud09->switchToGeometryShader(); particleCount += 1; Emitter* cloud10 = new Emitter(0, glm::vec3(-3.7, 0.8, 1.0), 0.0, 0.0, 1, 0.0, false); cloud10->setVelocity(0); cloud10->addTexture(comicExclamationMarkTex3, 1.0); cloud10->defineLook(true, 0.3, 2.0); cloud10->switchToGeometryShader(); particleCount += 1; Emitter* cloud11 = new Emitter(0, glm::vec3(-6.5, 2.4, 1.0), 0.0, 0.0, 1, 0.0, false); cloud11->setVelocity(0); cloud11->addTexture(comicExclamationMarkTex2, 1.0); cloud11->defineLook(true, 0.5, 2.0); cloud11->switchToGeometryShader(); particleCount += 1; ////////////////////////////////NOT FINAL EMITTER//////////////////////////////// //FINAL EMITTER MAXIMUM; SET POSITION Emitter* maximumParticle = new Emitter(0, glm::vec3(-21.0, -3.0, 0.0), 0.0, 0.2, 5000, 12.0, true); maximumParticle->setVelocity(3); maximumParticle->usePhysicDirectionGravity(glm::vec4(0.0, 1.0, 0.0, 0.2), 0.5); maximumParticle->defineLook(false, 0.01); int particleCountMax = 5000 * 12 / 0.2; //particleMax with Texture //!EMITTER FIRE Emitter* fireMiddle = new Emitter(0, glm::vec3(9.0, 0.0, 1.0), 0.0, 1.0, 3.0, 4.0, true); fireMiddle->setVelocity(3); fireMiddle->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.5), 0.2); fireMiddle->addTexture(fireTex1, 1.0); //fireMiddle->addTexture(fireTex2, 0.5); fireMiddle->addTexture(fireTex3, 0.0); fireMiddle->defineLook(true, 0.5, 1.0, 2.0); fireMiddle->switchToGeometryShader(); Emitter* fireSmoke = new Emitter(0, glm::vec3(9.0, -1.0, 1.0), 0.0, 0.4, 1, 8.0, true); fireSmoke->setVelocity(2); fireSmoke->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -0.8), 0.3f); fireSmoke->addTexture(smokeBlackTex1, 1.0); fireSmoke->addTexture(smokeBlackTex2, 0.08); std::vector<float> fireSmokeSize{ 0.1f, 0.4f, 0.8f, 1.2f }; std::vector<float> fireSmokeTime{ 0.0f, 0.2f, 0.75f, 1.0f }; fireSmoke->defineLook(true, fireSmokeSize, fireSmokeTime, 1.0, 4.0, 1.0, false, 0.3); fireSmoke->switchToGeometryShader(); Emitter* firefly = new Emitter(0, glm::vec3(9.1, -0.9, 1.0), 0.0, 1.3, 1, 9.0, true); firefly->setVelocity(3); firefly->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -1.5), 0.13f); firefly->addTexture(fireflyTex, 1.0); firefly->defineLook(true, 0.04, 2.0, 2.0, 0.0, false, 0.3); Emitter* fireSparkOrange = new Emitter(0, glm::vec3(9.1, -0.9, 1.0), 0.0, 0.1, 1, 0.8, true); fireSparkOrange->setVelocity(3); fireSparkOrange->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -1.0), 1.5f); fireSparkOrange->addTexture(fireSparkTex1, 1.0); fireSparkOrange->defineLook(true, 0.02, 0.4, 0.3, 0.0, false, 0.3); Emitter* fireSparkRed = new Emitter(0, glm::vec3(9.1, -0.9, 1.0), 0.0, 0.1, 1, 1.0, true); fireSparkRed->setVelocity(3); fireSparkRed->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, -1.5), 1.5f); fireSparkRed->addTexture(fireSparkTex2, 1.0); fireSparkRed->defineLook(true, 0.02, 0.4, 0.3, 0.0, false, 0.3); //!EMITTER FIREWORK Emitter* firework = new Emitter(0, glm::vec3(0.6, 0.6, 0.0), 0.0, 0.5, 5, 1.0, true); firework->setVelocity(4); firework->usePhysicDirectionGravity(glm::vec4(0.0,-1.0,0.0,0.1), 1.0f); //firework->addTexture(*fireWorkYellowTex, 0.0); //firework->defineLook(true, 0.8, 0.1, 0.2); Emitter* firework2 = new Emitter(0, glm::vec3(-0.6, -0.6, 0.0), 0.0, 0.5, 5, 1.0, true); firework2->setVelocity(4); firework2->usePhysicDirectionGravity(glm::vec4(0.0, -1.0, 0.0, 0.1), 1.0f); //firework2->addTexture(*fireWorkOrangeTex, 0.0); //firework2->defineLook(true, 0.8, 0.1, 0.2); //////////////////////////////////////OUR SCENE/////////////////////////////////////////////// //SKYBOX Cube cube; const char *textureNames[6] = { /*(char*)RESOURCES_PATH "/PereaBeach1/posx.jpg", (char*)RESOURCES_PATH "/PereaBeach1/negx.jpg", (char*)RESOURCES_PATH "/PereaBeach1/posy.jpg", (char*)RESOURCES_PATH "/PereaBeach1/negy.jpg", (char*)RESOURCES_PATH "/PereaBeach1/posz.jpg", (char*)RESOURCES_PATH "/PereaBeach1/negz.jpg"*/ (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png", (char*)RESOURCES_PATH "/Color/testTex.png" }; Skybox skybox(textureNames); Node skyboxNode("skybox"); skyboxNode.addGeometry(&cube); //OBJECTS Teapot teapot; teapot.loadBufferData(); Sphere sphere; sphere.loadBufferData(); Rect plane; plane.loadBufferData(); //TEXTURES Texture chrome((char*)RESOURCES_PATH "/Metal/chrome.jpg"); Texture marble((char*)RESOURCES_PATH "/Wall/seamless_marble.png"); //TODO JPG Texture cvLogo((char*)RESOURCES_PATH "/Symbol/cv_logo.bmp"); Texture bricks((char*)RESOURCES_PATH "/Wall/brick.bmp"); //CREATING NODES Level testLevel("testLevel"); Scene testScene("testScene"); testLevel.addScene(&testScene); testLevel.changeScene("testScene"); Node cube1("cube1"); cube1.addGeometry(&cube); cube1.addTexture(&chrome); cube1.setModelMatrix(glm::translate(cube1.getModelMatrix(), glm::vec3(-0.3, 0.25, 0.4))); cube1.setModelMatrix(glm::scale(cube1.getModelMatrix(), glm::vec3(0.3, 0.3, 0.3))); Node cube2("cube2"); cube2.addGeometry(&cube); cube2.addTexture(&chrome); cube2.setModelMatrix(glm::translate(cube2.getModelMatrix(), glm::vec3(0.7, 0.25, 0.4))); cube2.setModelMatrix(glm::scale(cube2.getModelMatrix(), glm::vec3(0.3, 0.3, 0.3))); Node wallNode1("wall1"); wallNode1.addGeometry(&plane); wallNode1.addTexture(&marble); wallNode1.setModelMatrix(glm::translate(wallNode1.getModelMatrix(), glm::vec3(0.0, -1.0, 0.0))); wallNode1.setModelMatrix(glm::rotate(wallNode1.getModelMatrix(), 90.0f, glm::vec3(1.0, 0.0, 0.0))); wallNode1.setModelMatrix(glm::scale(wallNode1.getModelMatrix(), glm::vec3(25.0, 2.0, 1.0))); Node wallNode2("wall2"); wallNode2.addGeometry(&plane); wallNode2.addTexture(&bricks); wallNode2.setModelMatrix(glm::translate(wallNode2.getModelMatrix(), glm::vec3(0.0, 0.0, 0.0))); wallNode2.setModelMatrix(glm::scale(wallNode2.getModelMatrix(), glm::vec3(25.0, 2.5, 1.0))); Node teaNode("teaNode"); teaNode.addGeometry(&teapot); teaNode.addTexture(&cvLogo); teaNode.setModelMatrix(glm::translate(teaNode.getModelMatrix(), glm::vec3(0.2, 0.3, 1.0))); teaNode.setModelMatrix(glm::scale(teaNode.getModelMatrix(), glm::vec3(0.3, 0.3, 0.3))); //CREATING A SCENEGRAPH testScene.getScenegraph()->getRootNode()->addChildrenNode(&wallNode1); testScene.getScenegraph()->getRootNode()->addChildrenNode(&wallNode2); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube1); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube2); testScene.getScenegraph()->getRootNode()->addChildrenNode(&teaNode); //ADD CAMERA TO SCENEGRAPH testScene.getScenegraph()->addCamera(&cam); testScene.getScenegraph()->getCamera("Pilotview"); testScene.getScenegraph()->setActiveCamera("Pilotview"); //GUI initGUI(); double startCamTime = glfwGetTime(); int outputFrames = 0; float dTime; while (!glfwWindowShouldClose(window.getWindow())) { //CAM dTime = glfwGetTime() - startCamTime; cam.setSensitivity(dTime); startCamTime = glfwGetTime(); //Maximum Particle if (!useMaximumParticle->isActive()){ //SKYBOX glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderSkybox.bind(); glDisable(GL_DEPTH_TEST); shaderSkybox.sendMat4("viewMatrix", cam.getViewMatrix()); shaderSkybox.sendMat4("projectionMatrix", cam.getProjectionMatrix()); shaderSkybox.sendSkyboxTexture("testTexture", skybox.getSkyboxTexture()); //skyboxNode.render(); shaderSkybox.unbind(); glEnable(GL_DEPTH_TEST); shaderObject.bind(); shaderObject.sendMat4("viewMatrix", cam.getViewMatrix()); shaderObject.sendMat4("projectionMatrix", cam.getProjectionMatrix()); shaderObject.sendInt("useTexture", 1); teaNode.setModelMatrix(glm::rotate(teaNode.getModelMatrix(), 3.0f, glm::vec3(0.0, 1.0, 0.0))); cube1.setModelMatrix(glm::rotate(cube1.getModelMatrix(), 3.0f, glm::vec3(0.0, 1.0, 0.0))); cube2.setModelMatrix(glm::rotate(cube2.getModelMatrix(), 3.0f, glm::vec3(0.0, 1.0, 0.0))); //testScene.render(shaderObject); shaderObject.unbind(); ///////////////////////////////////////FINAL EMITTER/////////////////////////////////////// glDisable(GL_DEPTH_TEST); //smokeWhite->update(); //smokeWhite->render(cam); //smokeBlack->update(); //smokeBlack->render(cam); fontaine->update(); fontaine->render(cam); //circle->update(); //circle->render(cam); //quad->update(); //quad->render(cam); //glowworm->update(); //glowworm->render(cam); //fruitFlies->update(); //fruitFlies->render(cam); //energyBall->update(); //energyBall->render(cam); //cloud01->update(); //cloud01->render(cam); //cloud02->update(); //cloud02->render(cam); //cloud03->update(); //cloud03->render(cam); //cloud04->update(); //cloud04->render(cam); //cloud05->update(); //cloud05->render(cam); //cloud06->update(); //cloud06->render(cam); //cloud07->update(); //cloud07->render(cam); //cloud08->update(); //cloud08->render(cam); //cloud09->update(); //cloud09->render(cam); //cloud10->update(); //cloud10->render(cam); //cloud11->update(); //cloud11->render(cam); } ////////////////////////////////FINAL SCREEN EMITTER////////////////////////////////////////////////// else{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); maximumParticle->update(); maximumParticle->render(cam); particleCount = particleCountMax; } if (useFruitFliesButton->isActive()){ screenFruitFlies->update(); screenFruitFlies->render(screen); } else{ screenFruitFlies->startTime(); } ////////////////////////////////FINAL GUI EMITTER/////////////////////////////////////////// if (useSnowButton->isActive()){ snow->update(glm::vec3(cam.getPosition())); snow->render(cam); } else{ snow->startTime(); } if (useStrongSnowButton->isActive()){ snowStrong->update(glm::vec3(cam.getPosition())); snowStrong->render(cam); } else{ snowStrong->startTime(); } if (useRainButton->isActive()){ rain->update(glm::vec3(cam.getPosition())); rain->render(cam); }{ rain->startTime(); } ////////////////////////////////WAITING FOR TEXTURES EMITTER//////////////////////////////// //todo: flamme //fireMiddle->update(); //fireMiddle->render(cam); //fireSmoke->update(); //fireSmoke->render(cam); //firefly->update(); //firefly->render(cam); //fireSparkOrange->update(); //fireSparkOrange->render(cam); //fireSparkRed->update(); //fireSparkRed->render(cam); // todo all //firework->update(); //firework->render(cam); //smokeCloud //smokeCloud->update(); //smokeCloud->render(cam); ////////////////////////////////BASICS/////////////////////////////////////////////////////// //renderer->renderGUI(*gui, window); //WINDOW window.swapAndPoll(); //FPS if (!(outputFrames % 30)){ outputFrames = 1; //std::cout << "FPS: " << static_cast<int> (1 / dTime) << "; Up to " << particleCount << " particles"<<std::endl; } outputFrames++; } glfwDestroyWindow(window.getWindow()); glfwTerminate(); return 0; }
bool UpdateGame(void) { Matrix2 orientation(gameShip.m_orientation); Vector2 gravity(0.0f,-0.004f); //gameShip.AddBodyForce(gravity); float k = 0.001f; if(debugSpring1) { Vector2 force = gameSpring1 - (gameShip.m_position + orientation * gameAnchor1); gameShip.AddBodyForce(force * k,gameShip.m_position + orientation * gameAnchor1); } if(debugSpring2) { Vector2 force = gameSpring2 - (gameShip.m_position + orientation * gameAnchor2); gameShip.AddBodyForce(force * k,gameShip.m_position + orientation * gameAnchor2); } if(HIWORD(GetAsyncKeyState(VK_LEFT))) { gameShip.m_rearEngineOrientation += GetElapsedTime() / 50.0f; gameShip.m_frontEngineOrientation += GetElapsedTime() / 50.0f; } if(HIWORD(GetAsyncKeyState(VK_RIGHT))) { gameShip.m_rearEngineOrientation -= GetElapsedTime() / 50.0f; gameShip.m_frontEngineOrientation -= GetElapsedTime() / 50.0f; } if(HIWORD(GetAsyncKeyState('B'))) { gameShip.m_mainEngineOrientation += GetElapsedTime() / 50.0f; } if(HIWORD(GetAsyncKeyState('N'))) { gameShip.m_mainEngineOrientation -= GetElapsedTime() / 50.0f; } if(HIWORD(GetAsyncKeyState(VK_UP))) { Matrix2 rotation(gameShip.m_frontEngineOrientation + gameShip.m_orientation); gameShip.AddBodyForce(rotation * Vector2(0.0f,0.002f),gameShip.m_position + orientation * gameShip.m_frontEnginePosition); gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_frontEnginePosition); } if(HIWORD(GetAsyncKeyState(VK_SPACE))) { Matrix2 rotation(gameShip.m_mainEngineOrientation + gameShip.m_orientation); gameShip.AddBodyForce(rotation * Vector2(0.0f,0.004f),gameShip.m_position + orientation * gameShip.m_mainEnginePosition); gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_mainEnginePosition); gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_mainEnginePosition); } if(HIWORD(GetAsyncKeyState(VK_UP))) { Matrix2 rotation(gameShip.m_rearEngineOrientation + gameShip.m_orientation); gameShip.AddBodyForce(rotation * Vector2(0.0f,0.001f),gameShip.m_position + orientation * gameShip.m_rearEnginePosition); gameEmitter.AddParticle(rotation * -Vector2(randf() / 60.0f,0.1f),gameShip.m_position + Vector2(randf(),randf())/50.0f + orientation * gameShip.m_rearEnginePosition); } gameShip.UpdateBody(); gameEmitter.UpdateParticles(); for(unsigned long i = 0; i < gameMissles.GetSize(); ++i) { Matrix2 orientation(gameMissles[i]->m_orientation); gameMissles[i]->AddBodyForce(gravity); Vector2 target = Matrix2(-gameMissles[i]->m_orientation) * (gameMissles[i]->m_target - gameMissles[i]->m_position); bool left = false,right = false; if(gameMissles[i]->m_life > 50.0f) { if(target.x > -0.1f && target.x < 0.1f && target.y > 0) left = right = true; else if(target.x < 0) right = true; else left = true; } if(left) { gameMissles[i]->AddBodyForce(orientation * Vector2(0.0f,0.008f),gameMissles[i]->m_position + orientation * gameMissles[i]->m_engines[0]); gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[0]); gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[0]); } if(right) { gameMissles[i]->AddBodyForce(orientation * Vector2(0.0f,0.008f),gameMissles[i]->m_position + orientation * gameMissles[i]->m_engines[1]); gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[1]); gameEmitter.AddParticle(orientation * -Vector2(randf() / 60.0f,0.1f),gameMissles[i]->m_position + Vector2(randf(),randf())/50.0f + orientation * gameMissles[i]->m_engines[1]); } gameMissles[i]->UpdateBody(); gameMissles[i]->m_life += GetElapsedTime(); if(gameMissles[i]->m_spring) { Vector2 force = *gameMissles[i]->m_spring - gameMissles[i]->m_position; gameMissles[i]->AddBodyForce(force * k); } if(gameMissles[i]->m_life > 1500.0f || target.GetLength() < 0.4f) { for(unsigned long j = 0; j < 256; ++j) gameEmitter.AddParticle(Vector2Normalize(Vector2(randf(),randf())) * randf() / 6.0f,gameMissles[i]->m_position); delete gameMissles[i]; gameMissles.Erase(i); --i; } } return true; }
void Options::Save() { Emitter out; out << BeginMap; out << Key << "Audio" << Value << BeginMap; { out << Key << "GuitarVolume" << Value << guitarVolume; out << Key << "BackingVolume" << Value << backingVolume; out << Key << "MetronomeVolume" << Value << metronomeVolume; out << Key << "InputDevice" << Value << inputDevice; out << Key << "OutputDevice" << Value << outputDevice; out << Key << "BufferSize" << Value << bufferSize; out << Key << "SampleRate" << Value << sampleRate; } out << EndMap; out << Key << "Video" << Value << BeginMap; { out << Key << "Resolution" << Value << screenResolution; out << Key << "Fullscreen" << Value << fullScreen; out << Key << "Detail" << Value << detailLevel; } out << EndMap; out << Key << "Game" << Value << BeginMap; { out << Key << "StringColors" << Value << Flow << BeginSeq; { out << stringColors[0] << stringColors[1] << stringColors[2]; out << stringColors[3] << stringColors[4] << stringColors[5]; } out << EndSeq; //out << Key << "DefaultDistortion" << Value << defaultDistortion; //out << Key << "DefaultStompBox" << Value << defaultStompbox; } out << EndMap; // directories out << Key << "Directories" << Value << BeginMap; { out << Key << "Songs" << Value << songDir; out << Key << "Tabs" << Value << tabDir; out << Key << "FX" << Value << fxDir; out << Key << "Backing" << Value << backingDir; } out << EndMap; // player out << Key << "Player" << Value << BeginMap; { out << Key << "UserName" << Value << userName; out << Key << "PasswordHash" << Value << Flow << BeginSeq; { out << passHash[0] << passHash[1] << passHash[2] << passHash[3]; } out << EndSeq; out << Key << "SavePassword" << Value << savePassword; out << Key << "AutoLogin" << Value << autoLogin; } out << EndMap; out << EndMap; if(out.good()); { ofstream o(optionsymlfile.c_str(), ios::binary); if(!o.fail()) { o.write(out.c_str(), out.size()); } } }
int main(int argc, char *argv[]) { int num_tests = INT_MAX, num_funcs_or_objs = INT_MAX; bool only_functions = false, only_objects = false, failures_printed = true, successes_printed = true; StringList tests_to_run(""); //Checks arguments if(argc >= 2) { int i = 1; while(i < argc) { if(strcmp(argv[i], "-n") == MATCH) { if(i >= argc - 1) { printf("Missing additional argument for '%s'.\n", argv[i]); print_usage(); return EXIT_FAILURE; } num_tests = atoi(argv[i+1]); i++; } else if(strcmp(argv[i], "-N") == MATCH) { if(i >= argc - 1) { printf("Missing additional argument for '%s'.\n", argv[i]); print_usage(); return EXIT_FAILURE; } num_funcs_or_objs = atoi(argv[i+1]); i++; } else if(strcmp(argv[i], "-F") == MATCH) only_functions = true; else if(strcmp(argv[i], "-O") == MATCH) only_objects = true; else if(strcmp(argv[i], "-f") == MATCH) successes_printed = false; else if(strcmp(argv[i], "-p") == MATCH) failures_printed = false; else if(strcmp(argv[i], "-y") == MATCH) { successes_printed = false; failures_printed = false; } else if(strcmp(argv[i], "-t") == MATCH) { if(i >= argc - 1) { printf("Missing additional argument(s) for '%s'.\n", argv[i]); print_usage(); return EXIT_FAILURE; } i++; int j = i; //Adds specific tests to list while(j < argc && argv[j][0] != '-') { tests_to_run.append(argv[j]); j++; } i = j - 1; } else if(strcmp(argv[i], "-h") == MATCH || strcmp(argv[i], "--help") == MATCH) { print_usage(); return EXIT_FAILURE; } else { printf("Invalid argument '%s'\n", argv[i]); print_usage(); return EXIT_FAILURE; } i++; } } //Need to initialize Winsocks on Windows. #ifdef WIN32 WSADATA wsaData; int iResult = WSAStartup(MAKEWORD(2,0), &wsaData); if(iResult != 0) { printf("Failed to initialize Winsock: %d\n", iResult); return EXIT_FAILURE; } #endif if(only_functions && only_objects) { only_functions = false; only_objects = false; } e.init(failures_printed, successes_printed); // set up the function driver FunctionDriver driver(num_funcs_or_objs); driver.init(num_tests); //Specific test(s) to run if(!tests_to_run.isEmpty()) { char* test = NULL; int i = 0; tests_to_run.rewind(); while((test = tests_to_run.next())) { i = 0; while(i < function_map_num_elems) { if(strcmp(function_map[i].name, test) == MATCH) { driver.register_function(function_map[i].func); break; } i++; } //Invalid test if(i >= function_map_num_elems) { printf("Invalid test '%s'.\n", test); #ifdef WIN32 //This technically can fail, but at this point we don't really care. WSACleanup(); #endif return EXIT_FAILURE; } } } //Many tests to run else { int i = 0; bool objects = false; while(i < function_map_num_elems) { if(!objects) { objects = (strcmp(function_map[i].name, "start of objects") == MATCH); if(!objects && !only_objects) driver.register_function(function_map[i].func); } else if(!only_functions) driver.register_function(function_map[i].func); i++; } } // run all the functions and return the result bool result = driver.do_all_functions(false); e.emit_summary(); #ifdef WIN32 //This technically can fail, but at this point we don't really care. WSACleanup(); #endif if(result) { printf ("Test suite has passed.\n"); return EXIT_SUCCESS; } printf ("Test suite has failed.\n"); return EXIT_FAILURE; }
Emitter *getElement(size_t i) { if (i != 0) return NULL; if (m_sunRadiusScale == 0) { Properties props("directional"); const Transform &trafo = m_worldTransform->eval(0); props.setVector("direction", -trafo(m_sunDir)); props.setFloat("samplingWeight", m_samplingWeight); props.setSpectrum("irradiance", m_radiance * m_solidAngle); Emitter *emitter = static_cast<Emitter *>( PluginManager::getInstance()->createObject( MTS_CLASS(Emitter), props)); emitter->configure(); return emitter; } /* Rasterizing the sphere to an environment map and checking the individual pixels for coverage (which is what Mitsuba 0.3.0 did) was slow and not very effective; for instance the power varied dramatically with resolution changes. Since the sphere generally just covers a few pixels, the code below rasterizes it much more efficiently by generating a few thousand QMC samples. Step 1: compute a *very* rough estimate of how many pixel in the output environment map will be covered by the sun */ size_t pixelCount = m_resolution*m_resolution/2; Float cosTheta = std::cos(m_theta * m_sunRadiusScale); /* Ratio of the sphere that is covered by the sun */ Float coveredPortion = 0.5f * (1 - cosTheta); /* Approx. number of samples that need to be generated, be very conservative */ size_t nSamples = (size_t) std::max((Float) 100, (pixelCount * coveredPortion * 1000)); ref<Bitmap> bitmap = new Bitmap(SUN_PIXELFORMAT, Bitmap::EFloat, Vector2i(m_resolution, m_resolution/2)); bitmap->clear(); Frame frame(m_sunDir); Point2 factor(bitmap->getWidth() / (2*M_PI), bitmap->getHeight() / M_PI); Spectrum *target = (Spectrum *) bitmap->getFloatData(); Spectrum value = m_radiance * (2 * M_PI * (1-std::cos(m_theta))) * static_cast<Float>(bitmap->getWidth() * bitmap->getHeight()) / (2 * M_PI * M_PI * nSamples); for (size_t i=0; i<nSamples; ++i) { Vector dir = frame.toWorld( Warp::squareToUniformCone(cosTheta, sample02(i))); Float sinTheta = math::safe_sqrt(1-dir.y*dir.y); SphericalCoordinates sphCoords = fromSphere(dir); Point2i pos( std::min(std::max(0, (int) (sphCoords.azimuth * factor.x)), bitmap->getWidth()-1), std::min(std::max(0, (int) (sphCoords.elevation * factor.y)), bitmap->getHeight()-1)); target[pos.x + pos.y * bitmap->getWidth()] += value / std::max((Float) 1e-3f, sinTheta); } /* Instantiate a nested envmap plugin */ Properties props("envmap"); Properties::Data bitmapData; bitmapData.ptr = (uint8_t *) bitmap.get(); bitmapData.size = sizeof(Bitmap); props.setData("bitmap", bitmapData); props.setAnimatedTransform("toWorld", m_worldTransform); props.setFloat("samplingWeight", m_samplingWeight); Emitter *emitter = static_cast<Emitter *>( PluginManager::getInstance()->createObject( MTS_CLASS(Emitter), props)); emitter->configure(); return emitter; }
Emitter* PugiXMLLoader::LoadEmitter( pugi::xml_node& node, const std::list<AnimImage*>& sprites, Effect *parent ) { Emitter* e = new Emitter; e->SetHandleX (node.attribute("HANDLE_X").as_int()); e->SetHandleY (node.attribute("HANDLE_Y").as_int()); e->SetBlendMode (node.attribute("BLENDMODE").as_int()); e->SetParticlesRelative (node.attribute("RELATIVE").as_bool()); e->SetRandomColor (node.attribute("RANDOM_COLOR").as_bool()); e->SetZLayer (node.attribute("LAYER").as_int()); e->SetSingleParticle (node.attribute("SINGLE_PARTICLE").as_bool()); e->SetName (node.attribute("NAME").as_string()); e->SetAnimate (node.attribute("ANIMATE").as_bool()); e->SetOnce (node.attribute("ANIMATE_ONCE").as_bool()); e->SetCurrentFrame (node.attribute("FRAME").as_float()); e->SetRandomStartFrame (node.attribute("RANDOM_START_FRAME").as_bool()); e->SetAnimationDirection(node.attribute("ANIMATION_DIRECTION").as_int()); e->SetUniform (node.attribute("UNIFORM").as_bool()); e->SetAngleType (node.attribute("ANGLE_TYPE").as_int()); e->SetAngleOffset (node.attribute("ANGLE_OFFSET").as_int()); e->SetLockAngle (node.attribute("LOCK_ANGLE").as_bool()); e->SetAngleRelative (node.attribute("ANGLE_RELATIVE").as_bool()); e->SetUseEffectEmission (node.attribute("USE_EFFECT_EMISSION").as_bool()); e->SetColorRepeat (node.attribute("COLOR_REPEAT").as_int()); e->SetAlphaRepeat (node.attribute("ALPHA_REPEAT").as_int()); e->SetOneShot (node.attribute("ONE_SHOT").as_bool()); e->SetHandleCenter (node.attribute("HANDLE_CENTERED").as_bool()); e->SetGroupParticles (node.attribute("GROUP_PARTICLES").as_bool()); if (e->GetAnimationDirection() == 0) e->SetAnimationDirection(1); e->SetParentEffect(parent); std::string path = parent->GetPath(); path = path + "/" + e->GetName(); e->SetPath(path.c_str()); pugi::xml_node sub; sub = node.child("SHAPE_INDEX"); if (sub) e->SetImage(GetSpriteInList(sprites, atoi(sub.child_value()))); sub = node.child("ANGLE_TYPE"); if (sub) e->SetAngleType(sub.attribute("VALUE").as_int()); sub = node.child("ANGLE_OFFSET"); if (sub) e->SetAngleOffset(sub.attribute("VALUE").as_int()); sub = node.child("LOCKED_ANGLE"); if (sub) e->SetLockAngle(sub.attribute("VALUE").as_bool()); sub = node.child("ANGLE_RELATIVE"); if (sub) e->SetAngleRelative(sub.attribute("VALUE").as_bool()); sub = node.child("USE_EFFECT_EMISSION"); if (sub) e->SetUseEffectEmission(sub.attribute("VALUE").as_bool()); sub = node.child("COLOR_REPEAT"); if (sub) e->SetColorRepeat(sub.attribute("VALUE").as_int()); sub = node.child("ALPHA_REPEAT"); if (sub) e->SetAlphaRepeat(sub.attribute("VALUE").as_int()); sub = node.child("ONE_SHOT"); if (sub) e->SetOneShot(sub.attribute("VALUE").as_bool()); sub = node.child("HANDLE_CENTERED"); if (sub) e->SetHandleCenter(sub.attribute("VALUE").as_bool()); AttributeNode* attr = NULL; pugi::xml_node attrnode; for (attrnode = node.child("LIFE"); attrnode; attrnode = attrnode.next_sibling("LIFE")) { attr = e->AddLife(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("AMOUNT"); attrnode; attrnode = attrnode.next_sibling("AMOUNT")) { attr = e->AddAmount(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("BASE_SPEED"); attrnode; attrnode = attrnode.next_sibling("BASE_SPEED")) { attr = e->AddBaseSpeed(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("BASE_WEIGHT"); attrnode; attrnode = attrnode.next_sibling("BASE_WEIGHT")) { attr = e->AddBaseWeight(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("BASE_SIZE_X"); attrnode; attrnode = attrnode.next_sibling("BASE_SIZE_X")) { attr = e->AddSizeX(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("BASE_SIZE_Y"); attrnode; attrnode = attrnode.next_sibling("BASE_SIZE_Y")) { attr = e->AddSizeY(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("BASE_SPIN"); attrnode; attrnode = attrnode.next_sibling("BASE_SPIN")) { attr = e->AddBaseSpin(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("SPLATTER"); attrnode; attrnode = attrnode.next_sibling("SPLATTER")) { attr = e->AddSplatter(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("LIFE_VARIATION"); attrnode; attrnode = attrnode.next_sibling("LIFE_VARIATION")) { attr = e->AddLifeVariation(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("AMOUNT_VARIATION"); attrnode; attrnode = attrnode.next_sibling("AMOUNT_VARIATION")) { attr = e->AddAmountVariation(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("VELOCITY_VARIATION"); attrnode; attrnode = attrnode.next_sibling("VELOCITY_VARIATION")) { attr = e->AddVelVariation(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("WEIGHT_VARIATION"); attrnode; attrnode = attrnode.next_sibling("WEIGHT_VARIATION")) { attr = e->AddWeightVariation(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("SIZE_X_VARIATION"); attrnode; attrnode = attrnode.next_sibling("SIZE_X_VARIATION")) { attr = e->AddSizeXVariation(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("SIZE_Y_VARIATION"); attrnode; attrnode = attrnode.next_sibling("SIZE_Y_VARIATION")) { attr = e->AddSizeYVariation(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("SPIN_VARIATION"); attrnode; attrnode = attrnode.next_sibling("SPIN_VARIATION")) { attr = e->AddSpinVariation(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("DIRECTION_VARIATION"); attrnode; attrnode = attrnode.next_sibling("DIRECTION_VARIATION")) { attr = e->AddDirectionVariation(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("ALPHA_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("ALPHA_OVERTIME")) { attr = e->AddAlpha(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("VELOCITY_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("VELOCITY_OVERTIME")) { attr = e->AddVelocity(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("WEIGHT_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("WEIGHT_OVERTIME")) { attr = e->AddWeight(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("SCALE_X_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("SCALE_X_OVERTIME")) { attr = e->AddScaleX(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("SCALE_Y_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("SCALE_Y_OVERTIME")) { attr = e->AddScaleY(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("SPIN_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("SPIN_OVERTIME")) { attr = e->AddSpin(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("DIRECTION"); attrnode; attrnode = attrnode.next_sibling("DIRECTION")) { attr = e->AddDirection(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("DIRECTION_VARIATIONOT"); attrnode; attrnode = attrnode.next_sibling("DIRECTION_VARIATIONOT")) { attr = e->AddDirectionVariationOT(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("FRAMERATE_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("FRAMERATE_OVERTIME")) { attr = e->AddFramerate(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("STRETCH_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("STRETCH_OVERTIME")) { attr = e->AddStretch(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("RED_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("RED_OVERTIME")) { attr = e->AddR(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); //LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("GREEN_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("GREEN_OVERTIME")) { attr = e->AddG(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); //LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("BLUE_OVERTIME"); attrnode; attrnode = attrnode.next_sibling("BLUE_OVERTIME")) { attr = e->AddB(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); //LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("GLOBAL_VELOCITY"); attrnode; attrnode = attrnode.next_sibling("GLOBAL_VELOCITY")) { attr = e->AddGlobalVelocity(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("EMISSION_ANGLE"); attrnode; attrnode = attrnode.next_sibling("EMISSION_ANGLE")) { attr = e->AddEmissionAngle(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } for (attrnode = node.child("EMISSION_RANGE"); attrnode; attrnode = attrnode.next_sibling("EMISSION_RANGE")) { attr = e->AddEmissionRange(attrnode.attribute("FRAME").as_float(), attrnode.attribute("VALUE").as_float()); LoadAttributeNode(attrnode, attr); } sub = node.child("EFFECT"); if (sub) e->AddEffect(LoadEffect(sub, sprites, e)); return e; }
Emitter *getElement(size_t i) { if (i != 0) return NULL; ref<Timer> timer = new Timer(); Log(EDebug, "Rasterizing skylight emitter to an %ix%i environment map ..", m_resolution, m_resolution/2); ref<Bitmap> bitmap = new Bitmap(SKY_PIXELFORMAT, Bitmap::EFloat, Vector2i(m_resolution, m_resolution/2)); Point2 factor((2*M_PI) / bitmap->getWidth(), M_PI / bitmap->getHeight()); #if defined(MTS_OPENMP) #pragma omp parallel for #endif for (int y=0; y<bitmap->getHeight(); ++y) { Float theta = (y+.5f) * factor.y; Spectrum *target = (Spectrum *) bitmap->getFloatData() + y * bitmap->getWidth(); for (int x=0; x<bitmap->getWidth(); ++x) { Float phi = (x+.5f) * factor.x; *target++ = getSkyRadiance(SphericalCoordinates(theta, phi)); } } Log(EDebug, "Done (took %i ms)", timer->getMilliseconds()); #if defined(MTS_DEBUG_SUNSKY) /* Write a debug image for inspection */ { int size = 513 /* odd-sized */, border = 2; int fsize = size+2*border, hsize = size/2; ref<Bitmap> debugBitmap = new Bitmap(Bitmap::ERGB, Bitmap::EFloat32, Vector2i(fsize)); debugBitmap->clear(); #if defined(MTS_OPENMP) #pragma omp parallel for #endif for (int y=0; y<size; ++y) { float *target = debugBitmap->getFloat32Data() + ((y + border) * fsize + border) * 3; for (int x=0; x<size; ++x) { Float xp = -(x - hsize) / (Float) hsize; Float yp = -(y - hsize) / (Float) hsize; Float radius = std::sqrt(xp*xp + yp*yp); Spectrum result(0.0f); if (radius < 1) { Float theta = radius * 0.5f * M_PI; Float phi = std::atan2(xp, yp); result = getSkyRadiance(SphericalCoordinates(theta, phi)); } Float r, g, b; result.toLinearRGB(r, g, b); *target++ = (float) r; *target++ = (float) g; *target++ = (float) b; } } ref<FileStream> fs = new FileStream("sky.exr", FileStream::ETruncReadWrite); debugBitmap->write(Bitmap::EOpenEXR, fs); } #endif /* Instantiate a nested environment map plugin */ Properties props("envmap"); Properties::Data bitmapData; bitmapData.ptr = (uint8_t *) bitmap.get(); bitmapData.size = sizeof(Bitmap); props.setData("bitmap", bitmapData); props.setAnimatedTransform("toWorld", m_worldTransform); props.setFloat("samplingWeight", m_samplingWeight); Emitter *emitter = static_cast<Emitter *>( PluginManager::getInstance()->createObject( MTS_CLASS(Emitter), props)); emitter->configure(); return emitter; }
virtual void visit(ast::AddOp& o) override { emit(e, o.a); emit(e, o.b); e.add(); }
virtual void visit(ast::Num& o) override { e.load(o.x); }