我试图了解此处给出的二进制空间分区方法实现(此代码也可作为小程序在此处获得)。大部分代码我都看懂了,但是看不懂方法:
public void renderLine(int[] l){
double x1=l[2];
double y1=l[3];
double x2=l[0];
double y2=l[1];
double pCos = Math.cos(eye_angle);
double pSin = Math.sin(eye_angle);
int[] x = new int[4];
int[] y = new int[4];
double pD=-pSin*eye_x+pCos*eye_y; //What is this line doing?
double pDp=pCos*eye_x+pSin*eye_y; //And this?
double rz1,rz2,rx1,rx2;
int Screen_x1=0,Screen_x2=0;
double Screen_y1,Screen_y2,Screen_y3,Screen_y4;
rz1=pCos*x1+pSin*y1-pDp; //perpendicular line to the players
rz2=pCos*x2+pSin*y2-pDp; //view point
if((rz1<1) && (rz2<1))
return;
rx1=pCos*y1-pSin*x1-pD;
rx2=pCos*y2-pSin*x2-pD;
double pTan = 0;
if((x2-x1) == 0)
pTan = Double.MAX_VALUE;
else
pTan = (y2-y1)/(x2-x1);
pTan = (pTan-Math.tan(eye_angle))/(1+
(pTan*Math.tan(eye_angle)));
if(rz1 < 1){
rx1+=(1-rz1)*pTan;
rz1=1;
}if(rz2 < 1){
rx2+=(1-rz2)*pTan;
rz2=1;
}
double z1 = m_width/2/rz1;
double z2 = m_width/2/rz2;
Screen_x1=(int)(m_width/2-rx1*z1);
Screen_x2=(int)(m_width/2-rx2*z2);
if(Screen_x1 > m_width)
return;
if(Screen_x2<0)
return;
int wt=88;
int wb=-40;
Screen_y1=(double)m_height/2-(double)wt*z1;
Screen_y4=(double)m_height/2-(double)wb*z1;
Screen_y2=(double)m_height/2-(double)wt*z2;
Screen_y3=(double)m_height/2-(double)wb*z2;
if(Screen_x1 < 0){
Screen_y1+=(0-Screen_x1)*(Screen_y2-Screen_y1)
/(Screen_x2-Screen_x1);
Screen_y4+=(0-Screen_x1)*(Screen_y3-Screen_y4)
/(Screen_x2-Screen_x1);
Screen_x1=0;
}if(Screen_x2 > (m_width)){
Screen_y2-=(Screen_x2-m_width)*(Screen_y2-Screen_y1)
/(Screen_x2-Screen_x1);
Screen_y3-=(Screen_x2-m_width)*(Screen_y3-Screen_y4)
/(Screen_x2-Screen_x1);
Screen_x2=m_width;
}if((Screen_x2-Screen_x1) == 0)
return;
x[0] = (int)Screen_x1;
y[0] = (int)(Screen_y1);
x[1] = (int)Screen_x2;
y[1] = (int)(Screen_y2);
x[2] = (int)Screen_x2;
y[2] = (int)(Screen_y3);
x[3] = (int)Screen_x1;
y[3] = (int)(Screen_y4);
double_graphics.setColor(new Color(l[4]));
double_graphics.fillPolygon(x,y,4);
}
我无法掌握实施此方法背后的坐标几何。你能给我解释一下吗?