Ejemplo n.º 1
0
 public GameProperties(Action <GameProperties> update, Action <GameProperties> rayCast, bool?grabbable,
                       InitialCollisionDetectedEventHandler <EntityCollidable> collisionHandler,
                       CollisionEndedEventHandler <EntityCollidable> collisionEndingHandler,
                       Action <GameModel> onTextureRipped  = null,
                       Action <GameModel> onTextureApplied = null)
 {
     this.update              = update;
     this.collisionHandler    = collisionHandler;
     this.endCollisionHandler = collisionEndingHandler;
     this.UpdateStateObject   = null;
     this.spaceUpdate         = null;
     this.grabbable           = grabbable;
     this.rayCastHit          = rayCast;
     this.onTextureRipped     = onTextureRipped;
     this.onTextureApplied    = onTextureApplied;
 }
Ejemplo n.º 2
0
        public override void EnableCollisionListening()
        {
            // If listener isn't already enabled
            if (this.listener != null)
            {
                return;
            }

            this.newCollisions   = new List <Int64>();
            this.endedCollisions = new List <Int64>();

            this.listener    = new InitialCollisionDetectedEventHandler <EntityCollidable>(CollisionHandler);
            this.endListener = new CollisionEndedEventHandler <EntityCollidable>(CollisionEndHandler);
            this.body.PhysicsEntity.CollisionInformation.Events.InitialCollisionDetected += this.listener;
            this.body.PhysicsEntity.CollisionInformation.Events.CollisionEnded           += this.endListener;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public AccumulationTestDemo(DemosGame game)
            : base(game)
        {
            //x and y, in terms of heightmaps, refer to their local x and y coordinates.  In world space, they correspond to x and z.
            //Setup the heights of the terrain.
            int xLength = 256;
            int zLength = 256;

            float xSpacing = .5f;
            float zSpacing = .5f;
            var heights = new float[xLength, zLength];
            for (int i = 0; i < xLength; i++)
            {
                for (int j = 0; j < zLength; j++)
                {
                    float x = i - xLength / 2;
                    float z = j - zLength / 2;
                    heights[i, j] = (float)(10 * (Math.Sin(x / 8) + Math.Sin(z / 8)));
                }
            }
            //Create the terrain.
            var terrain = new Terrain(heights, new AffineTransform(
                    new Vector3(xSpacing, 1, zSpacing),
                    Quaternion.Identity,
                    new Vector3(-xLength * xSpacing / 2, 0, -zLength * zSpacing / 2)));

            Space.Add(terrain);
            game.ModelDrawer.Add(terrain);

            eventHandler = (sender, other, pair) =>
            {

                var entityCollidable = other as EntityCollidable;
                if (entityCollidable == null || !entityCollidable.Entity.IsDynamic)
                {
                    sender.Events.RemoveAllEvents();
                    sender.Entity.LinearVelocity = new Vector3();
                    sender.Entity.AngularVelocity = new Vector3();
                    sender.Entity.BecomeKinematic();
                    sender.CollisionRules.Group = CollisionRules.DefaultDynamicCollisionGroup;
                }
            };

            game.Camera.Position = new Vector3(0, 30, 20);
        }
Ejemplo n.º 4
0
        public override void DisableCollisionListening()
        {
            // If listener is enabled
            if (this.listener == null)
            {
                return;
            }

            this.body.PhysicsEntity.CollisionInformation.Events.InitialCollisionDetected -= this.listener;
            this.body.PhysicsEntity.CollisionInformation.Events.CollisionEnded           -= this.endListener;

            this.listener = null;

            BroadcastCollisions();

            this.newCollisions.Clear();
            this.newCollisions = null;

            this.endedCollisions.Clear();
            this.endedCollisions = null;
        }
Ejemplo n.º 5
0
 public override void addCollisionEvent(InitialCollisionDetectedEventHandler<EntityCollidable> _function)
 {
     meshCollider.CollisionInformation.Events.InitialCollisionDetected += _function;
 }
Ejemplo n.º 6
0
 public abstract void addCollisionEvent(InitialCollisionDetectedEventHandler<EntityCollidable> _function);