1
0
Fork 0
This commit is contained in:
MrDev023 2015-07-20 20:52:45 +02:00
parent e53b56f460
commit d6b9d09d50
6 changed files with 263 additions and 161 deletions

View file

@ -7,78 +7,86 @@ import main.*;
import math.*;
public class Camera {
private static Vector3f position = new Vector3f(0,4,0);
private static Vector2f rotation = new Vector2f(0,120);
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));
private static final float HEIGHT = (float) (1.5f - (Block.getSize() / 2.0f));
public static boolean gravity = true;
public static float gravityFactor = 0;
public static boolean grounded = false;
public static boolean noClip = false;
public static void initCamera(){
public static void initCamera() {
playerRaycast = new PlayerRayCast();
}
public static void renderCamera(){
public static void renderCamera() {
if (position.getY() < (int)((new Noise(Main.getGame().getWorld().seed, Main
.getGame().getWorld().octave,
Main.getGame().getWorld().amplitude).getNoise(position.getX(),
position.getZ())) + 1)) {
position.setY((int)((new Noise(Main.getGame().getWorld().seed, Main
.getGame().getWorld().octave,
Main.getGame().getWorld().amplitude).getNoise(position.getX(),
position.getZ())) + 2));
}
glLoadIdentity();
glRotatef(rotation.getX(), 1, 0, 0);
glRotatef(rotation.getY(), 0, 1, 0);
glTranslatef(-position.getX(), -(position.getY()+getHeight()), -position.getZ());
glTranslatef(-position.getX(), -(position.getY() + getHeight()),
-position.getZ());
}
public static void move(float xa,float ya,float za){
if(true){
gravityFactor += World.GRAVITY * 0.01f;
if(grounded) gravityFactor = 0;
ya -= gravityFactor;
}else{
public static void move(float xa, float ya, float za) {
gravityFactor += World.GRAVITY * 0.01f;
if (grounded)
gravityFactor = 0;
}
int xStep = (int)Math.abs(xa * 100);
for(int i = 0; i < xStep; i++){
if(!isColliding(xa/xStep, 0, 0) || noClip){
position.x += xa/xStep;
}else{
ya -= gravityFactor;
int xStep = (int) Math.abs(xa * 100);
for (int i = 0; i < xStep; i++) {
if (!isColliding(xa / xStep, 0, 0) || noClip) {
position.x += xa / xStep;
} else {
xa = 0;
}
}
int yStep = (int)Math.abs(ya * 100);
for(int i = 0; i < yStep; i++){
if(!isColliding(0, ya/yStep, 0) || noClip){
position.y += ya/yStep;
}else{
int yStep = (int) Math.abs(ya * 100);
for (int i = 0; i < yStep; i++) {
if (!isColliding(0, ya / yStep, 0) || noClip) {
position.y += ya / yStep;
} else {
ya = 0;
}
}
int zStep = (int)Math.abs(za * 100);
for(int i = 0; i < zStep; i++){
if(!isColliding(0, 0, za/zStep) || noClip){
position.z += za/zStep;
}else{
int zStep = (int) Math.abs(za * 100);
for (int i = 0; i < zStep; i++) {
if (!isColliding(0, 0, za / zStep) || noClip) {
position.z += za / zStep;
} else {
za = 0;
}
}
}
public static Vector3f getDirection(){
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()));
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;
}
@ -106,86 +114,175 @@ public class Camera {
public static void setPlayerRaycast(PlayerRayCast playerRaycast) {
Camera.playerRaycast = playerRaycast;
}
public static boolean isColliding(float xa,float ya, float za){
public static boolean isColliding(float xa, float ya, float za) {
World world = Main.getGame().getWorld();
float r = 0.3f;
boolean nx = false, ny = false, nz = false;
int x0 = (int)(position.x + xa - r);
int x1 = (int)(position.x + xa + r);
int y0 = (int)(position.y + ya - r);
int y1 = (int)(position.y + ya + r);
int z0 = (int)(position.z + za - r);
int z1 = (int)(position.z + za + r);
int xmid = (int)(position.x + xa);
int yb = (int)(position.y + ya - r - 0.01f);
int zmid = (int)(position.z + za);
if(xmid < 0)nx = true;else nx = false;
if(yb < 0)ny = true;else ny = false;
if(zmid < 0)nz = true;else nz = false;
if(world.getBlock(xmid, yb, zmid,nx,ny,nz) != null ){
int x0 = (int) (position.x + xa - r);
int x1 = (int) (position.x + xa + r);
int y0 = (int) (position.y + ya - r);
int y1 = (int) (position.y + ya + r);
int z0 = (int) (position.z + za - r);
int z1 = (int) (position.z + za + r);
int xmid = (int) (position.x + xa);
int yb = (int) (position.y + ya - r - 0.01f);
int zmid = (int) (position.z + za);
if (xmid < 0)
nx = true;
else
nx = false;
if (yb < 0)
ny = true;
else
ny = false;
if (zmid < 0)
nz = true;
else
nz = false;
if (world.getBlock(xmid, yb, zmid, nx, ny, nz) != null) {
grounded = true;
}else{
} else {
grounded = false;
}
if(x0 < 0)nx = true;else nx = false;
if(y0 < 0)ny = true;else ny = false;
if(z0 < 0)nz = true;else nz = false;
if(world.getBlock(x0, y0, z0,nx,ny,nz) != null) return true;
if(x1 < 0)nx = true;else nx = false;
if(y0 < 0)ny = true;else ny = false;
if(z0 < 0)nz = true;else nz = false;
if(world.getBlock(x1, y0, z0,nx,ny,nz) != null) return true;
if(x1 < 0)nx = true;else nx = false;
if(y1 < 0)ny = true;else ny = false;
if(z0 < 0)nz = true;else nz = false;
if(world.getBlock(x1, y1, z0,nx,ny,nz) != null) return true;
if(x0 < 0)nx = true;else nx = false;
if(y1 < 0)ny = true;else ny = false;
if(z0 < 0)nz = true;else nz = false;
if(world.getBlock(x0, y1, z0,nx,ny,nz) != null) return true;
if(x0 < 0)nx = true;else nx = false;
if(y0 < 0)ny = true;else ny = false;
if(z1 < 0)nz = true;else nz = false;
if(world.getBlock(x0, y0, z1,nx,ny,nz) != null) return true;
if(x1 < 0)nx = true;else nx = false;
if(y0 < 0)ny = true;else ny = false;
if(z1 < 0)nz = true;else nz = false;
if(world.getBlock(x1, y0, z1,nx,ny,nz) != null) return true;
if(x1 < 0)nx = true;else nx = false;
if(y1 < 0)ny = true;else ny = false;
if(z1 < 0)nz = true;else nz = false;
if(world.getBlock(x1, y1, z1,nx,ny,nz) != null) return true;
if(x0 < 0)nx = true;else nx = false;
if(y1 < 0)ny = true;else ny = false;
if(z1 < 0)nz = true;else nz = false;
if(world.getBlock(x0, y1, z1,nx,ny,nz) != null) return true;
// if(world.getBlock(x0, y0+1, z0) != null) return true;
// if(world.getBlock(x1, y0+1, z0) != null) return true;
// if(world.getBlock(x1, y1+1, z0) != null) return true;
// if(world.getBlock(x0, y1+1, z0) != null) return true;
//
// if(world.getBlock(x0, y0+1, z1) != null) return true;
// if(world.getBlock(x1, y0+1, z1) != null) return true;
// if(world.getBlock(x1, y1+1, z1) != null) return true;
// if(world.getBlock(x0, y1+1, z1) != null) return true;
if (x0 < 0)
nx = true;
else
nx = false;
if (y0 < 0)
ny = true;
else
ny = false;
if (z0 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x0, y0, z0, nx, ny, nz) != null)
return true;
if (x1 < 0)
nx = true;
else
nx = false;
if (y0 < 0)
ny = true;
else
ny = false;
if (z0 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x1, y0, z0, nx, ny, nz) != null)
return true;
if (x1 < 0)
nx = true;
else
nx = false;
if (y1 < 0)
ny = true;
else
ny = false;
if (z0 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x1, y1, z0, nx, ny, nz) != null)
return true;
if (x0 < 0)
nx = true;
else
nx = false;
if (y1 < 0)
ny = true;
else
ny = false;
if (z0 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x0, y1, z0, nx, ny, nz) != null)
return true;
if (x0 < 0)
nx = true;
else
nx = false;
if (y0 < 0)
ny = true;
else
ny = false;
if (z1 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x0, y0, z1, nx, ny, nz) != null)
return true;
if (x1 < 0)
nx = true;
else
nx = false;
if (y0 < 0)
ny = true;
else
ny = false;
if (z1 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x1, y0, z1, nx, ny, nz) != null)
return true;
if (x1 < 0)
nx = true;
else
nx = false;
if (y1 < 0)
ny = true;
else
ny = false;
if (z1 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x1, y1, z1, nx, ny, nz) != null)
return true;
if (x0 < 0)
nx = true;
else
nx = false;
if (y1 < 0)
ny = true;
else
ny = false;
if (z1 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x0, y1, z1, nx, ny, nz) != null)
return true;
// if(world.getBlock(x0, y0+1, z0) != null) return true;
// if(world.getBlock(x1, y0+1, z0) != null) return true;
// if(world.getBlock(x1, y1+1, z0) != null) return true;
// if(world.getBlock(x0, y1+1, z0) != null) return true;
//
// if(world.getBlock(x0, y0+1, z1) != null) return true;
// if(world.getBlock(x1, y0+1, z1) != null) return true;
// if(world.getBlock(x1, y1+1, z1) != null) return true;
// if(world.getBlock(x0, y1+1, z1) != null) return true;
return false;
}
}

View file

@ -8,7 +8,7 @@ public class Game {
private int update = 0;
public Game(){
world= new World(0);
world= new World(0,120,50);
}
public void update(){

View file

@ -1,6 +1,5 @@
package main;
import rendering.*;
import game.*;
import java.util.concurrent.*;
@ -8,9 +7,6 @@ import java.util.concurrent.*;
import org.lwjgl.input.*;
import org.lwjgl.opengl.*;
import rendering.*;
import vanilla.java.affinity.*;
import vanilla.java.affinity.impl.*;
import world.*;
public class Main {
@ -100,10 +96,6 @@ 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:"
+ LAST_TICKS + " timeFps:" + timeFps + "ns timeTicks:"
+ timeTicks + "ns" + " | PX:"

View file

@ -22,14 +22,12 @@ public class Chunk {
private boolean IsGenerated = false;
private boolean IsCurrentGenerate = false;
private boolean IsDestroy = false;
private WorldNoise worldNoise;
public Chunk(int x, int y, int z, World world,WorldNoise worldNoise) {
public Chunk(int x, int y, int z, World world) {
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.worldNoise = worldNoise;
this.blocks = new Block[SIZE][SIZE][SIZE];
vbo = new VBO();
}
@ -297,14 +295,6 @@ public class Chunk {
public boolean isDestroy() {
return IsDestroy;
}
public WorldNoise getWorldNoise() {
return worldNoise;
}
public void setWorldNoise(WorldNoise worldNoise) {
this.worldNoise = worldNoise;
}
}
@ -336,9 +326,9 @@ class Generate implements Runnable {
long current = System.currentTimeMillis();
long elapsed1 = 0;
boolean IsError = true;
Noise noise = new Noise(world.seed, 50, 16);
Noise noise = new Noise(world.seed, world.octave, world.amplitude);;
Random random = new Random(world.seed);
Noise colorVariationNoise = new Noise(world.seed,50,2);
Noise colorVariationNoise = new Noise(world.seed,world.octave,2);
for (int x = 0; x < chunk.SIZE; x++) {
for (int z = 0; z < chunk.SIZE; z++) {
int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK;

View file

@ -5,27 +5,27 @@ import game.*;
import java.util.*;
import main.*;
import math.*;
import blocks.*;
public class World {
public long seed;
public int octave,amplitude;
public final int SIZE = 1,HEIGHT = 1;
public static final float GRAVITY = 1;
public static final int VIEW_CHUNK = 2;
public static WorldNoise worldNoise;
public ArrayList<Chunk> chunks = new ArrayList<Chunk>();
public World(long seed){
public World(long seed,int octave,int amplitude){
this.seed= seed;
this.worldNoise = new WorldNoise(seed);
this.octave = octave;
this.amplitude = amplitude;
for(int x = 0;x < SIZE;x++){
for(int y = 0;y < HEIGHT;y++){
for(int z = 0;z < SIZE;z++){
Chunk ch = new Chunk(x,y,z,this,worldNoise);
Chunk ch = new Chunk(x,y,z,this);
chunks.add(ch);
}
}
@ -47,7 +47,7 @@ public class World {
for(int k = 0;k <= delta_z;k++){
// for(int j = 0; j < HEIGHT; j++){
if(getChunk((xa + i), 0, (za + k)) != null)continue;
Chunk ch = new Chunk((xa + i),0,(za + k),this,worldNoise);
Chunk ch = new Chunk((xa + i),0,(za + k),this);
chunks.add(ch);
// }
}
@ -172,6 +172,46 @@ public class World {
return chunk.getBlock(xb, yb, zb);
}
public long getSeed() {
return seed;
}
public void setSeed(long seed) {
this.seed = seed;
}
public ArrayList<Chunk> getChunks() {
return chunks;
}
public void setChunks(ArrayList<Chunk> chunks) {
this.chunks = chunks;
}
public static long getUpdateWorldTime() {
return updateWorldTime;
}
public static void setUpdateWorldTime(long updateWorldTime) {
World.updateWorldTime = updateWorldTime;
}
public int getSIZE() {
return SIZE;
}
public int getHEIGHT() {
return HEIGHT;
}
public static float getGravity() {
return GRAVITY;
}
public static int getViewChunk() {
return VIEW_CHUNK;
}

View file

@ -1,17 +0,0 @@
package world;
import java.util.*;
public class WorldNoise {
public Noise noise;
public Noise colorVariationNoise;
public Random random;
public WorldNoise(long seed){
noise = new Noise(seed, 20, 5);
colorVariationNoise = new Noise(seed, 40, 2);
random = new Random(seed);
}
}