TestScene::TestScene(const glm::vec2& screenSize) {
    femaleModel = Resources().CreateOBJModel("Resources/Models/Maximo/GolferFemale.obj");
    std::string femaleDiffusePath = "Resources/Models/Maximo/GolferFemaleDiffuse.png";
    std::string femaleNormalPath = "Resources/Models/Maximo/GolferFemaleNormal.png";
    std::string femaleSpecularPath = "Resources/Models/Maximo/GolferFemaleSpecular.png";
    femaleModelObject = new ModelObject(femaleModel, femaleDiffusePath, femaleNormalPath, femaleSpecularPath);
    femaleModelObject->SetPosition(2.f, 0.f, 0.f);
    femaleModelObject->SetScale(glm::vec3(0.01f, 0.01f, 0.01f));
    
    maleModel = Resources().CreateOBJModel("Resources/Models/Maximo/GolferMale.obj");
    std::string maleDiffusePath = "Resources/Models/Maximo/GolferMaleDiffuse.png";
    std::string maleNormalPath = "Resources/Models/Maximo/GolferMaleNormal.png";
    std::string maleSpecularPath = "Resources/Models/Maximo/GolferMaleSpecular.png";
    maleModelObject = new ModelObject(maleModel, maleDiffusePath, maleNormalPath, maleSpecularPath);
    maleModelObject->SetPosition(2.f, 0.f, 0.f);
    maleModelObject->SetScale(glm::vec3(0.01f, 0.01f, 0.01f));
    
    iteratePlayers = 0;
    srand(time(NULL));
    
    // Map of all available clubtypes
    clubs["Wood 1"] = ClubType{ 0.2f, glm::radians<float>(11.f) };
    clubs["Wood 3"] = ClubType{ 0.208f, glm::radians<float>(15.f) };
    clubs["Wood 5"] = ClubType{ 0.218f, glm::radians<float>(18.f) };
    clubs["Iron 2"] = ClubType{ 0.232f, glm::radians<float>(18.f) };
    clubs["Iron 3"] = ClubType{ 0.239f, glm::radians<float>(21.f) };
    clubs["Iron 4"] = ClubType{ 0.246f, glm::radians<float>(24.f) };
    clubs["Iron 5"] = ClubType{ 0.253f, glm::radians<float>(27.f) };
    clubs["Iron 6"] = ClubType{ 0.260f, glm::radians<float>(31.f) };
    clubs["Iron 7"] = ClubType{ 0.267f, glm::radians<float>(35.f) };
    clubs["Iron 8"] = ClubType{ 0.274f, glm::radians<float>(39.f) };
    clubs["Iron 9"] = ClubType{ 0.281f, glm::radians<float>(43.f) };
    clubs["Pitching Wedge"] = ClubType{ 0.285f, glm::radians<float>(48.f) };
    clubs["Sand Wedge"] = ClubType{ 0.296f, glm::radians<float>(55.f) };
    clubs["Putter"] = ClubType{ 0.33f, glm::radians<float>(4.f) };
    clubIterator = clubs.begin();
    swingStrength = 0.f;
    maxSwingStrength = 40.f;
    swingTime = 1.f;
    swingDirection = 1.f;
    swingAngle = 0.f;
    
    // Font.
    font = Resources().CreateFontEmbedded(ABEEZEE_TTF, ABEEZEE_TTF_LENGTH, 24.f);
    
    // Terrain.
    terrain = new Geometry::Terrain("Resources/Terrain/TestMapSmall.png");
    terrain->SetTextureRepeat(glm::vec2(20.f, 20.f));
    terrainObject = new TerrainObject(terrain);
    terrainObject->SetPosition(0.f, -5.f, 0.f);
    terrainObject->SetScale(200.f, 10.f, 200.f);
    
    skyboxTexture = new CubeMapTexture(
                "Resources/TropicalSunnyDay/Right.png",
                "Resources/TropicalSunnyDay/Left.png",
                "Resources/TropicalSunnyDay/Up.png",
                "Resources/TropicalSunnyDay/Down.png",
                "Resources/TropicalSunnyDay/Back.png",
                "Resources/TropicalSunnyDay/Front.png"
                );
    skybox = new Skybox(skyboxTexture);
    
    deferredLighting = new DeferredLighting(screenSize);
    
    // Post processing.
    postProcessing = new PostProcessing(screenSize);
    fxaaFilter = new FXAAFilter();
    
    vertexShader = Resources().CreateShader(DEFAULT3D_VERT, DEFAULT3D_VERT_LENGTH, GL_VERTEX_SHADER);
    geometryShader = Resources().CreateShader(DEFAULT3D_GEOM, DEFAULT3D_GEOM_LENGTH, GL_GEOMETRY_SHADER);
    fragmentShader = Resources().CreateShader(FORWARDALPHA_FRAG, FORWARDALPHA_FRAG_LENGTH, GL_FRAGMENT_SHADER);
    shaderProgram = Resources().CreateShaderProgram({ vertexShader, geometryShader, fragmentShader });
    
    // Water.
    water =  new Water(screenSize);
    water->SetScale(400.f, 400.f, 400.f);
    water->SetPosition(0.f, -1.f, 0.f);
    water->SetTextureRepeat(glm::vec2(75.f, 75.f));
    
    gui = new GUI(screenSize);
    
    swingArrowTexture = Resources().CreateTexture2DFromFile("Resources/GUI/Arrow.png");
    swingArrowGeometry = Resources().CreateSquare();
    swingArrow = new GeometryObject(swingArrowGeometry);
    swingArrow->SetScale(0.25f, 1.f, 1.f);
    
    // Particle texture.
    particleTexture = Resources().CreateTexture2DFromFile("Resources/DustParticle.png");
    
    // Particle type.
    ParticleType dustParticle;
    dustParticle.texture = particleTexture;
    dustParticle.minLifetime = 6.f;
    dustParticle.maxLifetime = 10.f;
    dustParticle.minVelocity = glm::vec3(-0.025f, -0.01f, -0.025f);
    dustParticle.maxVelocity = glm::vec3(0.025f, -0.1f, 0.025f);
    dustParticle.minSize = glm::vec2(0.025f, 0.025f);
    dustParticle.maxSize = glm::vec2(0.05f, 0.05f);
    dustParticle.uniformScaling = true;
    dustParticle.color = glm::vec3(0.2f, 1.f, 0.f);
    
    // Particle system.
    particleSystem = new ParticleSystem(dustParticle, 1000);
    
    // Ducks
    duckFile = new VorbisFile("Resources/Audio/Duck.ogg");
    for (int i=0; i<10; i++) {
        ducks.push_back(new Duck(duckFile));
        glm::vec3 position;
        do {
            position = glm::vec3(rand() / static_cast<float>(RAND_MAX) * 200.f - 100.f, water->Position().y, rand() / static_cast<float>(RAND_MAX) * 200.f - 100.f);
        } while (terrainObject->GetY(position.x, position.z) > water->Position().y - 0.2f);
        ducks[i]->SetPosition(position);
        ducks[i]->SetRotation(rand() / static_cast<float>(RAND_MAX) * 360.f, 0.f, 0.f);
    }
    
    // Lily pads
    for (int i=0; i<50; i++) {
        lilypads.push_back(new LilyPad());
        glm::vec3 position;
        do {
            position = glm::vec3(rand() / static_cast<float>(RAND_MAX) * 200.f - 100.f, water->Position().y + 0.05f, rand() / static_cast<float>(RAND_MAX) * 200.f - 100.f);
        } while (terrainObject->GetY(position.x, position.z) > water->Position().y - 0.2f);
        lilypads[i]->SetPosition(position);
        lilypads[i]->SetRotation(rand() / static_cast<float>(RAND_MAX) * 360.f, 270.f, 0.f);
        lilypads[i]->SetScale(2.f, 2.f, 1.f);
    }
    
    explosionTexture = Resources().CreateTexture2DFromFile("Resources/FireParticle.png");
    
    // Particle type.
    ParticleType explosionParticle;
    explosionParticle.texture = explosionTexture;
    explosionParticle.minLifetime = .1f;
    explosionParticle.maxLifetime = .2f;
    explosionParticle.minVelocity = glm::vec3(-1.f, 1.f, -1.f);
    explosionParticle.maxVelocity = glm::vec3(1.f, -1.f, 1.f);
    explosionParticle.minSize = glm::vec2(0.025f, 0.025f);
    explosionParticle.maxSize = glm::vec2(0.05f, 0.05f);
    explosionParticle.uniformScaling = true;
    explosionParticle.color = glm::vec3(1.f, 0.5f, 0.5f);
    
    // Particle system.
    explosionParticleSystem = new ParticleSystem(explosionParticle, 1000);
    emitterAttached = false;
    
    // Initiate players
    numberOfPlayers = GameSettings::GetInstance().GetLong("Players");
    
    playerIndex = 0;
    glm::vec3 randPos;
    
    for (int i = 0; i < numberOfPlayers; i++){
        do {
			if (i > 0){
				randPos = glm::vec3(rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f, water->Position().y, rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f);
				while (glm::length(playerObjects[i-1].Position() - randPos) > 25.f)
					randPos = glm::vec3(rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f, water->Position().y, rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f);
			} else {
				randPos = glm::vec3(rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f, water->Position().y, rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f);
			}
        } while (terrainObject->GetY(randPos.x, randPos.z) < water->Position().y + 0.2f);
        playerObjects.push_back(PlayerObject{ glm::vec3(randPos.x, terrainObject->GetY(randPos.x, randPos.z) + 0.01f, randPos.z) });
    }
    
    playerIterator = playerObjects.begin();
    
    // Golf ball.
    golfBall = new GolfBall(GolfBall::TWOPIECE, terrainObject, water);
    golfBall->SetPosition(playerObjects[0].Position() + glm::vec3(0.f, golfBall->Radius(), 0.f));
    
    // Camera.
    player = new ThirdPersonPlayer(golfBall);
    player->SetMovementSpeed(2.f);
    wind = glm::vec3(static_cast<float>(rand() % 30 + (-15)), 0.f, static_cast<float>(rand() % 30 + (-15)));
    
    // Emitters.
    ParticleEmitter* emitter = new CuboidParticleEmitter(glm::vec3(0.f, 0.f, 0.f), glm::vec3(40.f, 15.f, 40.f), 0.01, 0.02, true);
    particleSystem->AddParticleEmitter(emitter);
    emitter->Update(5.0, particleSystem, golfBall);
    
    // Sound
    golfHitFile = new VorbisFile("Resources/Audio/GolfBallHit.ogg");
    golfHitBuffer = new SoundBuffer(golfHitFile);
    golfHitSound = new Sound(golfHitBuffer);
    waterFile = new VorbisFile("Resources/Audio/Water.ogg");
    waterBuffer = new SoundBuffer(waterFile);
    waterSound = new Sound(waterBuffer);
    waterSound->SetGain(0.15f);
    waterSound->SetLooping(AL_TRUE);
    waterSound->Play();
}
Example #2
0
RESULT
ParticleManager::Update( UINT64 elapsedMS )
{
    RESULT rval = S_OK;


    //
    // TODO: if our update frequency is less than 60Hz, we should
    // spread out the emitter updates, rather than updating ALL of them
    // every fourth frame (for example).
    // 
    
    static UINT64 lastUpdateTimeMS = 0;
    if ((elapsedMS - lastUpdateTimeMS) < m_updateIntervalMS)
    {
        return S_OK;
    }
    lastUpdateTimeMS = elapsedMS;


    // Release ParticleEmitters that were marked as done on previous frame.
    ParticleEmitterListIterator ppParticleEmitter;
    for (ppParticleEmitter = m_pendingReleaseParticleEmittersList.begin(); ppParticleEmitter != m_pendingReleaseParticleEmittersList.end(); ++ppParticleEmitter)
    {
        ParticleEmitter* pParticleEmitter = *ppParticleEmitter;
        if (!pParticleEmitter)
            continue;
        
        DEBUGMSG(ZONE_PARTICLES, "Releasing ParticleEmitter [%s], refCount = %d", pParticleEmitter->GetName().c_str(), pParticleEmitter->GetRefCount());
        
        //pParticleEmitter->Stop();
        
        CHR(Release( pParticleEmitter ));
    }
    m_pendingReleaseParticleEmittersList.clear();



    // Update every running ParticleEmitter.
    for (ppParticleEmitter = m_runningParticleEmittersList.begin(); ppParticleEmitter != m_runningParticleEmittersList.end(); /*++ppParticleEmitter*/)
    {
        ParticleEmitter* pParticleEmitter = *ppParticleEmitter;
        if (!pParticleEmitter)
        {
            ppParticleEmitter = m_runningParticleEmittersList.erase( ppParticleEmitter );
            continue;
        } 

//        if (Log::IsZoneEnabled(ZONE_PARTICLES | ZONE_VERBOSE))
//        {
//            char str[1024];
//            sprintf(str, "PE: %s", pParticleEmitter->GetName().c_str());
//            DebugRender.Text(str, Color::White(), 1.0f, 1.0f);
//        }
        
        
        if (FAILED(pParticleEmitter->Update( elapsedMS )))
        {
            pParticleEmitter->Stop();

            //
            // NOTE: if you erase a list member while iterating the list,
            // be sure to properly increment the iterator as seen below.
            //
            ppParticleEmitter = m_runningParticleEmittersList.erase( ppParticleEmitter );
        }
        else 
        {
            ++ppParticleEmitter;
        }
    }

Exit:
    return rval;
}
Example #3
0
	BOOST_FOREACH(ParticleEmitter& emitter, mParticleEmitters) {
		emitter.Update(time_diff, mPosition, mDirection, !mStopEmitting);
	}