示例#1
0
        public static Parallelepiped fromSizePosition(TGCVector3 size, TGCVector3 pos)
        {
            var box = new Parallelepiped();

            box.setVertex(size, pos);
            return(box);
        }
示例#2
0
        private void addTrees()
        {
            var pino = GetMeshFromScene("Pino-TgcScene.xml");

            pino.AlphaBlendEnable = false;//no se porque lo tenia seteado en true

            for (int j = 1; j < Chunks.chunksPerDim - 1; j++)
            {
                for (int k = 1; k < Chunks.chunksPerDim - 1; k++)
                {
                    if (coordsOccupied(j, k))
                    {
                        continue;
                    }

                    for (var i = 0; i < treesPerChunk; i++)
                    {
                        Meshc meshc = new Meshc();
                        meshc.mesh = pino;
                        meshc.type = 1;

                        TGCVector3 pos = genPosInChunk(j, k);

                        var scale = TGCVector3.One * Random.Next(20, 500);

                        meshc.originalMesh = TGCMatrix.Scaling(scale) * TGCMatrix.Translation(pos);

                        var box  = meshc.mesh.BoundingBox;
                        var size = box.calculateSize();
                        var posb = box.calculateBoxCenter();

                        size.X *= .1f;
                        size.Z *= .1f;

                        posb.X -= size.X * .2f;

                        meshc.paralleliped = Parallelepiped.fromSizePosition(
                            size,
                            posb
                            );


                        meshc.deformation     = new TGCMatrix();
                        meshc.deformation.M11 = (float)Random.NextDouble() * 2f - 1f;
                        meshc.deformation.M12 = (float)Random.NextDouble() * 2f - 1f;
                        meshc.deformation.M13 = (float)Random.NextDouble() * 2f - 1f;
                        meshc.deformation.M21 = (float)Random.NextDouble() * 2f - 1f;
                        meshc.deformation.M22 = (float)Random.NextDouble() * 2f - 1f;
                        meshc.deformation.M23 = (float)Random.NextDouble() * 2f - 1f;
                        meshc.deformation.M31 = (float)Random.NextDouble() * 2f - 1f;
                        meshc.deformation.M32 = (float)Random.NextDouble() * 2f - 1f;
                        meshc.deformation.M33 = (float)Random.NextDouble() * 2f - 1f;
                        meshc.deformation.M42 = -1.4f;

                        meshc.deform();
                    }
                }
            }
        }
示例#3
0
        public void addCandles()
        {
            candleMesh = GetMeshFromScene("Vela-TgcScene.xml");
            //candleMesh.Effect = shader;
            //candleMesh.Technique = "DIFFUSE_MAP";
            for (int i = 0; i < g.cameraSprites.candlesInMap; i++)
            {
                int j, k;
                do
                {
                    j = Random.Next(1, Chunks.chunksPerDim - 1);
                    k = Random.Next(1, Chunks.chunksPerDim - 1);

                    var pos = genPosInChunk(j, k);
                    pos.Y += 200f;

                    if (checkColission(pos, 700f))
                    {
                        continue;
                    }

                    var candleMeshc = new Meshc();
                    //un poco excesivo que sea un meshc, lo eficiente seria que vela sea un tipo propio con una colision
                    //por radio. Pero hacer eso hace agregar un nuevo tipo de meshc, lo que podria hacer el codigo mas lento
                    //si sigo el camino de no usar polimorfismo. Igual ni ganas de agregar otro tipo. Que sea un meshc tiene
                    //los beneficios de que se va a poder deformar, y estas colisiones van a evitar que las velas se superpongan
                    //aunque agregar codigo para que se haga eso tampoco es una locura

                    candleMeshc.mesh         = candleMesh;
                    candleMeshc.originalMesh = TGCMatrix.Scaling(new TGCVector3(10, 15, 10)) * TGCMatrix.Translation(pos);

                    var box  = candleMeshc.mesh.BoundingBox;
                    var size = box.calculateSize();
                    var posb = box.calculateBoxCenter();

                    size.X *= 2.5f;
                    size.Y *= 10f;
                    size.Z *= 2.5f; //estaria bueno que tgc tenga multiplicacion miembro a miembro

                    candleMeshc.paralleliped = Parallelepiped.fromSizePosition(
                        size,
                        posb
                        );

                    //no uso  transformColission porque hace caer 4 vertices, lo que tiene potencial de registrar la
                    //vela en mas de un chunk
                    candleMeshc.paralleliped.transform(candleMeshc.originalMesh);
                    Chunk c = g.chunks.fromCoordinates(candleMeshc.paralleliped.transformedVertex[0]);
                    if (c != null)
                    {
                        c.meshes.Add(candleMeshc);
                    }

                    break;
                } while (true);
            }
        }
示例#4
0
        public static Parallelepiped fromBounding(TgcBoundingAxisAlignBox b)
        {
            var box = new Parallelepiped();

            var size = b.calculateSize();
            var pos  = b.calculateBoxCenter();

            box.setVertex(size, pos);
            return(box);
        }
示例#5
0
        public void addVertexFall(Parallelepiped par, MultiMeshc meshc)
        {
            Action <TGCVector3> addToChunk = v =>
            {
                Chunk c = fromCoordinates(v);
                if (c != null)
                {
                    if (!c.multimeshes.Contains(meshc))
                    {
                        c.multimeshes.Add(meshc);
                        c.parallelepipedsOfMultimesh.Add(par);
                    }
                    else
                    {
                        if (!c.parallelepipedsOfMultimesh.Contains(par))
                        {
                            c.parallelepipedsOfMultimesh.Add(par);
                        }
                    }
                }
            };

            foreach (TGCVector3 vertex in par.transformedVertex)
            {
                addToChunk(vertex);
            }

            Action <int, int, float> extraVertex = (v1, v2, w1) =>
            {
                float w2     = 1f - w1;
                var   vertex = new TGCVector3(par.transformedVertex[v1].X * w1 + par.transformedVertex[v2].X * w2,
                                              0,
                                              par.transformedVertex[v1].Z * w1 + par.transformedVertex[v2].Z * w2);
                addToChunk(vertex);
            };

            extraVertex(0, 4, .5f);
            extraVertex(0, 1, .5f);
            extraVertex(1, 5, .5f);
            extraVertex(4, 5, .5f);//@optim puede que tirar vertex del piso no sea necesario, ver al final

            extraVertex(2, 6, .5f);
            extraVertex(2, 3, .5f);
            extraVertex(3, 7, .5f);
            extraVertex(6, 7, .5f);

            extraVertex(2, 7, .5f);
            extraVertex(2, 7, .25f);
            extraVertex(2, 7, .75f);

            extraVertex(4, 1, .5f);
            extraVertex(4, 1, .25f);
            extraVertex(4, 1, .75f);
        }
示例#6
0
        public bool pointParallelipedXZColission(Parallelepiped par, TGCVector3 pos, float colissionLen)
        {
            var ray = new TgcRay();

            ray.Direction = new TGCVector3(1, 0, 0);
            ray.Origin    = pos + new TGCVector3(-colissionLen, 0, 0);

            if (par.intersectRay(ray, out float t, out TGCVector3 q) && t < 2f * colissionLen)
            {
                return(true);
            }

            ray.Direction = new TGCVector3(0, 0, 1);
            ray.Origin    = pos + new TGCVector3(0, 0, -colissionLen);

            if (par.intersectRay(ray, out t, out q) && t < 2f * colissionLen)
            {
                return(true);
            }
            return(false);
        }
示例#7
0
        public static Parallelepiped fromVertex(
            float x0, float y0, float z0,
            float x1, float y1, float z1,
            float x2, float y2, float z2,
            float x3, float y3, float z3,
            float x4, float y4, float z4,
            float x5, float y5, float z5,
            float x6, float y6, float z6,
            float x7, float y7, float z7
            )
        {
            var box = new Parallelepiped();

            box.vertex[0] = new TGCVector3(x0, y0, z0);
            box.vertex[1] = new TGCVector3(x1, y1, z1);
            box.vertex[2] = new TGCVector3(x2, y2, z2);
            box.vertex[3] = new TGCVector3(x3, y3, z3);
            box.vertex[4] = new TGCVector3(x4, y4, z4);
            box.vertex[5] = new TGCVector3(x5, y5, z5);
            box.vertex[6] = new TGCVector3(x6, y6, z6);
            box.vertex[7] = new TGCVector3(x7, y7, z7);
            return(box);
        }
示例#8
0
        void addChurch()
        {
            var loader = new TgcSceneLoader();
            var scene  = loader.loadSceneFromFile(g.game.MediaDir + "church-TgcScene.xml");

            var mm = new MultiMeshc();

            mm.originalMesh = TGCMatrix.Translation(0, -160, 0)
                              * TGCMatrix.Scaling(75, 75, 75);

            int cantBoxes = 0;

            foreach (var m in scene.Meshes)
            {
                if (m.Name.StartsWith("Box"))
                {
                    cantBoxes++;
                }
            }
            const int putByHand = 7;

            mm.meshes        = new TgcMesh[scene.Meshes.Count - cantBoxes];
            mm.parallelipeds = new Parallelepiped[cantBoxes + putByHand];

            int meshIndex = 0;
            int parIndex  = 0;

            foreach (var m in scene.Meshes)
            {
                if (m.Name.StartsWith("Box"))
                {
                    var par = Parallelepiped.fromBounding(m.BoundingBox);
                    mm.parallelipeds[parIndex++] = par;
                    par.transform(mm.originalMesh);
                    g.chunks.addVertexFall(par, mm);
                }
                else
                {
                    m.AutoTransformEnable  = false;
                    mm.meshes[meshIndex++] = m;
                }
            }

            //---
            //+--
            //-+-
            //++-
            //--+
            //+-+
            //-++
            //+++

            //techito
            mm.parallelipeds[parIndex++] = Parallelepiped.fromVertex(
                1, 472, -257,
                66, 413, -257,
                1, 430, -257,
                32, 413, -257,
                1, 472, -214,
                66, 413, -214,
                1, 430, -214,
                32, 413, -214

                );
            mm.parallelipeds[parIndex++] = Parallelepiped.fromVertex(
                -62, 414, -257,
                -29, 414, -257,
                1, 469, -257,
                1, 430, -257,
                -62, 414, -213,
                -29, 414, -213,
                1, 469, -213,
                1, 430, -213
                );

            //bordes
            mm.parallelipeds[parIndex++] = Parallelepiped.fromVertex(
                -93, 279, -257,
                -58, 279, -257,
                -58, 327, -257,
                -58.5f, 327.5f, -257,
                -93, 279, -213,
                -58, 279, -213,
                -58, 327, -213,
                -58.5f, 327.5f, -213
                );
            mm.parallelipeds[parIndex++] = Parallelepiped.fromVertex(
                95, 279, -257,
                69, 279, -257,
                69, 317, -257,
                69.5f, 317.5f, -257,
                95, 279, -213,
                69, 279, -213,
                69, 317, -213,
                69.5f, 317.5f, -213
                );

            //fondo
            mm.parallelipeds[parIndex++] = Parallelepiped.fromVertex(
                166, 230, 260,
                -163, 230, 260,
                0, 332, 260,
                0.5f, 332.5f, 260,
                166, 230, 239,
                -163, 230, 239,
                0, 332, 239,
                0.5f, 332.5f, 239
                );


            //techo
            mm.parallelipeds[parIndex++] = Parallelepiped.fromVertex(
                172, 227, 264,
                0, 227f, 264,
                172, 231, 264,
                0, 341, 264,
                172, 227, -217,
                0, 227f, -217,
                172, 231, -217,
                0, 341, -217
                );
            mm.parallelipeds[parIndex++] = Parallelepiped.fromVertex(
                -172, 227, 264,
                0, 227f, 264,
                -172, 231, 264,
                0, 341, 264,
                -172, 227, -217,
                0, 227f, -217,
                -172, 231, -217,
                0, 341, -217
                );//puede que el que tenga forma de triangulo cause problemas con alguna deformacion por los
                  //vertex fall, pero por ahora no parece haber problema


            mm.deformation     = new TGCMatrix();
            mm.deformation.M21 = 1;
            mm.deformation.M22 = 1.5f;

            for (int i = cantBoxes; i < cantBoxes + putByHand; i++)
            {
                var par = mm.parallelipeds[i];
                par.transform(mm.originalMesh);
                g.chunks.addVertexFall(par, mm);
            }

            /*
             * //partes de la iglesia no caen en ningun vertex, las agrego manualmente
             * var addToChunk = new Action<TGCVector3>(v => {
             *  var c = g.chunks.fromCoordinates(v);
             *  if (!c.multimeshes.Contains(mm))
             *  {
             *      c.multimeshes.Add(mm);
             *  }
             * });
             *
             * addToChunk(new TGCVector3(-7168f, 0, 18671f));
             * addToChunk(new TGCVector3(124, 0, -345));
             * addToChunk(new TGCVector3(-1991, 0, -8930));
             * addToChunk(new TGCVector3(-3159, 0, 3621));
             * addToChunk(new TGCVector3(2258, 0, 3767));
             *
             * //centro de la iglesia ( -2879,753   -10917,6   3882,9  )
             */

            mm.type = 0;
        }