void enqueueTriangle(warp_Triangle tri)
        {
            if (tri.parent.material == null)
            {
                return;
            }
            if (tri.visible == false)
            {
                return;
            }
            if ((tri.parent.material.transparency == 255) &&
                (tri.parent.material.reflectivity == 0))
            {
                return;
            }

            if (tri.parent.material.transparency > 0)
            {
                transparentQueue.Add(tri);
            }
            else
            {
                opaqueQueue.Add(tri);
            }
        }
Пример #2
0
 public void registerNeighbor(warp_Triangle triangle)
 {
     if (!neighbor.Contains(triangle))
     {
         neighbor.Add(triangle);
     }
 }
        public warp_Object identifyObjectAt(int xpos, int ypos)
        {
            warp_Triangle tri = identifyTriangleAt(xpos, ypos);

            if (tri == null)
            {
                return(null);
            }
            return(tri.parent);
        }
        warp_Triangle[] getTransparentQueue()
        {
            if (transparentQueue.Count == 0)
            {
                return(null);
            }
            IEnumerator enumerator = transparentQueue.GetEnumerator();

            warp_Triangle[] tri = new warp_Triangle[transparentQueue.Count];

            int id = 0;

            while (enumerator.MoveNext())
            {
                tri [id++] = (warp_Triangle)enumerator.Current;
            }

            return(sortTriangles(tri, 0, tri.GetLength(0) - 1));
        }
Пример #5
0
		void drawWireframe (warp_Triangle tri, int defaultcolor)
		{
			drawLine (tri.p1, tri.p2, defaultcolor);
			drawLine (tri.p2, tri.p3, defaultcolor);
			drawLine (tri.p3, tri.p1, defaultcolor);
		}
Пример #6
0
		public void render (warp_Triangle tri)
		{
			if (!ready)
			{
				return;
			}
			if (tri.parent == null)
			{
				return;
			}
			if ((mode & W) != 0)
			{
				drawWireframe (tri, color);
				if ((mode & W) == 0)
				{
					return;
				}
			}

			p1 = tri.p1;
			p2 = tri.p2;
			p3 = tri.p3;

			if (p1.y > p2.y)
			{
				tempVertex = p1;
				p1 = p2;
				p2 = tempVertex;
			}
			if (p2.y > p3.y)
			{
				tempVertex = p2;
				p2 = p3;
				p3 = tempVertex;
			}
			if (p1.y > p2.y)
			{
				tempVertex = p1;
				p1 = p2;
				p2 = tempVertex;
			}

			if (p1.y >= height)
			{
				return;
			}
			if (p3.y < 0)
			{
				return;
			}
			if (p1.y == p3.y)
			{
				return;
			}

			if (mode == F)
			{
				lutID = (int)(tri.n2.x * 127 + 127) + ((int)(tri.n2.y * 127 + 127) << 8);
				c = warp_Color.multiply (color, diffuse [lutID]);
				s = warp_Color.scale (specular [lutID], reflectivity);
				currentColor = warp_Color.add (c, s);
			}

			currentId = (tri.parent.id << 16) | tri.id;

			x1 = p1.x << 8;
			x2 = p2.x << 8;
			x3 = p3.x << 8;
			y1 = p1.y;
			y2 = p2.y;
			y3 = p3.y;

			x4 = x1 + (x3 - x1) * (y2 - y1) / (y3 - y1);
			x1 <<= 8;
			x2 <<= 8;
			x3 <<= 8;
			x4 <<= 8;

			z1 = p1.z;
			z2 = p2.z;
			z3 = p3.z;
			nx1 = p1.nx << 16;
			nx2 = p2.nx << 16;
			nx3 = p3.nx << 16;
			ny1 = p1.ny << 16;
			ny2 = p2.ny << 16;
			ny3 = p3.ny << 16;

			sw1 = 1.0f / p1.sw;
			sw2 = 1.0f / p2.sw;
			sw3 = 1.0f / p3.sw;

			tx1 = p1.tx * sw1;
			tx2 = p2.tx * sw2;
			tx3 = p3.tx * sw3;
			ty1 = p1.ty * sw1;
			ty2 = p2.ty * sw2;
			ty3 = p3.ty * sw3;

			dx = (x4 - x2) >> 16;
			if (dx == 0)
			{
				return;
			}

			temp = 256 * (y2 - y1) / (y3 - y1);

			z4 = z1 + ((z3 - z1) >> 8) * temp;
			nx4 = nx1 + ((nx3 - nx1) >> 8) * temp;
			ny4 = ny1 + ((ny3 - ny1) >> 8) * temp;

			float tf = (float)(y2 - y1) / (float)(y3 - y1);

			tx4 = tx1 + ((tx3 - tx1) * tf);
			ty4 = ty1 + ((ty3 - ty1) * tf);

			sw4 = sw1 + ((sw3 - sw1) * tf);

			dz = (z4 - z2) / dx;
			dnx = (nx4 - nx2) / dx;
			dny = (ny4 - ny2) / dx;
			dtx = (tx4 - tx2) / dx;
			dty = (ty4 - ty2) / dx;
			dsw = (sw4 - sw2) / dx;

			if (dx < 0)
			{
				temp = x2;
				x2 = x4;
				x4 = temp;
				z2 = z4;
				tx2 = tx4;
				ty2 = ty4;
				sw2 = sw4;
				nx2 = nx4;
				ny2 = ny4;
			}
			if (y2 >= 0)
			{
				dy = y2 - y1;
				if (dy != 0)
				{
					dxL = (x2 - x1) / dy;
					dxR = (x4 - x1) / dy;
					dzBase = (z2 - z1) / dy;
					dnxBase = (nx2 - nx1) / dy;
					dnyBase = (ny2 - ny1) / dy;
					dtxBase = (tx2 - tx1) / dy;
					dtyBase = (ty2 - ty1) / dy;
					dswBase = (sw2 - sw1) / dy;
				}

				xBase = x1;
				xMax = x1;
				zBase = z1;
				nxBase = nx1;
				nyBase = ny1;
				txBase = tx1;
				tyBase = ty1;
				swBase = sw1;

				if (y1 < 0)
				{
					xBase -= y1 * dxL;
					xMax -= y1 * dxR;
					zBase -= y1 * dzBase;
					nxBase -= y1 * dnxBase;
					nyBase -= y1 * dnyBase;
					txBase -= y1 * dtxBase;
					tyBase -= y1 * dtyBase;
					swBase -= y1 * dswBase;
					y1 = 0;
				}

				y2 = (y2 < height) ? y2 : height;
				offset = y1 * width;
				for (y = y1; y < y2; y++)
				{
					renderLine ();
				}
			}

			if (y2 < height)
			{
				dy = y3 - y2;
				if (dy != 0)
				{
					dxL = (x3 - x2) / dy;
					dxR = (x3 - x4) / dy;
					dzBase = (z3 - z2) / dy;
					dnxBase = (nx3 - nx2) / dy;
					dnyBase = (ny3 - ny2) / dy;
					dtxBase = (tx3 - tx2) / dy;
					dtyBase = (ty3 - ty2) / dy;
					dswBase = (sw3 - sw2) / dy;
				}

				xBase = x2;
				xMax = x4;
				zBase = z2;
				nxBase = nx2;
				nyBase = ny2;
				txBase = tx2;
				tyBase = ty2;
				swBase = sw2;

				if (y2 < 0)
				{
					xBase -= y2 * dxL;
					xMax -= y2 * dxR;
					zBase -= y2 * dzBase;
					nxBase -= y2 * dnxBase;
					nyBase -= y2 * dnyBase;
					txBase -= y2 * dtxBase;
					tyBase -= y2 * dtyBase;
					swBase -= y2 * dswBase;
					y2 = 0;
				}

				y3 = (y3 < height) ? y3 : height;
				offset = y2 * width;

				for (y = y2; y < y3; y++)
				{
					renderLine ();
				}
			}
		}
 void drawWireframe(warp_Triangle tri, int defaultcolor)
 {
     drawLine(tri.p1, tri.p2, defaultcolor);
     drawLine(tri.p2, tri.p3, defaultcolor);
     drawLine(tri.p3, tri.p1, defaultcolor);
 }
        public void render(warp_Triangle tri)
        {
            if (!ready)
            {
                return;
            }
            if (tri.parent == null)
            {
                return;
            }
            if ((mode & W) != 0)
            {
                drawWireframe(tri, color);
                if ((mode & W) == 0)
                {
                    return;
                }
            }

            p1 = tri.p1;
            p2 = tri.p2;
            p3 = tri.p3;

            if (p1.y > p2.y)
            {
                tempVertex = p1;
                p1         = p2;
                p2         = tempVertex;
            }
            if (p2.y > p3.y)
            {
                tempVertex = p2;
                p2         = p3;
                p3         = tempVertex;
            }
            if (p1.y > p2.y)
            {
                tempVertex = p1;
                p1         = p2;
                p2         = tempVertex;
            }

            if (p1.y >= height)
            {
                return;
            }
            if (p3.y < 0)
            {
                return;
            }
            if (p1.y == p3.y)
            {
                return;
            }

            if (mode == F)
            {
                lutID        = (int)(tri.n2.x * 127 + 127) + ((int)(tri.n2.y * 127 + 127) << 8);
                c            = warp_Color.multiply(color, diffuse [lutID]);
                s            = warp_Color.scale(specular [lutID], reflectivity);
                currentColor = warp_Color.add(c, s);
            }

            currentId = (tri.parent.id << 16) | tri.id;

            x1 = p1.x << 8;
            x2 = p2.x << 8;
            x3 = p3.x << 8;
            y1 = p1.y;
            y2 = p2.y;
            y3 = p3.y;

            x4   = x1 + (x3 - x1) * (y2 - y1) / (y3 - y1);
            x1 <<= 8;
            x2 <<= 8;
            x3 <<= 8;
            x4 <<= 8;

            z1  = p1.z;
            z2  = p2.z;
            z3  = p3.z;
            nx1 = p1.nx << 16;
            nx2 = p2.nx << 16;
            nx3 = p3.nx << 16;
            ny1 = p1.ny << 16;
            ny2 = p2.ny << 16;
            ny3 = p3.ny << 16;

            sw1 = 1.0f / p1.sw;
            sw2 = 1.0f / p2.sw;
            sw3 = 1.0f / p3.sw;

            tx1 = p1.tx * sw1;
            tx2 = p2.tx * sw2;
            tx3 = p3.tx * sw3;
            ty1 = p1.ty * sw1;
            ty2 = p2.ty * sw2;
            ty3 = p3.ty * sw3;

            dx = (x4 - x2) >> 16;
            if (dx == 0)
            {
                return;
            }

            temp = 256 * (y2 - y1) / (y3 - y1);

            z4  = z1 + ((z3 - z1) >> 8) * temp;
            nx4 = nx1 + ((nx3 - nx1) >> 8) * temp;
            ny4 = ny1 + ((ny3 - ny1) >> 8) * temp;

            float tf = (float)(y2 - y1) / (float)(y3 - y1);

            tx4 = tx1 + ((tx3 - tx1) * tf);
            ty4 = ty1 + ((ty3 - ty1) * tf);

            sw4 = sw1 + ((sw3 - sw1) * tf);

            dz  = (z4 - z2) / dx;
            dnx = (nx4 - nx2) / dx;
            dny = (ny4 - ny2) / dx;
            dtx = (tx4 - tx2) / dx;
            dty = (ty4 - ty2) / dx;
            dsw = (sw4 - sw2) / dx;

            if (dx < 0)
            {
                temp = x2;
                x2   = x4;
                x4   = temp;
                z2   = z4;
                tx2  = tx4;
                ty2  = ty4;
                sw2  = sw4;
                nx2  = nx4;
                ny2  = ny4;
            }
            if (y2 >= 0)
            {
                dy = y2 - y1;
                if (dy != 0)
                {
                    dxL     = (x2 - x1) / dy;
                    dxR     = (x4 - x1) / dy;
                    dzBase  = (z2 - z1) / dy;
                    dnxBase = (nx2 - nx1) / dy;
                    dnyBase = (ny2 - ny1) / dy;
                    dtxBase = (tx2 - tx1) / dy;
                    dtyBase = (ty2 - ty1) / dy;
                    dswBase = (sw2 - sw1) / dy;
                }

                xBase  = x1;
                xMax   = x1;
                zBase  = z1;
                nxBase = nx1;
                nyBase = ny1;
                txBase = tx1;
                tyBase = ty1;
                swBase = sw1;

                if (y1 < 0)
                {
                    xBase  -= y1 * dxL;
                    xMax   -= y1 * dxR;
                    zBase  -= y1 * dzBase;
                    nxBase -= y1 * dnxBase;
                    nyBase -= y1 * dnyBase;
                    txBase -= y1 * dtxBase;
                    tyBase -= y1 * dtyBase;
                    swBase -= y1 * dswBase;
                    y1      = 0;
                }

                y2     = (y2 < height) ? y2 : height;
                offset = y1 * width;
                for (y = y1; y < y2; y++)
                {
                    renderLine();
                }
            }

            if (y2 < height)
            {
                dy = y3 - y2;
                if (dy != 0)
                {
                    dxL     = (x3 - x2) / dy;
                    dxR     = (x3 - x4) / dy;
                    dzBase  = (z3 - z2) / dy;
                    dnxBase = (nx3 - nx2) / dy;
                    dnyBase = (ny3 - ny2) / dy;
                    dtxBase = (tx3 - tx2) / dy;
                    dtyBase = (ty3 - ty2) / dy;
                    dswBase = (sw3 - sw2) / dy;
                }

                xBase  = x2;
                xMax   = x4;
                zBase  = z2;
                nxBase = nx2;
                nyBase = ny2;
                txBase = tx2;
                tyBase = ty2;
                swBase = sw2;

                if (y2 < 0)
                {
                    xBase  -= y2 * dxL;
                    xMax   -= y2 * dxR;
                    zBase  -= y2 * dzBase;
                    nxBase -= y2 * dnxBase;
                    nyBase -= y2 * dnyBase;
                    txBase -= y2 * dtxBase;
                    tyBase -= y2 * dtyBase;
                    swBase -= y2 * dswBase;
                    y2      = 0;
                }

                y3     = (y3 < height) ? y3 : height;
                offset = y2 * width;

                for (y = y2; y < y3; y++)
                {
                    renderLine();
                }
            }
        }
Пример #9
0
		public void registerNeighbor (warp_Triangle triangle)
		{
			if (!neighbor.Contains (triangle))
				neighbor.Add (triangle);
		}
 public void removeTriangle(warp_Triangle t)
 {
     triangleData.Remove(t);
 }
 public void addTriangle(warp_Triangle newTriangle)
 {
     newTriangle.parent = this;
     triangleData.Add(newTriangle);
     dirty = true;
 }
Пример #12
0
		warp_Triangle[] sortTriangles (warp_Triangle[] tri, int L, int R)
		{
			//FIX: Added Index bounds checking. (Was causing random exceptions) - Created by: X
			if (L < 0)
				L = 0;
			if (L > tri.Length)
				L = tri.Length;
			if (R < 0)
				R = 0;
			if (R > tri.Length)
				R = tri.Length;
			// - Created by: X

			float m = (tri [L].dist + tri [R].dist) * 0.5f;
			int i = L;
			int j = R;
			warp_Triangle temp;

			do
			{
				while (tri [i].dist > m)
					i++;
				while (tri [j].dist < m)
					j--;

				if (i <= j)
				{
					temp = tri [i];
					tri [i] = tri [j];
					tri [j] = temp;
					i++;
					j--;
				}
			} while (j >= i);

			if (L < j)
				sortTriangles (tri, L, j);
			if (R > i)
				sortTriangles (tri, i, R);

			return tri;
		}
Пример #13
0
		warp_Triangle[] getTransparentQueue ()
		{
			if (transparentQueue.Count == 0)
				return null;
			IEnumerator enumerator = transparentQueue.GetEnumerator ();
			warp_Triangle[] tri = new warp_Triangle[transparentQueue.Count];

			int id = 0;
			while (enumerator.MoveNext ())
				tri [id++] = (warp_Triangle)enumerator.Current;

			return sortTriangles (tri, 0, tri.GetLength (0) - 1);
		}
Пример #14
0
		void enqueueTriangle (warp_Triangle tri)
		{
			if (tri.parent.material == null)
			{
				return;
			}
			if (tri.visible == false)
			{
				return;
			}
			if ((tri.parent.material.transparency == 255) &&
			    (tri.parent.material.reflectivity == 0))
			{
				return;
			}

			if (tri.parent.material.transparency > 0)
			{
				transparentQueue.Add (tri);
			} else
			{
				opaqueQueue.Add (tri);
			}
		}
Пример #15
0
		public void removeTriangle (warp_Triangle t)
		{
			triangleData.Remove (t);
		}
Пример #16
0
		public void addTriangle (warp_Triangle newTriangle)
		{
			newTriangle.parent = this;
			triangleData.Add (newTriangle);
			dirty = true;
		}