diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj
index 25ebd53..4530bf3 100644
--- a/SQCSim2021/SQCSim2021.vcxproj
+++ b/SQCSim2021/SQCSim2021.vcxproj
@@ -64,27 +64,27 @@
Application
true
Unicode
- v142
+ ClangCL
Application
true
Unicode
- v142
+ ClangCL
Application
false
true
Unicode
- v142
+ ClangCL
Application
false
true
Unicode
- v142
+ ClangCL
@@ -168,7 +168,7 @@
true
true
true
- irrKlang.lib;sfml-main.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;GlU32.Lib;OpenGL32.Lib;DevIL.lib;ILU.lib;ILUT.lib;%(AdditionalDependencies);winmm.lib;mmsystem.lib
+ irrKlang.lib;sfml-main.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;GlU32.Lib;OpenGL32.Lib;DevIL.lib;ILU.lib;ILUT.lib;glew32.lib;%(AdditionalDependencies)
@@ -187,7 +187,7 @@
true
true
true
- irrKlang.lib;sfml-main.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;GlU32.Lib;OpenGL32.Lib;DevIL.lib;ILU.lib;ILUT.lib;%(AdditionalDependencies);winmm.lib;mmsystem.lib
+ irrKlang.lib;sfml-main.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;GlU32.Lib;OpenGL32.Lib;DevIL.lib;ILU.lib;ILUT.lib;glew32.lib;%(AdditionalDependencies)
diff --git a/SQCSim2021/audio.cpp b/SQCSim2021/audio.cpp
index e768842..bf4db7b 100644
--- a/SQCSim2021/audio.cpp
+++ b/SQCSim2021/audio.cpp
@@ -1,14 +1,47 @@
#include "audio.h"
-Audio::Audio() { m_WavEngine = irrklang::createIrrKlangDevice(); }
+irrklang::vec3df Audio::convertVector(Vector3f& vec) const { return irrklang::vec3df(vec.x, vec.y, vec.z); };
-Audio::~Audio() { m_WavEngine->drop(); }
-
-bool Audio::GetState() const { return m_state; }
-
-void Audio::SetState(bool state) {
- if (state)
- m_WavEngine->play2D(AUDIO_PATH "music01.wav", true);
- else m_WavEngine->stopAllSounds();
- m_state = state;
+Audio::Audio() {
+ m_engine = irrklang::createIrrKlangDevice();
+ m_engine->setDopplerEffectParameters(1);
+ m_engine->setRolloffFactor(1);
+ m_engine->setDefault3DSoundMinDistance(1);
+ m_engine->setDefault3DSoundMaxDistance(1000);
}
+
+Audio::Audio(const char * music) {
+ m_engine = irrklang::createIrrKlangDevice();
+ m_engine->setDopplerEffectParameters(1);
+ m_engine->setRolloffFactor(1);
+ m_engine->setDefault3DSoundMinDistance(1);
+ m_engine->setDefault3DSoundMaxDistance(1000);
+ m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
+}
+
+Audio::~Audio() {
+ m_music->drop();
+ m_engine->drop();
+}
+
+void Audio::Update3DAudio(Vector3f& pos, Vector3f& dir, Vector3f& speed) {
+ m_engine->setListenerPosition(convertVector(pos),
+ convertVector(dir),
+ convertVector(speed));
+}
+
+void Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f& pos, Vector3f& speed, float volume = 1) {
+ sound = m_engine->play3D(name, convertVector(pos), true, false, true, irrklang::ESM_NO_STREAMING, true);
+ sound->setVelocity(convertVector(speed));
+ sound->setVolume(volume);
+}
+
+void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& speed, float volume = 1) {
+ sound->setPosition(convertVector(pos));
+ sound->setVelocity(convertVector(speed));
+ sound->setVolume(volume);
+}
+
+void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
+
+void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }
diff --git a/SQCSim2021/audio.h b/SQCSim2021/audio.h
index 332d5f5..1ff240c 100644
--- a/SQCSim2021/audio.h
+++ b/SQCSim2021/audio.h
@@ -2,21 +2,31 @@
#define AUDIO_H__
#include
+#include
#include "define.h"
+#include "vector3.h"
class Audio {
private:
- irrklang::ISoundEngine* m_WavEngine;
- bool m_state = false;
+ irrklang::ISoundEngine* m_engine;
+ irrklang::ISound* m_music;
+
+ irrklang::vec3df convertVector(Vector3f& vec) const;
public:
Audio();
+ Audio(const char* music);
~Audio();
- bool GetState() const;
+ void Update3DAudio(Vector3f& pos, Vector3f& dir, Vector3f& speed);
- void SetState(bool state);
+ void Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f& pos, Vector3f& speed, float volume);
+ void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& speed, float volume);
+
+ void ToggleMusicState();
+
+ void PauseEngine();
};
#endif // AUDIO_H__
\ No newline at end of file
diff --git a/SQCSim2021/chunk.cpp b/SQCSim2021/chunk.cpp
index 935e6e2..95d9f76 100644
--- a/SQCSim2021/chunk.cpp
+++ b/SQCSim2021/chunk.cpp
@@ -56,25 +56,25 @@ void Chunk::AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType b
vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 0.f);
- vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z + .5f, 1.f, 1.f, 1.f, 0.f, 1.f);
- vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 1.f);
- vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 0.f);
- vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z + .5f, 1.f, 1.f, 1.f, 0.f, 0.f);
+ vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z + .5f, .9f, .9f, .9f, 0.f, 1.f);
+ vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z - .5f, .9f, .9f, .9f, 1.f, 1.f);
+ vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, .9f, .9f, .9f, 1.f, 0.f);
+ vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z + .5f, .9f, .9f, .9f, 0.f, 0.f);
- vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 0.f);
- vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 1.f);
- vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z + .5f, 1.f, 1.f, 1.f, 1.f, 1.f);
- vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z + .5f, 1.f, 1.f, 1.f, 1.f, 0.f);
+ vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, .9f, .9f, .9f, 0.f, 0.f);
+ vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z - .5f, .9f, .9f, .9f, 0.f, 1.f);
+ vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z + .5f, .9f, .9f, .9f, 1.f, 1.f);
+ vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z + .5f, .9f, .9f, .9f, 1.f, 0.f);
- vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 0.f);
- vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z + .5f, 1.f, 1.f, 1.f, 0.f, 1.f);
- vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z + .5f, 1.f, 1.f, 1.f, 1.f, 1.f);
- vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 0.f);
+ vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z - .5f, .8f, .8f, .8f, 0.f, 0.f);
+ vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z + .5f, .8f, .8f, .8f, 0.f, 1.f);
+ vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z + .5f, .8f, .8f, .8f, 1.f, 1.f);
+ vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z - .5f, .8f, .8f, .8f, 1.f, 0.f);
- vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z + .5f, 1.f, 1.f, 1.f, 0.f, 0.f);
- vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 1.f);
- vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 1.f);
- vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z + .5f, 1.f, 1.f, 1.f, 1.f, 0.f);
+ vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z + .5f, .8f, .8f, .8f, 0.f, 0.f);
+ vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, .8f, .8f, .8f, 0.f, 1.f);
+ vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, .8f, .8f, .8f, 1.f, 1.f);
+ vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z + .5f, .8f, .8f, .8f, 1.f, 0.f);
}
void Chunk::Render() const { m_vertexBuffer.Render(); }
diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp
index 463e79d..9ee179a 100644
--- a/SQCSim2021/engine.cpp
+++ b/SQCSim2021/engine.cpp
@@ -33,7 +33,7 @@ void Engine::Init()
// Light
GLfloat light0Pos[4] = { 0.0f, CHUNK_SIZE_Y, 0.0f, 1.0f };
- GLfloat light0Amb[4] = { 0.9f, 0.9f, 0.9f, 1.f };
+ GLfloat light0Amb[4] = { 0.2f, 0.2f, 0.2f, 1.f };
GLfloat light0Diff[4] = { 1.f, 1.f, 1.f, 1.f };
GLfloat light0Spec[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
@@ -47,7 +47,7 @@ void Engine::Init()
m_skybox.Init(0.00013f);
// Objet de musique!
- m_music.SetState(true);
+ m_audio.ToggleMusicState();
// Init testChunk
for (int x = 0; x < CHUNK_SIZE_X; ++x) {
@@ -106,12 +106,13 @@ void Engine::Render(float elapsedTime)
m_player.ApplyTransformation(all);
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation
// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
-
+ glDisable(GL_LIGHT0);
m_skybox.Render(skybox);
-
+
// Plancher
// Les vertex doivent etre affiches dans le sens anti-horaire (CCW)
all.Use();
+ glEnable(GL_LIGHT0);
m_shader01.Use();
m_textureFloor.Bind();
float nbRep = 10.f;
@@ -142,7 +143,7 @@ void Engine::Render(float elapsedTime)
m_testChunk.Update();
m_testChunk.Render();
- //Shader::Disable();
+ m_shader01.Disable();
}
@@ -204,7 +205,7 @@ void Engine::KeyReleaseEvent(unsigned char key)
{
switch (key) {
case 12:
- m_music.SetState(!m_music.GetState());
+ m_audio.ToggleMusicState();
break;
case 24: // Y
m_wireframe = !m_wireframe;
diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h
index 2d454b9..99ff609 100644
--- a/SQCSim2021/engine.h
+++ b/SQCSim2021/engine.h
@@ -42,7 +42,7 @@ private:
Skybox m_skybox;
Shader m_shader01;
Chunk m_testChunk;
- Audio m_music;
+ Audio m_audio = Audio(AUDIO_PATH "music01.wav");
Player m_player = Player(Vector3f(0, 0, 0));
diff --git a/SQCSim2021/media/shaders/shader01.frag b/SQCSim2021/media/shaders/shader01.frag
index a708679..c540d70 100644
--- a/SQCSim2021/media/shaders/shader01.frag
+++ b/SQCSim2021/media/shaders/shader01.frag
@@ -7,7 +7,6 @@ void main()
texel = texture2D(tex,gl_TexCoord[0].st);
texel *= light;
- texel.a *= gl_Position.z;
gl_FragColor = texel;
}
diff --git a/SQCSim2021/player.cpp b/SQCSim2021/player.cpp
index 1fdd124..91db755 100644
--- a/SQCSim2021/player.cpp
+++ b/SQCSim2021/player.cpp
@@ -70,8 +70,8 @@ void Player::Move(bool front, bool back, bool left, bool right, bool jump, bool
}
}
- if (dbljump < 1 && ( left || right || front || back) ||
- dash && !(left || right || front || back))
+ if ((dbljump < 1 && ( left || right || front || back)) ||
+ (dash && !(left || right || front || back)) )
{
yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
xrotrad = (m_rotX / 57.2957795056f);
@@ -139,3 +139,9 @@ void Player::ApplyTransformation(Transformation& transformation, bool rel) const
transformation.ApplyRotation(-m_rotY, 0, 1, 0);
if (rel) transformation.ApplyTranslation(-m_position);
}
+
+Vector3f Player::GetPosition() const { return m_position; }
+
+Vector3f Player::GetDirection(bool velocity = false) const {
+ return Vector3f(); // Temporaire.
+}
diff --git a/SQCSim2021/player.h b/SQCSim2021/player.h
index 23e707a..8891ec3 100644
--- a/SQCSim2021/player.h
+++ b/SQCSim2021/player.h
@@ -12,6 +12,9 @@ public:
void Move(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
void ApplyTransformation(Transformation& transformation, bool rel = true) const;
+ Vector3f GetPosition() const;
+ Vector3f GetDirection(bool velocity) const;
+
private:
Vector3f m_position;
float m_rotX = 0;
diff --git a/SQCSim2021/skybox.cpp b/SQCSim2021/skybox.cpp
index 10cb6d5..2bd16b4 100644
--- a/SQCSim2021/skybox.cpp
+++ b/SQCSim2021/skybox.cpp
@@ -48,6 +48,7 @@ void Skybox::Render(Transformation tran) const {
m_texture.Bind();
m_shader.Use();
m_vertexBuffer.Render();
+ m_shader.Disable();
glEnable(GL_DEPTH_TEST);
}