Correction du bug de getBlock dans la class World
This commit is contained in:
parent
521e58acb9
commit
98b7946cc2
10 changed files with 405 additions and 121 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
43
VBO/src/main/PlayerRayCast.java
Normal file
43
VBO/src/main/PlayerRayCast.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@ public class Vector2f {
|
|||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Vector2f copy() {
|
||||
return new Vector2f(x,y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Reference in a new issue