Maintenant je comprend les singes au début de 2001 A Space Odyssey

This commit is contained in:
MarcEricMartel 2023-11-15 08:27:51 -05:00
parent e011e2f1fc
commit 86536fbb99
5 changed files with 48 additions and 13 deletions

View File

@ -935,8 +935,10 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
int timer = GetCountdown(elapsedTime); int timer = GetCountdown(elapsedTime);
for (int i = 1; i < WORLD_SIZE_X; i++) for (int i = 1; i < WORLD_SIZE_X; i++)
{ {
if (timer <= COUNTDOWN - m_timerReductionChunk * i) if (timer <= COUNTDOWN - m_timerReductionChunk * i) {
m_world.RemoveChunk(m_nbReductionChunk * i); m_world.RemoveChunk(m_nbReductionChunk * i);
m_renderer.RemoveChunk(m_nbReductionChunk * i);
}
} }
if (m_keyK) { if (m_keyK) {
SystemNotification(m_messageNotification); SystemNotification(m_messageNotification);
@ -1081,7 +1083,7 @@ void Engine::Render(float elapsedTime) {
m_remotePlayer.Render(m_textureAtlas, m_shader01, elapsedTime);
//m_remotePlayer.ApplyTransformation(all); //m_remotePlayer.ApplyTransformation(all);
if (m_mouseWU) bloc++; if (m_mouseWU) bloc++;
@ -1138,15 +1140,15 @@ void Engine::Render(float elapsedTime) {
} }
} }
//m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas); if (m_isSkybox) m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo); m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo); m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
m_remotePlayer.Render(m_textureAtlas, m_shader01, elapsedTime);
if (m_isSkybox) m_skybox.Render(skybox); if (m_isSkybox) m_skybox.Render(skybox);
DrawHud(elapsedTime, bloc); if (m_isSkybox) DrawHud(elapsedTime, bloc);
DisplayPovGun(); if (m_isSkybox) DisplayPovGun();
ProcessNotificationQueue(); ProcessNotificationQueue();
if (m_damage) if (m_damage)
{ {

View File

@ -15,7 +15,7 @@ private:
Chunk* m_chunk; // NE PAS DÉTRUIRE ICI. Chunk* m_chunk; // NE PAS DÉTRUIRE ICI.
void AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt, int x, int y, int z, float u, float v, float s, World* world); void AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt, int x, int y, int z, float u, float v, float s, World* world);
void RemoveChunk(int nbReduit);
public: public:
Mesh(Chunk* chunk); Mesh(Chunk* chunk);
~Mesh(); ~Mesh();

View File

@ -87,15 +87,20 @@ void RemotePlayer::Feed(const netprot::Output out) {
void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, float elapsedTime) void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, float elapsedTime)
{ {
shader.Use();
//m_texture_front.Bind();
m_texture_front.Bind();
float u, v, w, h;
atlas.Bind();
atlas.TextureIndexToCoord(0, u, v, w, h);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(0, 500); glTexCoord2f(u, v); glVertex3f(0, 50., 0);
glTexCoord2f(1, 0); glVertex2f(500, 500); glTexCoord2f(u+w, v); glVertex3f(50., 50., 0);
glTexCoord2f(1, 1); glVertex2f(500, 0); glTexCoord2f(u+w, v+h); glVertex3f(50., 0, 0);
glTexCoord2f(0, 1); glVertex2f(0, 0); glTexCoord2f(u, v+h); glVertex3f(0, 0, 0);
glEnd(); glEnd();
shader.Disable();
} }
bool RemotePlayer::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError) bool RemotePlayer::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError)

View File

@ -7,6 +7,32 @@ Renderer::Renderer() {
Renderer::~Renderer() { Renderer::~Renderer() {
} }
void Renderer::RemoveChunk(int nbReduit)
{
for (int x = 0; x < WORLD_SIZE_X; ++x)
for (int y = 0; y < WORLD_SIZE_Y; ++y)
{
Mesh* chk = nullptr;
if (x < nbReduit)
chk = m_meshes.Remove(x, y);
if (y < nbReduit)
chk = m_meshes.Remove(x, y);
if (y > WORLD_SIZE_Y - nbReduit)
chk = m_meshes.Remove(x, y);
if (x > WORLD_SIZE_X - nbReduit)
chk = m_meshes.Remove(x, y);
// TODO: MakeDirty() les voisins pour qu'ils se redessinent.
if (!chk)
continue;
delete chk;
}
}
void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const { void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const {
rendercount = 0; rendercount = 0;
Vector3f angle; Vector3f angle;

View File

@ -21,6 +21,8 @@ public:
Renderer(); Renderer();
~Renderer(); ~Renderer();
void RemoveChunk(int nbReduit);
void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]); void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const; void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const;