Ejemplo n.º 1
0
        public Police(int numberOfInstances, List <TgcBoundingBox> listObjColisionables, TgcBoundingBox scene)
        {
            TgcSkeletalLoader loader    = new TgcSkeletalLoader();
            string            pathMesh  = GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\" + "CS_Gign-TgcSkeletalMesh.xml";
            string            mediaPath = GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\";

            original = loader.loadMeshFromFile(pathMesh, mediaPath);
            loader.loadAnimationFromFile(original, GuiController.Instance.AlumnoEjemplosMediaDir + "Kamikaze3D\\Animations\\Disparar-TgcSkeletalAnim.xml");
            loader.loadAnimationFromFile(original, GuiController.Instance.AlumnoEjemplosMediaDir + "Kamikaze3D\\Animations\\Muerte-TgcSkeletalAnim.xml");
            original.Scale = new Vector3(0.7f, 0.7f, 0.7f);
            addWeapon();

            //Crear la cantidad de instancias de este modelo, pero sin volver a cargar el modelo entero cada vez
            float offset         = 200;
            int   cantInstancias = numberOfInstances;

            instances = new List <TgcSkeletalMesh>();
            for (int i = 0; i < cantInstancias; i++)
            {
                TgcSkeletalMesh instance = original.createMeshInstance(original.Name + i);
                instance.move((i % 20) * offset, 3.5f, (i / 20) * offset);
                instance.Scale = original.Scale;

                if (TgcCollisionUtils.classifyBoxBox(instance.BoundingBox, scene) != TgcCollisionUtils.BoxBoxResult.Encerrando)
                {
                    continue; //si esta afuera del escenario lo descarto
                }
                bool colisionando = false;
                foreach (TgcBoundingBox bb in listObjColisionables)
                {
                    if (TgcCollisionUtils.classifyBoxBox(instance.BoundingBox, bb) != TgcCollisionUtils.BoxBoxResult.Afuera)
                    {
                        colisionando = true;
                        break;
                    }
                }
                if (colisionando)
                {
                    continue;              //Si colisiona con algo no se debe agregar
                }
                instances.Add(instance);
            }

            //Especificar la animación actual para todos los modelos
            original.playAnimation("Disparar");
            foreach (TgcSkeletalMesh instance in instances)
            {
                TgcBoundingBox bb = instance.BoundingBox;
                instance.playAnimation("Disparar");
                instance.BoundingBox = bb;
            }
            //foreach (TgcSkeletalMesh instance in instances)
            //{
            //    instance.playAnimation("Disparar");
            //}
        }
Ejemplo n.º 2
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear suelo
            TgcTexture pisoTexture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\TexturePack2\\rock_floor1.jpg");

            suelo = TgcBox.fromSize(new Vector3(500, 0, 500), new Vector3(2000, 0, 2000), pisoTexture);


            //Cargar malla original
            TgcSkeletalLoader loader    = new TgcSkeletalLoader();
            string            pathMesh  = GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\Robot-TgcSkeletalMesh.xml";
            string            mediaPath = GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\";

            original = loader.loadMeshFromFile(pathMesh, mediaPath);

            //Agregar animación a original
            loader.loadAnimationFromFile(original, mediaPath + "Patear-TgcSkeletalAnim.xml");

            //Agregar attachment a original
            TgcSkeletalBoneAttach attachment = new TgcSkeletalBoneAttach();
            TgcBox attachmentBox             = TgcBox.fromSize(new Vector3(3, 60, 3), Color.Green);

            attachment.Mesh   = attachmentBox.toMesh("attachment");
            attachment.Bone   = original.getBoneByName("Bip01 L Hand");
            attachment.Offset = Matrix.Translation(10, -40, 0);
            attachment.updateValues();
            original.Attachments.Add(attachment);


            //Crear 9 instancias mas de este modelo, pero sin volver a cargar el modelo entero cada vez
            float offset         = 200;
            int   cantInstancias = 4;

            instances = new List <TgcSkeletalMesh>();
            for (int i = 0; i < cantInstancias; i++)
            {
                TgcSkeletalMesh instance = original.createMeshInstance(original.Name + i);

                instance.move(i * offset, 0, 0);
                instances.Add(instance);
            }


            //Especificar la animación actual para todos los modelos
            original.playAnimation("Patear");
            foreach (TgcSkeletalMesh instance in instances)
            {
                instance.playAnimation("Patear");
            }


            //Camara en primera persona
            GuiController.Instance.FpsCamera.Enable        = true;
            GuiController.Instance.FpsCamera.MovementSpeed = 400;
            GuiController.Instance.FpsCamera.JumpSpeed     = 400;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(293.201f, 291.0797f, -604.6647f), new Vector3(299.1028f, -63.9185f, 330.1836f));
        }
Ejemplo n.º 3
0
        public override void Init()
        {
            //Crear suelo
            var pisoTexture = TgcTexture.createTexture(D3DDevice.Instance.Device,
                                                       MediaDir + "Texturas\\Quake\\TexturePack2\\rock_floor1.jpg");

            suelo = TgcBox.fromSize(new Vector3(500, 0, 500), new Vector3(2000, 0, 2000), pisoTexture);

            //Cargar malla original
            var loader    = new TgcSkeletalLoader();
            var pathMesh  = MediaDir + "SkeletalAnimations\\Robot\\Robot-TgcSkeletalMesh.xml";
            var mediaPath = MediaDir + "SkeletalAnimations\\Robot\\";

            original = loader.loadMeshFromFile(pathMesh, mediaPath);

            //Agregar animación a original
            loader.loadAnimationFromFile(original, mediaPath + "Patear-TgcSkeletalAnim.xml");

            //Agregar attachment a original
            var attachment    = new TgcSkeletalBoneAttach();
            var attachmentBox = TgcBox.fromSize(new Vector3(3, 60, 3), Color.Green);

            attachment.Mesh   = attachmentBox.toMesh("attachment");
            attachment.Bone   = original.getBoneByName("Bip01 L Hand");
            attachment.Offset = Matrix.Translation(10, -40, 0);
            attachment.updateValues();
            original.Attachments.Add(attachment);

            //Crear 9 instancias mas de este modelo, pero sin volver a cargar el modelo entero cada vez
            float offset         = 200;
            var   cantInstancias = 4;

            instances = new List <TgcSkeletalMesh>();
            for (var i = 0; i < cantInstancias; i++)
            {
                var instance = original.createMeshInstance(original.Name + i);

                instance.move(i * offset, 0, 0);
                instances.Add(instance);
            }

            //Especificar la animación actual para todos los modelos
            original.playAnimation("Patear");
            foreach (var instance in instances)
            {
                instance.playAnimation("Patear");
            }

            //Camara en primera persona
            Camara = new TgcFpsCamera(new Vector3(293.201f, 291.0797f, -604.6647f));
        }
Ejemplo n.º 4
0
        public override void init()
        {
            camara    = new TgcThirdPersonCamera();
            personaje = new Personaje(camara, new Explosion());

            this.camara.Enable = true;
            this.personaje.getPersonaje().Position = new Vector3(100, 0, 100);
            this.camara.setCamera(this.personaje.getPersonaje().Position, 50, -100);
            this.personaje.init();

            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear suelo
            TgcTexture pisoTexture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\TexturePack2\\rock_floor1.jpg");

            suelo = TgcBox.fromSize(new Vector3(500, 0, 500), new Vector3(4000, 0, 4000), pisoTexture);
            box1  = TgcBox.fromSize(new Vector3(500, 0, 500), new Vector3(550, 550, 550), pisoTexture);
            box2  = TgcBox.fromSize(new Vector3(100, 0, 100), new Vector3(550, 550, 550), pisoTexture);
            box3  = TgcBox.fromSize(new Vector3(1400, 0, 900), new Vector3(550, 550, 550), pisoTexture);

            //Cargar malla original
            TgcSkeletalLoader loader    = new TgcSkeletalLoader();
            string            pathMesh  = GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\" + "CS_Gign-TgcSkeletalMesh.xml";
            string            mediaPath = GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\";

            original = loader.loadMeshFromFile(pathMesh, mediaPath);

            string posicionStr = "Disparar";

            //Agregar animación a original
            loader.loadAnimationFromFile(original, GuiController.Instance.AlumnoEjemplosMediaDir + "Kamikaze3D\\Animations\\" + posicionStr + "-TgcSkeletalAnim.xml");
            //loader.loadAnimationFromFile(original, mediaPath + "Animations\\" + posicionStr + "-TgcSkeletalAnim.xml");

            //Agregar attachment a original
            TgcSkeletalBoneAttach attachment = new TgcSkeletalBoneAttach();
            TgcBox attachmentBox             = TgcBox.fromSize(new Vector3(1, 10, 1), Color.Black);

            Matrix offsetMatrix = Matrix.RotationY(Geometry.DegreeToRadian(190));

            offsetMatrix = Matrix.Multiply(offsetMatrix, Matrix.RotationZ(Geometry.DegreeToRadian(80)));
            offsetMatrix = Matrix.Multiply(offsetMatrix, Matrix.Translation(10, 0, 0));
            offsetMatrix = Matrix.Multiply(offsetMatrix, Matrix.RotationX(Geometry.DegreeToRadian(300)));
            offsetMatrix = Matrix.Multiply(offsetMatrix, Matrix.Translation(-2.5f, -1.5f, 0));

            attachment.Mesh   = attachmentBox.toMesh("attachment");
            attachment.Bone   = original.getBoneByName("Bip01 L Hand");
            attachment.Offset = offsetMatrix;
            attachment.updateValues();
            original.Scale = new Vector3(0.7f, 0.7f, 0.7f);
            original.Attachments.Add(attachment);


            //Crear 9 instancias mas de este modelo, pero sin volver a cargar el modelo entero cada vez
            float offset         = 200;
            int   cantInstancias = 150;

            instances = new List <TgcSkeletalMesh>();
            for (int i = 0; i < cantInstancias; i++)
            {
                TgcSkeletalMesh instance = original.createMeshInstance(original.Name + i);
                instance.move((i % 20) * offset, 0, (i / 20) * offset);
                instance.Scale = original.Scale;
                instances.Add(instance);
            }


            //Especificar la animación actual para todos los modelos
            original.playAnimation(posicionStr);
            foreach (TgcSkeletalMesh instance in instances)
            {
                instance.playAnimation(posicionStr);
            }

            //Crear quadtree
            quadtree = new Quadtree();
            //como el bounding box del suelo no tiene altura se la agrego
            Vector3 Pmax = suelo.BoundingBox.PMax;

            Pmax.Y = Pmax.Y + 500;
            TgcBoundingBox bb = new TgcBoundingBox(suelo.BoundingBox.PMin, Pmax);

            quadtree.create(instances, bb);
            quadtree.createDebugQuadtreeMeshes();

            return;

            //Camara en primera persona
            GuiController.Instance.FpsCamera.Enable        = true;
            GuiController.Instance.FpsCamera.MovementSpeed = 400;
            GuiController.Instance.FpsCamera.JumpSpeed     = 400;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(293.201f, 291.0797f, -604.6647f), new Vector3(299.1028f, -63.9185f, 330.1836f));
        }