Beispiel #1
0
        /* draw a line (for wireframe display) */
        static void wire(BITMAP b, VTX v1, VTX v2)
        {
            int col = MID(128, 255 - fixtoi(v1.z + v2.z) / 16, 255);

            line(b, fixtoi(v1.x), fixtoi(v1.y), fixtoi(v2.x), fixtoi(v2.y),
                 palette_color[col]);
        }
Beispiel #2
0
        /* draw a quad */
        static void draw_quad(BITMAP b, VTX v1, VTX v2, VTX v3, VTX v4, int mode)
        {
            int col;

            /* four vertices */
            V3D vtx1 = new V3D(0, 0, 0, 0, 0, 0);
            V3D vtx2 = new V3D(0, 0, 0, 32 << 16, 0, 0);
            V3D vtx3 = new V3D(0, 0, 0, 32 << 16, 32 << 16, 0);
            V3D vtx4 = new V3D(0, 0, 0, 0, 32 << 16, 0);

            vtx1.x = v1.x; vtx1.y = v1.y; vtx1.z = v1.z;
            vtx2.x = v2.x; vtx2.y = v2.y; vtx2.z = v2.z;
            vtx3.x = v3.x; vtx3.y = v3.y; vtx3.z = v3.z;
            vtx4.x = v4.x; vtx4.y = v4.y; vtx4.z = v4.z;

            /* cull backfaces */
            if ((mode != POLYTYPE_ATEX_MASK) && (mode != POLYTYPE_PTEX_MASK) &&
                (mode != POLYTYPE_ATEX_MASK_LIT) && (mode != POLYTYPE_PTEX_MASK_LIT) &&
                (polygon_z_normal(ref vtx1, ref vtx2, ref vtx3) < 0))
            {
                return;
            }

            /* set up the vertex color, differently for each rendering mode */
            switch (mode)
            {
            case POLYTYPE_FLAT:
                col    = MID(128, 255 - fixtoi(v1.z + v2.z) / 16, 255);
                vtx1.c = vtx2.c = vtx3.c = vtx4.c = palette_color[col];
                break;

            case POLYTYPE_GCOL:
                vtx1.c = palette_color[0xD0];
                vtx2.c = palette_color[0x80];
                vtx3.c = palette_color[0xB0];
                vtx4.c = palette_color[0xFF];
                break;

            case POLYTYPE_GRGB:
                vtx1.c = 0x000000;
                vtx2.c = 0x7F0000;
                vtx3.c = 0xFF0000;
                vtx4.c = 0x7F0000;
                break;

            case POLYTYPE_ATEX_LIT:
            case POLYTYPE_PTEX_LIT:
            case POLYTYPE_ATEX_MASK_LIT:
            case POLYTYPE_PTEX_MASK_LIT:
                vtx1.c = MID(0, 255 - fixtoi(v1.z) / 4, 255);
                vtx2.c = MID(0, 255 - fixtoi(v2.z) / 4, 255);
                vtx3.c = MID(0, 255 - fixtoi(v3.z) / 4, 255);
                vtx4.c = MID(0, 255 - fixtoi(v4.z) / 4, 255);
                break;
            }

            /* draw the quad */
            quad3d(b, mode, texture, ref vtx1, ref vtx2, ref vtx3, ref vtx4);
        }
Beispiel #3
0
        /* translate shapes from 3d world space to 2d screen space */
        static void translate_shapes()
        {
            int    c, d;
            MATRIX matrix   = new MATRIX();
            int    outpoint = 0;
            int    outface  = 0;

            for (c = 0; c < NUM_SHAPES; c++)
            {
                /* build a transformation matrix */
                get_transformation_matrix(ref matrix, itofix(1),
                                          shapes[c].rx, shapes[c].ry, shapes[c].rz,
                                          shapes[c].x, shapes[c].y, shapes[c].z);

                /* output the vertices */
                for (d = 0; d < NUM_VERTICES; d++)
                {
                    // TODO: salvare i valori in variabili temporanee e poi salvarle in output_points
                    apply_matrix(ref matrix, points[d].x, points[d].y, points[d].z,
                                 ref output_points[d + outpoint].x, ref output_points[d + outpoint].y, ref output_points[d + outpoint].z);
                    persp_project(output_points[d + outpoint].x, output_points[d + outpoint].y, output_points[d + outpoint].z,
                                  ref output_points[d + outpoint].x, ref output_points[d + outpoint].y);
                }

                /* output the faces */
                for (d = 0; d < NUM_FACES; d++)
                {
                    output_faces[d + outface] = faces[d].Clone();
                    VTX[] temp = new VTX[NUM_VERTICES];
                    Array.Copy(output_points, c * NUM_VERTICES, temp, 0, NUM_VERTICES);
                    output_faces[d + outface].vtxlist = temp;
                }

                outpoint += NUM_VERTICES;
                outface  += NUM_FACES;
            }
        }
Beispiel #4
0
        private void ReadRES(DataReader r)
        {
            if (new string(r.ReadChars(4)) != "$RSF")
            {
                Console.WriteLine("error");
            }

            int resourceCount1 = r.ReadInt32();

            r.ReadInt32();
            r.ReadInt32();
            int resourceCount2 = r.ReadInt32();

            r.ReadInt32();
            r.ReadInt32();
            r.ReadInt32();
            string name = r.ReadString(r.Position, -1);

            r.Position += (uint)name.Length;
            r.Align(0x10);

            Console.WriteLine(name);

            VTX prevVTX = null;
            TXR prevTXR = null;

            while (true)
            {
                var start = r.Position;

                if (r.Position >= r.Length)
                {
                    break;
                }

                r.BigEndian = true;
                string key   = r.ReadString(4);
                var    size  = r.ReadUInt32();
                var    flag1 = r.ReadInt32();
                var    flag2 = r.ReadInt32();

                var sectionStart = r.Position;

                r.BigEndian = false;

                Console.WriteLine(start.ToString("X") + " " + key + " " + size.ToString("X"));

                switch (key)
                {
                case "$CT0":
                    r.Position += 12;
                    break;

                case "$VTX":
                    prevVTX = new VTX(r);
                    VTXs.Add(prevVTX);
                    break;

                case "$TXR":
                    prevTXR = new TXR(r);
                    TXRs.Add(prevTXR);
                    break;

                case "$TXI":
                    break;

                case "$RSI":
                    if (prevVTX != null)
                    {
                        prevVTX.ReadResource(r);
                    }
                    if (prevTXR != null)
                    {
                        prevTXR.ReadResource(r);
                    }
                    prevVTX = null;
                    prevTXR = null;
                    break;

                case "$SKL":
                {
                    var f = r.ReadInt32();
                    r.ReadInt16();         // dunno
                    var boneCount = r.ReadInt16();
                    r.ReadInt16();         // dunno
                    r.ReadInt16();         // dunno
                    Stack <int> boneStack = new Stack <int>();
                    for (int i = 0; i < boneCount; i++)
                    {
                        GenericBone bone = new GenericBone();
                        bone.Name        = r.ReadString(sectionStart + r.ReadUInt32(), -1);
                        bone.ParentIndex = boneStack.Count > 0 ? boneStack.Peek() : -1;
                        r.ReadByte();
                        var depth = r.ReadByte();
                        var pop   = r.ReadSByte() + 1;
                        r.ReadByte();
                        boneStack.Push(i);
                        for (int j = 0; j < pop; j++)
                        {
                            boneStack.Pop();
                        }
                        bone.Transform = new OpenTK.Matrix4(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), 0,
                                                            r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), 0,
                                                            r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), 0,
                                                            r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), 1);
                        r.Skip(0x48);
                        Skeleton.Bones.Add(bone);
                    }
                }
                break;

                case "$SCN":

                    break;

                case "$MSH":

                    break;

                case "$TRE":

                    break;

                case "$CLT":

                    break;
                }

                r.Seek(start + size + 0x10);

                if (r.Position % 16 != 0)
                {
                    r.Position += 16 - (r.Position % 16);
                }
            }
        }