Esempio n. 1
0
        public objectX Analyse()
        {
            bool   lFace      = false;
            string TargetFace = "";
            int    FacesAdded = 0;

            List <objX> objects = new List <objX>();

            objX workObject = new objX();

            List <Face3D> readyToAdd = new List <Face3D>();



            int i = 1;

            int xID = 0;

            foreach (string s in FileInput)
            {
                string input = s;
                if (s.Contains("//"))
                {
                    input = s.Substring(0, s.IndexOf("//"));
                }

                if (input.StartsWith("object:"))
                {
                    if (lFace)
                    {
                        DrawInRed("Error on Line " + i.ToString() + ": Expected objectX Face. Got new objectX");
                    }

                    string name = input.Substring(input.IndexOf('"')).Substring(0, input.IndexOf('"')).Replace(@"""", "");

                    string LastVectors = input.Substring(input.IndexOf(":("));

                    LastVectors = LastVectors.Replace(":", "");

                    // MessageBox.Show(LastVectors);

                    Vector3[] rV = RetriveVectors(LastVectors);

                    if (!NameExists(name))
                    {
                        AddName(name);
                        workObject                = new objX();
                        workObject.Name           = name;
                        workObject.Position       = rV[0];
                        workObject.Rotation       = rV[1];
                        workObject.RotationOffset = rV[2];
                    }
                    else
                    {
                        DrawInRed("Error on Line " + i.ToString() + @": objectX """ + name + @""" exists more than once");
                    }
                    FacesAdded = 0;
                    lFace      = true;
                }
                else if (input.StartsWith(":"))
                {
                    if (!lFace)
                    {
                        DrawInRed("Error on Line " + i.ToString() + @": Expected anything but "":"". Got "":""");
                    }
                    else
                    {
                    }

                    if (FacesAdded == 0)
                    {
                        DrawInYellow("Warning on Line " + i.ToString() + @": ObjectX has no faces");
                    }


                    FacesAdded = 0;
                    lFace      = false;
                    //  objects.Add(workObject);

                    workObject.objectFaces = readyToAdd.ToArray();
                    objects.Add(workObject);
                    readyToAdd.Clear();
                }
                else if (input.StartsWith("("))
                {
                    if (!lFace)
                    {
                        DrawInRed("Error on Line " + i.ToString() + @": Expected new objectX. Got objectX Face");
                    }
                    else
                    {
                        Color facecolor = new Color();

                        Vector3[] fourCoords = new Vector3[0];

                        int amount = (input.Length - input.Replace(")(", "").Length) / 2;
                        FacesAdded++;

                        if (amount > 3)
                        {
                            DrawInRed("Error on Line " + i.ToString() + @": Maximum of 4 Vector3 or 2 Colors per objectX Face");
                        }

                        if (!input.Contains(".(") | !input.Contains("."))
                        {
                            DrawInRed("Error on Line " + i.ToString() + @": No Color Found For objectX Face");
                        }
                        else
                        {
                            string colSplit = input.Substring(input.IndexOf('.'));
                            if (!colSplit.Contains(";"))
                            {
                                DrawInRed("Error on Line " + i.ToString() + @": Expected "";""");
                            }
                            else
                            {
                                colSplit = colSplit.Replace(";", "");
                            }

                            if (colSplit.Contains('.'))
                            {
                                colSplit = colSplit.Replace(".", "");
                            }

                            if (colSplit.Contains(')'))
                            {
                                colSplit = colSplit.Replace(")", "");
                            }

                            if (colSplit.Contains('('))
                            {
                                colSplit = colSplit.Replace("(", "");
                            }

                            facecolor = ParseColor(colSplit, i);
                        }

                        if (input.Contains("."))
                        {
                            string dataSplit = input.Substring(0, input.IndexOf('.'));
                            int    Amount    = (dataSplit.Length - dataSplit.Replace(")(", "").Length) / 2;

                            if (Amount < 2 || Amount > 3)
                            {
                                DrawInRed("Error on Line " + i.ToString() + @": Only Three or Four Vector3 Positions are accepted");
                            }
                            else
                            {
                                fourCoords = RetriveVectors(dataSplit);
                            }
                        }
                        else
                        {
                            DrawInRed("Error on Line " + i.ToString() + @": Failed To Extract Face Data");
                        }



                        readyToAdd.Add(new Face3D(fourCoords, facecolor, 0));
                    }
                }



                i++;
            }

            objectX output = new objectX();

            output.objXData = objects.ToArray();

            return(output);
        }
Esempio n. 2
0
        public Bitmap ProcessData(Vector3 camPos, Vector3 camRot, objectX objectXData, Vector3 lightPosition, bool reBake = false)
        {
            GC.Collect();
            Bitmap bmp = new Bitmap(BitmapWidth, BitmapHeight);

            objX[]        TransformedObjects = new objX[objectXData.objXData.Length];
            List <Face3D> TransformedFaces   = new List <Face3D>();
            Stopwatch     sww = new Stopwatch();

            sww.Start();

            foreach (objX xData in objectXData.objXData)
            {
                int i = 0;
                foreach (Face3D fData in xData.objectFaces)
                {
                    Vector3[] FinalCoords = new Vector3[fData.FourCoords.Length];
                    int       ii          = 0;
                    foreach (Vector3 vData in fData.FourCoords)
                    {
                        Vector3 newXYZ = vData + xData.Position;                                                         //Moves The 3 Dimensional Point to the new Point

                        Vector3 newRot = FindNewPosition(newXYZ, xData.RotationOffset + xData.Position, xData.Rotation); //Calculates The new Vector3 Position After A Rotation

                        Vector3 newOUT = FindNewPosition(newRot, camPos, camRot);                                        //Calculates The Final Vector3 Point For The Camera Rotation

                        FinalCoords[ii] = newOUT;

                        ii++;
                    }

                    TransformedFaces.Add(new Face3D(FinalCoords, fData.col, fData.drawOrder));

                    i++;
                }
            }



            TransformedFaces = SortList(TransformedFaces, camPos); //Faces Sorted From Futherst To Closest

            sww.Stop();
            Console.WriteLine(sww.ElapsedMilliseconds.ToString() + "ms to process Faces");

            Stopwatch sw = new Stopwatch();

            sw.Start();
            foreach (Face3D fData in TransformedFaces)
            {
                Vector2[] outputPositions = new Vector2[fData.FourCoords.Length];
                int       i = 0;
                foreach (Vector3 vData in fData.FourCoords)
                {
                    i++;
                    if (!XYZtoXY(vData, camPos, FOV, out outputPositions[i - 1], AspectRatio))
                    {
                        continue; //TODO: Add A Better Camera Position Checking System
                    }
                }

                DrawFace(outputPositions, fData.col, bmp, false);
            }
            sw.Stop();

            Console.WriteLine(sw.ElapsedMilliseconds.ToString() + "ms to render Faces");

            // RayCast(new Vector3(0, 0, 0), new Vector3(25, 25, 25), objectXData);

            return(bmp);
        }