Exemplo n.º 1
0
        public int ClippingOrOperation(Form1.CSBits b1, Form1.CSBits b2)
        {
            int num = 0;

            if (b1.Above | b2.Above)
            {
                checked { num += 32; }
            }
            if (b1.Below | b2.Below)
            {
                checked { num += 16; }
            }
            if (b1.Right | b2.Right)
            {
                checked { num += 8; }
            }
            if (b1.Left | b2.Left)
            {
                checked { num += 4; }
            }
            if (b1.Front | b2.Front)
            {
                checked { num += 2; }
            }
            if (b1.Back | b2.Back)
            {
                checked { ++num; }
            }
            return(num);
        }
Exemplo n.º 2
0
        public bool DoClip(ref Form1.TPoint p1, ref Form1.TPoint p2)
        {
            bool flag1;
            bool flag2 = false;

            do
            {
                flag1 = false;
                Form1.CSBits csBits = this.ClippingSecretCode(p1);
                Form1.CSBits b2     = this.ClippingSecretCode(p2);
                if (this.ClippingOrOperation(csBits, b2) == 0)
                {
                    flag2 = true;
                }
                else if (this.ClippingAndOperation(csBits, b2) > 0)
                {
                    flag2 = false;
                }
                else
                {
                    flag1 = true;
                    Form1.CSBits b1;
                    Form1.TPoint tpoint1;
                    Form1.TPoint tpoint2;
                    if (this.ClippingAndOperation(csBits, csBits) > 0)
                    {
                        b1      = csBits;
                        tpoint1 = p2;
                        tpoint2 = p1;
                    }
                    else
                    {
                        b1      = b2;
                        tpoint1 = p1;
                        tpoint2 = p2;
                    }
                    double x;
                    double y;
                    double z;
                    if (b1.Above)
                    {
                        x = tpoint1.x + (tpoint2.x - tpoint1.x) * (1.0 - tpoint1.y) / (tpoint2.y - tpoint1.y);
                        y = 1.0;
                        z = tpoint1.z + (tpoint2.z - tpoint1.z) * (1.0 - tpoint1.y) / (tpoint2.y - tpoint1.y);
                    }
                    else if (b1.Below)
                    {
                        x = tpoint1.x + (tpoint2.x - tpoint1.x) * (-1.0 - tpoint1.y) / (tpoint2.y - tpoint1.y);
                        y = -1.0;
                        z = tpoint1.z + (tpoint2.z - tpoint1.z) * (-1.0 - tpoint1.y) / (tpoint2.y - tpoint1.y);
                    }
                    else if (b1.Right)
                    {
                        x = 1.0;
                        y = tpoint1.y + (tpoint2.y - tpoint1.y) * (1.0 - tpoint1.x) / (tpoint2.x - tpoint1.x);
                        z = tpoint1.z + (tpoint2.z - tpoint1.z) * (1.0 - tpoint1.x) / (tpoint2.x - tpoint1.x);
                    }
                    else if (b1.Left)
                    {
                        x = -1.0;
                        y = tpoint1.y + (tpoint2.y - tpoint1.y) * (-1.0 - tpoint1.x) / (tpoint2.x - tpoint1.x);
                        z = tpoint1.z + (tpoint2.z - tpoint1.z) * (-1.0 - tpoint1.x) / (tpoint2.x - tpoint1.x);
                    }
                    else if (b1.Front)
                    {
                        x = tpoint1.x + (tpoint2.x - tpoint1.x) * (0.0 - tpoint1.z) / (tpoint2.z - tpoint1.z);
                        y = tpoint1.y + (tpoint2.y - tpoint1.y) * (0.0 - tpoint1.z) / (tpoint2.z - tpoint1.z);
                        z = 0.0;
                    }
                    else
                    {
                        x = tpoint1.x + (tpoint2.x - tpoint1.x) * (-1.0 - tpoint1.z) / (tpoint2.z - tpoint1.z);
                        y = tpoint1.y + (tpoint2.y - tpoint1.y) * (-1.0 - tpoint1.z) / (tpoint2.z - tpoint1.z);
                        z = -1.0;
                    }
                    if (this.ClippingAndOperation(b1, csBits) == this.ClippingOrOperation(b1, csBits))
                    {
                        this.SetPoint(ref p1, x, y, z);
                        this.ClippingSecretCode(p1);
                    }
                    else
                    {
                        this.SetPoint(ref p2, x, y, z);
                        this.ClippingSecretCode(p2);
                    }
                }
            }while (flag1);
            return(flag2);
        }