Exemple #1
0
 public void CreateOOB()
 {
     //Hacemos un OOB a partir de un AABB mas chico porque el original es muy grande.
     this.OOB = TgcBoundingOrientedBox.computeFromAABB(new TgcBoundingAxisAlignBox(TGCVector3.Multiply(Scene.BoundingBox.PMin, OOBScale), TGCVector3.Multiply(Scene.BoundingBox.PMax, OOBScale)));
     this.OOB.move(this.MovementVector);
     this.OOB.rotate(this.RotationVector);
 }
        public PlataformaRotante(TgcMesh plataformaMesh, Escenario escenario, int coeficienteRotacion) : base(plataformaMesh, escenario)
        {
            this.plataformaMesh      = plataformaMesh;
            this.escenario           = escenario;
            this.coeficienteRotacion = coeficienteRotacion;

            this.plataformaMesh.AutoTransform         = false;
            this.plataformaMesh.AutoUpdateBoundingBox = false;


            //Defino angulo de rotacion --> coeficiente puede ser -1 o 1, define direccion de rotacion
            anguloRotacion  = FastMath.ToRad(15f);
            anguloRotacion *= coeficienteRotacion;


            //Defino Matrices para rotacion del mesh de la plataforma
            posicionInicialBB = this.plataformaMesh.BoundingBox.calculateBoxCenter();
            matrizTranslacionPosicionInicial = TGCMatrix.Translation(posicionInicialBB);
            matrizTranslacionOrigen          = TGCMatrix.Translation(new TGCVector3(-posicionInicialBB.X, -posicionInicialBB.Y, -posicionInicialBB.Z));

            //Defino OrientedBoundingBox y hago el Dispose() de la AABB
            OBB = TgcBoundingOrientedBox.computeFromAABB(this.plataformaMesh.BoundingBox);
            OBB.setRenderColor(System.Drawing.Color.Empty);
            vRotacionOBB = new TGCVector3(0f, anguloRotacion, 0f);

            // plataformaMesh.BoundingBox.Dispose();
        }
Exemple #3
0
        public static void updateObbFromSegment(TgcBoundingOrientedBox obb, TGCVector3 a, TGCVector3 b, float thickness)
        {
            var lineDiff   = b - a;
            var lineLength = lineDiff.Length();
            var lineVec    = TGCVector3.Normalize(lineDiff);

            //Obtener angulo y vector de rotacion
            var upVec        = TGCVector3.Up;
            var angle        = FastMath.Acos(TGCVector3.Dot(upVec, lineVec));
            var axisRotation = TGCVector3.Cross(upVec, lineVec);

            axisRotation.Normalize();

            //Obtener matriz de rotacion para este eje y angulo
            var rotM = TGCMatrix.RotationAxis(axisRotation, angle);

            //Actualizar orientacion de OBB en base a matriz de rotacion
            obb.Orientation[0] = new TGCVector3(rotM.M11, rotM.M12, rotM.M13);
            obb.Orientation[1] = new TGCVector3(rotM.M21, rotM.M22, rotM.M23);
            obb.Orientation[2] = new TGCVector3(rotM.M31, rotM.M32, rotM.M33);

            //Actualizar extent de OBB segun el thickness del segmento
            obb.Extents = new TGCVector3(thickness, lineLength / 2, thickness);

            //Actualizar centro del OBB segun centro del segmento
            obb.Center = a + TGCVector3.Scale(lineDiff, 0.5f);

            //Regenerar OBB
            obb.updateValues();
        }
Exemple #4
0
        private void computarBoundingBox()
        {
            obb = TgcBoundingOrientedBox.computeFromAABB(Mesh.BoundingBox);
            var yMin = Mesh.BoundingBox.PMin.Y;
            var yMax = Mesh.BoundingBox.PMax.Y;

            obbPosY     = (yMax + yMin) / 2 + yMin;
            obb.Extents = new Vector3(obb.Extents.X, obb.Extents.Y, obb.Extents.Z);
        }
        private void initBoxColisionador()
        {
            this.getMesh().AutoTransformEnable   = false;
            this.getMesh().AutoUpdateBoundingBox = false;
            boxDeColision = TgcBoundingOrientedBox.computeFromAABB(this.getMesh().BoundingBox);
            var yMin = this.getMesh().BoundingBox.PMin.Y;
            var yMax = this.getMesh().BoundingBox.PMax.Y;

            //            boxDeColision.Extents = new Vector3(boxDeColision.Extents.X, boxDeColision.Extents.Y, boxDeColision.Extents.Z * -1);
            boxDeColision.Extents = new Vector3(boxDeColision.Extents.X, boxDeColision.Extents.Y, boxDeColision.Extents.Z);

            largoDelMesh   = boxDeColision.Extents.Z;
            boxDeColisionY = (yMax + yMin) / 2 + yMin;
        }
        public override void Init()
        {
            var loader = new TgcSceneLoader();
            var scene  = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\Patrullero\\Patrullero-TgcScene.xml");

            mesh       = scene.Meshes[0];
            mesh.Scale = new Vector3(0.25f, 0.25f, 0.25f);

            //Cuerpo principal que se controla con el teclado
            //mesh = TgcBox.fromSize(new Vector3(0, 10, 0), new Vector3(10, 10, 10), Color.Blue).toMesh("box");

            //triangulo
            triangle    = new CustomVertex.PositionColored[3];
            triangle[0] = new CustomVertex.PositionColored(-100, 0, 0, Color.Green.ToArgb());
            triangle[1] = new CustomVertex.PositionColored(0, 0, 50, Color.Green.ToArgb());
            triangle[2] = new CustomVertex.PositionColored(0, 100, 0, Color.Green.ToArgb());
            triagleAABB =
                TgcBoundingAxisAlignBox.computeFromPoints(new[]
                                                          { triangle[0].Position, triangle[1].Position, triangle[2].Position });

            //box2
            box2 = TgcBox.fromSize(new Vector3(-50, 10, -20), new Vector3(15, 15, 15), Color.Violet);

            //sphere
            boundingSphere = new TgcBoundingSphere(new Vector3(30, 20, -20), 15);

            //OBB: computar OBB a partir del AABB del mesh.
            meshObb =
                loader.loadSceneFromFile(MediaDir +
                                         "MeshCreator\\Meshes\\Objetos\\Catapulta\\Catapulta-TgcScene.xml")
                .Meshes[0];
            meshObb.Scale    = new Vector3(0.1f, 0.1f, 0.1f);
            meshObb.Position = new Vector3(100, 0, 30);
            meshObb.updateBoundingBox();
            //Computar OBB a partir del AABB del mesh. Inicialmente genera el mismo volumen que el AABB, pero luego te permite rotarlo (cosa que el AABB no puede)
            obb = TgcBoundingOrientedBox.computeFromAABB(meshObb.BoundingBox);
            //Otra alternativa es computar OBB a partir de sus vertices. Esto genera un OBB lo mas apretado posible pero es una operacion costosa
            //obb = TgcBoundingOrientedBox.computeFromPoints(mesh.getVertexPositions());

            //Rotar mesh y rotar OBB. A diferencia del AABB, nosotros tenemos que mantener el OBB actualizado segun cada movimiento del mesh
            meshObb.Rotation = new Vector3(0, FastMath.PI / 4, 0);
            //Los obb tienen una especie de autotransform aun.
            obb.rotate(new Vector3(0, FastMath.PI / 4, 0));

            //Configurar camara en Tercer Persona
            camaraInterna = new TgcThirdPersonCamera(mesh.Position, 30, -75);
            Camara        = camaraInterna;
        }
Exemple #7
0
 public Disparo(TGCVector3 startPosition, TGCVector3 targetPosition, TGCVector3 size, Color color, string soundPath, Microsoft.DirectX.DirectSound.Device device)
 {
     vida                 = Stopwatch.StartNew();
     ShouldDie            = false;
     modelo               = TGCBox.fromSize(size, color);
     modelo.AutoTransform = true;
     modelo.Position      = startPosition;
     MovementDirection    = TGCVector3.Normalize(targetPosition - startPosition);
     modelo.Rotation      = new TGCVector3(ObtenerRotacionX(new TGCVector3(0, 0, 1), MovementDirection), ObtenerRotacionY(new TGCVector3(0, 0, 1), MovementDirection), 0);
     this.OOB             = TgcBoundingOrientedBox.computeFromAABB(modelo.BoundingBox);
     //this.OOB.move(this.MovementDirection);
     this.OOB.rotate(modelo.Rotation);
     this.sonido        = new Tgc3dSound(soundPath, modelo.Position, device);
     sonido.Position    = modelo.Position;
     sonido.MinDistance = 50f;
     sonido.play();
     //modelo.BoundingBox.transform(TGCMatrix.RotationYawPitchRoll(modelo.Rotation.Y,modelo.Rotation.X,0));
 }
 public TGCVector3 manageColisionEsferaOBB(TgcBoundingSphere esfera, TGCVector3 movementVector, TgcBoundingOrientedBox OBB)
 {
     //Si esta parador Arriba de la caja
     if (colisionaEsferaOBB(esfera, OBB) && esfera.Center.Y > OBB.Center.Y + OBB.Extents.Y)
     {
         esfera.moveCenter(movementVector);
         return(movementVector);
     }//Si choca por debajo a la plataforma
     else if (colisionaEsferaOBB(esfera, OBB) && esfera.Center.Y < OBB.Center.Y - OBB.Extents.Y)
     {
         movementVector.Y = -EPSILON;
         esfera.moveCenter(movementVector);
         return(movementVector);
     }
     else //Si la choca por los costados
     {
         movementVector.Y = 25 * EPSILON;
         esfera.moveCenter(-movementVector);
         return(-movementVector);
     }
 }
 public bool colisionaEsferaOBB(TgcBoundingSphere esfera, TgcBoundingOrientedBox obb) => TgcCollisionUtils.testSphereOBB(esfera, obb);
Exemple #10
0
        public Auto(string nombre, float vida, float avanceMaximo, float reversaMax,
                    float aceleracion, float desaceleracion,
                    TgcMesh mesh, GameModel model, Ruedas ruedasAdelante, Ruedas ruedasAtras, TgcMesh ruedaMainMesh, Velocimetro velocimetroIN)
        {
            DeformationConstant = 1f;
            MeshesCercanos      = new List <TgcMesh>();
            var scale = 0.4f;

            scale3 = new Vector3(scale, scale, scale);

            CrearHumoCanioDeEscape(model);
            humoChoque          = new HumoEscape(model, true);
            AvanceMax           = avanceMaximo;
            ReversaMax          = -reversaMax;
            Desaceleracion      = desaceleracion;
            InerciaNegativa     = 1f;
            DireccionRuedas     = 0f;
            Armas               = new List <Arma>();
            aceleracionVertical = 0f;
            Velocidad           = 0f;
            Mesh        = mesh;
            Mesh.Scale  = scale3;
            Aceleracion = aceleracion;
            GameModel   = model;

            RuedasTraseras   = ruedasAtras;
            RuedasDelanteras = ruedasAdelante;
            RuedaMainMesh    = ruedaMainMesh;

            //------------Ariel---------------
            Mesh.AutoTransformEnable   = false;
            Mesh.AutoUpdateBoundingBox = false;

            obb = TgcBoundingOrientedBox.computeFromAABB(Mesh.BoundingBox);
            var yMin = Mesh.BoundingBox.PMin.Y;
            var yMax = Mesh.BoundingBox.PMax.Y;

            obbPosY     = (yMax + yMin) / 2 + yMin;
            obb.Extents = new Vector3(obb.Extents.X, obb.Extents.Y, obb.Extents.Z * -1);

            largo = obb.Extents.Z;

            ciudadScene = model.MapScene;



            //--------luces

            Luces       = new LucesAuto(this, ruedasAdelante, ruedasAtras, CamaraAuto);
            RenderLuces = false;

            EsAutoJugador = true;
            fixEjecutado  = false; //para arreglar el temita de que el auto no aparece.

            //shader pal hummer
            TechniqueOriginal       = Mesh.Technique;
            efectoOriginal          = Mesh.Effect;
            efectoShaderNitroHummer = TgcShaders.loadEffect(GameModel.ShadersDir + "ShaderHummer.fx");
            velocimetro             = velocimetroIN;

            //GameModel.shadowMap = new ShadowMap(GameModel);// para shadowmapFIX

            TodosLosMeshes = getAllMeshes();
        }
Exemple #11
0
 public void ActualizarBoundingOrientedBox(TgcBoundingAxisAlignBox AABB)
 {
     this.obb = TgcBoundingOrientedBox.computeFromAABB(AABB);
     this.obb.rotate(new TGCVector3(0, this.rotacionObb, 0));
     this.obb.updateValues();
 }
Exemple #12
0
 public BoundingOrientedBox(TgcBoundingAxisAlignBox AABB)
 {
     this.obb = TgcBoundingOrientedBox.computeFromAABB(AABB);
     this.y   = this.obb.Position.Y;
 }