Merge branch 'SQC19_Booster' into online_boosts

This commit is contained in:
MarcEricMartel
2023-12-18 11:19:52 -05:00
15 changed files with 216 additions and 135 deletions

View File

@@ -20,7 +20,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="audio.h" />
<ClInclude Include="booster.h" />
<ClInclude Include="connector.h" />
<ClInclude Include="define.h" />
<ClInclude Include="engine.h" />
@@ -38,7 +37,6 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="audio.cpp" />
<ClCompile Include="booster.cpp" />
<ClCompile Include="connector.cpp" />
<ClCompile Include="engine.cpp" />
<ClCompile Include="main.cpp" />

View File

@@ -53,9 +53,6 @@
<ClInclude Include="remoteplayer.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="booster.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="settings.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
@@ -103,9 +100,6 @@
<ClCompile Include="remoteplayer.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="booster.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="settings.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>

View File

@@ -1,46 +0,0 @@
#include "booster.h"
void Booster::RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, 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(8, 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);
}

View File

@@ -1,14 +0,0 @@
#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, Shader& shader, Transformation tran);
};
#endif

View File

@@ -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
@@ -1308,6 +1307,8 @@ void Engine::Render(float elapsedTime) {
}
if (m_gamestate == GameState::PAUSE) {
booster_table[0] = Booster({ 215, 15, 195 }, BTYPE_SPEED);
booster_table[1] = Booster({ 213, 15, 195 }, BTYPE_HEAL);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -1349,7 +1350,7 @@ void Engine::Render(float elapsedTime) {
static bool leftright = false;
if (pollTime >= .005f) {
Player::Sound snd = m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime);
Player::Sound snd = m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime, booster_table);
switch (snd) {
case Player::Sound::STEP:
if (leftright)
@@ -1428,10 +1429,19 @@ void Engine::Render(float elapsedTime) {
}
}
}
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
for (Booster booster : booster_table) {
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);
//glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
//m_remotePlayer.Render(m_textureAtlas, m_shader01, all, elapsedTime);
m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
glEnable(GL_BLEND);

View File

@@ -14,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"
@@ -24,13 +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 Init();
virtual void DeInit();
virtual void LoadResource();
@@ -39,8 +42,8 @@ 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;
@@ -56,6 +59,7 @@ private:
void KillNotification(Player killer, Player killed);
void DisplayNotification(std::string message);
void DisplayCrosshair();
void DisplayPovGun();
void DisplayCurrentItem();
@@ -103,10 +107,9 @@ private:
Renderer m_renderer = Renderer();
Booster m_booster = Booster();
Booster booster_table[NB_BOOST];
BlockInfo* m_blockinfo[BTYPE_LAST];
BoostInfo* m_boostinfo[BTYPE_BOOST_LAST];
GameState m_gamestate = GameState::SPLASH;
Shader m_shader01;
@@ -169,9 +172,12 @@ private:
float m_splashTime = 2.0f;
float m_scale;
float m_time = 0;
float m_titleX = 0;
float m_titleY = 0;
int m_renderCount = 0;
int m_countdown = COUNTDOWN;
int m_nbReductionChunk = 4;
@@ -186,7 +192,7 @@ private:
bool m_selectedOptAudioMainBar = false;
bool m_selectedOptAudioMusicBar = false;
bool m_selectedOptAudioSfxBar = false;
bool m_selectedOptAudioSfxBar = false;
bool m_selectedGameplaySensitivityBar = false;
bool m_damage = false;
@@ -220,9 +226,10 @@ private:
bool m_singleReady = false;
bool m_multiReady = false;
bool m_key1 = false;
bool m_key2 = false;
bool m_keyK = false;
bool m_keyL = false;
bool m_keyW = false;
@@ -244,7 +251,7 @@ private:
float m_mousemy = 0;
bool m_networkgame = false;
Connector m_conn;
std::deque<netprot::ChunkMod*> m_chunkmod_manifest;
std::chrono::high_resolution_clock::time_point m_startTime;
@@ -258,4 +265,4 @@ private:
std::string m_messageNotification = "";
};
#endif // ENGINE_H__
#endif // ENGINE_H__

View File

@@ -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<Mesh*> 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();
}
}

View File

@@ -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;