diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index 7f1334e..3aec273 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -20,6 +20,7 @@ + @@ -36,6 +37,7 @@ + diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index 5c8a864..8246b5c 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -53,6 +53,9 @@ Fichiers d%27en-tĂȘte + + Fichiers d%27en-tĂȘte + @@ -97,5 +100,8 @@ Fichiers sources + + Fichiers sources + \ No newline at end of file diff --git a/SQCSim2021/booster.cpp b/SQCSim2021/booster.cpp new file mode 100644 index 0000000..cfef393 --- /dev/null +++ b/SQCSim2021/booster.cpp @@ -0,0 +1,46 @@ +#include "booster.h"; + +void Booster::RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran) +{ + // + //Vector3f playerToQuad = m_player.GetPosition() - m_position; + //playerToQuad.Normalize(); + //Vector3f targetPosition = m_player.GetPosition() + playerToQuad * 10.0f; + //Matrix4f rotationMatrix; + //rotationMatrix.SetLookAt(m_position, targetPosition, Vector3f(0, 1, 0)); + //glMultMatrixf(rotationMatrix.GetInternalValues()); + float x = pos.x; + float y = pos.y; + float z = pos.z; + float width = 1.0f; + float height = 1.0f; + //Pt override les collisions.. a ce point la je sais pas quoi faire + + //Matrix4 mat4 = tran.GetMatrix(); + //mat4 VP = pMatrix * vMatrix; + //Vector3f CameraRight = Vector3f(mat4.Get11(), mat4.Get21(), mat4.Get31()); + //Vector3f CameraUp = Vector3f(mat4.Get12(), mat4.Get22(), mat4.Get32()); + + //Vector3f v1 = (m_position + CameraRight * 0.5 * width + CameraUp * -0.5 * width); + //Vector3f v2 = (m_position + CameraRight * 0.5 * width + CameraUp * 0.5 * width); + //Vector3f v4 = (m_position + CameraRight * -0.5 * width + CameraUp * -0.5 * width); + //Vector3f v3 = (m_position + CameraRight * -0.5 * width + CameraUp * 0.5 * width); + + //tran.ApplyTranslation(m_position); + float u, v, w, h; + //glDisable(GL_DEPTH_TEST); + shader.Use(); + textureAtlas.Bind(); + textureAtlas.TextureIndexToCoord(idx, u, v, w, h); + //glLoadIdentity(); + glLoadMatrixf(tran.GetMatrix().GetInternalValues()); + glBegin(GL_QUADS); + glTexCoord2f(u, v); glVertex3f(x - width / 2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0); + glTexCoord2f(u + w, v); glVertex3f(x + width / 2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0); + glTexCoord2f(u + w, v + h); glVertex3f(x + width / 2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0); + glTexCoord2f(u, v + h); glVertex3f(x - width / 2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0); + glEnd(); + shader.Disable(); + //tran.ApplyTranslation(-m_position); + //glEnable(GL_DEPTH_TEST); +} \ No newline at end of file diff --git a/SQCSim2021/booster.h b/SQCSim2021/booster.h new file mode 100644 index 0000000..b9ff3b6 --- /dev/null +++ b/SQCSim2021/booster.h @@ -0,0 +1,14 @@ +#ifndef BOOSTER_H__ +#define BOOSTER_H__ +#include "define.h" +#include "textureatlas.h" +#include "shader.h" +#include "../SQCSim-common/vector3.h" +#include "../SQCSim-common/transformation.h" + + +class Booster { +public: + void RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran); +}; +#endif diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index 9ce9bd2..4d67655 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -34,6 +34,6 @@ #define AUDIO_PATH "./media/audio/" #define CHUNK_PATH "./media/chunks/" #define MENU_ITEM_PATH "./media/menu_items/" -#define BOOSTER_TEXTURE_PATH "./media/textures/Booster" +#define BOOSTER_TEXTURE_PATH "./media/textures/Booster/" #endif // DEFINE_H__ diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 6d3cc95..9c8b201 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -448,7 +448,7 @@ void Engine::LoadResource() { TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); - TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterMauve.png"); + TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterVert.png"); TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png"); TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png"); TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png"); @@ -1160,6 +1160,7 @@ void Engine::Render(float elapsedTime) { m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo); glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); m_remotePlayer.Render(m_textureAtlas, m_shader01, all, elapsedTime); + m_booster.RenderBillboard({ 120,20,120 }, m_textureAtlas, texBoostHeal, m_shader01, all); if (m_isSkybox) m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas); diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 23b62da..f5754aa 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -23,6 +23,7 @@ #include "connector.h" #include "renderer.h" #include "remoteplayer.h" +#include "booster.h" class Engine : public OpenglContext { @@ -74,6 +75,7 @@ private: World m_world = World(); Renderer m_renderer = Renderer(); + Booster m_booster = Booster(); Texture m_textureCrosshair; Texture m_textureFont; @@ -85,6 +87,8 @@ private: Texture m_textureMultiText; Texture m_textureTitle; + TextureAtlas::TextureIndex texBoostHeal; + Skybox m_skybox; Audio m_audio = Audio(AUDIO_PATH "start.wav"); diff --git a/SQCSim2021/remoteplayer.h b/SQCSim2021/remoteplayer.h index 6050356..36eb275 100644 --- a/SQCSim2021/remoteplayer.h +++ b/SQCSim2021/remoteplayer.h @@ -8,7 +8,6 @@ #include "texture.h" #include "openglcontext.h" #include "vertexbuffer.h" -#include "texture.h" #include "../SQCSim-common/matrix4.h" class RemotePlayer : public Player { diff --git a/SQCSim2021/renderer.cpp b/SQCSim2021/renderer.cpp index d2b9b30..3e5fc97 100644 --- a/SQCSim2021/renderer.cpp +++ b/SQCSim2021/renderer.cpp @@ -1,4 +1,9 @@ #include "renderer.h" +#include +#include + +#include +#include Renderer::Renderer() { m_meshes.Reset(nullptr); @@ -131,7 +136,8 @@ void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& play } shader.Disable(); glStencilFunc(GL_GREATER, 1, 0xFF); -}; +} + void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]) { int cx = player.x; @@ -238,6 +244,30 @@ void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* bloc } } +void Renderer::RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran) +{ + //float x = pos.x; + //float y = pos.y; + //float z = pos.z; + //float width = 1.0f; + //float height = 1.0f; + + //float u, v, w, h; + //shader.Use(); + //textureAtlas.Bind(); + //textureAtlas.TextureIndexToCoord(idx, u, v, w, h); + + //glLoadMatrixf(tran.GetMatrix().GetInternalValues()); + //glBegin(GL_QUADS); + //glTexCoord2f(u, v); glVertex3f(x - width / 2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0); + //glTexCoord2f(u + w, v); glVertex3f(x + width / 2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0); + //glTexCoord2f(u + w, v + h); glVertex3f(x + width / 2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0); + //glTexCoord2f(u, v + h); glVertex3f(x - width / 2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0); + //glEnd(); + //shader.Disable(); +} + + void Renderer::RenderPlayer(Player* player, Transformation tran) const { } diff --git a/SQCSim2021/renderer.h b/SQCSim2021/renderer.h index 0289baf..5a13709 100644 --- a/SQCSim2021/renderer.h +++ b/SQCSim2021/renderer.h @@ -9,6 +9,9 @@ #include "textureatlas.h" #include "shader.h" #include "remoteplayer.h" +#include "openglcontext.h" +#include "vertexbuffer.h" +#include "../SQCSim-common/matrix4.h" class Renderer { private: @@ -16,6 +19,7 @@ private: TextureAtlas* m_playertext = nullptr; Shader* m_playershader = nullptr; + bool test = true; public: Renderer(); @@ -25,6 +29,8 @@ public: void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]); + void RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran); + void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation world, Shader& shader, TextureAtlas& atlas) const; void RenderPlayer(Player* player, Transformation tran) const; void RenderPlayer(RemotePlayer* rplayer, const Vector3f& player_pos, const Vector3f& player_dir) const;