From 98b7946cc243dda76c41831034cc9fdc199274de Mon Sep 17 00:00:00 2001 From: MrDev023 Date: Sun, 19 Jul 2015 14:32:14 +0200 Subject: [PATCH] Correction du bug de getBlock dans la class World --- VBO/src/main/Camera.java | 38 +++++- VBO/src/main/DisplayManager.java | 43 ++++++- VBO/src/main/Game.java | 17 +++ VBO/src/main/Main.java | 18 ++- VBO/src/main/PlayerRayCast.java | 43 +++++++ VBO/src/main/Update.java | 93 +++++++++++++- VBO/src/math/Vector2f.java | 4 + VBO/src/math/Vector3f.java | 4 + VBO/src/world/Chunk.java | 214 ++++++++++++++++--------------- VBO/src/world/World.java | 52 ++++++-- 10 files changed, 405 insertions(+), 121 deletions(-) create mode 100644 VBO/src/main/PlayerRayCast.java diff --git a/VBO/src/main/Camera.java b/VBO/src/main/Camera.java index e617f01..3334657 100644 --- a/VBO/src/main/Camera.java +++ b/VBO/src/main/Camera.java @@ -9,13 +9,18 @@ public class Camera { private static Vector3f position = new Vector3f(0,4,0); private static Vector2f rotation = new Vector2f(0,120); + private static PlayerRayCast playerRaycast; private static final float HEIGHT = (float) (1.5f - (Block.getSize()/2.0f)); + public static void initCamera(){ + playerRaycast = new PlayerRayCast(); + } + public static void renderCamera(){ glLoadIdentity(); glRotatef(rotation.getX(), 1, 0, 0); glRotatef(rotation.getY(), 0, 1, 0); - glTranslatef(-position.getX(), -(position.getY()+HEIGHT), -position.getZ()); + glTranslatef(-position.getX(), -(position.getY()+getHeight()), -position.getZ()); } public static void move(float xa,float ya,float za){ @@ -52,6 +57,23 @@ public class Camera { } } + public static Vector3f getDirection(){ + Vector3f r = new Vector3f(); + + float cosY = (float)Math.cos(Math.toRadians(rotation.getY() - 90)); + float sinY = (float)Math.sin(Math.toRadians(rotation.getY() - 90)); + float cosP = (float)Math.cos(Math.toRadians(-rotation.getX())); + float sinP = (float)Math.sin(Math.toRadians(-rotation.getX())); + + r.setX(cosY * cosP); + r.setY(sinP); + r.setZ(sinY * cosP); + + r.normalize(); + + return r; + } + public static Vector3f getPosition() { return position; } @@ -67,5 +89,19 @@ public class Camera { public static void setRotation(Vector2f rotation) { Camera.rotation = rotation; } + + public static float getHeight() { + return HEIGHT; + } + + public static PlayerRayCast getPlayerRaycast() { + return playerRaycast; + } + + public static void setPlayerRaycast(PlayerRayCast playerRaycast) { + Camera.playerRaycast = playerRaycast; + } + + } diff --git a/VBO/src/main/DisplayManager.java b/VBO/src/main/DisplayManager.java index 4486a81..fa741e4 100644 --- a/VBO/src/main/DisplayManager.java +++ b/VBO/src/main/DisplayManager.java @@ -39,6 +39,9 @@ public class DisplayManager { */ public static void render3D(){ Main.getGame().render(); + if(Update.getSelectedBlock() != null && Update.getSelectedVector() !=null){ + renderBlock((int)Update.getSelectedVector().x,(int)Update.getSelectedVector().y,(int)Update.getSelectedVector().z); + } } /** @@ -83,5 +86,43 @@ public class DisplayManager { DisplayManager.fov = fov; } - + private static void renderBlock(int x,int y ,int z){ + float s = 1; + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glDisable(GL_CULL_FACE); + glLineWidth(2); + glBegin(GL_QUADS); + glVertex3f(x,y,z); + glVertex3f(x + s,y,z); + glVertex3f(x + s, y + s, z); + glVertex3f(x,y + s,z); + + glVertex3f(x + s,y,z + s); + glVertex3f(x,y,z + s); + glVertex3f(x,y + s,z + s); + glVertex3f(x + s, y + s, z + s); + + glVertex3f(x + s,y,z); + glVertex3f(x,y,z); + glVertex3f(x,y,z + s); + glVertex3f(x + s,y,z + s); + + glVertex3f(x,y + s,z); + glVertex3f(x + s,y + s,z); + glVertex3f(x + s,y + s,z + s); + glVertex3f(x,y + s,z + s); + + glVertex3f(x,y,z); + glVertex3f(x,y + s,z); + glVertex3f(x,y + s,z + s); + glVertex3f(x,y,z + s); + + glVertex3f(x + s,y + s,z); + glVertex3f(x + s,y,z); + glVertex3f(x + s,y,z + s); + glVertex3f(x + s,y + s,z + s); + glEnd(); + glEnable(GL_CULL_FACE); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } } diff --git a/VBO/src/main/Game.java b/VBO/src/main/Game.java index e670fe7..c004420 100644 --- a/VBO/src/main/Game.java +++ b/VBO/src/main/Game.java @@ -26,5 +26,22 @@ public class Game { public void renderGUI(){ } + + public World getWorld() { + return world; + } + + public void setWorld(World world) { + this.world = world; + } + + public int getUpdate() { + return update; + } + + public void setUpdate(int update) { + this.update = update; + } + } diff --git a/VBO/src/main/Main.java b/VBO/src/main/Main.java index 919b8ca..966e872 100644 --- a/VBO/src/main/Main.java +++ b/VBO/src/main/Main.java @@ -54,6 +54,7 @@ public class Main { skybox = new SkyBox(new String[] { right, left, top, bottom, back, front }); + Camera.initCamera(); game = new Game(); Mouse.setGrabbed(true); loop(); @@ -111,13 +112,20 @@ public class Main { if (elapsedInfo >= 1000) { LAST_FPS = FPS; LAST_TICKS = TICKS; + boolean nx = false, ny = false, nz = false; + if(Camera.getPosition().getX() < 0)nx = true; + if(Camera.getPosition().getY() < 0)ny = true; + if(Camera.getPosition().getZ() < 0)nz = true; Display.setTitle(TITLE + " | FPS:" + (int)(1000000000.0f/timeFps) + " TICKS:" - + (int)(1000000000.0f/timeTicks) + " timeFps:" + timeFps + "ns timeTicks:" + + LAST_TICKS + " timeFps:" + timeFps + "ns timeTicks:" + timeTicks + "ns" + " | PX:" + Camera.getPosition().getX() + " PY:" + Camera.getPosition().getY() + " PZ:" + Camera.getPosition().getZ() + " | " - + World.updateWorldTime + " " + DisplayManager.getDelta()); + + World.updateWorldTime + " " + DisplayManager.getDelta() + + " " + Update.getSelectedBlock() + " | " + + getGame().getWorld().getBlock((int)Camera.getPosition().getX(), (int) Camera.getPosition().getY(), (int) Camera.getPosition().getZ(),nx,ny,nz) + " | " + + getGame().getWorld().getLocalChunk((int)Camera.getPosition().getX(), (int) Camera.getPosition().getY(), (int) Camera.getPosition().getZ(),nx,ny,nz).toString()); FPS = 0; TICKS = 0; elapsedInfo = 0; @@ -127,6 +135,12 @@ public class Main { } } + public static String getStringByNoString(Object... a){ + String b = ""; + for(Object c : a)b+= c + " "; + return b; + } + public static boolean isRunning() { return IsRunning; } diff --git a/VBO/src/main/PlayerRayCast.java b/VBO/src/main/PlayerRayCast.java new file mode 100644 index 0000000..93be7a5 --- /dev/null +++ b/VBO/src/main/PlayerRayCast.java @@ -0,0 +1,43 @@ +package main; + +import java.util.*; + +import math.*; +import world.*; + +public class PlayerRayCast { + + private List points; + private int length = 10; + private int precision = 16; + + public PlayerRayCast(){ + this.points = new ArrayList(); + for(int i = 0; i < length * precision; i++){ + points.add(new Vector3f()); + } + } + + public void update(){ + int i = 0; + for(Vector3f v : points){ + Vector3f pos = Camera.getPosition().copy().add(0f,Camera.getHeight(),0f).add(Camera.getDirection().copy().mul(i/(float)precision)); + v.set(pos); + i++; + } + } + + public Vector3f getBlock(World world){ + for(Vector3f v : points){ + boolean nx = false, ny = false, nz = false; + if(v.x < 0)nx = true; + if(v.y < 0)ny = true; + if(v.z < 0)nz = true; + boolean block = world.getBlock((int)v.x, (int)v.y, (int)v.z,nx,ny,nz) != null; + + if(block) return new Vector3f(v.x, v.y,v.z); + } + return null; + } + +} diff --git a/VBO/src/main/Update.java b/VBO/src/main/Update.java index b79c498..9643e88 100644 --- a/VBO/src/main/Update.java +++ b/VBO/src/main/Update.java @@ -1,14 +1,19 @@ package main; +import math.*; + import org.lwjgl.input.*; import org.lwjgl.opengl.*; +import blocks.*; + public class Update { private static float xDir,yDir,zDir; private static float speed = 0.01f; private static float xa = 0,ya = 0,za = 0; - + private static Block selectedBlock = null; + private static Vector3f selectedVector = new Vector3f(0,0,0); /** * @Info Fonction permettant de gerer les action de la souris @@ -105,6 +110,92 @@ public class Update { */ public static void update(){ Main.getGame().update(); + Camera.getPlayerRaycast().update(); + if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()) != null){ + boolean nx = false, ny = false, nz = false; + if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).x < 0)nx = true; + if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).y < 0)ny = true; + if(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).z < 0)nz = true; + selectedBlock = Main.getGame().getWorld().getBlock((int)Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getX(), (int)Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getY(), (int)Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getZ(),nx,ny,nz); + selectedVector = new Vector3f(Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getX(), Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getY(), Camera.getPlayerRaycast().getBlock(Main.getGame().getWorld()).getZ()); + }else{ + selectedBlock = null; + selectedVector = null; + } + } + + public static float getxDir() { + return xDir; + } + + public static void setxDir(float xDir) { + Update.xDir = xDir; + } + + public static float getyDir() { + return yDir; + } + + public static void setyDir(float yDir) { + Update.yDir = yDir; + } + + public static float getzDir() { + return zDir; + } + + public static void setzDir(float zDir) { + Update.zDir = zDir; + } + + public static float getSpeed() { + return speed; + } + + public static void setSpeed(float speed) { + Update.speed = speed; + } + + public static float getXa() { + return xa; + } + + public static void setXa(float xa) { + Update.xa = xa; + } + + public static float getYa() { + return ya; + } + + public static void setYa(float ya) { + Update.ya = ya; + } + + public static float getZa() { + return za; + } + + public static void setZa(float za) { + Update.za = za; + } + + public static Block getSelectedBlock() { + return selectedBlock; + } + + public static void setSelectedBlock(Block selectedBlock) { + Update.selectedBlock = selectedBlock; + } + + public static Vector3f getSelectedVector() { + return selectedVector; + } + + public static void setSelectedVector(Vector3f selectedVector) { + Update.selectedVector = selectedVector; } + + } diff --git a/VBO/src/math/Vector2f.java b/VBO/src/math/Vector2f.java index 8663702..6cf0a90 100644 --- a/VBO/src/math/Vector2f.java +++ b/VBO/src/math/Vector2f.java @@ -25,6 +25,10 @@ public class Vector2f { public void setY(float y) { this.y = y; } + + public Vector2f copy() { + return new Vector2f(x,y); + } diff --git a/VBO/src/math/Vector3f.java b/VBO/src/math/Vector3f.java index 9170d11..b7f113f 100644 --- a/VBO/src/math/Vector3f.java +++ b/VBO/src/math/Vector3f.java @@ -189,6 +189,10 @@ public class Vector3f { return this; } + public String toString(){ + return x + " " + y + " " + z; + } + public static float distance(Vector3f a,Vector3f b){ return (float)Math.sqrt((Math.pow(b.getX()-a.getX(), 2))+(Math.pow(b.getY()-a.getY(), 2))+(Math.pow(b.getZ()-a.getZ(), 2))); } diff --git a/VBO/src/world/Chunk.java b/VBO/src/world/Chunk.java index aa25c60..374acdd 100644 --- a/VBO/src/world/Chunk.java +++ b/VBO/src/world/Chunk.java @@ -102,6 +102,7 @@ public class Chunk { } public void loopChunk(int x, int y, int z) { + world = Main.getGame().getWorld(); int xx = this.x * SIZE + x; int yy = this.y * SIZE + y; int zz = this.z * SIZE + z; @@ -111,12 +112,16 @@ public class Chunk { boolean right = true; boolean back = true; boolean front = true; -// up = world.getBlock(xx, yy + 1, zz) == null; -// down = world.getBlock(xx, yy - 1, zz) == null; -// left = world.getBlock(xx - 1, yy, zz) == null; -// right = world.getBlock(xx + 1, yy, zz) == null; -// front = world.getBlock(xx, yy, zz - 1) == null; -// back = world.getBlock(xx, yy, zz + 1) == null; + boolean nx = false, ny = false, nz = false; + if(this.x < 0)nx = true; + if(this.y < 0)ny = true; + if(this.z < 0)nz = true; + up = world.getBlock(xx, yy + 1, zz,nx,ny,nz) == null; + down = world.getBlock(xx, yy - 1, zz,nx,ny,nz) == null; + left = world.getBlock(xx - 1, yy, zz,nx,ny,nz) == null; + right = world.getBlock(xx + 1, yy, zz,nx,ny,nz) == null; + front = world.getBlock(xx, yy, zz - 1,nx,ny,nz) == null; + back = world.getBlock(xx, yy, zz + 1,nx,ny,nz) == null; if (!up && !down && !left && !right && !front && !back) return; if (blocks[x][y][z] == null) @@ -133,22 +138,22 @@ public class Chunk { // aa ab bb ba float[] a = new float[] { 1, 1, 1, 1 }; -// if (world.getBlock(xx - 1, yy + 1, zz) != null -// || world.getBlock(xx - 1, yy + 1, zz - 1) != null -// || world.getBlock(xx, yy + 1, zz - 1) != null) -// a[0] = ao; -// if (world.getBlock(xx + 1, yy + 1, zz) != null -// || world.getBlock(xx + 1, yy + 1, zz - 1) != null -// || world.getBlock(xx, yy + 1, zz - 1) != null) -// a[1] = ao; -// if (world.getBlock(xx + 1, yy + 1, zz) != null -// || world.getBlock(xx + 1, yy + 1, zz + 1) != null -// || world.getBlock(xx, yy + 1, zz + 1) != null) -// a[2] = ao; -// if (world.getBlock(xx - 1, yy + 1, zz) != null -// || world.getBlock(xx - 1, yy + 1, zz + 1) != null -// || world.getBlock(xx, yy + 1, zz + 1) != null) -// a[3] = ao; + if (world.getBlock(xx - 1, yy + 1, zz,nx,ny,nz) != null + || world.getBlock(xx - 1, yy + 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx, yy + 1, zz - 1,nx,ny,nz) != null) + a[0] = ao; + if (world.getBlock(xx + 1, yy + 1, zz,nx,ny,nz) != null + || world.getBlock(xx + 1, yy + 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx, yy + 1, zz - 1,nx,ny,nz) != null) + a[1] = ao; + if (world.getBlock(xx + 1, yy + 1, zz,nx,ny,nz) != null + || world.getBlock(xx + 1, yy + 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx, yy + 1, zz + 1,nx,ny,nz) != null) + a[2] = ao; + if (world.getBlock(xx - 1, yy + 1, zz,nx,ny,nz) != null + || world.getBlock(xx - 1, yy + 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx, yy + 1, zz + 1,nx,ny,nz) != null) + a[3] = ao; vbo.addDataByFloatArray(b.getDataUp(xx, yy, zz, a)); } @@ -156,22 +161,22 @@ public class Chunk { float[] a = new float[] { 1, 1, 1, 1 }; // ambient occlusion -// if (world.getBlock(xx - 1, yy - 1, zz) != null -// || world.getBlock(xx - 1, yy - 1, zz - 1) != null -// || world.getBlock(xx, yy - 1, zz - 1) != null) -// a[1] = ao; -// if (world.getBlock(xx + 1, yy - 1, zz) != null -// || world.getBlock(xx + 1, yy - 1, zz - 1) != null -// || world.getBlock(xx, yy - 1, zz - 1) != null) -// a[0] = ao; -// if (world.getBlock(xx + 1, yy - 1, zz) != null -// || world.getBlock(xx + 1, yy - 1, zz + 1) != null -// || world.getBlock(xx, yy - 1, zz + 1) != null) -// a[3] = ao; -// if (world.getBlock(xx - 1, yy - 1, zz) != null -// || world.getBlock(xx - 1, yy - 1, zz + 1) != null -// || world.getBlock(xx, yy - 1, zz + 1) != null) -// a[2] = ao; + if (world.getBlock(xx - 1, yy - 1, zz,nx,ny,nz) != null + || world.getBlock(xx - 1, yy - 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx, yy - 1, zz - 1,nx,ny,nz) != null) + a[1] = ao; + if (world.getBlock(xx + 1, yy - 1, zz,nx,ny,nz) != null + || world.getBlock(xx + 1, yy - 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx, yy - 1, zz - 1,nx,ny,nz) != null) + a[0] = ao; + if (world.getBlock(xx + 1, yy - 1, zz,nx,ny,nz) != null + || world.getBlock(xx + 1, yy - 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx, yy - 1, zz + 1,nx,ny,nz) != null) + a[3] = ao; + if (world.getBlock(xx - 1, yy - 1, zz,nx,ny,nz) != null + || world.getBlock(xx - 1, yy - 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx, yy - 1, zz + 1,nx,ny,nz) != null) + a[2] = ao; // affiche la face si il n'y a rien en dessous vbo.addDataByFloatArray(b.getDataDown(xx, yy, zz, a)); @@ -179,88 +184,88 @@ public class Chunk { if (left) { float[] a = new float[] { 1, 1, 1, 1 }; -// if (world.getBlock(xx - 1, yy - 1, zz) != null -// || world.getBlock(xx - 1, yy - 1, zz - 1) != null -// || world.getBlock(xx - 1, yy, zz - 1) != null) -// a[0] = ao; -// if (world.getBlock(xx - 1, yy + 1, zz) != null -// || world.getBlock(xx - 1, yy + 1, zz - 1) != null -// || world.getBlock(xx - 1, yy, zz - 1) != null) -// a[1] = ao; -// if (world.getBlock(xx - 1, yy + 1, zz) != null -// || world.getBlock(xx - 1, yy + 1, zz + 1) != null -// || world.getBlock(xx - 1, yy, zz + 1) != null) -// a[2] = ao; -// if (world.getBlock(xx - 1, yy - 1, zz) != null -// || world.getBlock(xx - 1, yy - 1, zz + 1) != null -// || world.getBlock(xx - 1, yy, zz + 1) != null) -// a[3] = ao; + if (world.getBlock(xx - 1, yy - 1, zz,nx,ny,nz) != null + || world.getBlock(xx - 1, yy - 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy, zz - 1,nx,ny,nz) != null) + a[0] = ao; + if (world.getBlock(xx - 1, yy + 1, zz,nx,ny,nz) != null + || world.getBlock(xx - 1, yy + 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy, zz - 1,nx,ny,nz) != null) + a[1] = ao; + if (world.getBlock(xx - 1, yy + 1, zz,nx,ny,nz) != null + || world.getBlock(xx - 1, yy + 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy, zz + 1,nx,ny,nz) != null) + a[2] = ao; + if (world.getBlock(xx - 1, yy - 1, zz,nx,ny,nz) != null + || world.getBlock(xx - 1, yy - 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy, zz + 1,nx,ny,nz) != null) + a[3] = ao; vbo.addDataByFloatArray(b.getDataLeft(xx, yy, zz, a)); } if (right) { float[] a = new float[] { 1, 1, 1, 1 }; -// if (world.getBlock(xx + 1, yy - 1, zz) != null -// || world.getBlock(xx + 1, yy - 1, zz - 1) != null -// || world.getBlock(xx + 1, yy, zz - 1) != null) -// a[1] = ao; -// if (world.getBlock(xx + 1, yy + 1, zz) != null -// || world.getBlock(xx + 1, yy + 1, zz - 1) != null -// || world.getBlock(xx + 1, yy, zz - 1) != null) -// a[0] = ao; -// if (world.getBlock(xx + 1, yy + 1, zz) != null -// || world.getBlock(xx + 1, yy + 1, zz + 1) != null -// || world.getBlock(xx + 1, yy, zz + 1) != null) -// a[3] = ao; -// if (world.getBlock(xx + 1, yy - 1, zz) != null -// || world.getBlock(xx + 1, yy - 1, zz + 1) != null -// || world.getBlock(xx + 1, yy, zz + 1) != null) -// a[2] = ao; + if (world.getBlock(xx + 1, yy - 1, zz,nx,ny,nz) != null + || world.getBlock(xx + 1, yy - 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy, zz - 1,nx,ny,nz) != null) + a[1] = ao; + if (world.getBlock(xx + 1, yy + 1, zz,nx,ny,nz) != null + || world.getBlock(xx + 1, yy + 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy, zz - 1,nx,ny,nz) != null) + a[0] = ao; + if (world.getBlock(xx + 1, yy + 1, zz,nx,ny,nz) != null + || world.getBlock(xx + 1, yy + 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy, zz + 1,nx,ny,nz) != null) + a[3] = ao; + if (world.getBlock(xx + 1, yy - 1, zz,nx,ny,nz) != null + || world.getBlock(xx + 1, yy - 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy, zz + 1,nx,ny,nz) != null) + a[2] = ao; vbo.addDataByFloatArray(b.getDataRight(xx, yy, zz, a)); } if (front) { float[] a = new float[] { 1, 1, 1, 1 }; -// if (world.getBlock(xx, yy - 1, zz - 1) != null -// || world.getBlock(xx - 1, yy - 1, zz - 1) != null -// || world.getBlock(xx - 1, yy, zz - 1) != null) -// a[0] = ao; -// if (world.getBlock(xx, yy + 1, zz - 1) != null -// || world.getBlock(xx - 1, yy + 1, zz - 1) != null -// || world.getBlock(xx - 1, yy, zz - 1) != null) -// a[3] = ao; -// if (world.getBlock(xx, yy + 1, zz - 1) != null -// || world.getBlock(xx + 1, yy + 1, zz - 1) != null -// || world.getBlock(xx + 1, yy, zz - 1) != null) -// a[2] = ao; -// if (world.getBlock(xx, yy - 1, zz - 1) != null -// || world.getBlock(xx + 1, yy - 1, zz - 1) != null -// || world.getBlock(xx + 1, yy, zz - 1) != null) -// a[1] = ao; + if (world.getBlock(xx, yy - 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy - 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy, zz - 1,nx,ny,nz) != null) + a[0] = ao; + if (world.getBlock(xx, yy + 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy + 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy, zz - 1,nx,ny,nz) != null) + a[3] = ao; + if (world.getBlock(xx, yy + 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy + 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy, zz - 1,nx,ny,nz) != null) + a[2] = ao; + if (world.getBlock(xx, yy - 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy - 1, zz - 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy, zz - 1,nx,ny,nz) != null) + a[1] = ao; vbo.addDataByFloatArray(b.getDataFront(xx, yy, zz, a)); } if (back) { float[] a = new float[] { 1, 1, 1, 1 }; -// if (world.getBlock(xx, yy - 1, zz + 1) != null -// || world.getBlock(xx - 1, yy - 1, zz + 1) != null -// || world.getBlock(xx - 1, yy, zz + 1) != null) -// a[1] = ao; -// if (world.getBlock(xx, yy + 1, zz + 1) != null -// || world.getBlock(xx - 1, yy + 1, zz + 1) != null -// || world.getBlock(xx - 1, yy, zz + 1) != null) -// a[2] = ao; -// if (world.getBlock(xx, yy + 1, zz + 1) != null -// || world.getBlock(xx + 1, yy + 1, zz + 1) != null -// || world.getBlock(xx + 1, yy, zz + 1) != null) -// a[3] = ao; -// if (world.getBlock(xx, yy - 1, zz + 1) != null -// || world.getBlock(xx + 1, yy - 1, zz + 1) != null -// || world.getBlock(xx + 1, yy, zz + 1) != null) -// a[0] = ao; + if (world.getBlock(xx, yy - 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy - 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy, zz + 1,nx,ny,nz) != null) + a[1] = ao; + if (world.getBlock(xx, yy + 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy + 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx - 1, yy, zz + 1,nx,ny,nz) != null) + a[2] = ao; + if (world.getBlock(xx, yy + 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy + 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy, zz + 1,nx,ny,nz) != null) + a[3] = ao; + if (world.getBlock(xx, yy - 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy - 1, zz + 1,nx,ny,nz) != null + || world.getBlock(xx + 1, yy, zz + 1,nx,ny,nz) != null) + a[0] = ao; vbo.addDataByFloatArray(b.getDataBack(xx, yy, zz, a)); } @@ -276,7 +281,12 @@ public class Chunk { public void setGenerated(boolean g) { IsGenerated = g; + } + + public String toString(){ + return x + " " + y + " " + z; } + public boolean isCurrentGenerate(){ return IsCurrentGenerate; diff --git a/VBO/src/world/World.java b/VBO/src/world/World.java index 968664b..f158190 100644 --- a/VBO/src/world/World.java +++ b/VBO/src/world/World.java @@ -111,28 +111,52 @@ public class World { chunk.addBlock(xb, yb, zb, b); } - - public Block getBlock(int x, int y, int z) { + + public Vector3f getLocalChunk(int x, int y, int z,boolean nx,boolean ny,boolean nz){ int xc = (x / Chunk.SIZE); int zc = (z / Chunk.SIZE); int yc = (y / Chunk.SIZE); + if(nx)xc -= 1; + if(ny)yc -= 1; + if(nz)zc -= 1; + return new Vector3f(xc,yc,zc); + } + + public Block getBlock(int x, int y, int z,boolean nx,boolean ny,boolean nz) { + int xc = (x / Chunk.SIZE); + int zc = (z / Chunk.SIZE); + int yc = (y / Chunk.SIZE); + + if(nx)xc -= 1; + if(ny)yc -= 1; + if(nz)zc -= 1; + Chunk chunk = getChunk(xc, yc, zc); if(chunk == null)return null; + int xb = 0; + int yb = 0; + int zb = 0; - int xb = x % Chunk.SIZE; - int yb = y % Chunk.SIZE; - int zb = z % Chunk.SIZE; + if( x <= 0 && nx){ + xb = (Chunk.SIZE-1)-((-x) % Chunk.SIZE) + 1; + }else{ + xb = x % Chunk.SIZE; + } -// if(xb < 0){ -// xb = -xb; -// } -// if(yb < 0){ -// yb = -yb; -// } -// if(zb < 0){ -// zb = -zb; -// } + + if( y <= 0 && ny){ + yb = (Chunk.SIZE-1)-((-y) % Chunk.SIZE) + 1; + }else{ + yb = y % Chunk.SIZE; + } + + + if( z <= 0 && nz){ + zb = (Chunk.SIZE-1)-((-z) % Chunk.SIZE) + 1; + }else{ + zb = z % Chunk.SIZE; + } return chunk.getBlock(xb, yb, zb); }