|
|
|
@ -771,17 +771,16 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
|
|
|
|
|
public void FillTexturedTriangle(List<Point<Double>>vPoints,List<Point<Double>>vTex,List<Color>vColour,Sprite sprTex){ |
|
|
|
|
try { |
|
|
|
|
Point<Double> p1 = vPoints.get(0); |
|
|
|
|
Point<Double> p2 = vPoints.get(1); |
|
|
|
|
Point<Double> p3 = vPoints.get(2); |
|
|
|
|
vColour=new ArrayList<Color>(vColour); |
|
|
|
|
Point<Double> p1 = vPoints.get(0).clone(); |
|
|
|
|
Point<Double> p2 = vPoints.get(1).clone(); |
|
|
|
|
Point<Double> p3 = vPoints.get(2).clone(); |
|
|
|
|
|
|
|
|
|
Double tempP; |
|
|
|
|
Color tempC; |
|
|
|
|
|
|
|
|
|
if (p2.y < p1.y){tempP=p1.y;p1.y=p2.y;p2.y=tempP;tempP=p1.x;p1.x=p2.x;p2.x=tempP;tempP=vTex.get(0).x;vTex.get(0).x=vTex.get(1).x;vTex.get(1).x=tempP;vTex.get(0).y=vTex.get(1).y;vTex.get(1).y=tempP;tempC=vColour.get(0).clone();vColour.set(0,vColour.get(1));vColour.set(1,tempC);} |
|
|
|
|
if (p3.y < p1.y){tempP=p1.y;p1.y=p3.y;p3.y=tempP;tempP=p1.x;p1.x=p3.x;p3.x=tempP;tempP=vTex.get(0).x;vTex.get(0).x=vTex.get(2).x;vTex.get(2).x=tempP;vTex.get(0).y=vTex.get(2).y;vTex.get(2).y=tempP;tempC=vColour.get(0).clone();vColour.set(0,vColour.get(2));vColour.set(2,tempC);} |
|
|
|
|
if (p3.y < p2.y){tempP=p2.y;p2.y=p3.y;p2.y=tempP;tempP=p2.x;p2.x=p3.x;p3.x=tempP;tempP=vTex.get(1).x;vTex.get(1).x=vTex.get(2).x;vTex.get(2).x=tempP;vTex.get(1).y=vTex.get(2).y;vTex.get(2).y=tempP;tempC=vColour.get(1).clone();vColour.set(1,vColour.get(2));vColour.set(2,tempC);} |
|
|
|
|
|
|
|
|
|
if (p2.y < p1.y){tempP=(double)p1.y;p1.y=p2.y;p2.y=tempP;tempP=(double)p1.x;p1.x=p2.x;p2.x=tempP;tempP=vTex.get(0).x;vTex.get(0).x=vTex.get(1).x;vTex.get(1).x=tempP;vTex.get(0).y=vTex.get(1).y;vTex.get(1).y=tempP;tempC=vColour.get(0);vColour.set(0,vColour.get(1));vColour.set(1,tempC);} |
|
|
|
|
if (p3.y < p1.y){tempP=(double)p1.y;p1.y=p3.y;p3.y=tempP;tempP=(double)p1.x;p1.x=p3.x;p3.x=tempP;tempP=vTex.get(0).x;vTex.get(0).x=vTex.get(2).x;vTex.get(2).x=tempP;vTex.get(0).y=vTex.get(2).y;vTex.get(2).y=tempP;tempC=vColour.get(0);vColour.set(0,vColour.get(2));vColour.set(2,tempC);} |
|
|
|
|
if (p3.y < p2.y){tempP=(double)p2.y;p2.y=p3.y;p3.y=tempP;tempP=(double)p2.x;p2.x=p3.x;p3.x=tempP;tempP=vTex.get(1).x;vTex.get(1).x=vTex.get(2).x;vTex.get(2).x=tempP;vTex.get(1).y=vTex.get(2).y;vTex.get(2).y=tempP;tempC=vColour.get(1);vColour.set(1,vColour.get(2));vColour.set(2,tempC);} |
|
|
|
|
Point<Integer> dPos1 = new Point<Integer>((int)(p2.x-p1.x),(int)(p2.y-p1.y)); |
|
|
|
|
Point<Integer> dTex1 = new Point<Integer>((int)(vTex.get(1).x-vTex.get(0).x),(int)(vTex.get(1).y-vTex.get(0).y)); |
|
|
|
|
int dcr1 = vColour.get(1).r - vColour.get(0).r; |
|
|
|
@ -869,7 +868,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
vColour.get(0).b + (int)((float)(i - p1.y) * dcb2_step), vColour.get(0).a + (int)((float)(i - p1.y) * dca2_step)); |
|
|
|
|
int temp; |
|
|
|
|
Point<Float> tempF; |
|
|
|
|
if (ax > bx) {temp=ax;ax=bx;bx=temp;tempF=tex_s.clone();tex_s=tex_e.clone();tex_e=tempF;tempC=col_e;tempC=col_s.clone();col_s=col_e;col_e=tempC;} |
|
|
|
|
if (ax > bx) {temp=ax;ax=bx;bx=temp;tempF=tex_s.clone();tex_s=tex_e.clone();tex_e=tempF;tempC=col_s.clone();col_s=col_e.clone();col_e=tempC;} |
|
|
|
|
|
|
|
|
|
float tstep = 1.0f / ((float)(bx - ax)); |
|
|
|
|
float t = 0.0f; |
|
|
|
@ -968,6 +967,50 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
Draw(x, y, col); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void FillTexturedPolygon(List<Point<Double>>vPoints,List<Point<Double>>vTex,List<Color>vColour,Sprite sprTex,PolygonStructure structure) { |
|
|
|
|
try { |
|
|
|
|
if (vPoints.size() < 3 || vTex.size() < 3 || vColour.size() < 3) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (structure == PolygonStructure.LIST) |
|
|
|
|
{ |
|
|
|
|
for (int tri = 0; tri < vPoints.size() / 3; tri++) |
|
|
|
|
{ |
|
|
|
|
List<Point<Double>> vP = new ArrayList<Point<Double>>(List.of(vPoints.get(tri * 3 + 0), vPoints.get(tri * 3 + 1), vPoints.get(tri * 3 + 2))); |
|
|
|
|
List<Point<Double>> vT = new ArrayList<Point<Double>>(List.of(vTex.get(tri * 3 + 0), vTex.get(tri * 3 + 1), vTex.get(tri * 3 + 2))); |
|
|
|
|
List<Color> vC = new ArrayList<Color>(List.of(vColour.get(tri * 3 + 0), vColour.get(tri * 3 + 1), vColour.get(tri * 3 + 2))); |
|
|
|
|
FillTexturedTriangle(vP, vT, vC, sprTex); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (structure == PolygonStructure.STRIP) |
|
|
|
|
{ |
|
|
|
|
for (int tri = 2; tri < vPoints.size(); tri++) |
|
|
|
|
{ |
|
|
|
|
List<Point<Double>> vP = new ArrayList<Point<Double>>(List.of(vPoints.get(tri - 2), vPoints.get(tri - 1), vPoints.get(tri))); |
|
|
|
|
List<Point<Double>> vT = new ArrayList<Point<Double>>(List.of(vTex.get(tri - 2), vTex.get(tri - 1), vTex.get(tri))); |
|
|
|
|
List<Color> vC = new ArrayList<Color>(List.of(vColour.get(tri - 2), vColour.get(tri - 1), vColour.get(tri))); |
|
|
|
|
FillTexturedTriangle(vP, vT, vC, sprTex); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (structure == PolygonStructure.FAN) |
|
|
|
|
{ |
|
|
|
|
for (int tri = 2; tri < vPoints.size(); tri++) |
|
|
|
|
{ |
|
|
|
|
List<Point<Double>> vP; |
|
|
|
|
vP = new ArrayList<Point<Double>>(List.of(vPoints.get(0).clone(), vPoints.get(tri - 1).clone(), vPoints.get(tri).clone())); |
|
|
|
|
List<Point<Double>> vT = new ArrayList<Point<Double>>(List.of(vTex.get(0).clone(), vTex.get(tri - 1).clone(), vTex.get(tri).clone())); |
|
|
|
|
List<Color> vC = new ArrayList<Color>(List.of(vColour.get(0).clone(), vColour.get(tri - 1).clone(), vColour.get(tri).clone())); |
|
|
|
|
FillTexturedTriangle(vP, vT, vC, sprTex); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} catch (CloneNotSupportedException e) {} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Color ColorLerp(Color c1, Color c2, float t) |
|
|
|
|
{ return new Color((int)((c2.r * t) + c1.r * (1.0f - t)),(int)((c2.g * t) + c1.g * (1.0f - t)),(int)((c2.b * t) + c1.b * (1.0f - t)),(int)((c2.a * t) + c1.a * (1.0f - t))); } |
|
|
|
|
|
|
|
|
|