Draw floors and ceilings
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
+45
@@ -397,13 +397,58 @@ void drawRays3D()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// * Draw ceiling
|
||||||
|
void drawCeiling()
|
||||||
|
{
|
||||||
|
float halfHeight = (float)(gameHeight / 2);
|
||||||
|
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
for (float distance = 0; distance < halfHeight; distance += 1.0f)
|
||||||
|
{
|
||||||
|
// Normalize color from 0.0 to 1.0 based on distance, multiplied by relative intensity
|
||||||
|
float colorIntensity = 0.5f + (distance / halfHeight);
|
||||||
|
glColor3f(0.25 * colorIntensity, 0.25 * colorIntensity, 0.25 * colorIntensity);
|
||||||
|
|
||||||
|
// Draw a horizontal strip at the current distance
|
||||||
|
glVertex2f(MAP_WIDTH + GAP, distance);
|
||||||
|
glVertex2f(MAP_WIDTH + GAP, distance + 1.0f);
|
||||||
|
glVertex2f(TOTAL_WIDTH, distance + 1.0f);
|
||||||
|
glVertex2f(TOTAL_WIDTH, distance);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
// * Draw floor
|
||||||
|
void drawFloor()
|
||||||
|
{
|
||||||
|
float halfHeight = (float)(gameHeight / 2);
|
||||||
|
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
for (float distance = 0; distance < halfHeight; distance += 1.0f)
|
||||||
|
{
|
||||||
|
|
||||||
|
float colorIntensity = 0.5f + (distance / halfHeight);
|
||||||
|
glColor3f(0.25 * colorIntensity, 0.25 * colorIntensity, 0.0f);
|
||||||
|
|
||||||
|
float y = halfHeight + distance;
|
||||||
|
glVertex2f(MAP_WIDTH + GAP, y);
|
||||||
|
glVertex2f(MAP_WIDTH + GAP, y + 1.0f);
|
||||||
|
glVertex2f(TOTAL_WIDTH, y + 1.0f);
|
||||||
|
glVertex2f(TOTAL_WIDTH, y);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
// * Main rendering
|
// * Main rendering
|
||||||
void display()
|
void display()
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
drawCeiling();
|
||||||
|
drawFloor();
|
||||||
drawMap2D();
|
drawMap2D();
|
||||||
drawRays3D();
|
drawRays3D();
|
||||||
drawPlayer();
|
drawPlayer();
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user