overlays végső állapot letöltése (ghostgame) openal letöltése include könyvtárak,lib...

19

Upload: nora-harbottle

Post on 01-Apr-2015

228 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák
Page 2: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak

OpenAL/include, OpenAL\include\AL OpenAL/lib

lib referenciák OpenAL32.lib, alut.lib

dll-ek bin-be másolása OpenAL/bin

OpenAL32.dll, alut.dll

Page 3: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

GameAudio.h#pragma once#include "Inputs.h"#include <AL/alut.h>

class GameAudio{public: GameAudio(int argc, char** argv) { printf("*** Initializing OpenAL ***\n"); alutInit (&argc, argv); ALenum error; error = alutGetError(); if(error != AL_NO_ERROR) { Ogre::LogManager::getSingleton().logMessage("Error initializing OpenAL: " +

Ogre::String(alutGetErrorString(error))); }

} ~GameAudio() { printf("*** Shutting down OpenAL ***\n"); alutExit(); } };

Page 4: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Main.cpp#include "GameAudio.h"...GameAudio* gameAudio;...int main(int argc, char** argv){ogreRoot = new Root("","");gameAudio = new GameAudio(argc, argv);

Page 5: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Próba... fordul-e, fut-e

Page 6: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Valamit játszunk leclass GameAudio{public: GameAudio(int argc, char** argv) { printf("*** Initializing OpenAL ***\n"); alutInit (&argc, argv);

ALuint helloBuffer, helloSource; helloBuffer = alutCreateBufferHelloWorld (); alGenSources (1, &helloSource); alSourcei (helloSource, AL_BUFFER,

helloBuffer); alSourcePlay (helloSource);

Page 7: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Játszadozzunk...alSourcei (helloSource, AL_LOOPING,

AL_TRUE); alSourcei (helloSource, AL_GAIN, 10); alSourcef (helloSource, AL_PITCH, 0.3); alListener3f(AL_POSITION, 0,0,0); alSource3f(helloSource, AL_POSITION, -

1,0,0); alSourcePlay (helloSource);

Hangerő

Folyamatoslejátszás

Lejátszássebessége

világtérbelipozíció

Page 8: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

File lejátszásahelloBuffer = alutCreateBufferFromFile(„media/titlemusic.wav"); error = alutGetError();if(error != AL_NO_ERROR){ Ogre::LogManager::getSingleton().logMessage("Cannot

load audio file: "+ Ogre::String(alutGetErrorString(error))); }

Próba

Page 9: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Error handing#define ALUT_SAFE_CALL(call, message) {call; \ALenum error = alutGetError(); \if(error != ALUT_ERROR_NO_ERROR) \Ogre::LogManager::getSingleton().logMessage(message +

Ogre::String(" ") + Ogre::String(alutGetErrorString(error))); \

}

#define AL_SAFE_CALL(call, message) {call; \ALenum error = alGetError(); \if(error != AL_NO_ERROR) \Ogre::LogManager::getSingleton().logMessage(message +

Ogre::String(" ") + Ogre::String(alutGetErrorString(error))); \

}

Page 10: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Title musicclass GameAudio{ ALuint ambientBuffer; ALuint ambientSource; float musicVolume;

ALuint loadFile(const char* filename) { ALenum error; ALuint newBuffer; ALUT_SAFE_CALL(newBuffer = alutCreateBufferFromFile(filename), "Cannot load audio file: " +

Ogre::String(filename)); return newBuffer; }

void createSource(ALuint* source) { AL_SAFE_CALL(alGenSources (1, source), "Unable to generate source"); }

public: void playTitleMusic() { AL_SAFE_CALL(alSourceStop(ambientSource), "unable to stop title source"); AL_SAFE_CALL(alSourcei (ambientSource, AL_BUFFER, ambientBuffer), "unable to bind buffer to ambient

source"); AL_SAFE_CALL(alSourcePlay (ambientSource), "unable to play title source"); }

Page 11: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Title MusicGameAudio(int argc, char** argv){…// az eddigi hellowBuffer és Source helyett ambientBuffer = loadFile("media/titlemusic.wav"); createSource(&ambientSource); AL_SAFE_CALL(alSourcei (ambientSource,

AL_BUFFER, ambientBuffer), "unable to bind title buffer");

AL_SAFE_CALL(alSourcei (ambientSource, AL_LOOPING, AL_TRUE), "unable to set looping");

musicVolume = 10; alSourcei (ambientSource, AL_GAIN, musicVolume);}

Page 12: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Title Musicint main(int argc, char* argv[]){…gameAudio = new GameAudio(argc, argv);gameAudio->playTitleMusic();

Próba

Page 13: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Egyébb bufferek//Uj publikus függvények a GameAudio osztályba

ALuint levelAmbientBuffer;

ALuint ghostBirthBuffer;

ALuint ghostDeathBuffer;

ALuint* ghostSources;

void loadLevelResources(int maxGhostCount)

{

levelAmbientBuffer = loadFile("media/ambient.wav");

ghostBirthBuffer = loadFile("media/ghostbirth.wav");

ghostDeathBuffer = loadFile("media/ghostdeath.wav");

ghostSources = new ALuint[maxGhostCount];

for(int i = 0; i < maxGhostCount; ++i)

{

alGenSources (1, &ghostSources[i]);

alSourcef(ghostSources[i], AL_GAIN, 0.2);

}

}

void playAmbientMusic()

{

AL_SAFE_CALL(alSourceStop(ambientSource), "unable to stop level ambient source");

AL_SAFE_CALL(alSourcei (ambientSource, AL_BUFFER, levelAmbientBuffer), "unable to bind buffer to ambient source");

AL_SAFE_CALL(alSourcePlay (ambientSource), "unable to play level ambient source");

}

//main.cpp

setupPostProc();gameAudio->loadLevelResources(ghosts->getParticleQuota());gameAudio->playAmbientMusic();

Próba

Page 14: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Szellem születik/meghal//Uj publikus függvények a GameAudio osztályba

void ghostBirth(int ghost)

{

AL_SAFE_CALL(alSourceStop(ghostSources[ghost]), "unable to stop ghost source" + Ogre::StringConverter::toString(ghost));

AL_SAFE_CALL(alSourcei (ghostSources[ghost], AL_BUFFER, ghostBirthBuffer), "unable to bind buffer to ghost source " + Ogre::StringConverter::toString(ghost));

AL_SAFE_CALL(alSourcePlay (ghostSources[ghost]), "unable to play ghost source" + Ogre::StringConverter::toString(ghost));

alSourcef(ghostSources[ghost], AL_PITCH, 1.0);

}

void ghostDeath(int ghost)

{

AL_SAFE_CALL(alSourceStop(ghostSources[ghost]), "unable to stop ghost source" + Ogre::StringConverter::toString(ghost));

AL_SAFE_CALL(alSourcei (ghostSources[ghost], AL_BUFFER, ghostDeathBuffer), "unable to bind buffer to ghost source " + Ogre::StringConverter::toString(ghost));

AL_SAFE_CALL(alSourcePlay (ghostSources[ghost]), "unable to play ghost source" + Ogre::StringConverter::toString(ghost));

alSourcef(ghostSources[ghost], AL_PITCH, 2.0);

}

Page 15: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Szellem születik/meghal//main.cppclass GhostCounter : public ParticleAffector{…void _initParticle(Particle* pParticle){…gameAudio->ghostBirth(ghosts->getNumParticles() - 1);}

class ShootController{…bool handleEvent{... ++ghostShooted; mainHUD->refreshScore(ghostBorn, ghostShooted); gameAudio->ghostDeath(ghostID);

Próba

Page 16: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Harangclass GameAudio

{

ALuint bellBuffer;

ALuint bellSource;

void loadLevelResources(int maxGhostCount)

{

bellBuffer = loadFile("media/churchbell.wav");

createSource(&bellSource);

AL_SAFE_CALL(alSourcei (bellSource, AL_BUFFER, bellBuffer), "unable to bind buffer to bell source");

alSourcei(bellSource, AL_LOOPING, AL_TRUE);

alSource3f(bellSource, AL_POSITION, 0.5f,10.0f,-8.0f);

alSourcef(bellSource, AL_GAIN, 30);

}

void playTitleMusic()

{

AL_SAFE_CALL(alSourcePause(bellSource), "unable to stop bell source");

}

void playAmbientMusic()

{

AL_SAFE_CALL(alSourcePlay (bellSource), "unable to play bell source");

} Próba

Page 17: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Hallgató//Uj publikus függvény a GameAudio osztályba

void setListenerPose(Ogre::Vector3 pos, Ogre::Vector3 dir){alListener3f(AL_POSITION, pos.x, pos.y, pos.z);float orient[] = {dir.x, dir.y, dir.z, 0, 1, 0};alListenerfv(AL_ORIENTATION, orient);}

//main.cpp

class CameraAnimation{…bool frameStarted{…camera->setDirection(oldDir * (1.0 - smooth) + newDir * smooth);

gameAudio->setListenerPose(camera->getPosition(), camera->getDirection());Próba

Page 18: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Szellemek pozíciója//Uj publikus függvény a GameAudio osztályba

void setGhostPosition(int ghost , Ogre::Vector3 pos){alSource3f(ghostSources[ghost],AL_POSITION, pos.x, pos.y, pos.z);}

//main.cpp

class GhostCounter : public ParticleAffector{void _affectParticles(ParticleSystem* pSystem, Real timeElapsed){ int ghostCount = ghosts->getNumParticles(); for(unsigned int i = 0; i < ghostCount; ++i) { gameAudio->setGhostPosition(i, ghosts->getParticle(i)->position + ghosts->getParentSceneNode()-

>getPosition()); }} Próba

Page 19: Overlays végső állapot letöltése (GhostGame) OpenAL letöltése Include könyvtárak,lib könyvtárak  OpenAL/include, OpenAL\include\AL  OpenAL/lib lib referenciák

Vége

Sok minden lehetne még……