190 likes | 320 Views
Hangok. 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 l ib referenciák OpenAL32.lib, alut.lib dll-ek bin-be másolása OpenAL /bin OpenAL32. dll , alut . dll. # pragma once
E N D
Overlays végső állapot letöltése (GhostGame) • OpenAL letöltése • Include könyvtárak,libkönyvtárak • OpenAL/include, OpenAL\include\AL • OpenAL/lib • libreferenciák • OpenAL32.lib, alut.lib • dll-ekbin-be másolása • OpenAL/bin • OpenAL32.dll, alut.dll
#pragmaonce #include "Inputs.h" #include <AL/alut.h> class GameAudio { public: GameAudio(intargc, 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(); } }; GameAudio.h
Main.cpp #include "GameAudio.h" ... GameAudio* gameAudio; ... int main(int argc, char** argv) { ogreRoot = new Root("",""); gameAudio = new GameAudio(argc, argv);
Valamit játszunk le class GameAudio { public: GameAudio(intargc, char** argv) { printf("*** Initializing OpenAL ***\n"); alutInit (&argc, argv); ALuinthelloBuffer, helloSource; helloBuffer = alutCreateBufferHelloWorld (); alGenSources (1, &helloSource); alSourcei (helloSource, AL_BUFFER, helloBuffer); alSourcePlay (helloSource);
Folyamatos lejátszás Játszadozzunk... Hangerő 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); Lejátszás sebessége világtérbeli pozíció
File lejátszása helloBuffer = 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
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))); \ }
Title music class GameAudio { ALuintambientBuffer; ALuintambientSource; float musicVolume; ALuintloadFile(constchar* filename) { ALenumerror; ALuintnewBuffer; ALUT_SAFE_CALL(newBuffer = alutCreateBufferFromFile(filename), "Cannotloadaudio file: " + Ogre::String(filename)); returnnewBuffer; } voidcreateSource(ALuint* source) { AL_SAFE_CALL(alGenSources (1, source), "Unabletogeneratesource"); } public: voidplayTitleMusic() { 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"); }
Title Music GameAudio(intargc, 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); }
Title Music int main(intargc, char* argv[]) { … gameAudio = new GameAudio(argc, argv); gameAudio->playTitleMusic(); Próba
Egyébb bufferek //Uj publikus függvények a GameAudio osztályba ALuintlevelAmbientBuffer; ALuintghostBirthBuffer; ALuintghostDeathBuffer; ALuint* ghostSources; void loadLevelResources(intmaxGhostCount) { levelAmbientBuffer= loadFile("media/ambient.wav"); ghostBirthBuffer= loadFile("media/ghostbirth.wav"); ghostDeathBuffer= loadFile("media/ghostdeath.wav"); ghostSources= new ALuint[maxGhostCount]; for(inti = 0; i < maxGhostCount; ++i) { alGenSources(1, &ghostSources[i]); alSourcef(ghostSources[i], AL_GAIN, 0.2); } } void playAmbientMusic() { AL_SAFE_CALL(alSourceStop(ambientSource), "unableto stop levelambientsource"); AL_SAFE_CALL(alSourcei (ambientSource, AL_BUFFER, levelAmbientBuffer), "unabletobindbuffertoambientsource"); AL_SAFE_CALL(alSourcePlay (ambientSource), "unableto play levelambientsource"); } //main.cpp setupPostProc(); gameAudio->loadLevelResources(ghosts->getParticleQuota()); gameAudio->playAmbientMusic(); Próba
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); }
Szellem születik/meghal //main.cpp class GhostCounter : public ParticleAffector { … void _initParticle(Particle* pParticle) { … gameAudio->ghostBirth(ghosts->getNumParticles() - 1); } class ShootController { … boolhandleEvent { ... ++ghostShooted; mainHUD->refreshScore(ghostBorn, ghostShooted); gameAudio->ghostDeath(ghostID); Próba
Harang class GameAudio { ALuintbellBuffer; ALuintbellSource; … void loadLevelResources(intmaxGhostCount) { … 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
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 { … boolframeStarted { … camera->setDirection(oldDir * (1.0 - smooth) + newDir * smooth); gameAudio->setListenerPose(camera->getPosition(), camera->getDirection()); Próba
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) { intghostCount = ghosts->getNumParticles(); for(unsigned inti = 0; i < ghostCount; ++i) { gameAudio->setGhostPosition(i, ghosts->getParticle(i)->position + ghosts->getParentSceneNode()->getPosition()); } } Próba
Vége Sok minden lehetne még……