1

ここに示されている Binary Space Partitioning メソッドの実装を理解しようとしていました(このコードはアプレットとしても利用できますここ)。私はほとんどのコードを理解しましたが、メソッドを理解できません:

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);
    }

このメソッドの実装の背後にある座標ジオメトリを把握できていません。説明してもらえますか?

4

1 に答える 1

3

前半は、仮想の目があるべき場所に対する線の角度を計算します。また、接線を使用して表示されるかどうかも計算します。2番目の部分は、画面に比例するように線のサイズを変更します。画面中央に座標系の原点を設定しているように見えます。

コードをざっと読んだだけなので、これらの詳細の一部がずれている可能性があります。

これを見てください。それは正しい方向にあなたを始めるかもしれません http://www.cs.uic.edu/~jbell/CourseNotes/ComputerGraphics/2DTransforms.html

于 2012-06-01T02:10:20.403 に答える