예제 #1
0
        private void RotateCDIPoly(zdb_CDIPoly cPoly, double angleX, double angleY)
        {
            double sinX = Math.Sin(angleX);
            double cosX = Math.Cos(angleX);

            double sinY = Math.Sin(angleY);
            double cosY = Math.Cos(angleY);

            int i;

            for (i = 0; i < cPoly.vertexCount; i++)
            {
                double x = System.Convert.ToDouble(cPoly.Vertices[i].X);
                double y = System.Convert.ToDouble(cPoly.Vertices[i].Y);
                double z = System.Convert.ToDouble(cPoly.Vertices[i].Z);

                cPoly.Vertices[i].X = System.Convert.ToSingle((x * cosX - z * sinX));
                cPoly.Vertices[i].Z = System.Convert.ToSingle((z * cosX + x * sinX));

                z = System.Convert.ToDouble(cPoly.Vertices[i].Z);

                cPoly.Vertices[i].Y = System.Convert.ToSingle((y * cosY - z * sinY));
                cPoly.Vertices[i].Z = System.Convert.ToSingle((z * cosY + y * sinY));
            }
        }
예제 #2
0
        private void button6_Click(object sender, EventArgs e)
        {
            DialogResult dlgRet;
            string       fName;

            openFileDialog1.FileName = "";
            openFileDialog1.Filter   = "*.RAW; *.BIN|*.raw;*.bin|*.* Any|*.*";
            dlgRet = openFileDialog1.ShowDialog();
            if (dlgRet.ToString() == "Cancel")
            {
                return;
            }
            fName = openFileDialog1.FileName;

            byte[] fData;
            if (System.IO.File.Exists(fName) == false)
            {
                return;
            }

            try
            {
                fData = System.IO.File.ReadAllBytes(fName);
            }
            catch
            {
                return;
            }

            int         i; int i2; long Mem32; int polyCount = 0;
            zdb_CDIPoly tmpPoly = new zdb_CDIPoly();

            cdiPoly.Clear();
            ZoomLevel     = 1;
            ShiftXAmmount = 0;
            ShiftYAmmount = 0;

            for (i = 0; i < fData.Count(); i += 4)
            {
                Mem32 = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i];
                if (Mem32 == 0x00843264)//0x006e5880)
                {
                    tmpPoly.Pointer_CDIPOLY = Mem32;
                    i += 4;
                    tmpPoly.Header_Line_1 = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i];
                    i += 4;
                    tmpPoly.Header_Line_2 = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i];
                    i += 4;
                    tmpPoly.Header_Line_3 = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i];
                    tmpPoly.vertexCount   = fData[i] / 4;
                    i += 4;
                    tmpPoly.Header_Line_4 = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i];
                    i += 4;
                    tmpPoly.Pointer_Vertices = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i];

                    if (tmpPoly.Pointer_Vertices > 0)
                    {
                        tmpPoly.AlignmentPadding = tmpPoly.Pointer_Vertices - i;

                        i += (int)tmpPoly.AlignmentPadding;

                        tmpPoly.Vertices = new zdb_CDIPoly_Vertex[tmpPoly.vertexCount];
                        for (i2 = 0; i2 < tmpPoly.vertexCount; i2++)
                        {
                            Mem32 = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i]; i += 4;
                            tmpPoly.Vertices[i2].X = BitConverter.ToSingle(BitConverter.GetBytes(Mem32), 0);
                            Mem32 = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i]; i += 4;
                            tmpPoly.Vertices[i2].Y = BitConverter.ToSingle(BitConverter.GetBytes(Mem32), 0);
                            Mem32 = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i]; i += 4;
                            tmpPoly.Vertices[i2].Z = BitConverter.ToSingle(BitConverter.GetBytes(Mem32), 0);
                            Mem32 = (fData[i + 3] * 0x1000000) + (fData[i + 2] * 0x10000) + (fData[i + 1] * 0x100) + fData[i]; i += 4;
                            tmpPoly.Vertices[i2].Unknown4 = Mem32;
                        }

                        cdiPoly.Add(tmpPoly);
                        polyCount++;
                    }
                }
            }

            Single smallestX = 1000000; Single largestX = -1000000;
            Single smallestY = 1000000; Single largestY = -1000000;
            Single smallestZ = 1000000; Single largestZ = -1000000;

            for (i = 0; i < cdiPoly.Count; i++)
            {
                if (cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].X < smallestX)
                {
                    smallestX = cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].X;
                }
                if (cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].Y < smallestY)
                {
                    smallestY = cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].Y;
                }
                if (cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].Z < smallestZ)
                {
                    smallestZ = cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].Z;
                }

                if (cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].X > largestX)
                {
                    largestX = cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].X;
                }
                if (cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].Y > largestY)
                {
                    largestY = cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].Y;
                }
                if (cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].Z > largestZ)
                {
                    largestZ = cdiPoly.ElementAt <zdb_CDIPoly>(i).Vertices[0].Z;
                }
            }

            MessageBox.Show(polyCount.ToString() + " Total CDIPoly"
                            + "\nSmallest X: " + smallestX.ToString()
                            + "\nSmallest Y: " + smallestY.ToString()
                            + "\nSmallest Z: " + smallestZ.ToString()
                            + "\nLargest X: " + largestX.ToString()
                            + "\nLargest Y: " + largestY.ToString()
                            + "\nLargest Z: " + largestZ.ToString());
        }