diff --git a/SQCSim-common/SQCSim-common.vcxproj b/SQCSim-common/SQCSim-common.vcxproj index c618082..c762f1d 100644 --- a/SQCSim-common/SQCSim-common.vcxproj +++ b/SQCSim-common/SQCSim-common.vcxproj @@ -131,6 +131,7 @@ + @@ -147,6 +148,7 @@ + diff --git a/SQCSim-common/SQCSim-common.vcxproj.filters b/SQCSim-common/SQCSim-common.vcxproj.filters index 45814cf..22804b4 100644 --- a/SQCSim-common/SQCSim-common.vcxproj.filters +++ b/SQCSim-common/SQCSim-common.vcxproj.filters @@ -54,6 +54,9 @@ Fichiers d%27en-tête + + Fichiers d%27en-tête + Fichiers d%27en-tête @@ -83,6 +86,9 @@ Fichiers sources + + Fichiers sources + Fichiers sources diff --git a/SQCSim-common/booster.cpp b/SQCSim-common/booster.cpp new file mode 100644 index 0000000..677a28d --- /dev/null +++ b/SQCSim-common/booster.cpp @@ -0,0 +1,38 @@ +#include "booster.h" + +Booster::Booster() +{ +} + +Booster::Booster(Vector3f tpos, BOOST_TYPE ttype) +{ + pos = tpos; + type = ttype; + available = true; +} + +Booster::~Booster() +{ + +} + +Vector3f Booster::GetPosition() +{ + return pos; +} + +BOOST_TYPE Booster::GetType() +{ + return type; +} + +bool Booster::GetAvailability() +{ + return available; +} + +void Booster::SetAvailability(bool value) +{ + available = value; +} + diff --git a/SQCSim2021/booster.h b/SQCSim-common/booster.h similarity index 53% rename from SQCSim2021/booster.h rename to SQCSim-common/booster.h index 3ab5de4..6bfbed5 100644 --- a/SQCSim2021/booster.h +++ b/SQCSim-common/booster.h @@ -1,18 +1,13 @@ #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" -#include "../SQCSim-common/player.h" - +#include "vector3.h" class Booster { public: + Booster(); Booster(Vector3f tpos, BOOST_TYPE ttype); ~Booster(); - void RenderBillboard(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player); Vector3f GetPosition(); BOOST_TYPE GetType(); bool GetAvailability(); diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index a4f1b90..4685cc4 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -31,7 +31,7 @@ #define TEXTURE_SIZE 512 #define MAX_BULLETS 512 -#define NB_BOOST 1 +#define NB_BOOST 2 #define TIME_SPEED_BOOST 10 //secondes #define TIME_DAMAGE_BOOST 10 //secondes #define TIME_INVINCIBLE_BOOST 4 //secondes diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 4845908..b22a5d2 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -216,7 +216,8 @@ void Player::TakeBooster(Booster booster_table[]) { for (int i = 0; i < sizeof(booster_table); i++) { - if (abs((m_position.x + m_position.y + m_position.z) - (booster_table[i].GetPosition().x + booster_table[i].GetPosition().y + booster_table[i].GetPosition().z)) <= 0.5f && booster_table[i].GetAvailability() == true) + Vector3f pos = booster_table[i].GetPosition(); + if (abs((m_position.x + m_position.y + m_position.z) - (pos.x + pos.y +pos.z)) <= 0.5f && booster_table[i].GetAvailability() == true) { GetBooster(booster_table[i].GetType()); booster_table[i].SetAvailability(false); diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index 015aea3..1b395c2 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -4,7 +4,7 @@ #include #include "transformation.h" #include "vector3.h" -#include "../SQCSim2021/booster.h" +#include "booster.h" #include "define.h" diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index 7d14bc6..b472f23 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -20,7 +20,6 @@ - @@ -38,7 +37,6 @@ - diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index 417ba37..ac1e31c 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -53,9 +53,6 @@ Fichiers d%27en-tête - - Fichiers d%27en-tête - Fichiers d%27en-tête @@ -103,9 +100,6 @@ Fichiers sources - - Fichiers sources - Fichiers sources diff --git a/SQCSim2021/booster.cpp b/SQCSim2021/booster.cpp deleted file mode 100644 index eff683f..0000000 --- a/SQCSim2021/booster.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "booster.h" - -Booster::Booster(Vector3f tpos, BOOST_TYPE ttype) -{ - pos = tpos; - type = ttype; -} - -Booster::~Booster() -{ - -} - -Vector3f Booster::GetPosition() -{ - return pos; -} - -BOOST_TYPE Booster::GetType() -{ - return type; -} - -bool Booster::GetAvailability() -{ - return available; -} - -void Booster::SetAvailability(bool value) -{ - available = value; -} - -void Booster::RenderBillboard(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player) -{ - float width = 1.0f; - float height = 1.7f; - - Matrix4 mat4 = tran.GetMatrix(); - - Vector3f DiffCam = GetPosition() - player.GetPosition(); - Vector3f UpCam = Vector3f(mat4.Get12(), mat4.Get22(), mat4.Get32()); - - Vector3f CrossA = DiffCam.Cross(UpCam); - Vector3f CrossB = DiffCam.Cross(CrossA); - CrossA.Normalize(); - CrossB.Normalize(); - - Vector3f playerPosition = GetPosition() + Vector3f(0.f, 0.f, 0.f); - - - Vector3f v1 = (playerPosition + CrossA * 0.5 * width + CrossB * 0.5 * height); - Vector3f v2 = (playerPosition - CrossA * 0.5 * width + CrossB * 0.5 * height); - Vector3f v3 = (playerPosition + CrossA * 0.5 * width - CrossB * 0.5 * height); - Vector3f v4 = (playerPosition - CrossA * 0.5 * width - CrossB * 0.5 * height); - - float u, v, w, h; - - shader.Use(); - textureAtlas.Bind(); - textureAtlas.TextureIndexToCoord(0, u, v, w, h); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - - glLoadMatrixf(tran.GetMatrix().GetInternalValues()); - glBegin(GL_QUADS); - glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z); - glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z); - glTexCoord2f(u + w, v + h); glVertex3f(v3.x, v3.y, v3.z); - glTexCoord2f(u, v + h); glVertex3f(v4.x, v4.y, v4.z); - - glEnd(); - - glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); - glBlendEquation(GL_FUNC_SUBTRACT); - glDisable(GL_BLEND); - - shader.Disable(); -} diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index fc5e6f1..ca3c4f7 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -3,13 +3,13 @@ //#define SFML_STATIC true -#include "../SQCSim-common/define.h" #include #include #include #include #include #include +#include "../SQCSim-common/define.h" #ifdef _WIN32 #include diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index e32b150..3cc3dbc 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -78,7 +78,6 @@ void Engine::LoadResource() { std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl; abort(); } - LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true); LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true); LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true); @@ -124,15 +123,15 @@ void Engine::LoadResource() { LoadTexture(m_textureMenuQuit, TEXTURE_PATH "menus/buttons/main/mainQuit.png", false); LoadTexture(m_textureMenuSingle, TEXTURE_PATH "menus/buttons/main/mainSingle.png", false); - TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); - TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); - TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); - TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); - TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.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"); + TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); //0 + TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); //1 + TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); //2 + TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); //3 + TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.png"); //4 + TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterVert.png"); //5 + TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png"); //6 + TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png"); //7 + TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png"); //8 //AJOUTER LES TEXTURES DANS L'ORDRE DE L'ÉNUM @@ -1326,6 +1325,8 @@ void Engine::Render(float elapsedTime) { static float pollTime = 0; static float bulletTime = 0; static BlockType bloc = 1; + booster_table[0] = Booster({ 215, 15, 195 }, BTYPE_SPEED); + booster_table[1] = Booster({ 213, 15, 195 }, BTYPE_HEAL); if (elapsedTime > 0.1f) return; @@ -1424,17 +1425,14 @@ void Engine::Render(float elapsedTime) { } } } - - gameTime += elapsedTime * 10; - - Vector3f dance = Vector3f(sin(gameTime), 0, cos(-gameTime)); - dance.Normalize(); - booster_table[0] = Booster({ 195, 16, 195 }, BTYPE_SPEED); - m_remotePlayer.ApplyPhysics(dance, &m_world, elapsedTime, booster_table); m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo); m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo); - m_remotePlayer.Render(m_animeAtlas, m_shader01, all, elapsedTime); - booster_table[0].RenderBillboard(m_textureAtlas, m_shader01, all, m_player); + glDisable(GL_CULL_FACE); + for (Booster booster : booster_table) { + glClear(GL_STENCIL_BUFFER_BIT); + m_renderer.RenderBooster(m_textureAtlas, m_shader01, all, m_player, booster); + } + glEnable(GL_CULL_FACE); 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 8e27ef9..c276348 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "../SQCSim-common/array2d.h" #include "../SQCSim-common/blockinfo.h" #include "../SQCSim-common/boostinfo.h" @@ -13,6 +14,7 @@ #include "../SQCSim-common/world.h" #include "../SQCSim-common/transformation.h" #include "../SQCSim-common/player.h" +#include "../SQCSim-common/booster.h" #include "define.h" #include "openglcontext.h" #include "texture.h" @@ -23,16 +25,15 @@ #include "connector.h" #include "renderer.h" #include "remoteplayer.h" -#include "booster.h" - +#include "settings.h" class Engine : public OpenglContext { public: Engine(); virtual ~Engine(); - virtual void DrawMenu(); - virtual void DrawPause(); - virtual void DrawSplachScreen(); + + + virtual void Init(); virtual void DeInit(); virtual void LoadResource(); @@ -41,96 +42,159 @@ public: virtual void KeyPressEvent(unsigned char key); virtual void KeyReleaseEvent(unsigned char key); virtual void MouseMoveEvent(int x, int y); - virtual void MousePressEvent(const MOUSE_BUTTON &button, int x, int y); - virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y); + virtual void MousePressEvent(const MOUSE_BUTTON& button, int x, int y); + virtual void MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y); private: int GetFps(float elapsedTime) const; int GetCountdown(float elapsedTime); + int GetOptionsChoice(); + bool StartMultiplayerGame(); bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); + void ChangeResolution(Resolution resolution); void InstantDamage(); void SystemNotification(std::string systemLog); void KillNotification(Player killer, Player killed); + void DisplayNotification(std::string message); - void ProcessNotificationQueue(); + void DisplayCrosshair(); void DisplayPovGun(); void DisplayCurrentItem(); void DisplayHud(int timer); - void DisplayInfo(float elapsedTime, BlockType bloc); - void DisplaySingleOrMultiplayerMenu(); void DrawHud(float elapsedTime, BlockType bloc); + void DisplayInfo(float elapsedTime, BlockType bloc); + + void DisplaySplashScreen(); + + void DisplayMainMenu(); + void DrawButtonBackgrounds(float centerX, float centerY, int iterations); + void DrawMainMenuButtons(float centerX, float centerY); + void DrawSingleMultiButtons(float centerX, float centerY); + + void DisplayLobbyMenu(float elapsedTime); + void SetPlayerUsername(float elapsedTime); + void SetServerAddress(float elapsedTime); + + void DisplayPauseMenu(float elapsedTime); + + void DisplayOptionsMenu(); + void DisplayAudioMenu(float centerX, float centerY); + void DisplayGraphicsMenu(float centerX, float centerY); + void DisplayGameplayMenu(float centerX, float centerY); + void DrawSliderBackground(float centerX, float centerY, float minVal, float maxVal, float bottomSideValue, float topSideValue); + void DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value); + void DrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue); + void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); + void ProcessNotificationQueue(); + char SimulateKeyboard(unsigned char key); + void HandlePlayerInput(float elapsedTime); + Audio m_audio = Audio(AUDIO_PATH "music01.wav", AUDIO_PATH "menumusic01.wav"); + irrklang::ISound* m_powpow, * m_scream; + irrklang::ISound* m_whoosh[MAX_BULLETS]; - + Bullet* m_bullets[MAX_BULLETS]; + //Menu + Vector3f m_otherplayerpos = Vector3f(999, 999, 999); - Connector m_conn; - Shader m_shader01; + World m_world = World(); + Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); + + Renderer m_renderer = Renderer(); + + Booster booster_table[NB_BOOST]; BlockInfo* m_blockinfo[BTYPE_LAST]; BoostInfo* m_boostinfo[BTYPE_BOOST_LAST]; + GameState m_gamestate = GameState::SPLASH; + + Shader m_shader01; + + Skybox m_skybox; + TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); TextureAtlas m_animeAtlas = TextureAtlas(TYPE_LAST + POS_LAST); - World m_world = World(); - Renderer m_renderer = Renderer(); - Booster* booster_table; + TextureAtlas::TextureIndex texBoostHeal; Texture m_textureCrosshair; Texture m_textureFont; Texture m_textureGun; Texture m_texturePovGun; Texture m_textureSkybox; - Texture m_textureSoloMultiMenu; - Texture m_textureSoloText; - Texture m_textureMultiText; - Texture m_textureTitle; - TextureAtlas::TextureIndex texBoostHeal; + Texture m_textureLobbyMenu; + Texture m_textureMainMenu; + Texture m_textureOptionsMenu; + Texture m_texturePauseMenu; + Texture m_textureSplashScreen; - Skybox m_skybox; - Audio m_audio = Audio(AUDIO_PATH "start.wav"); + Texture m_textureHd; + Texture m_textureFhd; + Texture m_textureQhd; + Texture m_textureUhd; - irrklang::ISound* m_powpow, - * m_scream; - irrklang::ISound *m_whoosh[MAX_BULLETS]; + Texture m_textureLobbyServer; + Texture m_textureLobbyIdentify; + Texture m_textureCheck; + Texture m_textureChecked; - Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); - - Bullet* m_bullets[MAX_BULLETS]; + Texture m_texturePauseResume; + Texture m_texturePauseMainMenu; - std::unordered_map m_players; - netprot::Buffer m_buf, m_bufout; - std::chrono::high_resolution_clock::time_point m_startTime; + Texture m_textureOptAudio; + Texture m_textureOptBack; + Texture m_textureOptGameplay; + Texture m_textureOptGraphics; + Texture m_textureOptMain; + Texture m_textureOptMusic; + Texture m_textureOptOptions; + Texture m_textureOptResolution; + Texture m_textureOptSensitivity; + Texture m_textureOptSfx; - //Menu - enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY, PAUSE }; - GameState m_gamestate = GameState::MAIN_MENU; - Texture MenuTitleTexture; - Texture MenuBGTexture; - Texture MenuStartTexture; - Texture MenuQuitTexture; - Texture MenuOptionsTexture; - Texture PauseBGTexture; - Texture SplachScreenTexture; + Texture m_textureMenuBack; + Texture m_textureMenuMulti; + Texture m_textureMenuOptions; + Texture m_textureMenuPlay; + Texture m_textureMenuQuit; + Texture m_textureMenuSingle; + Texture m_textureMenuTitle; + Settings m_options = Settings(m_audio); + Resolution m_resolution = HD; + + float m_splashTime = 2.0f; float m_scale; float m_time = 0; - float m_time_SplashScreen = 0; + float m_titleX = 0; float m_titleY = 0; - float m_Width = 0; - float m_Height = 0; + + int m_renderCount = 0; int m_countdown = COUNTDOWN; int m_nbReductionChunk = 4; int m_timerReductionChunk = 30; + float m_mainvolume; + float m_musicvolume; + float m_sfxvolume; + float m_sensitivity; + + int m_selectedOption = 0; + + bool m_selectedOptAudioMainBar = false; + bool m_selectedOptAudioMusicBar = false; + bool m_selectedOptAudioSfxBar = false; + bool m_selectedGameplaySensitivityBar = false; + bool m_damage = false; bool m_wireframe = false; @@ -143,7 +207,26 @@ private: bool m_resetcountdown = false; bool m_soloMultiChoiceMade = false; bool m_stopcountdown = false; - + + bool m_selectedPlayOptions = false; + bool m_selectedOptions = false; + bool m_selectedQuit = false; + + std::string m_currentInputString; + std::string m_username; + std::string m_serverAddr; + + char m_inputChar = 0; + bool m_invalidChar = false; + bool m_charChanged = false; + bool m_settingUsername = false; + bool m_settingServer = false; + bool m_selectedSinglePlayer = false; + bool m_selectedMultiPlayer = false; + bool m_singleReady = false; + bool m_multiReady = false; + + bool m_key1 = false; bool m_key2 = false; @@ -153,20 +236,31 @@ private: bool m_keyA = false; bool m_keyS = false; bool m_keyD = false; + bool m_keyEnter = false; bool m_keySpace = false; + bool m_keyShift = false; + bool m_keyBackspace = false; + bool m_mouseL = false; bool m_mouseR = false; bool m_mouseC = false; bool m_mouseWU = false; bool m_mouseWD = false; - //Pour trouver ou est la souris + float m_mousemx = 0; float m_mousemy = 0; bool m_networkgame = false; - netprot::PlayerInfo m_pinfo; - RemotePlayer m_remotePlayer = RemotePlayer(netprot::PlayerInfo(),Vector3f(5.5f, CHUNK_SIZE_Y + 1.8f, 5.5f)); + + Connector m_conn; + std::deque m_chunkmod_manifest; + std::chrono::high_resolution_clock::time_point m_startTime; + std::unordered_map m_players; + netprot::Buffer m_buf, m_bufout; + netprot::ChunkMod* m_chunkmod = nullptr; + + std::unordered_map m_syncs; std::string m_messageNotification = ""; }; -#endif // ENGINE_H__ +#endif // ENGINE_H__ \ No newline at end of file diff --git a/SQCSim2021/renderer.cpp b/SQCSim2021/renderer.cpp index 3e5fc97..31440a6 100644 --- a/SQCSim2021/renderer.cpp +++ b/SQCSim2021/renderer.cpp @@ -120,7 +120,7 @@ void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& play glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); unsigned int sx, sy, cx, cy; - origin->GetScope(sx,sy); + origin->GetScope(sx, sy); for (int index = 0; index < rendercount; ++index) { int chx = (renderManifest[index].x - sx) * CHUNK_SIZE_X, chy = (renderManifest[index].z - sy) * CHUNK_SIZE_Z; @@ -129,9 +129,9 @@ void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& play glLoadMatrixf(world.GetMatrix().GetInternalValues()); float blcolor = renderManifest[index].y / (VIEW_DISTANCE / 50.f); glBlendColor(blcolor, blcolor, blcolor, 1.f); - origin->ChunkAt(chx, 1, chy)->GetPosition(cx,cy); + origin->ChunkAt(chx, 1, chy)->GetPosition(cx, cy); if (m_meshes.Get(cx - sx, cy - sy)) - m_meshes.Get(cx - sx, cy -sy)->Render(); + m_meshes.Get(cx - sx, cy - sy)->Render(); world.ApplyTranslation(-chx, 0, -chy); } shader.Disable(); @@ -147,7 +147,7 @@ void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* bloc int threads = 0; std::future updateThList[THREADS_UPDATE_CHUNKS]; - unsigned int mx = 0 , my = 0, sx, sy; + unsigned int mx = 0, my = 0, sx, sy; origin->GetScope(sx, sy); @@ -244,27 +244,75 @@ 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) +void Renderer::RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player, Booster booster) { - //float x = pos.x; - //float y = pos.y; - //float z = pos.z; - //float width = 1.0f; - //float height = 1.0f; + if (booster.GetAvailability() == true) + { + float width = 1.f; + float height = 1.f; - //float u, v, w, h; - //shader.Use(); - //textureAtlas.Bind(); - //textureAtlas.TextureIndexToCoord(idx, u, v, w, h); + Vector3f DiffCam = booster.GetPosition() - player.GetPosition(); + Vector3f UpCam = Vector3f(0.f, 1.f, 0.f); - //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(); + Vector3f CrossA = DiffCam.Cross(UpCam); + Vector3f CrossB = DiffCam.Cross(CrossA); + + CrossA.Normalize(); + CrossB.Normalize(); + + Vector3f playerPosition = booster.GetPosition() + Vector3f(0.f, -.75f, 0.f); + + Vector3f v2 = (playerPosition + CrossA * 0.5 * width + CrossB * 0.5 * height); + Vector3f v1 = (playerPosition - CrossA * 0.5 * width + CrossB * 0.5 * height); + Vector3f v3 = (playerPosition + CrossA * 0.5 * width - CrossB * 0.5 * height); + Vector3f v4 = (playerPosition - CrossA * 0.5 * width - CrossB * 0.5 * height); + + int index; + BOOST_TYPE type = booster.GetType(); + + switch (type) + { + case BTYPE_HEAL: + index = 5; + break; + case BTYPE_DAMAGE: + index = 6; + break; + case BTYPE_SPEED: + index = 7; + break; + case BTYPE_INVINCIBLE: + index = 8; + break; + default: + index = 1; + break; + } + float u, v, w, h; + + shader.Use(); + textureAtlas.Bind(); + textureAtlas.TextureIndexToCoord(index, u, v, w, h); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glLoadMatrixf(tran.GetMatrix().GetInternalValues()); + glBegin(GL_QUADS); + glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z); + glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z); + glTexCoord2f(u + w, v + h); glVertex3f(v3.x, v3.y, v3.z); + glTexCoord2f(u, v + h); glVertex3f(v4.x, v4.y, v4.z); + + glEnd(); + + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendEquation(GL_FUNC_SUBTRACT); + glDisable(GL_BLEND); + + shader.Disable(); + } } diff --git a/SQCSim2021/renderer.h b/SQCSim2021/renderer.h index 5a13709..12df11c 100644 --- a/SQCSim2021/renderer.h +++ b/SQCSim2021/renderer.h @@ -29,7 +29,7 @@ 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 RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player, Booster booster); 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;