private static Vector3 SolidCollision(Vector3 normal, TrileInstance instance, Vector3 origin, Vector3 destination, Vector3 impulse, float elasticity) { Vector3 vector3_1 = instance.TransformedSize / 2f; Vector3 vector3_2 = instance.Center + vector3_1 * normal; Vector3 vector3_3 = Vector3.Zero; Vector3 vector3_4; if (instance.PhysicsState != null) { Vector3 vector3_5 = instance.PhysicsState.Sticky ? FezMath.XZMask : Vector3.One; vector3_4 = instance.Center - instance.PhysicsState.Velocity * vector3_5 + vector3_1 * normal; vector3_3 = vector3_2 - vector3_4; } else { vector3_4 = vector3_2; } Vector3 a1 = origin - vector3_4; Vector3 a2 = destination - vector3_2; if ((double)FezMath.AlmostClamp(FezMath.Dot(a1, normal)) < 0.0 || (double)FezMath.AlmostClamp(FezMath.Dot(a2, normal)) > 0.0) { return(Vector3.Zero); } Vector3 vector3_6 = FezMath.Abs(normal); return((double)elasticity <= 0.0 ? (vector3_2 - destination) * vector3_6 : (vector3_3 - impulse) * vector3_6 * (1f + elasticity)); }
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; } }
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); }
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); }
private void CheckForUp() { if (this.GameState.Loading || this.GameState.InMap || (this.GameState.Paused || !this.CameraManager.ActionRunning) || (!this.PlayerManager.Grounded || this.InputManager.GrabThrow != FezButtonState.Pressed || this.CameraManager.Viewpoint != FezMath.AsViewpoint(FezMath.OrientationFromDirection(FezMath.AlmostClamp(Vector3.Transform(Vector3.Left, this.TelescopeAo.Rotation)))))) { return; } Vector3 vector3 = Vector3.Transform(this.PlayerManager.Position - this.TelescopeAo.Position, this.TelescopeAo.Rotation); if ((double)Math.Abs(vector3.Z) >= 0.5 || (double)Math.Abs(vector3.Y) >= 0.5) { return; } this.Visible = true; this.State = TelescopeHost.StateType.In; this.BitTimer = 0.0f; this.MessageIndex = -3; this.Fader = TimeSpan.Zero; this.NowViewing = this.CameraManager.Viewpoint; this.PlayerManager.CanControl = false; this.PlayerManager.Action = ActionType.ReadTurnAround; this.DotManager.Hidden = true; this.DotManager.PreventPoI = true; }
public override void Update(GameTime gameTime) { if (this.GameState.Paused || this.GameState.InMap || (!this.CameraManager.ActionRunning || !FezMath.IsOrthographic(this.CameraManager.Viewpoint)) || this.GameState.Loading) { return; } Vector3 depthMask = FezMath.DepthMask(this.CameraManager.Viewpoint); Vector3 vector3_1 = FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint); if (this.RightPositions == 4) { this.SinceSolved += (float)gameTime.ElapsedGameTime.TotalSeconds; float num = FezMath.Saturate(this.SinceSolved); float amount = Easing.EaseIn((double)num, EasingType.Cubic); foreach (TrileInstance instance in this.Blocks) { Vector3 v = instance.Center - TetrisPuzzleHost.PuzzleCenter; if ((double)v.Length() > 0.5) { Vector3 vector3_2 = FezMath.Sign(FezMath.AlmostClamp(v, 0.1f)); Vector3 vector3_3 = (TetrisPuzzleHost.PuzzleCenter + vector3_2 * 1.75f) * FezMath.XZMask + Vector3.UnitY * instance.Center; Vector3 vector3_4 = (TetrisPuzzleHost.PuzzleCenter + vector3_2) * FezMath.XZMask + Vector3.UnitY * instance.Center; instance.PhysicsState.Center = Vector3.Lerp(vector3_3, vector3_4, amount); instance.PhysicsState.UpdateInstance(); this.LevelManager.UpdateInstance(instance); } } if ((double)num != 1.0) { return; } bool flag = false; foreach (TrileInstance instance in this.Blocks) { if (!flag) { ServiceHelper.AddComponent((IGameComponent) new GlitchyDespawner(this.Game, instance, TetrisPuzzleHost.PuzzleCenter + Vector3.UnitY)); flag = true; } else { ServiceHelper.AddComponent((IGameComponent) new GlitchyDespawner(this.Game, instance)); } } this.GameState.SaveData.ThisLevel.InactiveArtObjects.Add(0); foreach (Volume volume in Enumerable.Where <Volume>((IEnumerable <Volume>) this.LevelManager.Volumes.Values, (Func <Volume, bool>)(x => { if (x.ActorSettings != null && x.ActorSettings.IsPointOfInterest) { return(x.Enabled); } else { return(false); } }))) { volume.Enabled = false; this.GameState.SaveData.ThisLevel.InactiveVolumes.Add(volume.Id); } this.LevelService.ResolvePuzzle(); this.Enabled = false; } else { this.RightPositions = 0; int num1 = 0; int num2 = 0; this.Blocks.Sort((Comparison <TrileInstance>)((a, b) => b.LastTreasureSin.CompareTo(a.LastTreasureSin))); using (List <TrileInstance> .Enumerator enumerator = this.Blocks.GetEnumerator()) { while (enumerator.MoveNext()) { TrileInstance instance = enumerator.Current; if (!instance.PhysicsState.Grounded) { instance.LastTreasureSin = this.SinceStarted; } if ((double)instance.Position.Y >= 19.0 && (double)instance.Position.Y <= 20.5 && (this.PlayerManager.HeldInstance != instance && this.PlayerManager.PushedInstance != instance) && instance.PhysicsState.Grounded && instance.PhysicsState.Ground.First != this.PlayerManager.PushedInstance) { Vector3 vector3_2 = Vector3.Min(Vector3.Max(FezMath.Round((instance.Center - TetrisPuzzleHost.PuzzleCenter) / 1.75f), new Vector3(-3f, 0.0f, -3f)), new Vector3(3f, 1f, 3f)); Vector3 vector3_3 = (TetrisPuzzleHost.PuzzleCenter + vector3_2 * 1.75f - instance.Center) * FezMath.XZMask; float num3 = Math.Max(vector3_3.Length(), 0.1f); instance.PhysicsState.Velocity += 0.25f * vector3_3 / num3 * (float)gameTime.ElapsedGameTime.TotalSeconds; if ((double)num3 <= 0.100000001490116 && (double)vector3_2.Y == 0.0 && instance != this.PlayerManager.Ground.First && !Enumerable.Any <TrileInstance>((IEnumerable <TrileInstance>) this.Blocks, (Func <TrileInstance, bool>)(x => x.PhysicsState.Ground.First == instance)) && Enumerable.Any <TrileInstance>((IEnumerable <TrileInstance>) this.Blocks, (Func <TrileInstance, bool>)(b => { if (b != instance && FezMath.AlmostEqual(b.Position.Y, instance.Position.Y)) { return((double)Math.Abs(FezMath.Dot(b.Center - instance.Center, depthMask)) < 1.75); } else { return(false); } }))) { int num4 = Math.Sign(FezMath.Dot(instance.Center - TetrisPuzzleHost.PuzzleCenter, depthMask)); if (num4 == 0) { num4 = 1; } for (int index = -2; index <= 2; ++index) { int num5 = TetrisPuzzleHost.SpiralTraversal[index + 2] * num4; Vector3 tetativePosition = vector3_1 * instance.PhysicsState.Center + TetrisPuzzleHost.PuzzleCenter * depthMask + depthMask * (float)num5 * 1.75f; if (Enumerable.All <TrileInstance>((IEnumerable <TrileInstance>) this.Blocks, (Func <TrileInstance, bool>)(b => { if (b != instance && FezMath.AlmostEqual(b.Position.Y, instance.Position.Y)) { return((double)Math.Abs(FezMath.Dot(b.Center - tetativePosition, depthMask)) >= 1.57499992847443); } else { return(true); } }))) { instance.PhysicsState.Center = tetativePosition; break; } } } if (this.RightPositions < 4 && (double)num3 <= 0.100000001490116 && instance.PhysicsState.Grounded) { if ((double)instance.Position.Y == 20.0) { if ((double)vector3_2.X == (double)TetrisPuzzleHost.TwoHigh.X && (double)vector3_2.Z == (double)TetrisPuzzleHost.TwoHigh.Z) { this.RightPositions += 2; } } else { if ((double)vector3_2.X == (double)TetrisPuzzleHost.Interchangeable1_1.X && (double)vector3_2.Z == (double)TetrisPuzzleHost.Interchangeable1_1.Z || (double)vector3_2.X == (double)TetrisPuzzleHost.Interchangeable1_2.X && (double)vector3_2.Z == (double)TetrisPuzzleHost.Interchangeable1_2.Z) { ++num1; } if ((double)vector3_2.X == (double)TetrisPuzzleHost.Interchangeable2_1.X && (double)vector3_2.Z == (double)TetrisPuzzleHost.Interchangeable2_1.Z || (double)vector3_2.X == (double)TetrisPuzzleHost.Interchangeable2_2.X && (double)vector3_2.Z == (double)TetrisPuzzleHost.Interchangeable2_2.Z) { ++num2; } } } } } } if (this.RightPositions >= 4 || num1 != 2 && num2 != 2) { return; } this.RightPositions += 2; } }