예제 #1
0
        /// <summary>
        /// The default constructor for an explosion.
        /// </summary>
        /// <param name="physics">A reference to the physics engine.</param>
        /// <param name="explosionModel">The model to use for a particle in the explosion.</param>
        /// <param name="explosionTransforms">The graphical transforms to apply to the model.</param>
        /// <param name="explosionPosition">The position of the explosion.</param>
        public Explosion(PhysicsEngine.Environment physics, Model explosionModel,
                         Matrix[] explosionTransforms, Vector3 explosionPosition)
        {
            this.objectModel = explosionModel;
            this.transforms  = explosionTransforms;

            // Set up the particle parameters based on game constants
            ParticleSystemParameters psp = new ParticleSystemParameters();

            psp.BirthTime         = GameConstants.particleBirthTime;
            psp.BirthTimeVariance = 0;
            psp.Colour            = GameConstants.explosionColour;
            psp.ColourVariance    = GameConstants.colourVariance;
            psp.Direction         = GameConstants.particleBaseDirection;
            psp.DirectionVariance = GameConstants.particleDirectionVariance;
            psp.InitialParticles  = GameConstants.initialNumParticles;
            psp.LifeTime          = GameConstants.particleLifeTime;
            psp.LifeTimeVariance  = GameConstants.particleLifeTimeVariance;
            psp.Mass          = 1;
            psp.MassVariance  = 0.1f;
            psp.MaxParticles  = GameConstants.explosionNumParticles;
            psp.Position      = explosionPosition;
            psp.Speed         = GameConstants.explosionParticleSpeed;
            psp.SpeedVariance = 0;

            // Create the particle system and add it to the physics engine.
            this.physicsReference = new ParticleSystem(psp);
            physics.Add(physicsReference);
        }
예제 #2
0
 public GameObject(float radius, ConvexSegment hull, PhysicsEngine.Environment environment, Model model, Matrix[] transforms)
 {
     ConvexHull[] hulls = new ConvexHull[] { new ConvexHull(hull, Matrix.Identity) };
     physicsReference = new GameEntity(radius, new Hull(hulls), environment);
     environment.Add(physicsReference);
     this.objectModel = model;
     this.transforms  = transforms;
 }
예제 #3
0
 /// <summary>
 /// The default constructor for a bullet.
 /// </summary>
 /// <param name="radius">A radius that encloses the entire bullet model, centred at (0,0,0) in object space.</param>
 /// <param name="hulls">The convex hull segments that enclose the bullet.</param>
 /// <param name="environment">A reference to the physics engine.</param>
 /// <param name="model">The model used for the bullets.</param>
 /// <param name="transforms">The graphical transforms that are applied to the bullet.</param>
 /// <param name="initialPosition">The initial position of the bullet.</param>
 /// <param name="initialVelocity">The initial velocity of the bullet.</param>
 /// <param name="soundBank">A reference to the SoundBank used for the game's sound effects.</param>
 /// <param name="bullets">A reference to the list of bullets.</param>
 /// <param name="asteroids">A reference to the list of asteroids.</param>
 /// <param name="explosions">A reference to the list of explosions.</param>
 public Bullet(float radius, ConvexHull[] hulls, PhysicsEngine.Environment environment, Model model, Matrix[] transforms,
               Vector3 initialPosition, Vector3 initialVelocity, SoundBank soundBank, BulletList bullets, AsteroidList asteroids, ExplosionList explosions)
 {
     physicsReference = new NonForceEntity(initialPosition, Vector3.Up, 25, radius, new Hull(hulls), new BulletAsteroidCollision(1.0f, soundBank, bullets, asteroids, explosions));
     environment.Add(physicsReference);
     this.bulletModel          = model;
     this.transforms           = transforms;
     physicsReference.Velocity = initialVelocity;
 }
예제 #4
0
        /// <summary>
        /// Constructs a new ball.
        /// </summary>
        /// <param name="initialPosition">The initial position of the ball.</param>
        /// <param name="initialOrientation">The initial orientation of the ball.</param>
        /// <param name="mass">The mass of the ball.</param>
        /// <param name="ballRadius">The radius of the ball.</param>
        /// <param name="ballHull">The ball's hull.</param>
        /// <param name="collisionHandler">The ball's collision handler.</param>
        /// <param name="physics">The physics engine environment to which the ball belongs.</param>
        /// <param name="airResistance">The air resistance of the ball.</param>
        /// <param name="number">The ball's number.</param>
        /// <param name="ballModel">The ball's model.</param>
        public Ball(Vector3 initialPosition, Vector3 initialOrientation, float mass, float ballRadius, Hull ballHull,
                    CollisionHandler collisionHandler, PhysicsEngine.Environment physics, float airResistance, int number, Model ballModel)
        {
            physicsReference = new BallEntity(initialPosition, initialOrientation, mass, ballRadius, ballHull,
                                              collisionHandler, physics, airResistance);
            physics.Add(physicsReference);

            this.number = number;

            this.ballModel = ballModel;
        }
예제 #5
0
 /// <summary>
 /// The default constructor for an asteroid.
 /// </summary>
 /// <param name="radius">A radius that encloses the entire asteroid model, centred at (0,0,0) in object space.</param>
 /// <param name="hulls">The convex hull segments that enclose the asteroid.</param>
 /// <param name="environment">A reference to the physics engine.</param>
 /// <param name="model">The model used for the asteroids.</param>
 /// <param name="transforms">The graphical transforms that are applied to the asteroid.</param>
 /// <param name="initialPosition">The initial position of the asteroid.</param>
 /// <param name="initialVelocity">The initial velocity of the asteroid.</param>
 public Asteroid(float radius, ConvexHull[] hulls, PhysicsEngine.Environment environment, Model model, Matrix[] transforms,
                 Vector3 initialPosition, Vector3 initialVelocity)
 {
     physicsReference = new DefaultEntity(initialPosition, new Vector3(CommonFunctions.GenerateRandom(-1, 1),
                                                                       CommonFunctions.GenerateRandom(-1, 1),
                                                                       CommonFunctions.GenerateRandom(-1, 1)),
                                          40, radius, new Hull(hulls), new ElasticCollision(GameConstants.elasticityFactor),
                                          environment, 0.0f);
     environment.Add(physicsReference);
     this.objectModel          = model;
     this.transforms           = transforms;
     physicsReference.Position = initialPosition;
     physicsReference.Velocity = initialVelocity;
 }
예제 #6
0
        /// <summary>
        /// The default constructor for the ship class.
        /// </summary>
        /// <param name="radius">An estimate to the radius that encloses the ship, measured from (0,0,0) in object space.</param>
        /// <param name="hull">The convex hull for the ship model.</param>
        /// <param name="environment">A reference to the physics engine.</param>
        /// <param name="model">The model used to draw the ship.</param>
        /// <param name="transforms">The graphics transforms to be applied to the model.</param>
        /// <param name="initialPosition">The initial position of the ship.</param>
        /// <param name="initialSpeed">The initial speed of the ship.</param>
        /// <param name="soundBank">A reference to the game's SoundBank.</param>
        /// <param name="explosions">A reference to the list of explosions.</param>
        /// <param name="asteroids">A reference to the list of asteroids.</param>
        public Ship(float radius, ConvexSegment hull, PhysicsEngine.Environment environment, Model model, Matrix[] transforms,
                    Vector3 initialPosition, float initialSpeed, SoundBank soundBank, ExplosionList explosions, AsteroidList asteroids)
        {
            ConvexHull[] hulls = new ConvexHull[] { new ConvexHull(hull, Matrix.CreateScale(GameConstants.shipScale)) };
            physicsReference = new NonForceEntity(initialPosition, Vector3.Up, 25.0f, radius, new Hull(hulls),
                                                  new ShipAsteroidCollision(soundBank, explosions, this, asteroids));
            environment.Add(physicsReference);
            this.objectModel = model;
            this.transforms  = transforms;

            // Set the initial speed of the object
            physicsReference.Velocity = Vector3.UnitZ * initialSpeed;
            this.soundBank            = soundBank;
        }
예제 #7
0
        /// <summary>
        /// Constructs a new room.
        /// </summary>
        /// <param name="camera">The camera to be used to draw the room.</param>
        /// <param name="Content">The content manager to load models from.</param>
        /// <param name="physics">The physics environment to which the room belogns.</param>
        public Room(Camera camera, ContentManager Content, PhysicsEngine.Environment physics)
        {
            wallModel = Content.Load <Model>("Models\\Wall");
            wallGraphicsTransforms = CommonFunctions.SetupEffectDefaults(wallModel, camera);

            ConvexSegment wallSegment
                = PhysicsEngine.CommonFunctions.LoadConvexHull(new System.IO.StreamReader(@"..\..\..\Content/Hulls/Wall.hull"));

            wallHull = new ConvexHull[] { new ConvexHull(wallSegment, Matrix.Identity) };

            // Create wall entities
            leftWall   = CreateWallEntity(-Vector3.UnitX, -MathHelper.PiOver2 * Vector3.UnitZ);
            rightWall  = CreateWallEntity(Vector3.UnitX, +MathHelper.PiOver2 * Vector3.UnitZ);
            bottomWall = CreateWallEntity(-Vector3.UnitY, 0.0f * Vector3.UnitX);
            topWall    = CreateWallEntity(Vector3.UnitY, MathHelper.Pi * Vector3.UnitX);
            backWall   = CreateWallEntity(-Vector3.UnitZ, +MathHelper.PiOver2 * Vector3.UnitX);
            frontWall  = CreateWallEntity(Vector3.UnitZ, -MathHelper.PiOver2 * Vector3.UnitX);

            physics.Add(new Entity[] { leftWall, rightWall, bottomWall, topWall, backWall, frontWall });
        }