public StationaryCollisionCannon(CannonPathFinder path, Vector3 particlePos, params BaseModel[] models)
            : base(0, -1, models)
        {
            //explosion = new Explosion(explosionPos, explosionMag, 5, GameManager.Space);
            pathFinder = path;

            particles = new FocusedBurstSystem(Program.Game, Vector3.UnitZ, particlePos + 2 * Vector3.UnitZ);
            particles.AutoInitialize(RenderingDevice.GraphicsDevice, Program.Game.Content, RenderingDevice.SpriteBatch);
            initialParticleOrientation = particles.Emitter.OrientationData.Orientation;

            foreach(BaseModel m in modelList)
            {
                WeldJoint j = new WeldJoint(null, m.Ent);
                j.IsActive = true;
                joints.Add(j);
            }

            modelList[0].Ent.CollisionInformation.Events.PairTouching += onCollision;
        }
예제 #2
0
        //public Cannon(int machineNo, int soundIndex, float delayTime, Vector3 unitsToTranslate, Vector3 rotationAxis, Vector3 explosionPos, float explosionMag, params BaseModel[] models)
        //    : this(machineNo, soundIndex, unitsToTranslate, rotationAxis, explosionPos, explosionMag, models)
        //{
        //    delay = delayTime;
        //}
        public Cannon(int machineNo, int soundIndex, Vector3 unitsToTranslate, Vector3 rotationAxis, CannonPathFinder path, Vector3 particlePos, /*float explosionMag,*/ params BaseModel[] models)
            : base(machineNo, soundIndex, models)
        {
            this.unitsToTranslate = unitsToTranslate;
            this.rotationAxis = rotationAxis;
            //explosion = new Explosion(explosionPos, explosionMag, 5, GameManager.Space);
            this.path = path;
            Vector3 explosionDirection = Vector3.Normalize(Vector3.Transform(Vector3.UnitZ, Quaternion.CreateFromAxisAngle(rotationAxis, angle)));
            if(float.IsInfinity(explosionDirection.X) || float.IsInfinity(explosionDirection.X) || float.IsInfinity(explosionDirection.Z))
                explosionDirection = Vector3.UnitZ;

            particles = new FocusedBurstSystem(Program.Game, explosionDirection, particlePos + 3 * explosionDirection);
            particles.AutoInitialize(RenderingDevice.GraphicsDevice, Program.Game.Content, RenderingDevice.SpriteBatch);
            RenderingDevice.GDM.DeviceCreated += delegate { particles.AutoInitialize(RenderingDevice.GraphicsDevice, Program.Game.Content, RenderingDevice.SpriteBatch); };
            RenderingDevice.Add(particles);

            initialParticleOrientation = particles.Emitter.OrientationData.Orientation;

            baseJoint = new PerpendicularLineJoint(null, modelList[0].Ent, modelList[0].Ent.Position, Vector3.Normalize(unitsToTranslate),
                modelList[0].Ent.Position, rotationAxis);
            baseJoint.LinearMotor.IsActive = true;
            baseJoint.LinearMotor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            baseJoint.LinearMotor.Settings.Servo.Goal = 0;
            baseJoint.LinearMotor.Settings.Servo.BaseCorrectiveSpeed = baseJoint.LinearMotor.Settings.Servo.MaxCorrectiveVelocity = unitsToTranslate.Length() / 2;
            baseJoint.LinearMotor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.LinearMotor.Settings.Servo.SpringSettings.DampingConstant /= 15;
            baseJoint.LinearLimit.Maximum = unitsToTranslate.Length();
            baseJoint.LinearLimit.Minimum = 0;
            baseJoint.LinearLimit.IsActive = true;

            baseJoint.AngularMotor.IsActive = true;
            baseJoint.AngularMotor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            baseJoint.AngularMotor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.AngularMotor.Settings.Servo.SpringSettings.DampingConstant /= 12;
            baseJoint.AngularMotor.Settings.Servo.Goal = 0;
            baseJoint.AngularMotor.Settings.Servo.MaxCorrectiveVelocity = angle;
            baseJoint.AngularMotor.Settings.Servo.BaseCorrectiveSpeed = angle;
            baseJoint.AngularMotor.Basis.SetWorldAxes(rotationAxis, Vector3.UnitZ);
            baseJoint.AngularMotor.TestAxis = Vector3.UnitZ;
            baseJoint.AngularLimit.IsActive = true;
            baseJoint.AngularLimit.MinimumAngle = 0;
            baseJoint.AngularLimit.MaximumAngle = angle;
            baseJoint.AngularLimit.Basis.SetWorldAxes(rotationAxis, Vector3.UnitZ);
            baseJoint.AngularLimit.TestAxis = Vector3.UnitZ;

            if(modelList.Count > 1)
                foreach(BaseModel m in modelList)
                {
                    if(m == modelList[0])
                        continue;
                    WeldJoint j = new WeldJoint(modelList[0].Ent, m.Ent);
                    joints.Add(j);
                }

            //curve = new QuaternionSlerpCurve();
            //curve.ControlPoints.Add(0, Quaternion.Identity);
            //curve.ControlPoints.Add(2, Quaternion.Identity);
            //curve.ControlPoints.Add(3, Quaternion.CreateFromAxisAngle(rotationAxis, MathHelper.ToRadians(45)));
            //curve.ControlPoints.Add(4, Quaternion.CreateFromAxisAngle(rotationAxis, MathHelper.ToRadians(45)));
            //curve.PostLoop = CurveEndpointBehavior.Mirror;
            //curve.PreLoop = CurveEndpointBehavior.Mirror;
        }