Esempio n. 1
0
        public void AddCone(string name, Color c)
        {
            QuadList modl = new QuadList();

            List <VertexPositionColorTexture> vptc = new List <VertexPositionColorTexture>();

            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, -10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, -10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(0, 0, 0), MGConverter.Blend(Color.Black, c), new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, 10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            modl.PushQuad(vptc);

            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, 10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, 10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(0, 0, 0), MGConverter.Blend(Color.Black, c), new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, -10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            modl.PushQuad(vptc);

            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, -10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(10, 50, 10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, -10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            vptc.Add(new VertexPositionColorTexture(new Vector3(-10, 50, 10), MGConverter.Blend(Color.LightGray, c), new Vector2(0, 0)));
            modl.PushQuad(vptc);

            modl.Seal();

            instmodels.Add(name, modl);
        }
Esempio n. 2
0
        public void ResetCamera()
        {
            if (scn.Count > 0)
            {
                camera.Position    = MGConverter.ToVector3(scn[0].header.startGrid[0].Position);
                lowcamera.Position = camera.Position;

                camera.SetRotation((float)(scn[0].header.startGrid[0].Angle.Y / 1024 * Math.PI * 2), scn[0].header.startGrid[0].Angle.X / 1024);
                lowcamera.SetRotation((float)(scn[0].header.startGrid[0].Angle.Y / 1024 * Math.PI * 2), scn[0].header.startGrid[0].Angle.X / 1024);
                skycamera.SetRotation((float)(scn[0].header.startGrid[0].Angle.Y / 1024 * Math.PI * 2), scn[0].header.startGrid[0].Angle.X / 1024);

                Console.WriteLine(scn[0].header.startGrid[0].Angle.ToString());
            }
        }
Esempio n. 3
0
        public void ResetCamera()
        {
            if (scn.Count > 0)
            {
                camera.Position      = MGConverter.ToVector3(scn[0].header.startGrid[0].Position, 0.01f);
                rightCamera.Position = camera.Position;
                leftCamera.Position  = camera.Position;

                camera.SetRotation((float)(scn[0].header.startGrid[0].Angle.X / 4096f * Math.PI * 2), (float)(scn[0].header.startGrid[0].Angle.Z / 4096 * Math.PI * 2));
                rightCamera.SetRotation((float)(scn[0].header.startGrid[0].Angle.X / 4096f * Math.PI * 2), (float)(scn[0].header.startGrid[0].Angle.Z / 4096 * Math.PI * 2));
                leftCamera.SetRotation((float)(scn[0].header.startGrid[0].Angle.X / 4096f * Math.PI * 2), (float)(scn[0].header.startGrid[0].Angle.Z / 4096 * Math.PI * 2));
                skycamera.SetRotation((float)(scn[0].header.startGrid[0].Angle.X / 4096f * Math.PI * 2), (float)(scn[0].header.startGrid[0].Angle.Z / 4096 * Math.PI * 2));

                UpdateCameras(new GameTime());

                Console.WriteLine(scn[0].header.startGrid[0].Angle.ToString());
            }
        }
Esempio n. 4
0
        public MGLevel(SkyBox sb)
        {
            normal.textureEnabled   = false;
            normal.scrollingEnabled = false;

            for (int i = 0; i < sb.faces.Count; i++)
            {
                List <VertexPositionColorTexture> tri = new List <VertexPositionColorTexture>();
                tri.Add(MGConverter.ToVptc(sb.verts[sb.faces[i].X], new CTRFramework.Shared.Vector2b(0, 0), 0.01f));
                tri.Add(MGConverter.ToVptc(sb.verts[sb.faces[i].Y], new CTRFramework.Shared.Vector2b(0, 0), 0.01f));
                tri.Add(MGConverter.ToVptc(sb.verts[sb.faces[i].Z], new CTRFramework.Shared.Vector2b(0, 0), 0.01f));

                normal.PushTri(tri);
            }

            normal.Seal();

            wire = new TriList(normal);
            wire.SetColor(Color.Red);
        }
Esempio n. 5
0
        private void BspDraw(VisData visDat, Scene scene, int level)
        {
            List <VisData> childVisData = scene.GetVisDataChildren(visDat); // if node has children get those children

            if (childVisData != null && childVisData.Count > 0)             // has any children?
            {
                foreach (var b in childVisData)
                {
                    if (b.IsLeaf) // leaves don't have children
                    {
                        bbox2.Add(MGConverter.ToLineList(b.bbox, Color.Magenta));
                    }
                    else
                    {
                        BspDraw(b, scene, level + 1);
                        // show those children in different color than the parent
                        bbox.Add(MGConverter.ToLineList(b.bbox, colorLevelsOfBsp[level % colorLevelsOfBsp.Length]));
                    }
                }
            }
        }
Esempio n. 6
0
        private void LoadLevel()
        {
            if (File.Exists("karts.lev"))
            {
                Scene karts = Scene.FromFile("karts.lev");

                foreach (LODModel m in karts.dynamics)
                {
                    if (!instTris.ContainsKey(m.name) && m.name == "selectkart")
                    {
                        List <VertexPositionColorTexture> li = new List <VertexPositionColorTexture>();

                        foreach (var x in m.lh[0].verts)
                        {
                            li.Add(MGConverter.ToVptc(x, new Vector2b(0, 0)));
                        }

                        TriList t = new TriList();
                        t.textureEnabled   = false;
                        t.textureName      = "test";
                        t.scrollingEnabled = false;
                        t.PushTri(li);
                        t.Seal();

                        instTris.Add(m.name, t);
                    }
                }
            }

            RenderEnabled = false;

            //wait for the end of frame
            while (IsDrawing)
            {
            }
            ;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            Console.WriteLine("LoadLevel()");

            scn.Clear();
            levels.Clear();
            quads_low.Clear();
            instanced.Clear();

            string[] files = new string[] { };

            if (Directory.Exists(@"levels\"))
            {
                files = Directory.GetFiles(@"levels\", "*.lev");
            }

            if (files.Length == 0)
            {
                Console.WriteLine("no files");
                return;
            }

            foreach (string s in files)
            {
                scn.Add(Scene.FromFile(s));
            }

            Console.WriteLine("scenes parsed at: " + sw.Elapsed.TotalSeconds);


            foreach (Scene s in scn)
            {
                levels.Add(new MGLevel(s, Detail.Med));
                quads_low.Add(new MGLevel(s, Detail.Low));
            }

            Console.WriteLine("converted scenes to monogame render at: " + sw.Elapsed.TotalSeconds);

            //force 1st scene sky and back color
            if (scn.Count > 0)
            {
                backColor = MGConverter.ToColor(scn[0].header.backColor);
                if (scn[0].skybox != null)
                {
                    sky = new MGLevel(scn[0].skybox);
                }
            }

            foreach (Scene s in scn)
            {
                if (s.unkadv != null)
                {
                    foreach (PosAng pa in s.unkadv.smth)
                    {
                        instanced.Add(new InstancedModel("limecone", new Vector3(pa.Position.X, pa.Position.Y, pa.Position.Z), Vector3.Zero, 3));
                    }
                }

                if (s.header.ptru2 != 0)
                {
                    foreach (Vector3s v in s.posu2)
                    {
                        instanced.Add(new InstancedModel("goldcone", new Vector3(v.X, v.Y, v.Z), Vector3.Zero, 3));
                    }
                }

                if (s.header.ptrTrialData != 0)
                {
                    foreach (PosAng v in s.posu1)
                    {
                        instanced.Add(new InstancedModel("browncone", new Vector3(v.Position.X, v.Position.Y, v.Position.Z), Vector3.Zero, 30));
                    }
                }
            }


            foreach (Scene s in scn)
            {
                foreach (LODModel m in s.dynamics)
                {
                    if (!instTris.ContainsKey(m.name))
                    {
                        List <VertexPositionColorTexture> li = new List <VertexPositionColorTexture>();

                        foreach (var x in m.lh[0].verts)
                        {
                            li.Add(MGConverter.ToVptc(x, new Vector2b(0, 0)));
                        }

                        TriList t = new TriList();
                        t.textureEnabled   = false;
                        t.textureName      = "test";
                        t.scrollingEnabled = false;
                        t.PushTri(li);
                        t.Seal();

                        instTris.Add(m.name, t);
                    }
                }
            }

            karts.Add(new Kart("selectkart", MGConverter.ToVector3(scn[0].header.startGrid[0].Position), Vector3.Left, 0.5f));


            Console.WriteLine("extracted dynamics at: " + sw.Elapsed.TotalSeconds);



            foreach (Scene s in scn)
            {
                foreach (PosAng pa in s.header.startGrid)
                {
                    instanced.Add(new InstancedModel("purplecone", new Vector3(pa.Position.X, pa.Position.Y, pa.Position.Z), Vector3.Zero, 3));
                }

                foreach (PickupHeader ph in s.pickups)
                {
                    instanced.Add(new InstancedModel(
                                      ph.ModelName,
                                      new Vector3(ph.Position.X, ph.Position.Y, ph.Position.Z),
                                      new Vector3((float)(ph.Angle.X / 4094f * Math.PI * 2), (float)(ph.Angle.Y / 4094f * Math.PI * 2), (float)(ph.Angle.Z / 4094f * Math.PI * 2)),
                                      1));
                }

                foreach (PosAng n in s.restartPts)
                {
                    paths.Add(new InstancedModel("cyancone", new Vector3(n.Position.X, n.Position.Y, n.Position.Z), Vector3.Zero, 3));
                }

                if (s.nav.paths.Count == 3)
                {
                    foreach (NavFrame n in s.nav.paths[0].frames)
                    {
                        paths.Add(new InstancedModel("greencone", new Vector3(n.position.X, n.position.Y, n.position.Z), Vector3.Zero, 3));
                    }
                    foreach (NavFrame n in s.nav.paths[1].frames)
                    {
                        paths.Add(new InstancedModel("yellowcone", new Vector3(n.position.X, n.position.Y, n.position.Z), Vector3.Zero, 3));
                    }
                    foreach (NavFrame n in s.nav.paths[2].frames)
                    {
                        paths.Add(new InstancedModel("redcone", new Vector3(n.position.X, n.position.Y, n.position.Z), Vector3.Zero, 3));
                    }
                }
            }


            foreach (Scene s in scn)
            {
                s.ExportTexturesAll("levels\\tex");
            }

            Console.WriteLine("textures extracted at: " + sw.Elapsed.TotalSeconds);

            //files = Directory.GetFiles("tex", "*.png");

            foreach (MGLevel q in levels)
            {
                LoadTextures(q);
            }
            foreach (MGLevel q in quads_low)
            {
                LoadTextures(q);
            }

            sw.Stop();

            Console.WriteLine("textures loaded. level done: " + sw.Elapsed.TotalSeconds);

            RenderEnabled = true;
        }
Esempio n. 7
0
        private void LoadLevel(string[] lev)
        {
            if (lev == null)
            {
                lev = new string[] { }
            }
            ;

            Dispose();
            LoadGenericTextures(); //making sure we have default textures loaded. maybe should just allocate statically?

            if (File.Exists("karts.lev"))
            {
                Scene karts = Scene.FromFile("karts.lev");

                foreach (CtrModel m in karts.dynamics)
                {
                    if (!instTris.ContainsKey(m.Name) && m.Name == "selectkart")
                    {
                        List <VertexPositionColorTexture> li = new List <VertexPositionColorTexture>();

                        foreach (var x in m.headers[0].verts)
                        {
                            li.Add(MGConverter.ToVptc(x, new Vector2b(0, 0), 0.01f));
                        }

                        TriList t = new TriList();
                        t.textureEnabled   = false;
                        t.textureName      = "test";
                        t.scrollingEnabled = false;
                        t.PushTri(li);
                        t.Seal();

                        instTris.Add(m.Name, t);
                    }
                }
            }

            RenderEnabled = false;

            //wait for the end of frame, in case we are still rendering.
            while (IsDrawing)
            {
            }
            ;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            Console.WriteLine("LoadLevel()");

            string[] files = new string[] { };

            if (lev.Length == 0)
            {
                if (Directory.Exists(@"levels\"))
                {
                    files = Directory.GetFiles(@"levels\", "*.lev");
                }
            }
            else
            {
                files = lev;
            }

            if (files.Length == 0)
            {
                Console.WriteLine("no files");
                return;
            }

            foreach (string s in files)
            {
                scn.Add(Scene.FromFile(s));
            }

            Console.WriteLine("scenes parsed at: " + sw.Elapsed.TotalSeconds);

            //loading textures between scenes and conversion to monogame for alpha textures info
            LoadTextures();

            foreach (Scene s in scn)
            {
                MeshHigh.Add(new MGLevel(s, Detail.Med));
                MeshLow.Add(new MGLevel(s, Detail.Low));
            }

            Console.WriteLine("converted scenes to monogame render at: " + sw.Elapsed.TotalSeconds);

            //force 1st scene sky and back color
            if (scn.Count > 0)
            {
                backColor = MGConverter.ToColor(scn[0].header.backColor);
                if (scn[0].skybox != null)
                {
                    sky = new MGLevel(scn[0].skybox);
                }
            }

            foreach (Scene s in scn)
            {
                if (s.unkadv != null)
                {
                    foreach (var pa in s.unkadv.smth)
                    {
                        instanced.Add(new InstancedModel("limecone", MGConverter.ToVector3(pa.Position, 0.01f), Vector3.Zero, 0.03f));
                    }
                }

                if (s.header.ptru2 != 0)
                {
                    foreach (var v in s.posu2)
                    {
                        instanced.Add(new InstancedModel("goldcone", MGConverter.ToVector3(v, 0.01f), Vector3.Zero, 0.03f));
                    }
                }

                if (s.header.ptrTrialData != 0)
                {
                    foreach (var v in s.posu1)
                    {
                        instanced.Add(new InstancedModel("browncone", MGConverter.ToVector3(v.Position, 0.01f), Vector3.Zero, 0.03f));
                    }
                }
            }


            foreach (Scene s in scn)
            {
                foreach (CtrModel m in s.dynamics)
                {
                    if (!instTris.ContainsKey(m.Name))
                    {
                        List <VertexPositionColorTexture> li = new List <VertexPositionColorTexture>();

                        foreach (var x in m.headers[0].verts)
                        {
                            li.Add(MGConverter.ToVptc(x, new Vector2b(0, 0), 0.01f));
                        }

                        TriList t = new TriList();
                        t.textureEnabled   = false;
                        t.textureName      = "test";
                        t.scrollingEnabled = false;
                        t.PushTri(li);
                        t.Seal();

                        instTris.Add(m.Name, t);
                    }
                }
            }

            //karts.Add(new Kart("selectkart", MGConverter.ToVector3(scn[0].header.startGrid[0].Position), Vector3.Left, 0.5f));


            Console.WriteLine("extracted dynamics at: " + sw.Elapsed.TotalSeconds);

            foreach (Scene s in scn)
            {
                foreach (var pa in s.header.startGrid)
                {
                    instanced.Add(new InstancedModel("purplecone", MGConverter.ToVector3(pa.Position, 0.01f), Vector3.Zero, 0.03f));
                }

                foreach (var ph in s.pickups)
                {
                    instanced.Add(new InstancedModel(
                                      ph.ModelName,
                                      MGConverter.ToVector3(ph.Position, 0.01f),
                                      Vector3.Zero,//new Vector3((float)(ph.Angle.X / 4094f * Math.PI * 2), (float)(ph.Angle.Y / 4094f * Math.PI * 2), (float)(ph.Angle.Z / 4094f * Math.PI * 2)),
                                      1f));
                }

                foreach (var n in s.restartPts)
                {
                    paths.Add(new InstancedModel("cyancone", MGConverter.ToVector3(n.Position, 0.01f), Vector3.Zero, 0.03f));
                }

                if (s.nav.paths.Count == 3)
                {
                    foreach (NavFrame n in s.nav.paths[0].frames)
                    {
                        paths.Add(new InstancedModel("greencone", MGConverter.ToVector3(n.position, 0.01f), Vector3.Zero, 0.03f));
                    }
                    foreach (NavFrame n in s.nav.paths[1].frames)
                    {
                        paths.Add(new InstancedModel("yellowcone", MGConverter.ToVector3(n.position, 0.01f), Vector3.Zero, 0.03f));
                    }
                    foreach (NavFrame n in s.nav.paths[2].frames)
                    {
                        paths.Add(new InstancedModel("redcone", MGConverter.ToVector3(n.position, 0.01f), Vector3.Zero, 0.03f));
                    }
                }
            }



            //foreach (Scene s in scn)
            //    s.ExportTexturesAll(Path.Combine(Meta.BasePath, "levels\\tex"));


            Console.WriteLine("textures extracted at: " + sw.Elapsed.TotalSeconds);

            //files = Directory.GetFiles("tex", "*.png");

            foreach (Scene s in scn)
            {
                BspDraw(s.visdata[0], s, 0);
            }

            sw.Stop();

            Console.WriteLine("textures loaded. level done: " + sw.Elapsed.TotalSeconds);

            UpdateEffects();

            RenderEnabled = true;
        }
Esempio n. 8
0
        public MGLevel(Scene s, Detail detail)
        {
            List <VertexPositionColorTexture> monolist = new List <VertexPositionColorTexture>();
            List <CTRFramework.Vertex>        vts      = new List <Vertex>();

            switch (detail)
            {
            case Detail.Low:
            {
                Console.WriteLine("doin low");

                foreach (QuadBlock qb in s.quads)
                {
                    monolist.Clear();
                    vts = qb.GetVertexListq(s.verts, -1);

                    if (vts != null)
                    {
                        foreach (Vertex cv in vts)
                        {
                            monolist.Add(MGConverter.ToVptc(cv, cv.uv, 0.01f));
                        }

                        TextureLayout t = qb.texlow;

                        string texTag = t.Tag();

                        foreach (QuadFlags fl in (QuadFlags[])Enum.GetValues(typeof(QuadFlags)))
                        {
                            if (qb.quadFlags.HasFlag(fl))
                            {
                                Push(flagq, fl.ToString(), monolist, "flag");
                            }
                        }

                        if (qb.isWater)
                        {
                            Push(waterq, "water", monolist);
                            continue;
                        }

                        if (qb.quadFlags.HasFlag(QuadFlags.InvisibleTriggers))
                        {
                            Push(flagq, "invis", monolist);
                            continue;
                        }

                        if (Game1.alphalist.Contains(texTag))
                        {
                            Push(alphaq, texTag, monolist);
                        }
                        else
                        {
                            Push(normalq, texTag, monolist);
                        }
                    }
                }

                break;
            }

            case Detail.Med:
            {
                Console.WriteLine("doin med");

                foreach (QuadBlock qb in s.quads)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        monolist.Clear();
                        vts = qb.GetVertexListq(s.verts, j);

                        if (vts != null)
                        {
                            foreach (Vertex cv in vts)
                            {
                                monolist.Add(MGConverter.ToVptc(cv, cv.uv, 0.01f));
                            }

                            bool   isAnimated = false;
                            string texTag     = "test";

                            if (qb.ptrTexMid[j] != 0)
                            {
                                isAnimated = qb.tex[j].isAnimated;
                                if (texTag != "00000000")
                                {
                                    texTag = qb.tex[j].midlods[2].Tag();
                                }
                            }

                            foreach (QuadFlags fl in (QuadFlags[])Enum.GetValues(typeof(QuadFlags)))
                            {
                                if (qb.quadFlags.HasFlag(fl))
                                {
                                    Push(flagq, fl.ToString(), monolist, "flag");
                                }
                            }

                            if (qb.isWater)
                            {
                                Push(waterq, "water", monolist);
                                continue;
                            }

                            if (qb.quadFlags.HasFlag(QuadFlags.InvisibleTriggers))
                            {
                                Push(flagq, "invis", monolist);
                                continue;
                            }

                            Push((isAnimated ? animatedq : (Game1.alphalist.Contains(texTag) ? alphaq : normalq)), texTag, monolist);

                            if (isAnimated)
                            {
                                animatedq[texTag].scrollingEnabled = true;
                            }
                        }
                    }
                }

                break;
            }
            }

            foreach (var ql in normalq)
            {
                ql.Value.Seal();
            }

            foreach (var ql in waterq)
            {
                ql.Value.Seal();
            }

            foreach (var ql in alphaq)
            {
                ql.Value.Seal();
            }

            foreach (var ql in animatedq)
            {
                ql.Value.Seal();
            }

            foreach (var ql in flagq)
            {
                ql.Value.Seal();
            }
        }