Block click detection.
This commit is contained in:
parent
a99f5a81e3
commit
1865a973e7
@ -44,4 +44,8 @@ public class Block {
|
|||||||
SigRenderer.blockGrid.get(pos.x+"_"+(pos.y)+"_"+(pos.z-1)).neighbors.FORWARD=true;
|
SigRenderer.blockGrid.get(pos.x+"_"+(pos.y)+"_"+(pos.z-1)).neighbors.FORWARD=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Block [pos=" + pos + ", neighbors=" + neighbors + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,6 +218,7 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
return (z1<z2)?1:(z1==z2)?0:-1;
|
return (z1<z2)?1:(z1==z2)?0:-1;
|
||||||
}
|
}
|
||||||
});*/
|
});*/
|
||||||
|
SigRenderer.tempAnswer=null;
|
||||||
for (Triangle t : accumulatedTris) {
|
for (Triangle t : accumulatedTris) {
|
||||||
|
|
||||||
Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()};
|
Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()};
|
||||||
@ -249,7 +250,7 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
(int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w,
|
(int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w,
|
||||||
(int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w,
|
(int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w,
|
||||||
(int)tt.C.x,(int)tt.C.y,tt.V.u,tt.V.v,tt.V.w,
|
(int)tt.C.x,(int)tt.C.y,tt.V.u,tt.V.v,tt.V.w,
|
||||||
tt.tex,(tt.col&0xFF0000)>>16);
|
tt.tex,(tt.col&0xFF0000)>>16,tt);
|
||||||
} else {
|
} else {
|
||||||
DrawUtils.FillTriangle(p,(int)tt.A.x,(int)tt.A.y,(int)tt.B.x,(int)tt.B.y,(int)tt.C.x,(int)tt.C.y,tt.getColor());
|
DrawUtils.FillTriangle(p,(int)tt.A.x,(int)tt.A.y,(int)tt.B.x,(int)tt.B.y,(int)tt.C.x,(int)tt.C.y,tt.getColor());
|
||||||
}
|
}
|
||||||
@ -258,6 +259,8 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SigRenderer.request=null;
|
||||||
|
SigRenderer.answer=SigRenderer.tempAnswer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repaint() {
|
public void repaint() {
|
||||||
|
@ -50,8 +50,6 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
|
|||||||
final float MOVESPEED = 0.2f;
|
final float MOVESPEED = 0.2f;
|
||||||
final float TURNSPEED = 0.2f;
|
final float TURNSPEED = 0.2f;
|
||||||
|
|
||||||
public static Texture dirtTex;
|
|
||||||
|
|
||||||
public static float[] depthBuffer;
|
public static float[] depthBuffer;
|
||||||
|
|
||||||
public static Mesh DIRT_CUBE=new Mesh("cube.obj","dirt.png");
|
public static Mesh DIRT_CUBE=new Mesh("cube.obj","dirt.png");
|
||||||
@ -59,7 +57,9 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
|
|||||||
boolean upHeld=false,downHeld=false,leftHeld=false,rightHeld=false,
|
boolean upHeld=false,downHeld=false,leftHeld=false,rightHeld=false,
|
||||||
aHeld=false,sHeld=false,dHeld=false,wHeld=false;
|
aHeld=false,sHeld=false,dHeld=false,wHeld=false;
|
||||||
|
|
||||||
public static MouseEvent storedMouseEvent;
|
public static MouseEvent request;
|
||||||
|
public static Block answer;
|
||||||
|
public static Block tempAnswer = null;
|
||||||
|
|
||||||
public void runGameLoop() {
|
public void runGameLoop() {
|
||||||
if (upHeld) {
|
if (upHeld) {
|
||||||
@ -89,6 +89,10 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
|
|||||||
if (dHeld) {
|
if (dHeld) {
|
||||||
yaw+=TURNSPEED;
|
yaw+=TURNSPEED;
|
||||||
}
|
}
|
||||||
|
if (answer!=null) {
|
||||||
|
System.out.println(answer);
|
||||||
|
answer=null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addBlock(Vector pos,Mesh type) {
|
public static void addBlock(Vector pos,Mesh type) {
|
||||||
@ -167,11 +171,12 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
storedMouseEvent=e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
|
request=e;
|
||||||
|
answer=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,7 +5,7 @@ public class Triangle {
|
|||||||
Vector A,B,C;
|
Vector A,B,C;
|
||||||
Vector2 T,U,V;
|
Vector2 T,U,V;
|
||||||
int col = Color.WHITE.getRGB();
|
int col = Color.WHITE.getRGB();
|
||||||
Block b = null;
|
public Block b = null;
|
||||||
public Texture tex = null;
|
public Texture tex = null;
|
||||||
public Triangle() {
|
public Triangle() {
|
||||||
this(new Vector(),new Vector(),new Vector());
|
this(new Vector(),new Vector(),new Vector());
|
||||||
|
@ -6,6 +6,7 @@ import java.awt.image.BufferedImage;
|
|||||||
|
|
||||||
import sig.SigRenderer;
|
import sig.SigRenderer;
|
||||||
import sig.Texture;
|
import sig.Texture;
|
||||||
|
import sig.Triangle;
|
||||||
|
|
||||||
public class DrawUtils {
|
public class DrawUtils {
|
||||||
static void drawLine(int[] canvas,int sx,int ex,int ny,int col) {
|
static void drawLine(int[] canvas,int sx,int ex,int ny,int col) {
|
||||||
@ -17,7 +18,7 @@ public class DrawUtils {
|
|||||||
int x1, int y1, float u1,float v1,float w1,
|
int x1, int y1, float u1,float v1,float w1,
|
||||||
int x2, int y2, float u2,float v2,float w2,
|
int x2, int y2, float u2,float v2,float w2,
|
||||||
int x3, int y3, float u3,float v3,float w3,
|
int x3, int y3, float u3,float v3,float w3,
|
||||||
Texture texture, int colorMult
|
Texture texture, int colorMult,Triangle ref
|
||||||
) {
|
) {
|
||||||
if (y2<y1) {int t=y1;y1=y2;y2=t;t=x1;x1=x2;x2=t;float u=u1;u1=u2;u2=u;float v=v1;v1=v2;v2=v;float w=w1;w1=w2;w2=w;}
|
if (y2<y1) {int t=y1;y1=y2;y2=t;t=x1;x1=x2;x2=t;float u=u1;u1=u2;u2=u;float v=v1;v1=v2;v2=v;float w=w1;w1=w2;w2=w;}
|
||||||
if (y3<y1) {int t=y1;y1=y3;y3=t;t=x1;x1=x3;x3=t;float u=u1;u1=u3;u3=u;float v=v1;v1=v3;v3=v;float w=w1;w1=w3;w3=w;}
|
if (y3<y1) {int t=y1;y1=y3;y3=t;t=x1;x1=x3;x3=t;float u=u1;u1=u3;u3=u;float v=v1;v1=v3;v3=v;float w=w1;w1=w3;w3=w;}
|
||||||
@ -80,6 +81,9 @@ public class DrawUtils {
|
|||||||
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
|
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
|
||||||
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
|
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
|
||||||
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) {
|
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) {
|
||||||
|
if (SigRenderer.request!=null&&j==SigRenderer.request.getX()&&i==SigRenderer.request.getY()) {
|
||||||
|
SigRenderer.tempAnswer=ref.b;
|
||||||
|
}
|
||||||
Draw(canvas,j,i,texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f));
|
Draw(canvas,j,i,texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f));
|
||||||
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
|
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
|
||||||
}
|
}
|
||||||
@ -132,6 +136,9 @@ public class DrawUtils {
|
|||||||
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
|
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
|
||||||
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
|
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
|
||||||
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) {
|
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) {
|
||||||
|
if (SigRenderer.request!=null&&j==SigRenderer.request.getX()&&i==SigRenderer.request.getY()) {
|
||||||
|
SigRenderer.tempAnswer=ref.b;
|
||||||
|
}
|
||||||
Draw(canvas,j,i,texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f));
|
Draw(canvas,j,i,texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f));
|
||||||
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
|
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user