Esempio n. 1
0
        public void addVertex(float x, float y, float z, float u, float v)
        {
            warp_Vertex vert = new warp_Vertex(x, y, z);

            vert.setUV(u, v);
            addVertex(vert);
        }
Esempio n. 2
0
        public warp_Vertex getClone()
        {
            warp_Vertex newVertex = new warp_Vertex();

            newVertex.pos = pos.getClone();
            newVertex.n   = n.getClone();
            newVertex.u   = u;
            newVertex.v   = v;

            return(newVertex);
        }
Esempio n. 3
0
        public static warp_Object ROTATIONOBJECT(warp_Vector[] path, int sides)
        {
            int         steps = sides + 1;
            warp_Object newObject = new warp_Object();
            double      alpha = 2 * pi / ((double)steps - 1);
            float       qx, qz;
            int         nodes = path.GetLength(0);
            warp_Vertex vertex = null;
            float       u, v;       // Texture coordinates

            for (int j = 0; j < steps; j++)
            {
                u = (float)(steps - j - 1) / (float)(steps - 1);
                for (int i = 0; i < nodes; i++)
                {
                    v  = (float)i / (float)(nodes - 1);
                    qx = (float)(path[i].x * Math.Cos(j * alpha) +
                                 path[i].z * Math.Sin(j * alpha));
                    qz = (float)(path[i].z * Math.Cos(j * alpha) -
                                 path[i].x * Math.Sin(j * alpha));
                    vertex   = new warp_Vertex(qx, path[i].y, qz);
                    vertex.u = u;
                    vertex.v = v;
                    newObject.addVertex(vertex);
                }
            }

            for (int j = 0; j < steps - 1; j++)
            {
                for (int i = 0; i < nodes - 1; i++)
                {
                    newObject.addTriangle(i + nodes * j, i + nodes * (j + 1),
                                          i + 1 + nodes * j);
                    newObject.addTriangle(i + nodes * (j + 1),
                                          i + 1 + nodes * (j + 1),
                                          i + 1 + nodes * j);
                }
            }

            for (int i = 0; i < nodes - 1; i++)
            {
                newObject.addTriangle(i + nodes * (steps - 1), i,
                                      i + 1 + nodes * (steps - 1));
                newObject.addTriangle(i, i + 1, i + 1 + nodes * (steps - 1));
            }
            return(newObject);
        }
Esempio n. 4
0
 public warp_Edge(warp_Vertex v1, warp_Vertex v2)
 {
     a = v1;
     b = v2;
 }
Esempio n. 5
0
 public bool equals(warp_Vertex v, float tolerance)
 {
     return(Math.Abs(warp_Vector.sub(pos, v.pos).length()) < tolerance);
 }
Esempio n. 6
0
 public bool equals(warp_Vertex v)
 {
     return((pos.x == v.pos.x) && (pos.y == v.pos.y) && (pos.z == v.pos.z));
 }
Esempio n. 7
0
        public static warp_Object TUBE(warp_Vector[] path, float r, int steps, bool closed)
        {
            warp_Vector[] circle = new warp_Vector[steps];
            float         angle;

            for (int i = 0; i < steps; i++)
            {
                angle     = 2 * 3.14159265f * (float)i / (float)steps;
                circle[i] = new warp_Vector(r * warp_Math.cos(angle),
                                            r * warp_Math.sin(angle), 0f);
            }

            warp_Object newObject = new warp_Object();
            int         segments = path.GetLength(0);
            warp_Vector forward, up, right;
            warp_Matrix frenetmatrix;
            warp_Vertex tempvertex;
            float       relx, rely;
            int         a, b, c, d;

            for (int i = 0; i < segments; i++)
            {
                // Calculate frenet frame matrix

                if (i != segments - 1)
                {
                    forward = warp_Vector.sub(path[i + 1], path[i]);
                }
                else
                {
                    if (!closed)
                    {
                        forward = warp_Vector.sub(path[i], path[i - 1]);
                    }
                    else
                    {
                        forward = warp_Vector.sub(path[1], path[0]);
                    }
                }

                forward.normalize();
                up           = new warp_Vector(0f, 0f, 1f);
                right        = warp_Vector.getNormal(forward, up);
                up           = warp_Vector.getNormal(forward, right);
                frenetmatrix = new warp_Matrix(right, up, forward);
                frenetmatrix.shift(path[i].x, path[i].y, path[i].z);

                // Add nodes

                relx = (float)i / (float)(segments - 1);
                for (int k = 0; k < steps; k++)
                {
                    rely         = (float)k / (float)steps;
                    tempvertex   = new warp_Vertex(circle[k].transform(frenetmatrix));
                    tempvertex.u = relx;
                    tempvertex.v = rely;
                    newObject.addVertex(tempvertex);
                }
            }

            for (int i = 0; i < segments - 1; i++)
            {
                for (int k = 0; k < steps - 1; k++)
                {
                    a = i * steps + k;
                    b = a + 1;
                    c = a + steps;
                    d = b + steps;
                    newObject.addTriangle(a, c, b);
                    newObject.addTriangle(b, c, d);
                }
                a = (i + 1) * steps - 1;
                b = a + 1 - steps;
                c = a + steps;
                d = b + steps;
                newObject.addTriangle(a, c, b);
                newObject.addTriangle(b, c, d);
            }

            return(newObject);
        }
Esempio n. 8
0
 public warp_Triangle(warp_Vertex a, warp_Vertex b, warp_Vertex c)
 {
     p1 = a;
     p2 = b;
     p3 = c;
 }
Esempio n. 9
0
 public void removeVertex(warp_Vertex v)
 {
     vertexData.Remove(v);
 }
Esempio n. 10
0
 public void addVertex(warp_Vertex newVertex)
 {
     newVertex.parent = this;
     vertexData.Add(newVertex);
     dirty = true;
 }
Esempio n. 11
0
 public void addTriangle(warp_Vertex a, warp_Vertex b, warp_Vertex c)
 {
     addTriangle(new warp_Triangle(a, b, c));
 }
Esempio n. 12
0
        private unsafe void drawLine(warp_Vertex a, warp_Vertex b, int color)
        {
            warp_Vertex temp;

            if ((a.clipcode & b.clipcode) != 0)
            {
                return;
            }

            dx = (int)Math.Abs(a.x - b.x);
            dy = (int)Math.Abs(a.y - b.y);
            dz = 0;

            fixed(int *sp = screen.pixels, zB = zBuffer)
            {
                if (dx > dy)
                {
                    if (a.x > b.x)
                    {
                        temp = a;
                        a    = b;
                        b    = temp;
                    }
                    if (dx > 0)
                    {
                        dz = (b.z - a.z) / dx;
                        dy = ((b.y - a.y) << 16) / dx;
                    }
                    z = a.z;
                    y = a.y << 16;
                    for (int x = a.x; x <= b.x; x++)
                    {
                        int y2 = y >> 16;
                        if (warp_Math.inrange(x, 0, width - 1) && warp_Math.inrange(y2, 0, height - 1))
                        {
                            offset = y2 * width + x;
                            if (z < zB[offset])
                            {
                                {
                                    sp[offset] = color;
                                    zB[offset] = z;
                                }
                            }
                        }
                        z += dz;
                        y += dy;
                    }
                }
                else
                {
                    if (a.y > b.y)
                    {
                        temp = a;
                        a    = b;
                        b    = temp;
                    }
                    if (dy > 0)
                    {
                        dz = (b.z - a.z) / dy;
                        dx = ((b.x - a.x) << 16) / dy;
                    }
                    z = a.z;
                    int x = a.x << 16;
                    for (y = a.y; y <= b.y; y++)
                    {
                        int x2 = x >> 16;
                        if (warp_Math.inrange(x2, 0, width - 1) && warp_Math.inrange(y, 0, height - 1))
                        {
                            offset = y * width + x2;
                            if (z < zB[offset])
                            {
                                {
                                    sp[offset] = color;
                                    zB[offset] = z;
                                }
                            }
                        }
                        z += dz;
                        x += dx;
                    }
                }
            }
        }
Esempio n. 13
0
        public void render(warp_Triangle tri)
        {
            if (!ready || tri.parent == null)
            {
                return;
            }

            if ((mode & W) != 0)
            {
                drawWireframe(tri, color);
                if ((mode & ~W) == 0)
                {
                    return;
                }
            }


            warp_Vertex p1 = tri.p1;
            warp_Vertex p2 = tri.p2;
            warp_Vertex p3 = tri.p3;
            warp_Vertex tempVertex;

            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)
            {
                int lutID = (int)(tri.n2.x * 127 + 127) + ((int)(tri.n2.y * 127 + 127) << 8);
                int c     = warp_Color.multiply(color, diffuse[lutID]);
                int s     = warp_Color.scale(specular[lutID], reflectivity);
                currentColor = warp_Color.add(c, s);
            }

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

            dy = y2 - y1;
            int dy31 = y3 - y1;

            float tf = (float)dy / dy31;
            int   x4 = x1 + (int)((x3 - x1) * tf);

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

            x1 <<= 8;
            x2 <<= 8;
            x3 <<= 8;
            x4 <<= 8;

            //temp = (dy21 << 8) / dy31;

            int z1 = p1.z;
            int z3 = p3.z;
            //z4 = z1 + ((z3 - z1) >> 8) * temp;
            int z4 = z1 + (int)((z3 - z1) * tf);
            int z2 = p2.z;

            dz = (z4 - z2) / dx;

            int nx1 = p1.nx;
            int nx3 = p3.nx;
            //nx4 = nx1 + ((nx3 - nx1) >> 8) * temp;
            int nx4 = nx1 + (int)((nx3 - nx1) * tf);
            int nx2 = p2.nx;

            dnx = (nx4 - nx2) / dx;

            int ny1 = p1.ny;
            int ny3 = p3.ny;
            //ny4 = ny1 + ((ny3 - ny1) >> 8) * temp;
            int ny4 = ny1 + (int)((ny3 - ny1) * tf);
            int ny2 = p2.ny;

            dny = (ny4 - ny2) / dx;

            float tx1 = p1.tx * tw;
            float tx3 = p3.tx * tw;
            float tx4 = tx1 + ((tx3 - tx1) * tf);
            float tx2 = p2.tx * tw;

            dtx = (tx4 - tx2) / dx;

            float ty1 = p1.ty * th;
            float ty3 = p3.ty * th;
            float ty4 = ty1 + ((ty3 - ty1) * tf);
            float ty2 = p2.ty * th;

            dty = (ty4 - ty2) / dx;

            float sw1 = p1.invZ;
            float sw3 = p3.invZ;
            float sw4 = sw1 + ((sw3 - sw1) * tf);
            float sw2 = p2.invZ;

            dsw = (sw4 - sw2) / dx;

            if (dx < 0)
            {
                int temp = x2;
                x2  = x4;
                x4  = temp;
                z2  = z4;
                tx2 = tx4;
                ty2 = ty4;
                sw2 = sw4;
                nx2 = nx4;
                ny2 = ny4;
            }

            if (y2 >= 0 && 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;
                }

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

            dy = y3 - y2;
            if (y2 < height && 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;
                }

                if (y3 > height)
                {
                    y3 = height;
                }
                offset = y2 * width;

                for (y = y2; y < y3; y++)
                {
                    renderLine();
                }
            }
        }