Пример #1
0
        /// <inheritdoc />
        protected override void LoadContent()
        {
            // Load the models
            Robot = Game.Content.Load <Model>(ContentFolder3D + "tgcito-classic/tgcito-classic");

            Chair = Game.Content.Load <Model>(ContentFolder3D + "chair/chair");

            Tank = Game.Content.Load <Model>(ContentFolder3D + "tank/tank");

            // Enable the default lighting for the models
            EnableDefaultLighting(Robot);
            EnableDefaultLighting(Tank);
            EnableDefaultLighting(Chair);

            // Save our RobotEffect
            RobotEffect = ((BasicEffect)Robot.Meshes.FirstOrDefault()?.Effects.FirstOrDefault());


            // Create an AABB
            // This gets an AABB with the bounds of the robot model
            RobotBox = BoundingVolumesExtensions.CreateAABBFrom(Robot);
            // Scale it down half-size as the model is scaled down as well
            RobotBox = BoundingVolumesExtensions.Scale(RobotBox, 0.3f);



            // Create an OBB for a model
            // First, get an AABB from the model
            var temporaryCubeAABB = BoundingVolumesExtensions.CreateAABBFrom(Chair);

            // Scale it to match the model's transform
            temporaryCubeAABB = BoundingVolumesExtensions.Scale(temporaryCubeAABB, 0.5f);
            // Create an Oriented Bounding Box from the AABB
            ChairBox = OrientedBoundingBox.FromAABB(temporaryCubeAABB);
            // Move the center
            ChairBox.Center = Vector3.UnitX * 50f;
            // Then set its orientation!
            ChairBox.Orientation = Matrix.CreateRotationY(ChairAngle);


            // Create a Bounding Sphere for a model
            _tankSphere         = BoundingVolumesExtensions.CreateSphereFrom(Tank);
            _tankSphere.Center  = TankPosition;
            _tankSphere.Radius *= 3f;


            // Set depth to default
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            base.LoadContent();
        }
        public Laser(Vector3 pos, Matrix rotation, Matrix srt, Vector3 fd, Vector3 c)
        {
            Position       = pos;
            SRT            = srt;
            FrontDirection = fd;
            Color          = c;

            Game = TGCGame.Instance;
            //BoundingCylinder = new BoundingCylinder(Position, 10f, 20f);
            //BoundingCylinder.Rotation = rotation;

            var tempAABB = BoundingVolumesExtensions.CreateAABBFrom(Game.Drawer.LaserModel);

            tempAABB                = BoundingVolumesExtensions.Scale(tempAABB, 0.3f);
            BoundingBox             = OrientedBoundingBox.FromAABB(tempAABB);
            BoundingBox.Center      = pos;
            BoundingBox.Orientation = rotation;
        }
Пример #3
0
        public void Update(float elapsedTime, MyCamera camera)
        {
            Time = elapsedTime;
            // cuanto tengo que rotar (roll), dependiendo de que tanto giro la camara
            //TurnDelta = camera.delta;
            //updateRoll();
            //actualizo todos los parametros importantes del xwing
            updateSRT(camera);

            updateFireRate();

            updateSlideDamage();

            updateEnergyRegen(elapsedTime);
            if (boundingSphere == null)
            {
                boundingSphere = new BoundingSphere(Position, 15f);
            }
            else
            {
                boundingSphere.Center = Position;
            }

            var min = Position - new Vector3(10, 5, 10);
            var max = Position + new Vector3(10, 5, 10);

            if (BB == null)
            {
                //BB = BoundingVolumesExtensions.CreateAABBFrom(Model);
                //BB = BoundingVolumesExtensions.Scale(BB, 0.026f);
                BB = new BoundingBox(min, max);
            }
            BB.Min = min;
            BB.Max = max;

            if (OBB == null)
            {
                var temporaryCubeAABB = BoundingVolumesExtensions.CreateAABBFrom(Game.Drawer.XwingModel);
                // Scale it to match the model's transform
                temporaryCubeAABB = BoundingVolumesExtensions.Scale(temporaryCubeAABB, 0.026f);
                // Create an Oriented Bounding Box from the AABB
                OBB = OrientedBoundingBox.FromAABB(temporaryCubeAABB);

                var halfW = BoundingVolumesExtensions.Scale(temporaryCubeAABB, new Vector3(0.5f, 0.3f, 1f));

                var halfH = BoundingVolumesExtensions.Scale(temporaryCubeAABB, new Vector3(0.8f, 0.5f, 1f));

                OBBL = OrientedBoundingBox.FromAABB(halfW);
                OBBR = OrientedBoundingBox.FromAABB(halfW);
                OBBU = OrientedBoundingBox.FromAABB(halfH);
                OBBD = OrientedBoundingBox.FromAABB(halfH);
            }

            OBB.Center = Position;

            OBBL.Center = Position - RightDirection * 7;
            OBBR.Center = Position + RightDirection * 7;
            OBBU.Center = Position + UpDirection * 2;
            OBBD.Center = Position - UpDirection * 2;


            OBB.Orientation = YPR;

            OBBL.Orientation = YPR;
            OBBR.Orientation = YPR;
            OBBU.Orientation = YPR;
            OBBD.Orientation = YPR;



            float blockSize = MapLimit / MapSize;

            CurrentBlock = new Vector2(
                (int)((Position.X / blockSize) + 0.5), (int)((Position.Z / blockSize) + 0.5));

            CurrentBlock.X = MathHelper.Clamp(CurrentBlock.X, 0, MapSize - 1);
            CurrentBlock.Y = MathHelper.Clamp(CurrentBlock.Y, 0, MapSize - 1);
        }