示例#1
0
        public void ScanConvertLine(Vertex minYVert, Vertex maxYVert, int whichSide)
        {
            int yStart = (int)minYVert.GetY();
            int yEnd   = (int)maxYVert.GetY();
            int xStart = (int)minYVert.GetX();
            int xEnd   = (int)maxYVert.GetX();


            int yDist = yEnd - yStart;
            int xDist = xEnd - xStart;


            if (yDist <= 0)
            {
                return;
            }


            float xStep = (float)xDist / (float)yDist;
            float curX  = (float)xStart;


            for (int j = yStart; j < yEnd; j++)
            {
                m_scanBuffer[j * 2 + whichSide] = (int)curX;
                curX += xStep;
            }
        }
示例#2
0
        public float TriangleAreaTimes2(Vertex b, Vertex c)
        {
            float x1 = b.GetX() - m_pos.GetX();
             		    float y1 = b.GetY() - m_pos.GetY();

             		    float x2 = c.GetX() - m_pos.GetX();
             		    float y2 = c.GetY() - m_pos.GetY();

             		    return (x1 * y2 - x2 * y1);
        }
示例#3
0
        public void FillTriangle(Vertex v1, Vertex v2, Vertex v3)
        {
            Matrix4f screenSpaceTransform =
                new Matrix4f().InitScreenSpaceTransform(backBuffer.Width / 2, backBuffer.Height / 2);
            Vertex minYVert = v1.Transform(screenSpaceTransform).PerspectiveDivide();
            Vertex midYVert = v2.Transform(screenSpaceTransform).PerspectiveDivide();
            Vertex maxYVert = v3.Transform(screenSpaceTransform).PerspectiveDivide();



            if (maxYVert.GetY() < midYVert.GetY())
            {
                Vertex temp = maxYVert;
                maxYVert = midYVert;
                midYVert = temp;
            }


            if (midYVert.GetY() < minYVert.GetY())
            {
                Vertex temp = midYVert;
                midYVert = minYVert;
                minYVert = temp;
            }


            if (maxYVert.GetY() < midYVert.GetY())
            {
                Vertex temp = maxYVert;
                maxYVert = midYVert;
                midYVert = temp;
            }


            float area       = minYVert.TriangleAreaTimes2(maxYVert, midYVert);
            int   handedness = area >= 0 ? 1 : 0;


            ScanConvertTriangle(minYVert, midYVert, maxYVert, handedness);
            FillShape((int)minYVert.GetY(), (int)maxYVert.GetY());
        }
示例#4
0
        public float TriangleAreaTimes2(Vertex b, Vertex c)
        {
            float x1 = b.GetX() - m_pos.GetX();
            float y1 = b.GetY() - m_pos.GetY();


            float x2 = c.GetX() - m_pos.GetX();
            float y2 = c.GetY() - m_pos.GetY();


            return(x1 * y2 - x2 * y1);
        }
        public void ScanConvertLine(Vertex minYVert, Vertex maxYVert, int whichSide)
        {
            int yStart = (int)minYVert.GetY();
            int yEnd   = (int)maxYVert.GetY();
             		    int xStart = (int)minYVert.GetX();
            int xEnd   = (int)maxYVert.GetX();

             		    int yDist = yEnd - yStart;
            int xDist = xEnd - xStart;

            if(yDist <= 0)
             		    {
                return;
            }

             		    float xStep = (float)xDist/(float)yDist;
             		    float curX = (float)xStart;

             		    for(int j = yStart; j < yEnd; j++)
             		    {
             			    m_scanBuffer[j * 2 + whichSide] = (int)curX;
             			    curX += xStep;
             		    }
        }