Stashing old staircase physics

origin
Joshua Sigona 3 years ago
parent 9c922e3de8
commit cc9bcb988d
  1. 2
      src/sig/Mesh.java
  2. 20
      src/sig/SigRenderer.java
  3. 68
      src/sig/models/Staircase.java

@ -27,7 +27,7 @@ public class Mesh {
protected List<Triangle> prepareRender(Block b) {
return b.block.triangles;
}
public boolean handleCollision(Block b) {
public boolean handleCollision(Block b,float x,float y) {
return false;
}
}

@ -31,7 +31,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
public static boolean WIREFRAME = false;
public static boolean PROFILING = false;
public static boolean FLYING_MODE = true;
public static boolean FLYING_MODE = false;
public static int SCREEN_WIDTH=1280;
public static int SCREEN_HEIGHT=720;
public final static long TIMEPERTICK = 16666667l;
@ -106,7 +106,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
zSpeed+=v.z;
}
boolean checkCollisionSquare(float x,float y,float z) {
public static boolean checkCollisionSquare(float x,float y,float z) {
for (int yy=0;yy<cameraHeight;yy++) {
Block b1 = blockGrid.get((float)Math.floor(vCamera.x+x+cameraCollisionPadding)+"_"+(float)Math.floor(vCamera.y+y+yy)+"_"+(float)Math.floor(vCamera.z+z+cameraCollisionPadding));
Block b2 = blockGrid.get((float)Math.floor(vCamera.x+x-cameraCollisionPadding)+"_"+(float)Math.floor(vCamera.y+y+yy)+"_"+(float)Math.floor(vCamera.z+z+cameraCollisionPadding));
@ -118,10 +118,10 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
b4!=null && !(b4.block instanceof Staircase)) {
return false;
}
if (b1!=null) {if (!b1.block.handleCollision(b1)) {return false;}}
if (b2!=null) {if (!b2.block.handleCollision(b2)) {return false;}}
if (b3!=null) {if (!b3.block.handleCollision(b3)) {return false;}}
if (b4!=null) {if (!b4.block.handleCollision(b4)) {return false;}}
if (b1!=null) {if (!b1.block.handleCollision(b1,x,z)) {return false;}}
if (b2!=null) {if (!b2.block.handleCollision(b2,x,z)) {return false;}}
if (b3!=null) {if (!b3.block.handleCollision(b3,x,z)) {return false;}}
if (b4!=null) {if (!b4.block.handleCollision(b4,x,z)) {return false;}}
}
return true;
}
@ -188,10 +188,10 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
Block b2 = blockGrid.get((float)Math.floor(vCamera.x-cameraCollisionPadding)+"_"+(float)Math.floor(vCamera.y-0.5f+yy)+"_"+(float)Math.floor(vCamera.z+cameraCollisionPadding));
Block b3 = blockGrid.get((float)Math.floor(vCamera.x+cameraCollisionPadding)+"_"+(float)Math.floor(vCamera.y-0.5f+yy)+"_"+(float)Math.floor(vCamera.z-cameraCollisionPadding));
Block b4 = blockGrid.get((float)Math.floor(vCamera.x-cameraCollisionPadding)+"_"+(float)Math.floor(vCamera.y-0.5f+yy)+"_"+(float)Math.floor(vCamera.z-cameraCollisionPadding));
if (b1!=null && b1.block instanceof Staircase) {found=true;}
if (b2!=null && b2.block instanceof Staircase) {found=true;}
if (b3!=null && b3.block instanceof Staircase) {found=true;}
if (b4!=null && b4.block instanceof Staircase) {found=true;}
if (b1!=null && b1.block instanceof Staircase) {found=true;break;}
if (b2!=null && b2.block instanceof Staircase) {found=true;break;}
if (b3!=null && b3.block instanceof Staircase) {found=true;break;}
if (b4!=null && b4.block instanceof Staircase) {found=true;break;}
}
if (!found) {
SigRenderer.currentStaircase=null;

@ -77,50 +77,90 @@ public class Staircase extends Mesh{
tris.add(b.block.triangles.get(7));
return tris;
}
public boolean handleCollision(Block b) {
if (SigRenderer.currentStaircase!=null) {
float diffX=SigRenderer.vCamera.x-b.pos.x;
float diffZ=SigRenderer.vCamera.z-b.pos.z;
boolean checkCollision(float x,float y,float z) {
for (int yy=0;yy<SigRenderer.cameraHeight;yy++) {
Block b1 = SigRenderer.blockGrid.get((float)Math.floor(x+SigRenderer.cameraCollisionPadding)+"_"+(float)Math.floor(y+yy)+"_"+(float)Math.floor(z+SigRenderer.cameraCollisionPadding));
Block b2 = SigRenderer.blockGrid.get((float)Math.floor(x-SigRenderer.cameraCollisionPadding)+"_"+(float)Math.floor(y+yy)+"_"+(float)Math.floor(z+SigRenderer.cameraCollisionPadding));
Block b3 = SigRenderer.blockGrid.get((float)Math.floor(x+SigRenderer.cameraCollisionPadding)+"_"+(float)Math.floor(y+yy)+"_"+(float)Math.floor(z-SigRenderer.cameraCollisionPadding));
Block b4 = SigRenderer.blockGrid.get((float)Math.floor(x-SigRenderer.cameraCollisionPadding)+"_"+(float)Math.floor(y+yy)+"_"+(float)Math.floor(z-SigRenderer.cameraCollisionPadding));
//System.out.println(b1+","+b2+","+b3+","+b4);
if ((b1!=null&&!b1.block.equals(SigRenderer.currentStaircase))||
(b2!=null&&!b2.block.equals(SigRenderer.currentStaircase))||
(b3!=null&&!b3.block.equals(SigRenderer.currentStaircase))||
(b4!=null&&!b4.block.equals(SigRenderer.currentStaircase))) {
System.out.println(b1+","+b2+","+b3+","+b4);
return false;
}
}
return true;
}
public boolean handleCollision(Block b,float x,float z) {
if (SigRenderer.currentStaircase!=null&&
SigRenderer.currentStaircase==this) {
float diffX=Math.min(1,Math.max(0.3f,SigRenderer.vCamera.x-b.pos.x));
float diffZ=Math.min(1,Math.max(0.3f,SigRenderer.vCamera.z-b.pos.z));
switch (b.getFacingDirection()) {
case EAST: {
SigRenderer.vCamera.y=b.pos.y+diffX+0.7f;
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+diffX+1.3f, SigRenderer.vCamera.z+z)) {
SigRenderer.vCamera.y=b.pos.y+diffX+0.3f;
} else {
SigRenderer.fallSpd=0;
return false;
}
}break;
case NORTH: {
SigRenderer.vCamera.y=b.pos.y+(1-diffZ)+0.7f;
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+(1-diffZ)+1.3f, SigRenderer.vCamera.z+z)) {
SigRenderer.vCamera.y=b.pos.y+(1-diffZ)+0.3f;
} else {
SigRenderer.fallSpd=0;
return false;
}
}break;
case SOUTH: {
SigRenderer.vCamera.y=b.pos.y+diffZ+0.7f;
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+diffZ+1.3f, SigRenderer.vCamera.z+z)) {
SigRenderer.vCamera.y=b.pos.y+diffZ+0.3f;
} else {
SigRenderer.fallSpd=0;
return false;
}
}break;
case WEST: {
SigRenderer.vCamera.y=b.pos.y+(1-diffX)+0.7f;
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+(1-diffX)+1.3f, SigRenderer.vCamera.z+z)) {
SigRenderer.vCamera.y=b.pos.y+(1-diffX)+0.3f;
} else {
SigRenderer.fallSpd=0;
return false;
}
}break;
}
SigRenderer.fallSpd=0;
return true;
}
if (SigRenderer.vCamera.y>=b.pos.y) {
if (this!=SigRenderer.currentStaircase && SigRenderer.vCamera.y>=b.pos.y) {
boolean valid=false;
if (SigRenderer.vCamera.y>=b.pos.y+1f) {
if (SigRenderer.vCamera.y>=b.pos.y+3f) {
valid=true;
} else {
float diffX=Math.min(1,Math.max(0.3f,SigRenderer.vCamera.x-b.pos.x));
float diffZ=Math.min(1,Math.max(0.3f,SigRenderer.vCamera.z-b.pos.z));
switch (b.getFacingDirection()) {
case EAST: {
if (SigRenderer.vCamera.x<b.pos.x+0.5f) {
if (SigRenderer.vCamera.x<b.pos.x+0.5f&&checkCollision(SigRenderer.vCamera.x+x, b.pos.y+diffX+1.3f, SigRenderer.vCamera.z+z)) {
valid=true;
}
}break;
case NORTH: {
if (SigRenderer.vCamera.z>b.pos.z+0.5f) {
if (SigRenderer.vCamera.z>b.pos.z+0.5f&&checkCollision(SigRenderer.vCamera.x+x, b.pos.y+(1-diffZ)+1.3f, SigRenderer.vCamera.z+z)) {
valid=true;
}
}break;
case SOUTH: {
if (SigRenderer.vCamera.z<b.pos.z+0.5f) {
if (SigRenderer.vCamera.z<b.pos.z+0.5f&&checkCollision(SigRenderer.vCamera.x+x, b.pos.y+diffZ+1.3f, SigRenderer.vCamera.z+z)) {
valid=true;
}
}break;
case WEST: {
if (SigRenderer.vCamera.x>b.pos.x+0.5f) {
if (SigRenderer.vCamera.x>b.pos.x+0.5f&&checkCollision(SigRenderer.vCamera.x+x, b.pos.y+(1-diffX)+1.3f, SigRenderer.vCamera.z+z)) {
valid=true;
}
}break;

Loading…
Cancel
Save