Fix texture disappearing on rotation and block placing for cubes.

origin
Joshua Sigona 3 years ago
parent 1f5cbd514a
commit 52ccce0610
  1. 10
      src/sig/Block.java
  2. 1
      src/sig/Cube.java
  3. 6
      src/sig/Panel.java
  4. 6
      src/sig/SigRenderer.java

@ -35,14 +35,24 @@ public class Block {
if (block instanceof Cube) {
Texture t1 = block.triangles.get(Texture.SOUTH).tex;
Texture t2 = block.triangles.get(Texture.SOUTH+1).tex;
int dir1 = block.triangles.get(Texture.SOUTH).dir;
int dir2 = block.triangles.get(Texture.SOUTH+1).dir;
block.triangles.get(Texture.SOUTH).tex=block.triangles.get(Texture.EAST).tex;
block.triangles.get(Texture.SOUTH).dir=block.triangles.get(Texture.EAST).dir;
block.triangles.get(Texture.SOUTH+1).tex=block.triangles.get(Texture.EAST+1).tex;
block.triangles.get(Texture.SOUTH+1).dir=block.triangles.get(Texture.EAST+1).dir;
block.triangles.get(Texture.EAST).tex=block.triangles.get(Texture.NORTH).tex;
block.triangles.get(Texture.EAST).dir=block.triangles.get(Texture.NORTH).dir;
block.triangles.get(Texture.EAST+1).tex=block.triangles.get(Texture.NORTH+1).tex;
block.triangles.get(Texture.EAST+1).dir=block.triangles.get(Texture.NORTH+1).dir;
block.triangles.get(Texture.NORTH).tex=block.triangles.get(Texture.WEST).tex;
block.triangles.get(Texture.NORTH).dir=block.triangles.get(Texture.WEST).dir;
block.triangles.get(Texture.NORTH+1).tex=block.triangles.get(Texture.WEST+1).tex;
block.triangles.get(Texture.NORTH+1).dir=block.triangles.get(Texture.WEST+1).dir;
block.triangles.get(Texture.WEST).tex=t1;
block.triangles.get(Texture.WEST).dir=dir1;
block.triangles.get(Texture.WEST+1).tex=t2;
block.triangles.get(Texture.WEST+1).dir=dir2;
for (int i=8;i<=11;i++) {
Triangle t = block.triangles.get(i);
Vector2[] tt = new Vector2[]{t.T,t.U,t.V};

@ -52,6 +52,7 @@ public class Cube extends Mesh{
if (!b.neighbors.FORWARD) {
tris.add(b.block.triangles.get(4));
tris.add(b.block.triangles.get(5));
System.out.println("No forward neighbor.");
}
if (!b.neighbors.BACKWARD) {
tris.add(b.block.triangles.get(0));

@ -371,13 +371,17 @@ public class Panel extends JPanel implements Runnable {
triPreTransform.unmodifiedTri=t;
if (t.b!=null) {
if (!(t.b.block instanceof Cube)) {
matWorld = Matrix.MakeRotationY((float)(t.b.getFacingDirection().ordinal()*(Math.PI/2)));
}
triTransformed.A = Matrix.MultiplyVector(matWorld,triPreTransform.A);
triTransformed.B = Matrix.MultiplyVector(matWorld,triPreTransform.B);
triTransformed.C = Matrix.MultiplyVector(matWorld,triPreTransform.C);
triPreTransform.copyExtraDataTo(triTransformed);
} else {
triTransformed=triPreTransform;
}
}
if (t.b!=null) {
matWorld = Matrix.MakeTranslation(t.b.pos.x+0.5f,t.b.pos.y,t.b.pos.z+0.5f);

@ -33,7 +33,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
public static boolean WIREFRAME = false;
public static boolean PROFILING = false;
public static boolean FLYING_MODE = false;
public static boolean FLYING_MODE = true;
public static int SCREEN_WIDTH=1280;
public static int SCREEN_HEIGHT=720;
public final static long TIMEPERTICK = 16666667l;
@ -391,8 +391,8 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
SigRenderer(JFrame f) {
//cube = new Mesh(OBJReader.ReadOBJFile("teapot.obj",false));
Random r = new Random(438107);
for (int x=0;x<64;x++) {
for (int z=0;z<64;z++) {
for (int x=0;x<1;x++) {
for (int z=0;z<1;z++) {
addBlock(new Vector(x,0,z),Cube.class,BlockType.GRASS,FacingDirection.SOUTH);
//addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH);
//addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH);

Loading…
Cancel
Save