booster quasi fonctionnel

affichage seulement visible a travers un autre booster.
ne se ramasse pas encore.
This commit is contained in:
Frederic Leger
2023-12-15 23:02:20 -05:00
parent 570bef266c
commit 2364fb9c1f
15 changed files with 285 additions and 192 deletions

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