1
0
Fork 0

Correction du bug de getBlock dans la class World

This commit is contained in:
MrDev023 2015-07-19 14:32:14 +02:00
parent 521e58acb9
commit 98b7946cc2
10 changed files with 405 additions and 121 deletions

View file

@ -9,13 +9,18 @@ public class Camera {
private static Vector3f position = new Vector3f(0,4,0); private static Vector3f position = new Vector3f(0,4,0);
private static Vector2f rotation = new Vector2f(0,120); private static Vector2f rotation = new Vector2f(0,120);
private static PlayerRayCast playerRaycast;
private static final float HEIGHT = (float) (1.5f - (Block.getSize()/2.0f)); private static final float HEIGHT = (float) (1.5f - (Block.getSize()/2.0f));
public static void initCamera(){
playerRaycast = new PlayerRayCast();
}
public static void renderCamera(){ public static void renderCamera(){
glLoadIdentity(); glLoadIdentity();
glRotatef(rotation.getX(), 1, 0, 0); glRotatef(rotation.getX(), 1, 0, 0);
glRotatef(rotation.getY(), 0, 1, 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){ 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() { public static Vector3f getPosition() {
return position; return position;
} }
@ -67,5 +89,19 @@ public class Camera {
public static void setRotation(Vector2f rotation) { public static void setRotation(Vector2f rotation) {
Camera.rotation = 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;
}
} }

View file

@ -39,6 +39,9 @@ public class DisplayManager {
*/ */
public static void render3D(){ public static void render3D(){
Main.getGame().render(); 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; 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);
}
} }

View file

@ -26,5 +26,22 @@ public class Game {
public void renderGUI(){ 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;
}
} }

View file

@ -54,6 +54,7 @@ public class Main {
skybox = new SkyBox(new String[] { right, left, top, bottom, back, skybox = new SkyBox(new String[] { right, left, top, bottom, back,
front }); front });
Camera.initCamera();
game = new Game(); game = new Game();
Mouse.setGrabbed(true); Mouse.setGrabbed(true);
loop(); loop();
@ -111,13 +112,20 @@ public class Main {
if (elapsedInfo >= 1000) { if (elapsedInfo >= 1000) {
LAST_FPS = FPS; LAST_FPS = FPS;
LAST_TICKS = TICKS; 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:" 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:" + timeTicks + "ns" + " | PX:"
+ Camera.getPosition().getX() + " PY:" + Camera.getPosition().getX() + " PY:"
+ Camera.getPosition().getY() + " PZ:" + Camera.getPosition().getY() + " PZ:"
+ Camera.getPosition().getZ() + " | " + 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; FPS = 0;
TICKS = 0; TICKS = 0;
elapsedInfo = 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() { public static boolean isRunning() {
return IsRunning; return IsRunning;
} }

View file

@ -0,0 +1,43 @@
package main;
import java.util.*;
import math.*;
import world.*;
public class PlayerRayCast {
private List<Vector3f> points;
private int length = 10;
private int precision = 16;
public PlayerRayCast(){
this.points = new ArrayList<Vector3f>();
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;
}
}

View file

@ -1,14 +1,19 @@
package main; package main;
import math.*;
import org.lwjgl.input.*; import org.lwjgl.input.*;
import org.lwjgl.opengl.*; import org.lwjgl.opengl.*;
import blocks.*;
public class Update { public class Update {
private static float xDir,yDir,zDir; private static float xDir,yDir,zDir;
private static float speed = 0.01f; private static float speed = 0.01f;
private static float xa = 0,ya = 0,za = 0; 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 * @Info Fonction permettant de gerer les action de la souris
@ -105,6 +110,92 @@ public class Update {
*/ */
public static void update(){ public static void update(){
Main.getGame().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;
} }
} }

View file

@ -25,6 +25,10 @@ public class Vector2f {
public void setY(float y) { public void setY(float y) {
this.y = y; this.y = y;
} }
public Vector2f copy() {
return new Vector2f(x,y);
}

View file

@ -189,6 +189,10 @@ public class Vector3f {
return this; return this;
} }
public String toString(){
return x + " " + y + " " + z;
}
public static float distance(Vector3f a,Vector3f b){ 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))); 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)));
} }

View file

@ -102,6 +102,7 @@ public class Chunk {
} }
public void loopChunk(int x, int y, int z) { public void loopChunk(int x, int y, int z) {
world = Main.getGame().getWorld();
int xx = this.x * SIZE + x; int xx = this.x * SIZE + x;
int yy = this.y * SIZE + y; int yy = this.y * SIZE + y;
int zz = this.z * SIZE + z; int zz = this.z * SIZE + z;
@ -111,12 +112,16 @@ public class Chunk {
boolean right = true; boolean right = true;
boolean back = true; boolean back = true;
boolean front = true; boolean front = true;
// up = world.getBlock(xx, yy + 1, zz) == null; boolean nx = false, ny = false, nz = false;
// down = world.getBlock(xx, yy - 1, zz) == null; if(this.x < 0)nx = true;
// left = world.getBlock(xx - 1, yy, zz) == null; if(this.y < 0)ny = true;
// right = world.getBlock(xx + 1, yy, zz) == null; if(this.z < 0)nz = true;
// front = world.getBlock(xx, yy, zz - 1) == null; up = world.getBlock(xx, yy + 1, zz,nx,ny,nz) == null;
// back = world.getBlock(xx, yy, zz + 1) == 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) if (!up && !down && !left && !right && !front && !back)
return; return;
if (blocks[x][y][z] == null) if (blocks[x][y][z] == null)
@ -133,22 +138,22 @@ public class Chunk {
// aa ab bb ba // aa ab bb ba
float[] a = new float[] { 1, 1, 1, 1 }; float[] a = new float[] { 1, 1, 1, 1 };
// if (world.getBlock(xx - 1, yy + 1, zz) != null if (world.getBlock(xx - 1, yy + 1, zz,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy + 1, zz - 1) != null || world.getBlock(xx - 1, yy + 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx, yy + 1, zz - 1) != null) || world.getBlock(xx, yy + 1, zz - 1,nx,ny,nz) != null)
// a[0] = ao; a[0] = ao;
// if (world.getBlock(xx + 1, yy + 1, zz) != null if (world.getBlock(xx + 1, yy + 1, zz,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy + 1, zz - 1) != null || world.getBlock(xx + 1, yy + 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx, yy + 1, zz - 1) != null) || world.getBlock(xx, yy + 1, zz - 1,nx,ny,nz) != null)
// a[1] = ao; a[1] = ao;
// if (world.getBlock(xx + 1, yy + 1, zz) != null if (world.getBlock(xx + 1, yy + 1, zz,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy + 1, zz + 1) != null || world.getBlock(xx + 1, yy + 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx, yy + 1, zz + 1) != null) || world.getBlock(xx, yy + 1, zz + 1,nx,ny,nz) != null)
// a[2] = ao; a[2] = ao;
// if (world.getBlock(xx - 1, yy + 1, zz) != null if (world.getBlock(xx - 1, yy + 1, zz,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy + 1, zz + 1) != null || world.getBlock(xx - 1, yy + 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx, yy + 1, zz + 1) != null) || world.getBlock(xx, yy + 1, zz + 1,nx,ny,nz) != null)
// a[3] = ao; a[3] = ao;
vbo.addDataByFloatArray(b.getDataUp(xx, yy, zz, a)); vbo.addDataByFloatArray(b.getDataUp(xx, yy, zz, a));
} }
@ -156,22 +161,22 @@ public class Chunk {
float[] a = new float[] { 1, 1, 1, 1 }; float[] a = new float[] { 1, 1, 1, 1 };
// ambient occlusion // ambient occlusion
// if (world.getBlock(xx - 1, yy - 1, zz) != null if (world.getBlock(xx - 1, yy - 1, zz,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy - 1, zz - 1) != null || world.getBlock(xx - 1, yy - 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx, yy - 1, zz - 1) != null) || world.getBlock(xx, yy - 1, zz - 1,nx,ny,nz) != null)
// a[1] = ao; a[1] = ao;
// if (world.getBlock(xx + 1, yy - 1, zz) != null if (world.getBlock(xx + 1, yy - 1, zz,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy - 1, zz - 1) != null || world.getBlock(xx + 1, yy - 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx, yy - 1, zz - 1) != null) || world.getBlock(xx, yy - 1, zz - 1,nx,ny,nz) != null)
// a[0] = ao; a[0] = ao;
// if (world.getBlock(xx + 1, yy - 1, zz) != null if (world.getBlock(xx + 1, yy - 1, zz,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy - 1, zz + 1) != null || world.getBlock(xx + 1, yy - 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx, yy - 1, zz + 1) != null) || world.getBlock(xx, yy - 1, zz + 1,nx,ny,nz) != null)
// a[3] = ao; a[3] = ao;
// if (world.getBlock(xx - 1, yy - 1, zz) != null if (world.getBlock(xx - 1, yy - 1, zz,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy - 1, zz + 1) != null || world.getBlock(xx - 1, yy - 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx, yy - 1, zz + 1) != null) || world.getBlock(xx, yy - 1, zz + 1,nx,ny,nz) != null)
// a[2] = ao; a[2] = ao;
// affiche la face si il n'y a rien en dessous // affiche la face si il n'y a rien en dessous
vbo.addDataByFloatArray(b.getDataDown(xx, yy, zz, a)); vbo.addDataByFloatArray(b.getDataDown(xx, yy, zz, a));
@ -179,88 +184,88 @@ public class Chunk {
if (left) { if (left) {
float[] a = new float[] { 1, 1, 1, 1 }; float[] a = new float[] { 1, 1, 1, 1 };
// if (world.getBlock(xx - 1, yy - 1, zz) != null if (world.getBlock(xx - 1, yy - 1, zz,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy - 1, zz - 1) != null || world.getBlock(xx - 1, yy - 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy, zz - 1) != null) || world.getBlock(xx - 1, yy, zz - 1,nx,ny,nz) != null)
// a[0] = ao; a[0] = ao;
// if (world.getBlock(xx - 1, yy + 1, zz) != null if (world.getBlock(xx - 1, yy + 1, zz,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy + 1, zz - 1) != null || world.getBlock(xx - 1, yy + 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy, zz - 1) != null) || world.getBlock(xx - 1, yy, zz - 1,nx,ny,nz) != null)
// a[1] = ao; a[1] = ao;
// if (world.getBlock(xx - 1, yy + 1, zz) != null if (world.getBlock(xx - 1, yy + 1, zz,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy + 1, zz + 1) != null || world.getBlock(xx - 1, yy + 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy, zz + 1) != null) || world.getBlock(xx - 1, yy, zz + 1,nx,ny,nz) != null)
// a[2] = ao; a[2] = ao;
// if (world.getBlock(xx - 1, yy - 1, zz) != null if (world.getBlock(xx - 1, yy - 1, zz,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy - 1, zz + 1) != null || world.getBlock(xx - 1, yy - 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy, zz + 1) != null) || world.getBlock(xx - 1, yy, zz + 1,nx,ny,nz) != null)
// a[3] = ao; a[3] = ao;
vbo.addDataByFloatArray(b.getDataLeft(xx, yy, zz, a)); vbo.addDataByFloatArray(b.getDataLeft(xx, yy, zz, a));
} }
if (right) { if (right) {
float[] a = new float[] { 1, 1, 1, 1 }; float[] a = new float[] { 1, 1, 1, 1 };
// if (world.getBlock(xx + 1, yy - 1, zz) != null if (world.getBlock(xx + 1, yy - 1, zz,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy - 1, zz - 1) != null || world.getBlock(xx + 1, yy - 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy, zz - 1) != null) || world.getBlock(xx + 1, yy, zz - 1,nx,ny,nz) != null)
// a[1] = ao; a[1] = ao;
// if (world.getBlock(xx + 1, yy + 1, zz) != null if (world.getBlock(xx + 1, yy + 1, zz,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy + 1, zz - 1) != null || world.getBlock(xx + 1, yy + 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy, zz - 1) != null) || world.getBlock(xx + 1, yy, zz - 1,nx,ny,nz) != null)
// a[0] = ao; a[0] = ao;
// if (world.getBlock(xx + 1, yy + 1, zz) != null if (world.getBlock(xx + 1, yy + 1, zz,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy + 1, zz + 1) != null || world.getBlock(xx + 1, yy + 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy, zz + 1) != null) || world.getBlock(xx + 1, yy, zz + 1,nx,ny,nz) != null)
// a[3] = ao; a[3] = ao;
// if (world.getBlock(xx + 1, yy - 1, zz) != null if (world.getBlock(xx + 1, yy - 1, zz,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy - 1, zz + 1) != null || world.getBlock(xx + 1, yy - 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy, zz + 1) != null) || world.getBlock(xx + 1, yy, zz + 1,nx,ny,nz) != null)
// a[2] = ao; a[2] = ao;
vbo.addDataByFloatArray(b.getDataRight(xx, yy, zz, a)); vbo.addDataByFloatArray(b.getDataRight(xx, yy, zz, a));
} }
if (front) { if (front) {
float[] a = new float[] { 1, 1, 1, 1 }; float[] a = new float[] { 1, 1, 1, 1 };
// if (world.getBlock(xx, yy - 1, zz - 1) != null if (world.getBlock(xx, yy - 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy - 1, zz - 1) != null || world.getBlock(xx - 1, yy - 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy, zz - 1) != null) || world.getBlock(xx - 1, yy, zz - 1,nx,ny,nz) != null)
// a[0] = ao; a[0] = ao;
// if (world.getBlock(xx, yy + 1, zz - 1) != null if (world.getBlock(xx, yy + 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy + 1, zz - 1) != null || world.getBlock(xx - 1, yy + 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy, zz - 1) != null) || world.getBlock(xx - 1, yy, zz - 1,nx,ny,nz) != null)
// a[3] = ao; a[3] = ao;
// if (world.getBlock(xx, yy + 1, zz - 1) != null if (world.getBlock(xx, yy + 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy + 1, zz - 1) != null || world.getBlock(xx + 1, yy + 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy, zz - 1) != null) || world.getBlock(xx + 1, yy, zz - 1,nx,ny,nz) != null)
// a[2] = ao; a[2] = ao;
// if (world.getBlock(xx, yy - 1, zz - 1) != null if (world.getBlock(xx, yy - 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy - 1, zz - 1) != null || world.getBlock(xx + 1, yy - 1, zz - 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy, zz - 1) != null) || world.getBlock(xx + 1, yy, zz - 1,nx,ny,nz) != null)
// a[1] = ao; a[1] = ao;
vbo.addDataByFloatArray(b.getDataFront(xx, yy, zz, a)); vbo.addDataByFloatArray(b.getDataFront(xx, yy, zz, a));
} }
if (back) { if (back) {
float[] a = new float[] { 1, 1, 1, 1 }; float[] a = new float[] { 1, 1, 1, 1 };
// if (world.getBlock(xx, yy - 1, zz + 1) != null if (world.getBlock(xx, yy - 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy - 1, zz + 1) != null || world.getBlock(xx - 1, yy - 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy, zz + 1) != null) || world.getBlock(xx - 1, yy, zz + 1,nx,ny,nz) != null)
// a[1] = ao; a[1] = ao;
// if (world.getBlock(xx, yy + 1, zz + 1) != null if (world.getBlock(xx, yy + 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy + 1, zz + 1) != null || world.getBlock(xx - 1, yy + 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx - 1, yy, zz + 1) != null) || world.getBlock(xx - 1, yy, zz + 1,nx,ny,nz) != null)
// a[2] = ao; a[2] = ao;
// if (world.getBlock(xx, yy + 1, zz + 1) != null if (world.getBlock(xx, yy + 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy + 1, zz + 1) != null || world.getBlock(xx + 1, yy + 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy, zz + 1) != null) || world.getBlock(xx + 1, yy, zz + 1,nx,ny,nz) != null)
// a[3] = ao; a[3] = ao;
// if (world.getBlock(xx, yy - 1, zz + 1) != null if (world.getBlock(xx, yy - 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy - 1, zz + 1) != null || world.getBlock(xx + 1, yy - 1, zz + 1,nx,ny,nz) != null
// || world.getBlock(xx + 1, yy, zz + 1) != null) || world.getBlock(xx + 1, yy, zz + 1,nx,ny,nz) != null)
// a[0] = ao; a[0] = ao;
vbo.addDataByFloatArray(b.getDataBack(xx, yy, zz, a)); vbo.addDataByFloatArray(b.getDataBack(xx, yy, zz, a));
} }
@ -276,7 +281,12 @@ public class Chunk {
public void setGenerated(boolean g) { public void setGenerated(boolean g) {
IsGenerated = g; IsGenerated = g;
}
public String toString(){
return x + " " + y + " " + z;
} }
public boolean isCurrentGenerate(){ public boolean isCurrentGenerate(){
return IsCurrentGenerate; return IsCurrentGenerate;

View file

@ -111,28 +111,52 @@ public class World {
chunk.addBlock(xb, yb, zb, b); 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 xc = (x / Chunk.SIZE);
int zc = (z / Chunk.SIZE); int zc = (z / Chunk.SIZE);
int yc = (y / 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); Chunk chunk = getChunk(xc, yc, zc);
if(chunk == null)return null; if(chunk == null)return null;
int xb = 0;
int yb = 0;
int zb = 0;
int xb = x % Chunk.SIZE; if( x <= 0 && nx){
int yb = y % Chunk.SIZE; xb = (Chunk.SIZE-1)-((-x) % Chunk.SIZE) + 1;
int zb = z % Chunk.SIZE; }else{
xb = x % Chunk.SIZE;
}
// if(xb < 0){
// xb = -xb; if( y <= 0 && ny){
// } yb = (Chunk.SIZE-1)-((-y) % Chunk.SIZE) + 1;
// if(yb < 0){ }else{
// yb = -yb; yb = y % Chunk.SIZE;
// } }
// if(zb < 0){
// zb = -zb;
// } if( z <= 0 && nz){
zb = (Chunk.SIZE-1)-((-z) % Chunk.SIZE) + 1;
}else{
zb = z % Chunk.SIZE;
}
return chunk.getBlock(xb, yb, zb); return chunk.getBlock(xb, yb, zb);
} }