Add Fog and have the squares follow the player
when the player moves to a new chunk the ground movies over to accommodate this, therefore the player is always in the center of the drawn ground.
This commit is contained in:
@@ -3,7 +3,6 @@ package backsun.lod.util;
|
||||
import java.awt.Color;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GLContext;
|
||||
import org.lwjgl.util.glu.Project;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -27,6 +26,9 @@ public class CustomRenderer
|
||||
private Tessellator tessellator;
|
||||
private BufferBuilder worldRenderer;
|
||||
|
||||
// make sure this is an even number, or else it won't align with the chunk grid
|
||||
public final int viewDistanceMultiplier = 12;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
@@ -54,7 +56,7 @@ public class CustomRenderer
|
||||
GlStateManager.matrixMode(GL11.GL_PROJECTION);
|
||||
GlStateManager.loadIdentity();
|
||||
// farPlaneDistance // 10 chunks = 160
|
||||
Project.gluPerspective(fov, (float) this.mc.displayWidth / (float) this.mc.displayHeight, 0.0125f, farPlaneDistance * 12.0f);
|
||||
Project.gluPerspective(fov, (float) this.mc.displayWidth / (float) this.mc.displayHeight, 0.0125f, farPlaneDistance * viewDistanceMultiplier);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,9 +68,7 @@ public class CustomRenderer
|
||||
{
|
||||
farPlaneDistance = this.mc.gameSettings.renderDistanceChunks * 16;
|
||||
|
||||
// TODO add fog
|
||||
//setupFog();
|
||||
GlStateManager.disableFog();
|
||||
setupFog();
|
||||
|
||||
// set the new model view matrix
|
||||
setProjectionMatrix(partialTicks);
|
||||
@@ -92,41 +92,54 @@ public class CustomRenderer
|
||||
double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks;
|
||||
double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks;
|
||||
|
||||
int playerXChunkOffset = ((int) x / 16) * 16;
|
||||
int playerZChunkOffset = ((int) z / 16) * 16;
|
||||
|
||||
Color grass = new Color(80, 104, 50, 255);
|
||||
Color black = Color.BLACK;
|
||||
Color white = Color.WHITE;
|
||||
Color black = grass;//Color.BLACK;
|
||||
Color white = grass;//Color.WHITE;
|
||||
|
||||
// set how big the squares will be and how far they will go
|
||||
int totalLength = (int) farPlaneDistance * 9;
|
||||
int singleLength = 160;
|
||||
int numbOfBoxesWide = totalLength / singleLength;
|
||||
int totalLength = (int) farPlaneDistance * viewDistanceMultiplier;
|
||||
int squareSideLength = 16;
|
||||
int numbOfBoxesWide = totalLength / squareSideLength;
|
||||
|
||||
// size of a single square
|
||||
int bbx = singleLength;
|
||||
int bbx = squareSideLength;
|
||||
int bby = 0;
|
||||
int bbz = singleLength;
|
||||
int bbz = squareSideLength;
|
||||
|
||||
// this where we will start drawing squares
|
||||
int startXZ = -singleLength * numbOfBoxesWide;
|
||||
|
||||
// (exactly half the total width)
|
||||
int startX = (-squareSideLength * (numbOfBoxesWide / 2)) + playerXChunkOffset;
|
||||
int startZ = (-squareSideLength * (numbOfBoxesWide / 2)) + playerZChunkOffset;
|
||||
|
||||
AxisAlignedBB bb;
|
||||
|
||||
// this is used to alternate the colors of the drawn squares
|
||||
boolean alternateColor = false;
|
||||
boolean evenWidth = false;
|
||||
if (numbOfBoxesWide % 2 == 0)
|
||||
evenWidth = true;
|
||||
|
||||
// x axis
|
||||
for (int i = 0; i < numbOfBoxesWide; i++)
|
||||
{
|
||||
if (evenWidth)
|
||||
alternateColor = !alternateColor;
|
||||
|
||||
// z axis
|
||||
for (int j = 0; j < numbOfBoxesWide; j++)
|
||||
{
|
||||
// update where this square will be drawn
|
||||
double xoffset = -x + (singleLength * i * 2) + startXZ;
|
||||
double xoffset = -x + (squareSideLength * i) + startX;
|
||||
double yoffset = -y;
|
||||
double zoffset = -z + (singleLength * j * 2) + startXZ;
|
||||
double zoffset = -z + (squareSideLength * j) + startZ;
|
||||
|
||||
|
||||
|
||||
// create a new bounding box to store our points
|
||||
bb = new AxisAlignedBB(bbx, bby, bbz, -bbx, bby, -bbz).offset(xoffset, yoffset, zoffset);
|
||||
bb = new AxisAlignedBB(bbx, bby, bbz, 0, bby, 0).offset(xoffset, yoffset, zoffset);
|
||||
|
||||
// draw the squares as a black and white checker board
|
||||
Color c;
|
||||
@@ -134,6 +147,9 @@ public class CustomRenderer
|
||||
c = white;
|
||||
else
|
||||
c = black;
|
||||
// draw the first square as green
|
||||
if (i == 0 && j == 0)
|
||||
c = grass;
|
||||
alternateColor = !alternateColor;
|
||||
|
||||
// draw the square
|
||||
@@ -168,10 +184,13 @@ public class CustomRenderer
|
||||
private void drawBox(AxisAlignedBB bb, int red, int green, int blue, int alpha)
|
||||
{
|
||||
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
|
||||
|
||||
worldRenderer.pos(bb.minX, bb.minY, bb.minZ).color(red, green, blue, alpha).endVertex();
|
||||
worldRenderer.pos(bb.maxX, bb.minY, bb.minZ).color(red, green, blue, alpha).endVertex();
|
||||
worldRenderer.pos(bb.maxX, bb.minY, bb.maxZ).color(red, green, blue, alpha).endVertex();
|
||||
worldRenderer.pos(bb.minX, bb.minY, bb.maxZ).color(red, green, blue, alpha).endVertex();
|
||||
|
||||
// only draw the other 5 sides if there is some thickness to this box
|
||||
if (bb.minY != bb.maxY)
|
||||
{
|
||||
|
||||
@@ -202,37 +221,18 @@ public class CustomRenderer
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
//TODO are these needed?
|
||||
// worldRenderer.finishDrawing();
|
||||
// worldRenderer.reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the fog to be rendered. If the argument passed in is -1 the fog starts at 0 and goes to 80% of far plane
|
||||
* distance and is used for sky rendering.
|
||||
* Sets up and enables the fog to be rendered.
|
||||
*/
|
||||
private void setupFog()
|
||||
{
|
||||
GlStateManager.glNormal3f(0.0F, -1.0F, 0.0F);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
|
||||
float f = this.farPlaneDistance * 15.0f; //15 linear
|
||||
GlStateManager.setFog(GlStateManager.FogMode.LINEAR);
|
||||
|
||||
GlStateManager.setFogDensity(0.0f);
|
||||
GlStateManager.setFogStart(f * 0.7F); // 0.7
|
||||
float f = this.farPlaneDistance * (viewDistanceMultiplier * 0.5f);
|
||||
GlStateManager.setFogDensity(0.1f);
|
||||
GlStateManager.setFogStart(farPlaneDistance * (viewDistanceMultiplier * 0.25f));
|
||||
GlStateManager.setFogEnd(f);
|
||||
|
||||
if (GLContext.getCapabilities().GL_NV_fog_distance)
|
||||
{
|
||||
GlStateManager.glFogi(34138, 34139);
|
||||
}
|
||||
|
||||
|
||||
GlStateManager.enableColorMaterial();
|
||||
GlStateManager.enableFog();
|
||||
GlStateManager.colorMaterial(1028, 4608);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user