Added Audio module
Fixed examples resources not being commited Temporary removed static build configurations
This commit is contained in:
37
examples/DopplerEffect/build.lua
Normal file
37
examples/DopplerEffect/build.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
kind "ConsoleApp"
|
||||
|
||||
files "main.cpp"
|
||||
|
||||
if (_OPTIONS["one-library"]) then
|
||||
configuration "DebugStatic"
|
||||
links "NazaraEngine-s-d"
|
||||
|
||||
configuration "ReleaseStatic"
|
||||
links "NazaraEngine-s"
|
||||
|
||||
configuration "DebugDLL"
|
||||
links "NazaraEngine-d"
|
||||
|
||||
configuration "ReleaseDLL"
|
||||
links "NazaraEngine"
|
||||
else
|
||||
configuration "DebugStatic"
|
||||
links "NazaraAudio-s-d"
|
||||
links "NazaraUtility-s-d"
|
||||
links "NazaraCore-s-d"
|
||||
|
||||
configuration "ReleaseStatic"
|
||||
links "NazaraAudio-s"
|
||||
links "NazaraUtility-s"
|
||||
links "NazaraCore-s"
|
||||
|
||||
configuration "DebugDLL"
|
||||
links "NazaraAudio-d"
|
||||
links "NazaraUtility-d"
|
||||
links "NazaraCore-d"
|
||||
|
||||
configuration "ReleaseDLL"
|
||||
links "NazaraAudio"
|
||||
links "NazaraUtility"
|
||||
links "NazaraCore"
|
||||
end
|
||||
68
examples/DopplerEffect/main.cpp
Normal file
68
examples/DopplerEffect/main.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <Nazara/Audio.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Thread.hpp> // Thread::Sleep
|
||||
#include <Nazara/Utility/Keyboard.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
// NzKeyboard ne nécessite pas l'initialisation d'Utility
|
||||
NzInitializer<NzAudio> audio;
|
||||
if (!audio)
|
||||
{
|
||||
std::cout << "Failed to initialize audio module" << std::endl;
|
||||
std::getchar();
|
||||
return 1;
|
||||
}
|
||||
|
||||
NzSound sound;
|
||||
if (!sound.LoadFromFile("resources/siren.wav"))
|
||||
{
|
||||
std::cout << "Failed to load sound" << std::endl;
|
||||
std::getchar();
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Demonstration de l'effet doppler avec Nazara" << std::endl;
|
||||
std::cout << "Appuyez sur entree pour demarrer" << std::endl;
|
||||
std::cout << "Appuyez sur echap pour arreter" << std::endl;
|
||||
|
||||
std::getchar();
|
||||
|
||||
// On fait en sorte de répéter le son
|
||||
sound.EnableLooping(true);
|
||||
|
||||
// La source du son se situe en (50, 0, 5)
|
||||
sound.SetPosition(50, 0, 5);
|
||||
|
||||
// Et possède une vitesse de -10 par seconde sur l'axe X
|
||||
sound.SetVelocity(-10, 0, 0);
|
||||
|
||||
// On joue le son
|
||||
sound.Play();
|
||||
|
||||
// La boucle du programme (Pour déplacer le son)
|
||||
NzClock clock;
|
||||
while (sound.GetStatus() == nzSoundStatus_Playing)
|
||||
{
|
||||
// Comme le son se joue dans un thread séparé, on peut mettre en pause celui-ci régulièrement
|
||||
int sleepTime = 1000/60 - clock.GetMilliseconds(); // 60 FPS
|
||||
|
||||
if (sleepTime > 0)
|
||||
NzThread::Sleep(sleepTime);
|
||||
|
||||
// On bouge la source du son en fonction du au temps depuis chaque mise à jour
|
||||
NzVector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds();
|
||||
sound.SetPosition(pos);
|
||||
|
||||
std::cout << "Sound position: " << pos << std::endl;
|
||||
|
||||
// Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap
|
||||
if (pos.x < -50.f || NzKeyboard::IsKeyPressed(NzKeyboard::Escape))
|
||||
sound.Stop(); // On arrête le son (Stoppant également la boucle)
|
||||
|
||||
clock.Restart();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user