Exemplo n.º 1
0
 public void RemoveEntity(IPhysicsEntity entity)
 {
     if (!Entities.Contains(entity))
         return;
     lock (EntityLock)
         Entities.Remove(entity);
 }
Exemplo n.º 2
0
 private void DetermineOverlapsInternal(IPhysicsEntity entity, Viewpoint viewpoint)
 {
   QueryOptions options = QueryOptions.None;
   if (entity.Background)
     options |= QueryOptions.Background;
   Vector3 center = entity.Center;
   if (entity.CornerCollision.Length == 1)
   {
     entity.CornerCollision[0] = new PointCollision(center, this.LevelManager.NearestTrile(center, options, new Viewpoint?(viewpoint)));
   }
   else
   {
     Vector3 vector3_1 = FezMath.RightVector(viewpoint);
     Vector3 vector3_2 = entity.Size / 2f - new Vector3(1.0 / 1000.0);
     if ((double) this.CollisionManager.GravityFactor < 0.0)
       vector3_2 *= new Vector3(1f, -1f, 1f);
     Vector3 vector3_3 = center + (vector3_1 + Vector3.Up) * vector3_2;
     entity.CornerCollision[0] = new PointCollision(vector3_3, this.LevelManager.NearestTrile(vector3_3, options, new Viewpoint?(viewpoint)));
     if (entity.CornerCollision[0].Instances.Deep == null && this.PlayerManager.CarriedInstance != null)
     {
       this.PlayerManager.CarriedInstance.PhysicsState.UpdatingPhysics = true;
       entity.CornerCollision[0] = new PointCollision(center, this.LevelManager.NearestTrile(center, options, new Viewpoint?(viewpoint)));
       this.PlayerManager.CarriedInstance.PhysicsState.UpdatingPhysics = false;
     }
     Vector3 vector3_4 = center + (vector3_1 + Vector3.Down) * vector3_2;
     entity.CornerCollision[1] = new PointCollision(vector3_4, this.LevelManager.NearestTrile(vector3_4, options, new Viewpoint?(viewpoint)));
     Vector3 vector3_5 = center + (-vector3_1 + Vector3.Up) * vector3_2;
     entity.CornerCollision[2] = new PointCollision(vector3_5, this.LevelManager.NearestTrile(vector3_5, options, new Viewpoint?(viewpoint)));
     Vector3 vector3_6 = center + (-vector3_1 + Vector3.Down) * vector3_2;
     entity.CornerCollision[3] = new PointCollision(vector3_6, this.LevelManager.NearestTrile(vector3_6, options, new Viewpoint?(viewpoint)));
   }
 }
Exemplo n.º 3
0
 public void AddEntity(IPhysicsEntity entity)
 {
     if (Entities.Contains(entity))
         return;
     lock (EntityLock)
         Entities.Add(entity);
 }
Exemplo n.º 4
0
        public static DisposeCallback RegisterMaintainSpawning(DemoOpenInfo info, Key key, SpawnCallback callback)
        {
            IPhysicsEntity current = null;
            EventHandler <KeyboardEventArgs> downHandler = delegate(object sender, KeyboardEventArgs e)
            {
                if (e.Key == key)
                {
                    current = callback(info.Viewport.MousePosition);
                }
            };
            EventHandler <KeyboardEventArgs> upHandler = delegate(object sender, KeyboardEventArgs e)
            {
                if (e.Key == key)
                {
                    if (current != null)
                    {
                        current.Lifetime.IsExpired = true;
                        current = null;
                    }
                }
            };

            Events.KeyboardDown += downHandler;
            Events.KeyboardUp   += upHandler;
            return(delegate()
            {
                Events.KeyboardDown -= downHandler;
                Events.KeyboardUp -= upHandler;
            });
        }
Exemplo n.º 5
0
 public void RemoveEntity(IPhysicsEntity entity)
 {
     if (!Entities.Contains(entity))
     {
         return;
     }
     Entities.Remove(entity);
 }
Exemplo n.º 6
0
        private void HandleLeftMouseDrag(ref MouseState mouseState)
        {
            IPhysicsEntity entity = selectionContainer.SelectedEntity;

            if (entity != null)
            {
                entity.Position = WorldMousePosition - selectionOffset;
            }
        }
Exemplo n.º 7
0
 public void DetermineInBackground(IPhysicsEntity entity, bool allowEnterInBackground, bool postRotation, bool keepInFront)
 {
     if (allowEnterInBackground)
     {
         if (entity is IComplexPhysicsEntity)
         {
             IComplexPhysicsEntity complexPhysicsEntity = entity as IComplexPhysicsEntity;
             Vector3      impulse = 1.0 / 32.0 * Vector3.Down;
             QueryOptions options = QueryOptions.None;
             if (complexPhysicsEntity.Background)
             {
                 options |= QueryOptions.Background;
             }
             bool flag = BoxCollisionResultExtensions.AnyHit(this.CollisionManager.CollideEdge(entity.Center, impulse, entity.Size / 2f, Direction2D.Vertical, options));
             if (!flag)
             {
                 flag = flag | BoxCollisionResultExtensions.AnyHit(this.CollisionManager.CollideEdge(entity.Center, impulse, entity.Size / 2f, Direction2D.Vertical, options, 0.0f, FezMath.GetOpposite(this.CameraManager.Viewpoint)));
             }
             if (complexPhysicsEntity.Grounded && !flag)
             {
                 this.DebuggingBag.Add("zz. had to re-clamp to ground", (object)"POSITIF");
                 MultipleHits <CollisionResult> result = this.CollisionManager.CollideEdge(entity.Center, impulse, entity.Size / 2f, Direction2D.Vertical, options, 0.0f, this.CameraManager.LastViewpoint);
                 if (BoxCollisionResultExtensions.AnyCollided(result))
                 {
                     this.ClampToGround(entity, new Vector3?(BoxCollisionResultExtensions.First(result).NearestDistance), this.CameraManager.LastViewpoint);
                 }
             }
         }
         entity.Background = false;
         PhysicsManager.WallHuggingResult wallHuggingResult;
         do
         {
             this.DetermineOverlapsInternal(entity, this.CameraManager.Viewpoint);
             wallHuggingResult = this.HugWalls(entity, true, postRotation, keepInFront);
         }while (wallHuggingResult.Hugged);
         entity.Background = wallHuggingResult.Behind;
         this.DetermineOverlapsInternal(entity, this.CameraManager.Viewpoint);
         this.HugWalls(entity, false, false, keepInFront);
     }
     else
     {
         if (!entity.Background)
         {
             return;
         }
         bool flag = true;
         foreach (PointCollision pointCollision in entity.CornerCollision)
         {
             flag = flag & !this.IsHuggable(pointCollision.Instances.Deep, entity);
         }
         if (!flag)
         {
             return;
         }
         entity.Background = false;
     }
 }
Exemplo n.º 8
0
 public void AddEntity(IPhysicsEntity entity)
 {
     if (Entities.Contains(entity))
     {
         return;
     }
     lock (EntityLock)
         Entities.Add(entity);
 }
Exemplo n.º 9
0
        public void ClampToGround(IPhysicsEntity entity, Vector3?distance, Viewpoint viewpoint)
        {
            if (!distance.HasValue)
            {
                return;
            }
            Vector3 mask = FezMath.GetMask(FezMath.VisibleAxis(viewpoint));

            entity.Center = distance.Value * mask + (Vector3.One - mask) * entity.Center;
        }
Exemplo n.º 10
0
 private bool IsHuggable(TrileInstance instance, IPhysicsEntity entity)
 {
     if (instance != null && instance.Enabled && !instance.Trile.Immaterial && ((!instance.Trile.Thin || instance.Trile.ForceHugging) && (instance != this.PlayerManager.CarriedInstance && instance != this.PlayerManager.PushedInstance)) && (!ActorTypeExtensions.IsBomb(instance.Trile.ActorSettings.Type) && (instance.PhysicsState == null || instance.PhysicsState != entity)))
     {
         return(!FezMath.In <CollisionType>(instance.GetRotatedFace(entity.Background ? FezMath.GetOpposite(this.CameraManager.VisibleOrientation) : this.CameraManager.VisibleOrientation), CollisionType.Immaterial, CollisionType.TopNoStraightLedge, CollisionType.AllSides, (IEqualityComparer <CollisionType>)CollisionTypeComparer.Default));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 11
0
 private void RedefineCorners(IPhysicsEntity entity)
 {
     if (entity is IComplexPhysicsEntity)
     {
         this.DetermineOverlaps(entity as IComplexPhysicsEntity);
     }
     else
     {
         this.DetermineOverlaps(entity as ISimplePhysicsEntity);
     }
 }
Exemplo n.º 12
0
        public TractorBeam(IPhysicsEntity from, IPhysicsEntity to)
        {
            this.from = from;
            this.to   = to;

            this.Components.BeginSetup();
            {
                this.Components.Add(this.behaveable);
            }
            this.Components.EndSetup();

            this.HookEvents();
        }
Exemplo n.º 13
0
        public static TractorBeam CreateTractorBeam(IPhysicsEntity from, IPhysicsEntity to)
        {
            if (Atom.Math.Vector2.DistanceSquared(from.Position, to.Position) >= 700.0f)
            {
                return(null);
            }

            var beam = new TractorBeam(from, to);

            beam.DrawStrategy = new TractorBeamDrawStrategy();

            return(beam);
        }
Exemplo n.º 14
0
        private bool CanSelect(IPhysicsEntity entity)
        {
            var breakableEntity = entity as IBreakableEntity;

            if (breakableEntity != null)
            {
                return(!breakableEntity.Breakable.IsBroken);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 15
0
        private void MoveAlongWithGround(IPhysicsEntity entity, QueryOptions queryOptions)
        {
            TrileInstance trileInstance = (TrileInstance)null;
            bool          flag          = false;

            if (PhysicsManager.IsInstanceStateful(entity.Ground.NearLow))
            {
                trileInstance = entity.Ground.NearLow;
            }
            else if (PhysicsManager.IsInstanceStateful(entity.Ground.FarHigh))
            {
                trileInstance = entity.Ground.FarHigh;
            }
            Vector3 vector3 = entity.GroundMovement;

            if (trileInstance != null)
            {
                entity.GroundMovement = FezMath.AlmostClamp(trileInstance.PhysicsState.Velocity + trileInstance.PhysicsState.GroundMovement);
                if (trileInstance.PhysicsState.Sticky)
                {
                    flag = true;
                }
            }
            else
            {
                vector3 = Vector3.Clamp(vector3, -FezMath.XZMask, Vector3.One);
                entity.GroundMovement = Vector3.Zero;
            }
            if (entity.GroundMovement != Vector3.Zero)
            {
                MultipleHits <CollisionResult> horizontalResults;
                MultipleHits <CollisionResult> verticalResults;
                this.CollisionManager.CollideRectangle(entity.Center, entity.GroundMovement, entity.Size, queryOptions, entity.Elasticity, out horizontalResults, out verticalResults);
                entity.GroundMovement += (BoxCollisionResultExtensions.AnyCollided(horizontalResults) ? BoxCollisionResultExtensions.First(horizontalResults).Response : Vector3.Zero) + (BoxCollisionResultExtensions.AnyCollided(verticalResults) ? BoxCollisionResultExtensions.First(verticalResults).Response : Vector3.Zero);
                Vector3 min = flag ? -Vector3.One : -FezMath.XZMask;
                entity.Center += Vector3.Clamp(entity.GroundMovement, min, Vector3.One);
                if (!(vector3 == Vector3.Zero) || (double)entity.Velocity.Y <= 0.0)
                {
                    return;
                }
                entity.Velocity -= entity.GroundMovement * Vector3.UnitY;
            }
            else
            {
                if (flag || !(vector3 != Vector3.Zero))
                {
                    return;
                }
                entity.Velocity += vector3 * 0.85f;
            }
        }
Exemplo n.º 16
0
        private bool CreateTractorBeamTo(IPhysicsEntity entity)
        {
            if (entity != null && !entity.Physics.IsStatic)
            {
                this.beam = EntityFactory.CreateTractorBeam(this.player, entity);

                if (beam != null)
                {
                    this.world.AddEntity(beam);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 17
0
        private void TruncateVelocity(IPhysicsEntity entity, float dt)
        {
            entity.Velocity = TruncateVelocity(entity.Velocity);

            /*if (Math.Abs(entity.Velocity.X) < 0.005f)
             *      entity.Velocity = new Vector3(0, entity.Velocity.Y, entity.Velocity.Z);
             *
             * if (Math.Abs(entity.Velocity.Y) < 0.005f)
             *      entity.Velocity = new Vector3(entity.Velocity.X, 0, entity.Velocity.Z);
             *
             * if (Math.Abs(entity.Velocity.Z) < 0.005f)
             *      entity.Velocity = new Vector3(entity.Velocity.X, entity.Velocity.Y, 0);
             */
            //entity.Velocity.Clamp();
        }
Exemplo n.º 18
0
        private void HandleRightMouseDrag(ref MouseState mouseState)
        {
            IPhysicsEntity entity = selectionContainer.SelectedEntity;

            if (entity != null)
            {
                float angle = (float)Math.Atan2(WorldMousePosition.Y - entity.Position.Y, WorldMousePosition.X - entity.Position.X);

                if (keyState.IsKeyDown(Keys.LeftShift))
                {
                    angle = MathUtilities.RoundToMultiple(angle, Constants.PiOver4);
                }

                entity.Rotation = angle;
            }
        }
Exemplo n.º 19
0
 private void TruncateVelocity(IPhysicsEntity entity, double multiplier)
 {
     if (Math.Abs(entity.Velocity.X) < 0.1 * multiplier)
     {
         entity.Velocity = new Vector3(0, entity.Velocity.Y, entity.Velocity.Z);
     }
     if (Math.Abs(entity.Velocity.Y) < 0.1 * multiplier)
     {
         entity.Velocity = new Vector3(entity.Velocity.X, 0, entity.Velocity.Z);
     }
     if (Math.Abs(entity.Velocity.Z) < 0.1 * multiplier)
     {
         entity.Velocity = new Vector3(entity.Velocity.X, entity.Velocity.Y, 0);
     }
     entity.Velocity.Clamp(entity.TerminalVelocity);
 }
Exemplo n.º 20
0
        public virtual void ApplyForce(Force force, IPhysicsEntity actor = null)
        {
            if (dynamicOnForce)
            {
                Rig.isKinematic = false;
                timeToSleep     = TimeToSleep;
                Rig.AddForce(force);
            }

            if (returnForce)
            {
                if (actor != null)
                {
                    actor.ApplyForce(-force * returnForceMultiplier);
                }
            }
        }
Exemplo n.º 21
0
        private void TruncateVelocity(IPhysicsEntity entity, float dt)
        {
            if (Math.Abs(entity.Velocity.X) < 0.1 * dt)
            {
                entity.Velocity = new Vector3(0, entity.Velocity.Y, entity.Velocity.Z);
            }

            if (Math.Abs(entity.Velocity.Y) < 0.1f * dt)
            {
                entity.Velocity = new Vector3(entity.Velocity.X, 0, entity.Velocity.Z);
            }

            if (Math.Abs(entity.Velocity.Z) < 0.1 * dt)
            {
                entity.Velocity = new Vector3(entity.Velocity.X, entity.Velocity.Y, 0);
            }

            //entity.Velocity.Clamp();
        }
Exemplo n.º 22
0
        private void HandleLeftRightMouseDrag(ref MouseState mouseState)
        {
            IPhysicsEntity entity = selectionContainer.SelectedEntity;

            if (entity != null)
            {
                var scaleable = entity.Physics as IScaleable;

                if (scaleable != null)
                {
                    Vector2 delta = entity.Position - WorldMousePosition;
                    delta *= 2.0f;

                    scaleable.ScaleTo(delta);
                }
            }

            this.wasLeftRightClicking = true;
        }
Exemplo n.º 23
0
        public IPhysicsEntity Unselect()
        {
            if (this.selectedEntity != null)
            {
                this.selectedEntity.DrawStrategy.ColorTints.Remove(this.SelectionColorTint);
                this.selectedEntity.Removed -= this.OnSelectedEntityRemoved;

                var breakableEntity = selectedEntity as IBreakableEntity;

                if (breakableEntity != null)
                {
                    breakableEntity.Breakable.Broken -= this.OnSelectedEntityBroken;
                }
            }

            IPhysicsEntity entity = this.selectedEntity;

            this.selectedEntity = null;
            return(entity);
        }
Exemplo n.º 24
0
        public bool Select(IPhysicsEntity entity)
        {
            if (this.selectedEntity == entity && entity != null)
            {
                if (this.DeselectOnDoubleSelection)
                {
                    this.Unselect();
                }

                return(true);
            }
            else
            {
                Unselect();

                if (this.CanSelect(entity))
                {
                    this.selectedEntity = entity;

                    if (this.selectedEntity != null)
                    {
                        this.SelectionColorTint.Reset();
                        this.selectedEntity.DrawStrategy.ColorTints.Add(this.SelectionColorTint);
                        this.selectedEntity.Removed += this.OnSelectedEntityRemoved;

                        var breakableEntity = selectedEntity as IBreakableEntity;

                        if (breakableEntity != null)
                        {
                            breakableEntity.Breakable.Broken += this.OnSelectedEntityBroken;
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 25
0
        private void DetermineOverlapsInternal(IPhysicsEntity entity, Viewpoint viewpoint)
        {
            QueryOptions options = QueryOptions.None;

            if (entity.Background)
            {
                options |= QueryOptions.Background;
            }
            Vector3 center = entity.Center;

            if (entity.CornerCollision.Length == 1)
            {
                entity.CornerCollision[0] = new PointCollision(center, this.LevelManager.NearestTrile(center, options, new Viewpoint?(viewpoint)));
            }
            else
            {
                Vector3 vector3_1 = FezMath.RightVector(viewpoint);
                Vector3 vector3_2 = entity.Size / 2f - new Vector3(1.0 / 1000.0);
                if ((double)this.CollisionManager.GravityFactor < 0.0)
                {
                    vector3_2 *= new Vector3(1f, -1f, 1f);
                }
                Vector3 vector3_3 = center + (vector3_1 + Vector3.Up) * vector3_2;
                entity.CornerCollision[0] = new PointCollision(vector3_3, this.LevelManager.NearestTrile(vector3_3, options, new Viewpoint?(viewpoint)));
                if (entity.CornerCollision[0].Instances.Deep == null && this.PlayerManager.CarriedInstance != null)
                {
                    this.PlayerManager.CarriedInstance.PhysicsState.UpdatingPhysics = true;
                    entity.CornerCollision[0] = new PointCollision(center, this.LevelManager.NearestTrile(center, options, new Viewpoint?(viewpoint)));
                    this.PlayerManager.CarriedInstance.PhysicsState.UpdatingPhysics = false;
                }
                Vector3 vector3_4 = center + (vector3_1 + Vector3.Down) * vector3_2;
                entity.CornerCollision[1] = new PointCollision(vector3_4, this.LevelManager.NearestTrile(vector3_4, options, new Viewpoint?(viewpoint)));
                Vector3 vector3_5 = center + (-vector3_1 + Vector3.Up) * vector3_2;
                entity.CornerCollision[2] = new PointCollision(vector3_5, this.LevelManager.NearestTrile(vector3_5, options, new Viewpoint?(viewpoint)));
                Vector3 vector3_6 = center + (-vector3_1 + Vector3.Down) * vector3_2;
                entity.CornerCollision[3] = new PointCollision(vector3_6, this.LevelManager.NearestTrile(vector3_6, options, new Viewpoint?(viewpoint)));
            }
        }
Exemplo n.º 26
0
        private float GetDistance(IPhysicsEntity entity)
        {
            var list = entity.Physics.Body.FixtureList;

            float maxDistance = -1.0f;

            if (list != null)
            {
                foreach (var fixture in list)
                {
                    AABB box;
                    fixture.GetAABB(out box, 0);

                    float distance = box.Extents.Length();

                    if (distance > maxDistance)
                    {
                        maxDistance = distance;
                    }
                }
            }

            return(maxDistance);
        }
Exemplo n.º 27
0
 private bool UpdateInternal(IPhysicsEntity entity, MultipleHits<CollisionResult> horizontalResults, MultipleHits<CollisionResult> verticalResults, Vector3? clampToGroundDistance, bool wasGrounded, bool hugWalls, bool velocityIrrelevant, bool simple)
 {
   Vector3 velocity = entity.Velocity;
   if (!simple)
   {
     MultipleHits<CollisionResult> multipleHits = new MultipleHits<CollisionResult>();
     if (BoxCollisionResultExtensions.AnyCollided(horizontalResults))
     {
       if (horizontalResults.NearLow.Collided)
         multipleHits.NearLow = horizontalResults.NearLow;
       if (horizontalResults.FarHigh.Collided)
         multipleHits.FarHigh = horizontalResults.FarHigh;
     }
     entity.WallCollision = multipleHits;
   }
   if (horizontalResults.NearLow.Collided)
     velocity += horizontalResults.NearLow.Response;
   else if (horizontalResults.FarHigh.Collided)
     velocity += horizontalResults.FarHigh.Response;
   if (verticalResults.NearLow.Collided)
     velocity += verticalResults.NearLow.Response;
   else if (verticalResults.FarHigh.Collided)
     velocity += verticalResults.FarHigh.Response;
   Vector3 vector3_1 = !(entity is IComplexPhysicsEntity) || !(entity as IComplexPhysicsEntity).Swimming ? (entity.Grounded || wasGrounded ? (entity.Sliding ? PhysicsManager.SlidingFrictionV : PhysicsManager.GroundFrictionV) : PhysicsManager.AirFrictionV) : PhysicsManager.WaterFrictionV;
   float amount = (float) ((1.20000004768372 + (double) Math.Abs(this.CollisionManager.GravityFactor) * 0.800000011920929) / 2.0);
   Vector3 vector3_2 = FezMath.AlmostClamp(velocity * Vector3.Lerp(Vector3.One, vector3_1, amount), 1E-06f);
   if (!entity.NoVelocityClamping)
   {
     float max = entity is IComplexPhysicsEntity ? 0.4f : 0.38f;
     vector3_2.Y = MathHelper.Clamp(vector3_2.Y, -max, max);
   }
   Vector3 center = entity.Center;
   Vector3 a = center + vector3_2;
   bool flag = !FezMath.AlmostEqual(a, center);
   entity.Velocity = vector3_2;
   if (flag)
     entity.Center = a;
   if (velocityIrrelevant || flag)
   {
     this.DetermineInBackground(entity, false, false, hugWalls);
     this.ClampToGround(entity, clampToGroundDistance, this.CameraManager.Viewpoint);
     if (hugWalls)
       this.HugWalls(entity, false, false, true);
   }
   if (!simple && (!(entity is ISimplePhysicsEntity) || !(entity as ISimplePhysicsEntity).IgnoreCollision))
   {
     if (this.LevelManager.IsInvalidatingScreen)
       this.ScheduleRedefineCorners(entity);
     else
       this.RedefineCorners(entity);
   }
   return flag;
 }
Exemplo n.º 28
0
 private void ScheduleRedefineCorners(IPhysicsEntity entity)
 {
   this.LevelManager.ScreenInvalidated += (Action) (() => this.RedefineCorners(entity));
 }
Exemplo n.º 29
0
 private void RedefineCorners(IPhysicsEntity entity)
 {
   if (entity is IComplexPhysicsEntity)
     this.DetermineOverlaps(entity as IComplexPhysicsEntity);
   else
     this.DetermineOverlaps(entity as ISimplePhysicsEntity);
 }
Exemplo n.º 30
0
 private void ScheduleRedefineCorners(IPhysicsEntity entity)
 {
     this.LevelManager.ScreenInvalidated += (Action)(() => this.RedefineCorners(entity));
 }
Exemplo n.º 31
0
 public PhysicsManager.WallHuggingResult HugWalls(IPhysicsEntity entity, bool determineBackground, bool postRotation, bool keepInFront)
 {
   Vector3 vector3_1 = FezMath.ForwardVector(this.CameraManager.Viewpoint);
   if (!entity.Background)
     vector3_1 = -vector3_1;
   float num1 = 1.0 / 500.0;
   if (entity is ISimplePhysicsEntity)
     num1 = 1.0 / 16.0;
   PhysicsManager.WallHuggingResult wallHuggingResult = new PhysicsManager.WallHuggingResult();
   Vector3 vector3_2 = new Vector3();
   if (entity.Background && entity.Grounded)
     return wallHuggingResult;
   foreach (PointCollision pointCollision in entity.CornerCollision)
   {
     TrileInstance trileInstance1 = (TrileInstance) null;
     if (this.IsHuggable(pointCollision.Instances.Surface, entity))
     {
       FaceOrientation face = FaceOrientation.Down;
       TrileEmplacement traversal = pointCollision.Instances.Surface.Emplacement.GetTraversal(ref face);
       TrileInstance trileInstance2 = this.LevelManager.TrileInstanceAt(ref traversal);
       if (trileInstance2 != null && trileInstance2.Enabled && trileInstance2.GetRotatedFace(this.CameraManager.VisibleOrientation) != CollisionType.None)
         trileInstance1 = pointCollision.Instances.Surface;
     }
     if (trileInstance1 == null && this.IsHuggable(pointCollision.Instances.Deep, entity))
       trileInstance1 = pointCollision.Instances.Deep;
     if (trileInstance1 != null && (!(entity is ISimplePhysicsEntity) || trileInstance1.PhysicsState == null || !trileInstance1.PhysicsState.Puppet) && trileInstance1.PhysicsState != entity)
     {
       Vector3 vector3_3 = trileInstance1.Center + vector3_1 * trileInstance1.TransformedSize / 2f;
       Vector3 vector1 = entity.Center - vector3_1 * entity.Size / 2f - vector3_3 + num1 * -vector3_1;
       float x = Vector3.Dot(vector1, vector3_1);
       if ((double) FezMath.AlmostClamp(x) < 0.0)
       {
         if (determineBackground && (!trileInstance1.Trile.Thin || trileInstance1.Trile.ForceHugging))
         {
           float num2 = Math.Abs(FezMath.Dot(trileInstance1.TransformedSize / 2f + entity.Size / 2f, vector3_1));
           // ISSUE: explicit reference operation
           // ISSUE: variable of a reference type
           PhysicsManager.WallHuggingResult& local = @wallHuggingResult;
           // ISSUE: explicit reference operation
           int num3 = (^local).Behind | (double) Math.Abs(x) > (double) num2 ? 1 : 0;
           // ISSUE: explicit reference operation
           (^local).Behind = num3 != 0;
         }
         else if (keepInFront)
         {
           Vector3 vector3_4 = vector1 * FezMath.Abs(vector3_1);
           vector3_2 -= vector3_4;
           entity.Center -= vector3_4;
           wallHuggingResult.Hugged = true;
         }
       }
     }
     if (postRotation)
     {
       Vector3 vector3_3 = FezMath.AsVector(FezMath.VisibleOrientation(this.CameraManager.LastViewpoint));
       TrileInstance instance = this.LevelManager.ActualInstanceAt(pointCollision.Point + vector3_2);
       if (this.IsHuggable(instance, entity))
       {
         Vector3 vector3_4 = instance.Center + vector3_3 * FezMath.ZYX(instance.TransformedSize) / 2f;
         Vector3 vector1 = entity.Center - vector3_3 * entity.Size / 2f - vector3_4 + 1.0 / 500.0 * vector3_3;
         float x = Vector3.Dot(vector1, vector3_3);
         if ((double) FezMath.AlmostClamp(x) < 0.0 && (double) x > -1.0 && keepInFront)
         {
           Vector3 vector3_5 = vector1 * FezMath.Abs(vector3_3);
           vector3_2 -= vector3_5;
           entity.Center -= vector3_5;
           wallHuggingResult.Hugged = true;
         }
       }
     }
   }
   return wallHuggingResult;
 }
Exemplo n.º 32
0
 public void ClampToGround(IPhysicsEntity entity, Vector3? distance, Viewpoint viewpoint)
 {
   if (!distance.HasValue)
     return;
   Vector3 mask = FezMath.GetMask(FezMath.VisibleAxis(viewpoint));
   entity.Center = distance.Value * mask + (Vector3.One - mask) * entity.Center;
 }
Exemplo n.º 33
0
 public void Hover(IPhysicsEntity entity)
 {
     this.hoveredEntity = entity;
 }
Exemplo n.º 34
0
        public static bool IsPhysicsEntity(this Collider2D collider2D, out IPhysicsEntity physicsEntity)
        {
            physicsEntity = collider2D.GetComponent <IPhysicsEntity>();

            return(physicsEntity != null);
        }
Exemplo n.º 35
0
 private static void CheckChild(IPhysicsEntity child)
 {
     if (child.Engine != null) { throw new InvalidOperationException("The IPhysicsEntity cannot be added to more then one engine or added twice."); }
 }
Exemplo n.º 36
0
        public static bool IsPhysicsEntity(this GameObject gameObject, out IPhysicsEntity physicsEntity)
        {
            physicsEntity = gameObject.GetComponent <IPhysicsEntity>();

            return(physicsEntity != null);
        }
Exemplo n.º 37
0
 public static void ApplyForceFrom(this IPhysicsEntity physicsEntity, Transform to,
                                   Transform from, float power, ForceMode mode = ForceMode.VelocityChange)
 {
     physicsEntity.ApplyForce(
         new Force((to.position - from.position).normalized * power, mode));
 }
Exemplo n.º 38
0
 public void DetermineInBackground(IPhysicsEntity entity, bool allowEnterInBackground, bool postRotation, bool keepInFront)
 {
   if (allowEnterInBackground)
   {
     if (entity is IComplexPhysicsEntity)
     {
       IComplexPhysicsEntity complexPhysicsEntity = entity as IComplexPhysicsEntity;
       Vector3 impulse = 1.0 / 32.0 * Vector3.Down;
       QueryOptions options = QueryOptions.None;
       if (complexPhysicsEntity.Background)
         options |= QueryOptions.Background;
       bool flag = BoxCollisionResultExtensions.AnyHit(this.CollisionManager.CollideEdge(entity.Center, impulse, entity.Size / 2f, Direction2D.Vertical, options));
       if (!flag)
         flag = flag | BoxCollisionResultExtensions.AnyHit(this.CollisionManager.CollideEdge(entity.Center, impulse, entity.Size / 2f, Direction2D.Vertical, options, 0.0f, FezMath.GetOpposite(this.CameraManager.Viewpoint)));
       if (complexPhysicsEntity.Grounded && !flag)
       {
         this.DebuggingBag.Add("zz. had to re-clamp to ground", (object) "POSITIF");
         MultipleHits<CollisionResult> result = this.CollisionManager.CollideEdge(entity.Center, impulse, entity.Size / 2f, Direction2D.Vertical, options, 0.0f, this.CameraManager.LastViewpoint);
         if (BoxCollisionResultExtensions.AnyCollided(result))
           this.ClampToGround(entity, new Vector3?(BoxCollisionResultExtensions.First(result).NearestDistance), this.CameraManager.LastViewpoint);
       }
     }
     entity.Background = false;
     PhysicsManager.WallHuggingResult wallHuggingResult;
     do
     {
       this.DetermineOverlapsInternal(entity, this.CameraManager.Viewpoint);
       wallHuggingResult = this.HugWalls(entity, true, postRotation, keepInFront);
     }
     while (wallHuggingResult.Hugged);
     entity.Background = wallHuggingResult.Behind;
     this.DetermineOverlapsInternal(entity, this.CameraManager.Viewpoint);
     this.HugWalls(entity, false, false, keepInFront);
   }
   else
   {
     if (!entity.Background)
       return;
     bool flag = true;
     foreach (PointCollision pointCollision in entity.CornerCollision)
       flag = flag & !this.IsHuggable(pointCollision.Instances.Deep, entity);
     if (!flag)
       return;
     entity.Background = false;
   }
 }
Exemplo n.º 39
0
 private bool IsHuggable(TrileInstance instance, IPhysicsEntity entity)
 {
   if (instance != null && instance.Enabled && !instance.Trile.Immaterial && ((!instance.Trile.Thin || instance.Trile.ForceHugging) && (instance != this.PlayerManager.CarriedInstance && instance != this.PlayerManager.PushedInstance)) && (!ActorTypeExtensions.IsBomb(instance.Trile.ActorSettings.Type) && (instance.PhysicsState == null || instance.PhysicsState != entity)))
     return !FezMath.In<CollisionType>(instance.GetRotatedFace(entity.Background ? FezMath.GetOpposite(this.CameraManager.VisibleOrientation) : this.CameraManager.VisibleOrientation), CollisionType.Immaterial, CollisionType.TopNoStraightLedge, CollisionType.AllSides, (IEqualityComparer<CollisionType>) CollisionTypeComparer.Default);
   else
     return false;
 }
Exemplo n.º 40
0
 private void MoveAlongWithGround(IPhysicsEntity entity, QueryOptions queryOptions)
 {
   TrileInstance trileInstance = (TrileInstance) null;
   bool flag = false;
   if (PhysicsManager.IsInstanceStateful(entity.Ground.NearLow))
     trileInstance = entity.Ground.NearLow;
   else if (PhysicsManager.IsInstanceStateful(entity.Ground.FarHigh))
     trileInstance = entity.Ground.FarHigh;
   Vector3 vector3 = entity.GroundMovement;
   if (trileInstance != null)
   {
     entity.GroundMovement = FezMath.AlmostClamp(trileInstance.PhysicsState.Velocity + trileInstance.PhysicsState.GroundMovement);
     if (trileInstance.PhysicsState.Sticky)
       flag = true;
   }
   else
   {
     vector3 = Vector3.Clamp(vector3, -FezMath.XZMask, Vector3.One);
     entity.GroundMovement = Vector3.Zero;
   }
   if (entity.GroundMovement != Vector3.Zero)
   {
     MultipleHits<CollisionResult> horizontalResults;
     MultipleHits<CollisionResult> verticalResults;
     this.CollisionManager.CollideRectangle(entity.Center, entity.GroundMovement, entity.Size, queryOptions, entity.Elasticity, out horizontalResults, out verticalResults);
     entity.GroundMovement += (BoxCollisionResultExtensions.AnyCollided(horizontalResults) ? BoxCollisionResultExtensions.First(horizontalResults).Response : Vector3.Zero) + (BoxCollisionResultExtensions.AnyCollided(verticalResults) ? BoxCollisionResultExtensions.First(verticalResults).Response : Vector3.Zero);
     Vector3 min = flag ? -Vector3.One : -FezMath.XZMask;
     entity.Center += Vector3.Clamp(entity.GroundMovement, min, Vector3.One);
     if (!(vector3 == Vector3.Zero) || (double) entity.Velocity.Y <= 0.0)
       return;
     entity.Velocity -= entity.GroundMovement * Vector3.UnitY;
   }
   else
   {
     if (flag || !(vector3 != Vector3.Zero))
       return;
     entity.Velocity += vector3 * 0.85f;
   }
 }
Exemplo n.º 41
0
 public void Splash(IPhysicsEntity entity, bool outwards, float velocityBonus)
 {
   // ISSUE: unable to decompile the method.
 }
Exemplo n.º 42
0
        private bool UpdateInternal(IPhysicsEntity entity, MultipleHits <CollisionResult> horizontalResults, MultipleHits <CollisionResult> verticalResults, Vector3?clampToGroundDistance, bool wasGrounded, bool hugWalls, bool velocityIrrelevant, bool simple)
        {
            Vector3 velocity = entity.Velocity;

            if (!simple)
            {
                MultipleHits <CollisionResult> multipleHits = new MultipleHits <CollisionResult>();
                if (BoxCollisionResultExtensions.AnyCollided(horizontalResults))
                {
                    if (horizontalResults.NearLow.Collided)
                    {
                        multipleHits.NearLow = horizontalResults.NearLow;
                    }
                    if (horizontalResults.FarHigh.Collided)
                    {
                        multipleHits.FarHigh = horizontalResults.FarHigh;
                    }
                }
                entity.WallCollision = multipleHits;
            }
            if (horizontalResults.NearLow.Collided)
            {
                velocity += horizontalResults.NearLow.Response;
            }
            else if (horizontalResults.FarHigh.Collided)
            {
                velocity += horizontalResults.FarHigh.Response;
            }
            if (verticalResults.NearLow.Collided)
            {
                velocity += verticalResults.NearLow.Response;
            }
            else if (verticalResults.FarHigh.Collided)
            {
                velocity += verticalResults.FarHigh.Response;
            }
            Vector3 vector3_1 = !(entity is IComplexPhysicsEntity) || !(entity as IComplexPhysicsEntity).Swimming ? (entity.Grounded || wasGrounded ? (entity.Sliding ? PhysicsManager.SlidingFrictionV : PhysicsManager.GroundFrictionV) : PhysicsManager.AirFrictionV) : PhysicsManager.WaterFrictionV;
            float   amount    = (float)((1.20000004768372 + (double)Math.Abs(this.CollisionManager.GravityFactor) * 0.800000011920929) / 2.0);
            Vector3 vector3_2 = FezMath.AlmostClamp(velocity * Vector3.Lerp(Vector3.One, vector3_1, amount), 1E-06f);

            if (!entity.NoVelocityClamping)
            {
                float max = entity is IComplexPhysicsEntity ? 0.4f : 0.38f;
                vector3_2.Y = MathHelper.Clamp(vector3_2.Y, -max, max);
            }
            Vector3 center = entity.Center;
            Vector3 a      = center + vector3_2;
            bool    flag   = !FezMath.AlmostEqual(a, center);

            entity.Velocity = vector3_2;
            if (flag)
            {
                entity.Center = a;
            }
            if (velocityIrrelevant || flag)
            {
                this.DetermineInBackground(entity, false, false, hugWalls);
                this.ClampToGround(entity, clampToGroundDistance, this.CameraManager.Viewpoint);
                if (hugWalls)
                {
                    this.HugWalls(entity, false, false, true);
                }
            }
            if (!simple && (!(entity is ISimplePhysicsEntity) || !(entity as ISimplePhysicsEntity).IgnoreCollision))
            {
                if (this.LevelManager.IsInvalidatingScreen)
                {
                    this.ScheduleRedefineCorners(entity);
                }
                else
                {
                    this.RedefineCorners(entity);
                }
            }
            return(flag);
        }
Exemplo n.º 43
0
        public PhysicsManager.WallHuggingResult HugWalls(IPhysicsEntity entity, bool determineBackground, bool postRotation, bool keepInFront)
        {
            Vector3 vector3_1 = FezMath.ForwardVector(this.CameraManager.Viewpoint);

            if (!entity.Background)
            {
                vector3_1 = -vector3_1;
            }
            float num1 = 1.0 / 500.0;

            if (entity is ISimplePhysicsEntity)
            {
                num1 = 1.0 / 16.0;
            }
            PhysicsManager.WallHuggingResult wallHuggingResult = new PhysicsManager.WallHuggingResult();
            Vector3 vector3_2 = new Vector3();

            if (entity.Background && entity.Grounded)
            {
                return(wallHuggingResult);
            }
            foreach (PointCollision pointCollision in entity.CornerCollision)
            {
                TrileInstance trileInstance1 = (TrileInstance)null;
                if (this.IsHuggable(pointCollision.Instances.Surface, entity))
                {
                    FaceOrientation  face           = FaceOrientation.Down;
                    TrileEmplacement traversal      = pointCollision.Instances.Surface.Emplacement.GetTraversal(ref face);
                    TrileInstance    trileInstance2 = this.LevelManager.TrileInstanceAt(ref traversal);
                    if (trileInstance2 != null && trileInstance2.Enabled && trileInstance2.GetRotatedFace(this.CameraManager.VisibleOrientation) != CollisionType.None)
                    {
                        trileInstance1 = pointCollision.Instances.Surface;
                    }
                }
                if (trileInstance1 == null && this.IsHuggable(pointCollision.Instances.Deep, entity))
                {
                    trileInstance1 = pointCollision.Instances.Deep;
                }
                if (trileInstance1 != null && (!(entity is ISimplePhysicsEntity) || trileInstance1.PhysicsState == null || !trileInstance1.PhysicsState.Puppet) && trileInstance1.PhysicsState != entity)
                {
                    Vector3 vector3_3 = trileInstance1.Center + vector3_1 * trileInstance1.TransformedSize / 2f;
                    Vector3 vector1   = entity.Center - vector3_1 * entity.Size / 2f - vector3_3 + num1 * -vector3_1;
                    float   x         = Vector3.Dot(vector1, vector3_1);
                    if ((double)FezMath.AlmostClamp(x) < 0.0)
                    {
                        if (determineBackground && (!trileInstance1.Trile.Thin || trileInstance1.Trile.ForceHugging))
                        {
                            float num2 = Math.Abs(FezMath.Dot(trileInstance1.TransformedSize / 2f + entity.Size / 2f, vector3_1));
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            PhysicsManager.WallHuggingResult& local = @wallHuggingResult;
                            // ISSUE: explicit reference operation
                            int num3 = (^ local).Behind | (double)Math.Abs(x) > (double)num2 ? 1 : 0;
                            // ISSUE: explicit reference operation
                            (^ local).Behind = num3 != 0;
                        }
                        else if (keepInFront)
                        {
                            Vector3 vector3_4 = vector1 * FezMath.Abs(vector3_1);
                            vector3_2               -= vector3_4;
                            entity.Center           -= vector3_4;
                            wallHuggingResult.Hugged = true;
                        }
                    }
                }
                if (postRotation)
                {
                    Vector3       vector3_3 = FezMath.AsVector(FezMath.VisibleOrientation(this.CameraManager.LastViewpoint));
                    TrileInstance instance  = this.LevelManager.ActualInstanceAt(pointCollision.Point + vector3_2);
                    if (this.IsHuggable(instance, entity))
                    {
                        Vector3 vector3_4 = instance.Center + vector3_3 * FezMath.ZYX(instance.TransformedSize) / 2f;
                        Vector3 vector1   = entity.Center - vector3_3 * entity.Size / 2f - vector3_4 + 1.0 / 500.0 * vector3_3;
                        float   x         = Vector3.Dot(vector1, vector3_3);
                        if ((double)FezMath.AlmostClamp(x) < 0.0 && (double)x > -1.0 && keepInFront)
                        {
                            Vector3 vector3_5 = vector1 * FezMath.Abs(vector3_3);
                            vector3_2               -= vector3_5;
                            entity.Center           -= vector3_5;
                            wallHuggingResult.Hugged = true;
                        }
                    }
                }
            }
            return(wallHuggingResult);
        }
Exemplo n.º 44
0
 public void Splash(IPhysicsEntity entity, bool outwards)
 {
   this.Splash(entity, outwards, 0.0f);
 }