Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Commit

Permalink
Build-145: Fixed Friction Based Physics.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guerra24 committed Jan 8, 2016
1 parent b3c576b commit 168e41a
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 86 deletions.
4 changes: 2 additions & 2 deletions assets/game/settings.conf
@@ -1,12 +1,12 @@
#Voxel Settings
#Mon Jan 04 23:08:03 CST 2016
#Fri Jan 08 16:51:45 CST 2016
UPS=30
VSYNC=false
useMotionBlur=false
useFXAA=false
DrawDistance=2
SettingsVersion=3
useVolumetricLight=true
useVolumetricLight=false
TESTXMOD=Hello Voxel
useDOF=false
FPS=30
Expand Down
2 changes: 1 addition & 1 deletion assets/shaders/FragmentComposite1.glsl
Expand Up @@ -102,7 +102,7 @@ void main(void){
do {
i += 0.05;
rayTrace += refl*incr;
incr *= 1.3;
incr *= 1.4;
newScreen = projectionMatrix * viewMatrix * vec4(rayTrace, 1);
newScreen /= newScreen.w;
newPos = texture(gPosition, newScreen.xy/2.0+0.5).xyz;
Expand Down
2 changes: 1 addition & 1 deletion assets/shaders/FragmentComposite5.glsl
Expand Up @@ -66,7 +66,7 @@ uniform int useVolumetricLight;
/*--------------------------------------------------------*/

const int NUM_SAMPLES = 50;
const float density = 0.005;
const float density = 0.01;
const float gradient = 2.0;

/*--------------------------------------------------------*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/guerra24/voxel/client/core/Voxel.java
Expand Up @@ -117,6 +117,8 @@ private void init() {
BlocksResources.createBlocks(gameResources.getLoader());
gameResources.loadResources();
Logger.log("Initializing Threads");
gameResources.getRenderer().prepare();

/*
* new Thread(new Runnable() { public void run() {
* Thread.currentThread().setName("Voxel-Client"); client = new
Expand Down
Expand Up @@ -32,7 +32,6 @@

import org.lwjgl.BufferUtils;

import net.guerra24.voxel.client.api.ModInitialization;
import net.guerra24.voxel.client.core.GlobalStates;
import net.guerra24.voxel.client.core.GlobalStates.GameState;
import net.guerra24.voxel.client.core.State;
Expand Down Expand Up @@ -70,10 +69,10 @@ public void update(Voxel voxel, GlobalStates states, float delta) {
gm.getRenderer().getWaterRenderer().update(delta);
ParticleMaster.getInstance().update(delta, gm.getCamera());

if (!display.isDisplayFocused() && !VoxelVariables.debug) {
gm.getCamera().unlockMouse();
states.setState(GameState.IN_PAUSE);
}
//if (!display.isDisplayFocused()) {
// gm.getCamera().unlockMouse();
// states.setState(GameState.IN_PAUSE);
//}
}

@Override
Expand Down
Expand Up @@ -67,6 +67,27 @@ public static void renderLabel(String text, String font, float x, float y, float
nvgText(vg, x, y + h * 0.5f, text, NULL);
}

public static void renderProgressBar(float x, float y, float w, float h, float pos) {
long vg = Display.getVg();
nvgBoxGradient(vg, x + 1, y + 1, w - 2, h, 3, 4, rgba(32, 32, 32, 255, colorA), rgba(92, 92, 92, 255, colorB),
paintA);
nvgBeginPath(vg);
nvgRoundedRect(vg, x, y, w, h, 3);
nvgFillPaint(vg, paintA);
nvgFill(vg);

float value = Math.min(Math.max(0.0f, pos), 1.0f);
int barPos = (int) (Math.round(w - 2) * value);

nvgBoxGradient(vg, x, y, barPos + 1.5f, h - 1, 3, 4, rgba(220, 220, 220, 255, colorC),
rgba(128, 100, 128, 255, colorB), paintB);

nvgBeginPath(vg);
nvgRoundedRect(vg, x + 1, y + 1, barPos, h - 2, 3);
nvgFillPaint(vg, paintB);
nvgFill(vg);
}

public static void renderWindow(String title, String font, float x, float y, float w, float h) {
float cornerRadius = 3.0f;
NVGPaint shadowPaint = paintA;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/net/guerra24/voxel/client/menu/MainMenu.java
Expand Up @@ -54,6 +54,8 @@ public MainMenu(GameResources gm) {
webRenderer.update();
}

float b = 0;

public void render() {
MenuRendering.renderButton(null, "Play", "Roboto-Bold", 170 * xScale, 112 * yScale, 215 * xScale, 80 * yScale,
MenuRendering.rgba(255, 255, 255, 255, MenuRendering.colorA), playButton.insideButton());
Expand All @@ -65,15 +67,14 @@ public void render() {
MenuRendering.renderButton(null, "Exit", "Roboto-Bold", 170 * xScale, 425 * yScale, 215 * xScale, 80 * yScale,
MenuRendering.rgba(255, 255, 255, 255, MenuRendering.colorA), exitButton.insideButton());


MenuRendering.renderText(
"Voxel " + VoxelVariables.version + " " + VoxelVariables.state + " Build " + VoxelVariables.build,
"Roboto-Bold", 0, 710 * yScale, 20);
MenuRendering.renderWindow("Voxel News", "Roboto-Bold", 450 * xScale, 50 * yScale, 750 * xScale, 600 * yScale);
webRenderer.render();
MenuRendering.renderButton(null, "Reload", "Roboto-Bold", 1096 * xScale, 53 * yScale, 100 * xScale,
40 * yScale, MenuRendering.rgba(80, 80, 80, 80, MenuRendering.colorA),
newsRefreshButton.insideButton());
MenuRendering.renderButton(null, "Reload", "Roboto-Bold", 1096 * xScale, 53 * yScale, 100 * xScale, 40 * yScale,
MenuRendering.rgba(80, 80, 80, 80, MenuRendering.colorA), newsRefreshButton.insideButton());

}

public void update() {
Expand Down
Expand Up @@ -50,6 +50,7 @@ public OptionsMenu(GameResources gm) {
godraysButton = new Button(new Vector2f(32 * xScale, 560 * yScale), new Vector2f(215 * xScale, 80 * yScale));
shadowsButton = new Button(new Vector2f(32 * xScale, 460 * yScale), new Vector2f(215 * xScale, 80 * yScale));
dofButton = new Button(new Vector2f(32 * xScale, 360 * yScale), new Vector2f(215 * xScale, 80 * yScale));
slider.setPos(VoxelVariables.radius / 32f);
}

public void update() {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/guerra24/voxel/client/util/Maths.java
Expand Up @@ -142,6 +142,19 @@ public static float clamp(double d) {
return (float) Math.max(0, Math.min(128, d));
}

/**
*
* Clamp a value
*
* @param d
* Value
* @return Clamped Value
* @author Guerra24 <pablo230699@hotmail.com>
*/
public static float clamp(double d, double min, double max) {
return (float) Math.max(min, Math.min(max, d));
}

/**
* Gets a Random int from Range
*
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/guerra24/voxel/client/world/InfinityWorld.java
Expand Up @@ -89,7 +89,7 @@ public void startWorld(String name, Random seed, int chunkDim, GameResources gm)
this.name = name;
this.seed = seed;
this.chunkDim = chunkDim;
gm.getCamera().setPosition(new Vector3f(0, 80, 0));
gm.getCamera().setPosition(new Vector3f(0, 256, 0));
if (existWorld()) {
loadWorld(gm);
}
Expand All @@ -100,13 +100,13 @@ public void startWorld(String name, Random seed, int chunkDim, GameResources gm)

@Override
public void init(GameResources gm) {
particleSystem = new ParticleSystem(gm.getTorchTexture(), 5, 1, -0.01f, 4, 0.5f);
particleSystem = new ParticleSystem(gm.getTorchTexture(), 2, 1, -0.01f, 4, 0.5f);
particleSystem.setDirection(new Vector3f(0, 1, 0), 0.1f);
particleSystem.setLifeError(0.8f);
particleSystem.setScaleError(0.2f);
particleSystem.setSpeedError(0.2f);
seedi = seed.nextInt();
noise = new SimplexNoise(128, 0.3f, seedi);
noise = new SimplexNoise(256, 0.3f, seedi);
lightNodes = new LinkedList<>();
chunks = new HashMap<ChunkKey, Chunk>();
chunkGenerator = new ChunkGenerator();
Expand Down Expand Up @@ -171,20 +171,20 @@ public void updateChunksGeneration(GameResources gm, float delta) {
} else {
if (VoxelVariables.generateChunks) {
addChunk(new Chunk(chunkDim, xx, yy, zz, this, gm));
saveChunk(chunkDim, xx, yy, zz, gm);
//saveChunk(chunkDim, xx, yy, zz, gm);
}
}
}
} else {
Chunk chunk = getChunk(chunkDim, xx, yy, zz);
for (ParticlePoint particlePoint : chunk.getParticlePoints()) {
particleSystem.generateParticles(particlePoint, delta);
}
chunk.update(this, worldService, gm.getCamera());
if (gm.getFrustum().cubeInFrustum(chunk.posX, chunk.posY, chunk.posZ, chunk.posX + 16,
chunk.posY + 16, chunk.posZ + 16)) {
chunk.rebuild(worldService, this);
}
for (ParticlePoint particlePoint : chunk.getParticlePoints()) {
particleSystem.generateParticles(particlePoint, delta);
}
}
}
if (zr * zr + xr * xr + yr * yr <= VoxelVariables.genRadius * VoxelVariables.genRadius
Expand Down Expand Up @@ -522,7 +522,7 @@ public void lighting(int x, int y, int z, int val) {
lightNodes.add(new LightNode(x, y, z));
}
}

@Override
public float getLight(int x, int y, int z) {
int cx = x >> 4;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/guerra24/voxel/client/world/chunks/Chunk.java
Expand Up @@ -199,8 +199,7 @@ protected void createBasicTerrain(IWorld world) {
for (int z = 0; z < sizeZ; z++) {
for (int y = 0; y < 128; y++) {
if (y >= cy * 16 && y < 16 + cy * 16) {
if (y <= 64)
setLocalBlock(x, y, z, Block.Water.getId());
setLocalBlock(x, y, z, Block.Water.getId());
}
}
}
Expand All @@ -210,14 +209,14 @@ protected void createBasicTerrain(IWorld world) {
double tempHeight = world.getNoise().getNoise((int) ((x + cx * 16) / Biomes.OCEAN.getMultiplier()),
(int) ((z + cz * 16) / Biomes.OCEAN.getMultiplier()));
tempHeight += 1;
int height = (int) (64 * Maths.clamp(tempHeight));
int height = (int) (128 * Maths.clamp(tempHeight));
for (int y = 0; y < height; y++) {
if (y >= cy * 16 && y < 16 + cy * 16) {
if (y == height - 1 && y > 65)
if (y == height - 1 && y > 128)
setLocalBlock(x, y, z, Block.Grass.getId());
else if (y == height - 2 && y > 65)
else if (y == height - 2 && y > 128)
setLocalBlock(x, y, z, Block.Dirt.getId());
else if (y == height - 1 && y < 66)
else if (y == height - 1 && y < 129)
setLocalBlock(x, y, z, Block.Sand.getId());
else
setLocalBlock(x, y, z, Block.Stone.getId());
Expand All @@ -236,7 +235,7 @@ protected void decorate(IWorld world) {
double tempHeight = world.getNoise().getNoise((int) ((xx + cx * 16) / Biomes.OCEAN.getMultiplier()),
(int) ((zz + cz * 16) / Biomes.OCEAN.getMultiplier()));
tempHeight += 1;
int height = (int) (64 * Maths.clamp(tempHeight));
int height = (int) (128 * Maths.clamp(tempHeight));
int h = getLocalBlock(xx, height - 1, zz);
if (h == Block.Grass.getId() || h == Block.Dirt.getId())
world.getChunkGenerator().addTree(world, xx + cx * 16, height, zz + cz * 16, Maths.randInt(4, 10),
Expand Down Expand Up @@ -275,7 +274,8 @@ private void rebuildChunkSection(IWorld world) {
for (int y = 0; y < sizeY; y++) {
if (Block.getBlock(blocks[x][y][z]) == Block.Torch) {
} else if (Block.getBlock(blocks[x][y][z]) != Block.Air
&& Block.getBlock(blocks[x][y][z]) != Block.Water) {
&& Block.getBlock(blocks[x][y][z]) != Block.Water
&& !Block.getBlock(blocks[x][y][z]).usesSingleModel()) {
tess.generateCube(x + cx * sizeX, y + cy * sizeY, (z + cz * sizeZ) - 1, 1,
cullFaceUpSolidBlock(x + cx * sizeX, y + cy * sizeY, z + cz * sizeZ, world),
cullFaceDown(x + cx * sizeX, y + cy * sizeY, z + cz * sizeZ, world),
Expand Down

This file was deleted.

19 changes: 12 additions & 7 deletions src/main/java/net/guerra24/voxel/client/world/entities/Camera.java
Expand Up @@ -193,21 +193,26 @@ public void update(float delta, GameResources gm, IWorld world, DedicatedClient
isMoved = true;
}
if (isKeyDown(KEY_SPACE)) {
velocityComponent.y = 12;
velocityComponent.y = 200 * delta;
}
if (isKeyDown(KEY_LSHIFT)) {
multiplierMovement = 1;
multiplierMovement = 1 * delta;
} else {
multiplierMovement = 5;
multiplierMovement = 120 * delta;
}
if (isKeyDown(KEY_LCONTROL)) {
multiplierMovement = 12;
multiplierMovement = 200 * delta;
} else {
multiplierMovement = 5;
multiplierMovement = 120 * delta;
}

if (isKeyDown(Keyboard.KEY_Y))
System.out.println(positionComponent.position);
velocityComponent.x = Maths.clamp(velocityComponent.x, -2, 2);
velocityComponent.z = Maths.clamp(velocityComponent.z, -2, 2);

if (isKeyDown(Keyboard.KEY_Y)) {
System.out.println(positionComponent.toString());
System.out.println(velocityComponent.toString());
}

if (isKeyDown(KEY_T)) {
gm.getEngine()
Expand Down
Expand Up @@ -30,4 +30,9 @@

public class PositionComponent implements Component {
public Vector3f position = new Vector3f();

@Override
public String toString() {
return "[x:" + position.x + "]" + "[y:" + position.y + "]" + "[z:" + position.z + "]";
}
}
Expand Up @@ -30,4 +30,9 @@ public class VelocityComponent implements Component {
public float x = 0.0f;
public float y = 0.0f;
public float z = 0.0f;

@Override
public String toString() {
return "[x:" + x + "]" + "[y:" + y + "]" + "[z:" + z + "]";
}
}

0 comments on commit 168e41a

Please sign in to comment.