public static TranslateTransform Create(TransformableEntity entity, Vector2 goalPosition, float duration)
 {
     TranslateTransform transform = Pool.Acquire<TranslateTransform>();
     transform._entity = entity;
     transform._goalPosition = goalPosition;
     transform.Duration = duration;
     return transform;
 }
 public static RotateTransform Create(TransformableEntity entity, float goalRotation, float duration)
 {
     RotateTransform transform = Pool.Acquire<RotateTransform>();
     transform._entity = entity;
     transform._goalRotation = goalRotation;
     transform.Duration = duration;
     return transform;
 }
Beispiel #3
0
 public static BlinkTransform Create(TransformableEntity entity, float rate, float duration)
 {
     BlinkTransform transform = Pool.Acquire<BlinkTransform>();
     transform._entity = entity;
     transform._blinkRate = transform._nextBlink = MathExtensions.Clamp(rate, 0f, duration);
     transform.Duration = duration;
     return transform;
 }
Beispiel #4
0
 public static FadeTransform Create(TransformableEntity entity, float goalAlpha, float duration)
 {
     FadeTransform transform = Pool.Acquire<FadeTransform>();
     transform._entity = entity;
     transform._goalAlpha = MathExtensions.Clamp(goalAlpha, 0f, 1f);
     transform.Duration = duration;
     return transform;
 }
Beispiel #5
0
 protected override void Recycle(bool isReleasing)
 {
     _entity = null;
     Duration = 0;
     PercentFinished = 0;
     InterpolationMethod = MathHelper.Lerp;
     base.Recycle(isReleasing);
 }
Beispiel #6
0
 public static ScaleTransform Create(TransformableEntity entity, Vector2 goalScale, float duration)
 {
     ScaleTransform transform = Pool.Acquire<ScaleTransform>();
     transform._entity = entity;
     transform._goalScale = goalScale;
     transform.Duration = duration;
     return transform;
 }
 public static FlickerTransform Create(TransformableEntity entity, float min, float max, float duration)
 {
     FlickerTransform transform = Pool.Acquire<FlickerTransform>();
     transform._entity = entity;
     transform._minAlpha = MathExtensions.Clamp(min, 0f, max);
     transform._maxAlpha = MathExtensions.Clamp(max, min, 1f);
     transform.Duration = duration;
     return transform;
 }
Beispiel #8
0
 public void Follow(TransformableEntity target)
 {
     if (target == null)
     {
         return;
     }
     Tracking = target;
     Mode     = CameraMode.TrackTarget;
 }
Beispiel #9
0
 public RacingExample() : base("RacingExample")
 {
     ClearColor = Color.Black;
     G.World.Add(player1 = new PhysicsCar());
     G.World.Add(player2 = new PhysicsCar());
     G.World.Add(track = new RaceTrack());
     player2.Position = player1.Position + new Vector2(100, 0);
     G.World.Camera.Offset = G.ScreenCenter;
 }
Beispiel #10
0
        public static CollisionBody Create(TransformableEntity entity, CollisionShape shape)
        {
            CollisionBody collider = Pool.Acquire <CollisionBody>();

            collider.Owner            = entity;
            collider.Shape            = shape;
            collider.OnCollision     += collider.HandleOnCollision;
            collider.BeforeCollision += collider.HandleBeforeCollision;
            return(collider);
        }
Beispiel #11
0
 protected override void Recycle(bool isReleasing)
 {
     _elapsed = 0;
     _repeat = 0;
     _entity = null;
     _onTransformFinished = null;
     _onSequenceFinished = null;
     if (isReleasing)
         _transforms.Clear();
     base.Recycle(isReleasing);
 }
Beispiel #12
0
        public static Sound3D Create(string name, Cue cue, TransformableEntity source, TransformableEntity dest, Action <string> onFinished)
        {
            Sound3D freshSound = Pool.Acquire <Sound3D>();

            freshSound.Name       = name;
            freshSound._cue       = cue;
            freshSound._source    = source;
            freshSound._dest      = dest;
            freshSound.OnFinished = onFinished;
            return(freshSound);
        }
Beispiel #13
0
 protected override void Recycle(bool isReleasing)
 {
     Name           = String.Empty;
     OnFinished     = null;
     _source        = null;
     _dest          = null;
     _audioEmitter  = null;
     _audioListener = null;
     if (isReleasing)
     {
         _cue.Dispose();
     }
     base.Recycle(isReleasing);
 }
Beispiel #14
0
        public void PlayPositionalSound(string soundName, bool force, TransformableEntity source, Action <string> onFinished)
        {
            if (!_waveBank.IsPrepared || !_streamingBank.IsPrepared)
            {
                throw new InvalidOperationException("AudioManager is not prepared; update it some more.");
            }
            // play the sound if not already playing, otherwise force play another instance of the sound
            if (!IsPlaying(soundName) || force)
            {
                TransformableEntity dest       = Listener;
                Sound3D             freshSound = Sound3D.Create(soundName, _soundBank.GetCue(soundName), source, dest, onFinished);
                freshSound.Play();

                _sounds.Add(freshSound);
            }
        }
Beispiel #15
0
        protected override void LoadContent()
        {
            _map = Content.Load<Map>(@"Maps\Plains\3");
            G.World.Camera.BoundsEnabled = true;
            G.World.Camera.BoundedArea = new Rectangle(0, 0, _map.Width * _map.TileWidth, _map.Height * _map.TileHeight);
            G.Collision.DefineWorld(_map.Width * _map.TileWidth, _map.Height * _map.TileHeight, 32);

            G.World.Add(_map);
            G.World.Camera.Follow(_player = TransformableEntity.Get("Lily") as TransformableEntity);
            G.EditorForm.grdProperty.SelectedObject = Entity.Get("flowermagic") as SpriteEmitter;

            Label lblControls = new Label();
            lblControls.Text.Append(CONTROLS);
            lblControls.Position = new Vector2(G.ScreenCenter.X, 0);
            lblControls.BackColor = Color.Gray;
            lblControls.ForeColor = Color.White;
            G.UI.HUD.Add(lblControls);

            base.LoadContent();
        }
        protected override void LoadContent()
        {
            _map = Content.Load<Map>(@"Maps\Plains\4");
            G.World.Camera.BoundsEnabled = true;
            G.World.Camera.BoundedArea = new Rectangle(0, 0, _map.Width * _map.TileWidth, _map.Height * _map.TileHeight);
            G.Collision.DefineWorld(_map.Width * _map.TileWidth, _map.Height * _map.TileHeight, 32);

            G.World.Add(_map);
            G.World.Camera.Follow(_player = TransformableEntity.Get("Lily") as TransformableEntity);

            //add objects to editor form
            List<object> objs = Entity.GlobalEntities.Cast<object>().ToList<object>();
            G.EditorForm.AddObjects(objs);

            Label lblControls = new Label();
            lblControls.Text.Append(CONTROLS);
            lblControls.Position = new Vector2(G.ScreenCenter.X, 0);
            lblControls.BackColor = Color.Gray;
            lblControls.ForeColor = Color.White;
            G.UI.HUD.Add(lblControls);

            base.LoadContent();
        }
Beispiel #17
0
 public void PlayPositionalSound(string soundName, TransformableEntity source)
 {
     PlayPositionalSound(soundName, false, source, null);
 }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public MPRTestDemo(DemosGame game)
            : base(game)
        {
            var shapeA = new BoxShape(1, 1, 1);
            shapeA.CollisionMargin = 0;
            var shapeB = new BoxShape(1, 1, 1);
            shapeB.CollisionMargin = 0;

            var transformA = new RigidTransform(new Vector3(0, 0, 0));
            var transformB = new RigidTransform(new Vector3(.5f, .5f, 0));
            Vector3 overlap;
            bool overlapped = MPRToolbox.GetLocalOverlapPosition(shapeA, shapeB, ref transformB, out overlap);
            Vector3 normal;
            float depth;
            Vector3 direction = new Vector3(0, -1, 0);
            MPRToolbox.LocalSurfaceCast(shapeA, shapeB, ref transformB, ref direction, out depth, out normal);

            ContactData contactData;
            //bool overlappedOld = MPRToolboxOld.AreObjectsColliding(shapeA, shapeB, ref transformA, ref transformB, out contactData);

            //Random rand = new Random(0);
            //for (int i = 0; i < 10000000; i++)
            //{
            //    transformA = new RigidTransform(new Vector3((float)rand.NextDouble() * 10 - 5, (float)rand.NextDouble() * 10 - 5, (float)rand.NextDouble() * 10 - 5),
            //        Quaternion.CreateFromYawPitchRoll((float)rand.NextDouble() * 1000, (float)rand.NextDouble() * 1000, (float)rand.NextDouble() * 1000));
            //    transformB = new RigidTransform(new Vector3((float)rand.NextDouble() * 10 - 5, (float)rand.NextDouble() * 10 - 5, (float)rand.NextDouble() * 10 - 5),
            //        Quaternion.CreateFromYawPitchRoll((float)rand.NextDouble() * 1000, (float)rand.NextDouble() * 1000, (float)rand.NextDouble() * 1000));

            //    overlapped = MPRTesting.GetOverlapPosition(shapeA, shapeB, ref transformA, ref transformB, out overlap);

            //    overlappedOld = MPRToolbox.AreObjectsColliding(shapeA, shapeB, ref transformA, ref transformB, out contactData);

            //    if (overlapped && !overlappedOld &&
            //        (!MPRToolbox.IsPointInsideShape(ref overlap, shapeA, ref transformA) ||
            //        !MPRToolbox.IsPointInsideShape(ref overlap, shapeB, ref transformB)))
            //        Debug.WriteLine("Break.");
            //    if (overlappedOld && !overlapped &&
            //        (!MPRToolbox.IsPointInsideShape(ref contactData.Position, shapeA, ref transformA) ||
            //        !MPRToolbox.IsPointInsideShape(ref contactData.Position, shapeB, ref transformB)))
            //        Debug.WriteLine("Break.");
            //    if (overlapped && overlappedOld &&
            //        (!MPRToolbox.IsPointInsideShape(ref overlap, shapeA, ref transformA) ||
            //        !MPRToolbox.IsPointInsideShape(ref overlap, shapeB, ref transformB) ||
            //        !MPRToolbox.IsPointInsideShape(ref contactData.Position, shapeA, ref transformA) ||
            //        !MPRToolbox.IsPointInsideShape(ref contactData.Position, shapeB, ref transformB)))
            //        Debug.WriteLine("Break.");
            //}
            
            //Do these tests with rotationally immobile objects.
            CollisionDetectionSettings.DefaultMargin = 0;
            groundWidth = 10;
            groundHeight = .1f;
            groundLength = 10;
            //a = new Box(new Vector3(0, -5, 0), groundWidth, groundHeight, groundLength, 1);
            //a = new TransformableEntity(new Vector3(0,0,0), new TriangleShape(new Vector3(-5, -5, -5), new Vector3(5, -5, -5), new Vector3(-5, -5, 5)), Matrix3x3.Identity);         
            a = new Triangle(new Vector3(0, -5, 0), new Vector3(5, -5, 0), new Vector3(5, -5, 5), 1);
            Space.Add(a);
            
            Space.ForceUpdater.Gravity = new Vector3();
            boxWidth = .25f;
            boxHeight = .05f;
            boxLength = 1f;
            b = new TransformableEntity(new Vector3(0, 2, 0), new BoxShape(boxWidth, boxHeight, boxLength), Matrix3x3.Identity, 1);
            //b = new Cone(new Vector3(0, 2, 0), .2f, .1f, 1);
            //b = new Capsule(new Vector3(0, 2, 0), 1, .5f, 1);
            //b = new Capsule(new Vector3(0, 2, 0), 1, .5f, 1);
            b.LocalInertiaTensorInverse = new Matrix3x3();
            CollisionRules.AddRule(b, a, CollisionRule.NoSolver);
            b.ActivityInformation.IsAlwaysActive = true;
            Space.Add(b);
            //Space.Add(new TransformableEntity(new Vector3(0, 4, 0), new BoxShape(1, 1, 1), Matrix3x3.Identity, 1));
            //Space.Add( new TransformableEntity(new Vector3(0, 6, 0), new BoxShape(1, 1, 1), Matrix3x3.Identity, 1));

            //Vector3[] vertices = new Vector3[] { new Vector3(0, -5, 0), new Vector3(5, -5, 0), new Vector3(5, -5, 5), new Vector3(0, -60, 5) };
            //int[] indices = new int[] { 0, 1, 2 , 0, 2, 3 };
            //StaticMesh mesh = new StaticMesh(vertices, indices);
            //Space.Add(mesh);
            //mesh.ImproveBoundaryBehavior = true;
            //mesh.Sidedness = TriangleSidedness.Counterclockwise;
            //game.ModelDrawer.Add(mesh);
            //mesh.CollisionRules.Personal = CollisionRule.NoSolver;
        }
Beispiel #19
0
 public void Orbit(Vector2 position)
 {
     _orbiting = null;
     _center = position;
     IsOrbiting = true;
 }
Beispiel #20
0
 public void Orbit(TransformableEntity e)
 {
     _orbiting = e;
     IsOrbiting = true;
 }
Beispiel #21
0
 public EmptyTransform(TransformableEntity entity, float duration)
 {
 }
Beispiel #22
0
 /// <summary>
 /// Start a sequence of Transforms using this Entity.
 /// </summary>
 /// <param name="entity">Entity to transform.</param>
 /// <returns></returns>
 public static Transformer ThisEntity(TransformableEntity entity)
 {
     Transformer transform = Create(entity);
     G.World.Add(transform);
     return transform;
 }
Beispiel #23
0
 static Transformer Create(TransformableEntity entity)
 {
     Transformer transformer = Pool.Acquire<Transformer>();
     transformer._entity = entity;
     return transformer;
 }
 public CollisionBody(TransformableEntity entity, CollisionShape shape)
     : this()
 {
     Owner = entity;
     Shape = shape;
 }
Beispiel #25
0
 public  void PlayPositionalSound(string soundName, TransformableEntity source)
 {
     PlayPositionalSound(soundName, false, source, null);
 }
Beispiel #26
0
 public bool IsViewable(TransformableEntity e)
 {
     return(IsViewable(e.Position)); // TODO: Add hitbox testing too.
 }
 // shortcut
 public static IWrappedBody CreateBody(TransformableEntity entity, CollisionShape shape)
 {
     return Create(entity, shape) as IWrappedBody;
 }
Beispiel #28
0
 public CollisionBody(TransformableEntity entity, CollisionShape shape)
     : this()
 {
     Owner = entity;
     Shape = shape;
 }
 public static CollisionBody Create(TransformableEntity entity, CollisionShape shape)
 {
     CollisionBody collider = Pool.Acquire<CollisionBody>();
     collider.Owner = entity;
     collider.Shape = shape;
     collider.OnCollision += collider.HandleOnCollision;
     collider.BeforeCollision += collider.HandleBeforeCollision;
     return collider;
 }
Beispiel #30
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public FancyShapesDemo(DemosGame game)
            : base(game)
        {
            var points = new List<Vector3>();

            //Setup a random distribution in a cube and compute a convex hull.
            var random = new Random(0);
            for (int k = 0; k < 40; k++)
            {
                points.Add(new Vector3(3 * (float)random.NextDouble(), 5 * (float)random.NextDouble(), 3 * (float)random.NextDouble()));
            }
            var convexHull = new ConvexHull(new Vector3(0, 7, 0), points, 10);

            Space.Add(convexHull);

            points.Clear();

            //Create another random distribution, but this time with more points.
            points.Clear();
            for (int k = 0; k < 400; k++)
            {
                points.Add(new Vector3(1 * (float)random.NextDouble(), 3 * (float)random.NextDouble(), 1 * (float)random.NextDouble()));
            }

            convexHull = new ConvexHull(new Vector3(4, 7, 0), points, 10);
            Space.Add(convexHull);

            //Minkowski Sums are fancy 'combinations' of objects, where the result is the sum of the individual points making up shapes.
            //Think of it as sweeping one shape around and through another; a sphere and a box would produce a rounded-edge box.
            var minkowskiSum = new MinkowskiSum(new Vector3(4, -3, 0),
                    new OrientedConvexShapeEntry(new BoxShape(2, 2, 2)),
                    new OrientedConvexShapeEntry(new ConeShape(2, 2)), 10);
            Space.Add(minkowskiSum);

            minkowskiSum = new MinkowskiSum(new Vector3(0, 3, 0),
                    new OrientedConvexShapeEntry(Quaternion.CreateFromYawPitchRoll(1, 2, 3), new ConeShape(1, 1)),
                    new OrientedConvexShapeEntry(new TriangleShape(Vector3.Zero, Vector3.Right, Vector3.Forward)), 1);
            Space.Add(minkowskiSum);

            //Note how this minkowski sum is composed of a cylinder, and another minkowski sum shape.
            minkowskiSum = new MinkowskiSum(new Vector3(-4, 10, 0),
                    new OrientedConvexShapeEntry(new CylinderShape(1, 2)),
                    new OrientedConvexShapeEntry(new MinkowskiSumShape(
                        new OrientedConvexShapeEntry(new TriangleShape(new Vector3(1, 1, 1), new Vector3(-2, 0, 0), new Vector3(0, -1, 0))),
                        new OrientedConvexShapeEntry(new BoxShape(.3f, 1, .3f)))), 10);
            Space.Add(minkowskiSum);

            //Minkowski sums can also be used on more than two shapes at once.  The two-shape constructor is just a convenience wrapper.

            //Wrapped objects use an implicit convex hull around a set of shapes.

            //Oblique cone:
            var cone = new List<ConvexShapeEntry>
            {
                new ConvexShapeEntry(new CylinderShape(0, 1)),
                new ConvexShapeEntry(new RigidTransform(new Vector3(1f, 2, 0)), new SphereShape(0))
            };
            Space.Add(new WrappedBody(new Vector3(-5, 0, 0), cone, 10));

            //Rather odd shape:
            var oddShape = new List<ConvexShapeEntry>();
            var bottom = new ConvexShapeEntry(new Vector3(-2, 2, 0), new SphereShape(2));
            var middle = new ConvexShapeEntry(
                new RigidTransform(
                    new Vector3(-2, 3, 0),
                    Quaternion.CreateFromAxisAngle(Vector3.Right, (float)Math.PI / 6)),
                    new CylinderShape(0, 3));
            var top = new ConvexShapeEntry(new Vector3(-2, 4, 0), new SphereShape(1f));
            oddShape.Add(bottom);
            oddShape.Add(middle);
            oddShape.Add(top);
            Space.Add(new WrappedBody(new Vector3(-3, 4, 0), oddShape, 10));

            //Transformable shapes can be any other kind of convex primitive transformed by any affine transformation.
            Matrix3x3 transform;
            transform = Matrix3x3.Identity;
            transform.M23 = .5f;
            transform.M13 = .5f;
            var transformable = new TransformableEntity(new Vector3(0, 0, 4), new BoxShape(1, 1, 1), transform, 10);
            Space.Add(transformable);

            Space.Add(new Box(new Vector3(0, -10, 0), 70, 5, 70));

            game.Camera.Position = new Vector3(0, 0, 30);
        }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public MPRTestDemo(DemosGame game)
            : base(game)
        {
            var shapeA = new BoxShape(1, 1, 1);

            shapeA.CollisionMargin = 0;
            var shapeB = new BoxShape(1, 1, 1);

            shapeB.CollisionMargin = 0;

            var     transformA = new RigidTransform(new Vector3(0, 0, 0));
            var     transformB = new RigidTransform(new Vector3(.5m, .5m, 0));
            Vector3 overlap;
            bool    overlapped = MPRToolbox.GetLocalOverlapPosition(shapeA, shapeB, ref transformB, out overlap);
            Vector3 normal;
            Fix64   depth;
            Vector3 direction = new Vector3(0, -1, 0);

            MPRToolbox.LocalSurfaceCast(shapeA, shapeB, ref transformB, ref direction, out depth, out normal);

            ContactData contactData;

            //bool overlappedOld = MPRToolboxOld.AreObjectsColliding(shapeA, shapeB, ref transformA, ref transformB, out contactData);

            //Random rand = new Random(0);
            //for (int i = 0; i < 10000000; i++)
            //{
            //    transformA = new RigidTransform(new Vector3((Fix64)rand.NextDouble() * 10 - 5, (Fix64)rand.NextDouble() * 10 - 5, (Fix64)rand.NextDouble() * 10 - 5),
            //        Quaternion.CreateFromYawPitchRoll((Fix64)rand.NextDouble() * 1000, (Fix64)rand.NextDouble() * 1000, (Fix64)rand.NextDouble() * 1000));
            //    transformB = new RigidTransform(new Vector3((Fix64)rand.NextDouble() * 10 - 5, (Fix64)rand.NextDouble() * 10 - 5, (Fix64)rand.NextDouble() * 10 - 5),
            //        Quaternion.CreateFromYawPitchRoll((Fix64)rand.NextDouble() * 1000, (Fix64)rand.NextDouble() * 1000, (Fix64)rand.NextDouble() * 1000));

            //    overlapped = MPRTesting.GetOverlapPosition(shapeA, shapeB, ref transformA, ref transformB, out overlap);

            //    overlappedOld = MPRToolbox.AreObjectsColliding(shapeA, shapeB, ref transformA, ref transformB, out contactData);

            //    if (overlapped && !overlappedOld &&
            //        (!MPRToolbox.IsPointInsideShape(ref overlap, shapeA, ref transformA) ||
            //        !MPRToolbox.IsPointInsideShape(ref overlap, shapeB, ref transformB)))
            //        Debug.WriteLine("Break.");
            //    if (overlappedOld && !overlapped &&
            //        (!MPRToolbox.IsPointInsideShape(ref contactData.Position, shapeA, ref transformA) ||
            //        !MPRToolbox.IsPointInsideShape(ref contactData.Position, shapeB, ref transformB)))
            //        Debug.WriteLine("Break.");
            //    if (overlapped && overlappedOld &&
            //        (!MPRToolbox.IsPointInsideShape(ref overlap, shapeA, ref transformA) ||
            //        !MPRToolbox.IsPointInsideShape(ref overlap, shapeB, ref transformB) ||
            //        !MPRToolbox.IsPointInsideShape(ref contactData.Position, shapeA, ref transformA) ||
            //        !MPRToolbox.IsPointInsideShape(ref contactData.Position, shapeB, ref transformB)))
            //        Debug.WriteLine("Break.");
            //}

            //Do these tests with rotationally immobile objects.
            CollisionDetectionSettings.DefaultMargin = 0;
            groundWidth  = 10;
            groundHeight = .1m;
            groundLength = 10;
            //a = new Box(new Vector3(0, -5, 0), groundWidth, groundHeight, groundLength, 1);
            //a = new TransformableEntity(new Vector3(0,0,0), new TriangleShape(new Vector3(-5, -5, -5), new Vector3(5, -5, -5), new Vector3(-5, -5, 5)), Matrix3x3.Identity);
            a = new Triangle(new Vector3(0, -5, 0), new Vector3(5, -5, 0), new Vector3(5, -5, 5), 1);
            Space.Add(a);

            Space.ForceUpdater.Gravity = new Vector3();
            boxWidth  = .25m;
            boxHeight = .05m;
            boxLength = 1;
            b         = new TransformableEntity(new Vector3(0, 2, 0), new BoxShape(boxWidth, boxHeight, boxLength), Matrix3x3.Identity, 1);
            //b = new Cone(new Vector3(0, 2, 0), .2m, .1m, 1);
            //b = new Capsule(new Vector3(0, 2, 0), 1, .5m, 1);
            //b = new Capsule(new Vector3(0, 2, 0), 1, .5m, 1);
            b.LocalInertiaTensorInverse = new Matrix3x3();
            CollisionRules.AddRule(b, a, CollisionRule.NoSolver);
            b.ActivityInformation.IsAlwaysActive = true;
            Space.Add(b);
            //Space.Add(new TransformableEntity(new Vector3(0, 4, 0), new BoxShape(1, 1, 1), Matrix3x3.Identity, 1));
            //Space.Add( new TransformableEntity(new Vector3(0, 6, 0), new BoxShape(1, 1, 1), Matrix3x3.Identity, 1));

            //Vector3[] vertices = new Vector3[] { new Vector3(0, -5, 0), new Vector3(5, -5, 0), new Vector3(5, -5, 5), new Vector3(0, -60, 5) };
            //int[] indices = new int[] { 0, 1, 2 , 0, 2, 3 };
            //StaticMesh mesh = new StaticMesh(vertices, indices);
            //Space.Add(mesh);
            //mesh.ImproveBoundaryBehavior = true;
            //mesh.Sidedness = TriangleSidedness.Counterclockwise;
            //game.ModelDrawer.Add(mesh);
            //mesh.CollisionRules.Personal = CollisionRule.NoSolver;
        }
Beispiel #32
0
 // shortcut
 public static IWrappedBody CreateBody(TransformableEntity entity, CollisionShape shape)
 {
     return(Create(entity, shape) as IWrappedBody);
 }
Beispiel #33
0
        public  void PlayPositionalSound(string soundName, bool force, TransformableEntity source, Action<string> onFinished)
        {
            if (!_waveBank.IsPrepared || !_streamingBank.IsPrepared)
            {
                throw new InvalidOperationException("AudioManager is not prepared; update it some more.");
            }
            // play the sound if not already playing, otherwise force play another instance of the sound
            if (!IsPlaying(soundName) || force)
            {
                TransformableEntity dest = Listener;
                Sound3D freshSound = Sound3D.Create(soundName, _soundBank.GetCue(soundName), source, dest, onFinished);
                freshSound.Play();

                _sounds.Add(freshSound);
            }
        }
Beispiel #34
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public FancyShapesDemo(DemosGame game)
            : base(game)
        {
            var points = new List <Vector3>();


            //Setup a random distribution in a cube and compute a convex hull.
            var random = new Random(0);

            for (int k = 0; k < 40; k++)
            {
                points.Add(new Vector3(3 * (Fix64)random.NextDouble(), 5 * (Fix64)random.NextDouble(), 3 * (Fix64)random.NextDouble()));
            }
            var convexHull = new ConvexHull(new Vector3(0, 7, 0), points, 10);

            Space.Add(convexHull);

            points.Clear();


            //Create another random distribution, but this time with more points.
            points.Clear();
            for (int k = 0; k < 400; k++)
            {
                points.Add(new Vector3(1 * (Fix64)random.NextDouble(), 3 * (Fix64)random.NextDouble(), 1 * (Fix64)random.NextDouble()));
            }


            convexHull = new ConvexHull(new Vector3(4, 7, 0), points, 10);
            Space.Add(convexHull);



            //Minkowski Sums are fancy 'combinations' of objects, where the result is the sum of the individual points making up shapes.
            //Think of it as sweeping one shape around and through another; a sphere and a box would produce a rounded-edge box.
            var minkowskiSum = new MinkowskiSum(new Vector3(4, -3, 0),
                                                new OrientedConvexShapeEntry(new BoxShape(2, 2, 2)),
                                                new OrientedConvexShapeEntry(new ConeShape(2, 2)), 10);

            Space.Add(minkowskiSum);

            minkowskiSum = new MinkowskiSum(new Vector3(0, 3, 0),
                                            new OrientedConvexShapeEntry(Quaternion.CreateFromYawPitchRoll(1, 2, 3), new ConeShape(1, 1)),
                                            new OrientedConvexShapeEntry(new TriangleShape(Vector3.Zero, Vector3.Right, Vector3.Forward)), 1);
            Space.Add(minkowskiSum);

            //Note how this minkowski sum is composed of a cylinder, and another minkowski sum shape.
            minkowskiSum = new MinkowskiSum(new Vector3(-4, 10, 0),
                                            new OrientedConvexShapeEntry(new CylinderShape(1, 2)),
                                            new OrientedConvexShapeEntry(new MinkowskiSumShape(
                                                                             new OrientedConvexShapeEntry(new TriangleShape(new Vector3(1, 1, 1), new Vector3(-2, 0, 0), new Vector3(0, -1, 0))),
                                                                             new OrientedConvexShapeEntry(new BoxShape(.3m, 1, .3m)))), 10);
            Space.Add(minkowskiSum);

            //Minkowski sums can also be used on more than two shapes at once.  The two-shape constructor is just a convenience wrapper.


            //Wrapped objects use an implicit convex hull around a set of shapes.

            //Oblique cone:
            var cone = new List <ConvexShapeEntry>
            {
                new ConvexShapeEntry(new CylinderShape(0, 1)),
                new ConvexShapeEntry(new RigidTransform(new Vector3(1, 2, 0)), new SphereShape(0))
            };

            Space.Add(new WrappedBody(new Vector3(-5, 0, 0), cone, 10));



            //Rather odd shape:
            var oddShape = new List <ConvexShapeEntry>();
            var bottom   = new ConvexShapeEntry(new Vector3(-2, 2, 0), new SphereShape(2));
            var middle   = new ConvexShapeEntry(
                new RigidTransform(
                    new Vector3(-2, 3, 0),
                    Quaternion.CreateFromAxisAngle(Vector3.Right, MathHelper.Pi / 6)),
                new CylinderShape(0, 3));
            var top = new ConvexShapeEntry(new Vector3(-2, 4, 0), new SphereShape(1));

            oddShape.Add(bottom);
            oddShape.Add(middle);
            oddShape.Add(top);
            Space.Add(new WrappedBody(new Vector3(-3, 4, 0), oddShape, 10));

            //Transformable shapes can be any other kind of convex primitive transformed by any affine transformation.
            Matrix3x3 transform;

            transform     = Matrix3x3.Identity;
            transform.M23 = .5m;
            transform.M13 = .5m;
            var transformable = new TransformableEntity(new Vector3(0, 0, 4), new BoxShape(1, 1, 1), transform, 10);

            Space.Add(transformable);


            Space.Add(new Box(new Vector3(0, -10, 0), 70, 5, 70));

            game.Camera.Position = new Vector3(0, 0, 30);
        }