diff --git a/models/auvBG.png b/models/auvBG.png new file mode 100644 index 0000000..456e3d6 Binary files /dev/null and b/models/auvBG.png differ diff --git a/models/plant.mtl b/models/plant.mtl new file mode 100644 index 0000000..082f084 --- /dev/null +++ b/models/plant.mtl @@ -0,0 +1,20 @@ +# Exported from Wings 3D 2.2.6.1 +newmtl Cube2_auv +Ns 19.999999999999996 +d 1.0 +illum 2 +Kd 1.0 1.0 1.0 +Ka 0.0 0.0 0.0 +Ks 0.19 0.19 0.19 +Ke 0.0 0.0 0.0 +map_Kd auvBG.png + +newmtl default +Ns 19.999999999999996 +d 1.0 +illum 2 +Kd 0.7898538076923077 0.8133333333333334 0.6940444444444445 +Ka 0.0 0.0 0.0 +Ks 0.1689853807692308 0.17133333333333334 0.15940444444444446 +Ke 0.0 0.0 0.0 + diff --git a/models/plant.obj b/models/plant.obj new file mode 100644 index 0000000..900d28e --- /dev/null +++ b/models/plant.obj @@ -0,0 +1,73 @@ +# Exported from Wings 3D 2.2.6.1 +mtllib plant.mtl +o Cube2 +#28 vertices, 32 faces +v -3.2421582e-3 -1.5355904e-2 4.4110059e-3 +v 0.98670734 -1.5355904e-2 0.99436050 +v -3.2421582e-3 0.98464410 4.4110059e-3 +v 0.98670734 0.98464410 0.99436050 +v -3.2421582e-3 -1.5355904e-2 4.4110059e-3 +v 0.98670734 -1.5355904e-2 0.99436050 +v -3.2421582e-3 0.98464410 4.4110059e-3 +v 0.98670734 0.98464410 0.99436050 +v 0.49173259 0.48464410 0.49938575 +v 0.49173259 0.48464410 0.49938575 +v 0.49173259 -1.5355904e-2 0.49938575 +v 0.49173259 0.98464410 0.49938575 +v 0.49173259 -1.5355904e-2 0.49938575 +v 0.49173259 0.98464410 0.49938575 +v 0.98670734 -1.5355904e-2 4.4110059e-3 +v -3.2421582e-3 -1.5355904e-2 0.99436050 +v 0.98670734 0.98464410 4.4110059e-3 +v -3.2421582e-3 0.98464410 0.99436050 +v 0.98670734 -1.5355904e-2 4.4110059e-3 +v -3.2421582e-3 -1.5355904e-2 0.99436050 +v 0.98670734 0.98464410 4.4110059e-3 +v -3.2421582e-3 0.98464410 0.99436050 +v 0.49173259 0.48464410 0.49938575 +v 0.49173259 0.48464410 0.49938575 +v 0.49173259 -1.5355904e-2 0.49938575 +v 0.49173259 0.98464410 0.49938575 +v 0.49173259 -1.5355904e-2 0.49938575 +v 0.49173259 0.98464410 0.49938575 +vt 0.0000000e+0 -1.1102230e-16 +vt 0.0000000e+0 2.2204460e-16 +vt 2.2204460e-16 1.00000000 +vt 2.2204460e-16 1.00000000 +vt 0.50000000 0.0000000e+0 +vt 0.50000000 2.2204460e-16 +vt 0.50000000 0.50000000 +vt 0.50000000 0.50000000 +vt 0.50000000 1.00000000 +vt 0.50000000 1.00000000 +vt 1.00000000 1.1102230e-16 +vt 1.00000000 -1.1102230e-16 +vt 1.00000000 1.00000000 +vt 1.00000000 1.00000000 +g Cube2_Cube2_auv +usemtl Cube2_auv +s 1 +f 1/1/ 9/7/ 3/3/ +f 3/3/ 9/7/ 14/10/ +f 4/13/ 9/7/ 2/12/ +f 4/13/ 14/10/ 9/7/ +f 5/11/ 10/8/ 11/6/ +f 6/2/ 10/8/ 8/4/ +f 6/2/ 11/6/ 10/8/ +f 7/14/ 10/8/ 5/11/ +f 9/7/ 13/5/ 2/12/ +f 10/8/ 12/9/ 8/4/ +f 12/9/ 10/8/ 7/14/ +f 13/5/ 9/7/ 1/1/ +f 15/1/ 23/7/ 17/3/ +f 17/3/ 23/7/ 28/10/ +f 18/13/ 23/7/ 16/12/ +f 18/13/ 28/10/ 23/7/ +f 19/11/ 24/8/ 25/6/ +f 20/2/ 24/8/ 22/4/ +f 20/2/ 25/6/ 24/8/ +f 21/14/ 24/8/ 19/11/ +f 23/7/ 27/5/ 16/12/ +f 24/8/ 26/9/ 22/4/ +f 26/9/ 24/8/ 21/14/ +f 27/5/ 23/7/ 15/1/ \ No newline at end of file diff --git a/models/plant.wings b/models/plant.wings new file mode 100644 index 0000000..7822c5e Binary files /dev/null and b/models/plant.wings differ diff --git a/models/plant.wings~ b/models/plant.wings~ new file mode 100644 index 0000000..4667a4f Binary files /dev/null and b/models/plant.wings~ differ diff --git a/src/sig/SigRenderer.java b/src/sig/SigRenderer.java index 41b6ccb..a437067 100644 --- a/src/sig/SigRenderer.java +++ b/src/sig/SigRenderer.java @@ -2,6 +2,7 @@ package sig; import javax.imageio.ImageIO; import javax.swing.JFrame; +import sig.models.Plant; import sig.models.Staircase; import java.awt.event.MouseEvent; @@ -28,9 +29,12 @@ import java.awt.Cursor; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.event.MouseWheelListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowFocusListener; -public class SigRenderer implements KeyListener,MouseListener,MouseMotionListener,MouseWheelListener{ +public class SigRenderer implements WindowFocusListener,KeyListener,MouseListener,MouseMotionListener,MouseWheelListener{ + public static boolean windowActive=true; public static boolean WIREFRAME = false; public static boolean PROFILING = false; public static boolean FLYING_MODE = false; @@ -99,6 +103,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene public static MouseHandler tempAnswer = null; public static Panel panel; + public static JFrame frame; public static Cursor invisibleCursor; @@ -191,6 +196,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene } public void runGameLoop() { + if (!FLYING_MODE) { move(); if (SigRenderer.currentStaircase!=null) { @@ -255,7 +261,8 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene roll+=MOVESPEED; } if (wHeld||sHeld) { - Vector forward = Vector.multiply(vLookDir,MOVESPEED); + Vector newDir = Vector.normalize(new Vector(vLookDir.x,0,vLookDir.z)); + Vector forward = Vector.multiply(newDir,MOVESPEED); if (!FLYING_MODE) { forward.y=0; } @@ -389,6 +396,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene } SigRenderer(JFrame f) { + SigRenderer.frame=f; //cube = new Mesh(OBJReader.ReadOBJFile("teapot.obj",false)); Random r = new Random(438107); for (int x=0;x<64;x++) { @@ -420,7 +428,10 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene }*/ } } - addBlock(new Vector(31,1,31),Staircase.class,BlockType.ICE,FacingDirection.NORTH); + addBlock(new Vector(31,1,31),Plant.class,BlockType.SUGARCANE,FacingDirection.NORTH); + addBlock(new Vector(31,2,31),Plant.class,BlockType.SUGARCANE,FacingDirection.NORTH); + addBlock(new Vector(31,3,31),Plant.class,BlockType.SUGARCANE,FacingDirection.NORTH); + addBlock(new Vector(31,4,31),Plant.class,BlockType.SUGARCANE,FacingDirection.NORTH); /*addBlock(new Vector(31,2,32),Staircase.class,BlockType.PLANKS,FacingDirection.EAST); addBlock(new Vector(31,3,33),Staircase.class,BlockType.PLANKS,FacingDirection.WEST); addBlock(new Vector(31,4,34),Staircase.class,BlockType.PLANKS,FacingDirection.SOUTH); @@ -559,7 +570,9 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene int diffY=-Math.max(-100,Math.min(100,e.getYOnScreen()-middle.y)); yaw+=diffX*TURNSPEED*1.5; pitch=(float)Math.max(-Math.PI/2+0.01f,Math.min(Math.PI/2-0.01f,pitch+diffY*TURNSPEED)); - myRobot.mouseMove(middle.x,middle.y); + if (windowActive) { + myRobot.mouseMove(middle.x,middle.y); + } } @Override @@ -659,4 +672,14 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene selectedMode+=Math.signum(e.getWheelRotation()); System.out.println("Mode "+selectedMode+"."); } + + @Override + public void windowGainedFocus(WindowEvent e) { + windowActive=true; + } + + @Override + public void windowLostFocus(WindowEvent e) { + windowActive=false; + } } diff --git a/src/sig/models/Plant.java b/src/sig/models/Plant.java new file mode 100644 index 0000000..a52e3ac --- /dev/null +++ b/src/sig/models/Plant.java @@ -0,0 +1,21 @@ +package sig.models; + +import sig.Block; +import sig.BlockType; +import sig.Mesh; +import sig.Triangle; +import sig.utils.OBJReader; + +public class Plant extends Mesh{ + public Plant(BlockType type) { + super(type); + this.type=type; + this.triangles=OBJReader.ReadOBJFile("models/plant.obj",true); + for (Triangle t : triangles) { + t.tex=type.getTexture(BlockType.FRONT); + } + } + public boolean handleCollision(Block b,float x,float z) { + return true; + } +}