private static void selectBetterResult(ref HitResult? currentBest, ref float currentBestF, HitResult? candidate) { if (candidate.HasValue) { var f = candidate.Value.RayFactor; if (f < currentBestF) { currentBest = candidate; currentBestF = f; } } }
private void drawDebug(HitResult? result) { var geo = GeometryManager.Instance.PrimitivesOverlay; geo.LineWidth = 0.05f; if (result.HasValue) { var p = result.Value.Point.NumericValue; geo.Color = Color.Green; geo.DrawLine(this.Start.NumericValue, p); geo.DrawCircle(p, 0.2f); } else { geo.Color = Color.Red; geo.DrawLine(this.Start.NumericValue, (this.Start + this.Direction).NumericValue); } }
protected virtual void onHit(HitResult hitResult) { this.Delete(); }
public Data UpdateTo(GameState game, TimeSpan time, out HitResult? hitResult) { hitResult = this.Update(game, time); return this; }
public HitResult? Update(GameState game, TimeSpan time) { var vDelta = this.velocity * time; var hitResult = new Ray(this.position, vDelta) .Shoot(game, true, this.collideWithProjectileColliders); var f = hitResult.HasValue ? hitResult.Value.RayFactor : 1; var zDelta = this.vz * time; var z = this.z + zDelta; if (z < 0.U()) { f = this.z / zDelta; z = 0.U(); hitResult = new HitResult(this.position + vDelta * f, Direction2.Zero, f, false); } this.position += vDelta * f; this.z = z; this.vz += game.Gravity * time; return hitResult; }
public HitResult? TryHit(Ray ray) { var start = ray.Start.NumericValue; var direction = ray.Direction.NumericValue; var topLeft = this.TopLeft.NumericValue; var bottomRight = (this.TopLeft + this.Size).NumericValue; HitResult? result = null; var bestF = 1f; if (direction.X != 0) { { // left var f = (topLeft.X - start.X) / direction.X; if (f >= 0 && f < bestF) { var y = start.Y + direction.Y * f; if (y >= topLeft.Y && y <= bottomRight.Y) { bestF = f; result = new HitResult(new Position2(topLeft.X, y), Direction2.FromDegrees(180), f, start.X > topLeft.X); } } } { // right var f = (bottomRight.X - start.X) / direction.X; if (f >= 0 && f < bestF) { var y = start.Y + direction.Y * f; if (y >= topLeft.Y && y <= bottomRight.Y) { bestF = f; result = new HitResult(new Position2(bottomRight.X, y), Direction2.FromDegrees(0), f, start.X < bottomRight.X); } } } } if (direction.Y != 0) { { // top var f = (topLeft.Y - start.Y) / direction.Y; if (f >= 0 && f < bestF) { var x = start.X + direction.X * f; if (x >= topLeft.X && x <= bottomRight.X) { bestF = f; result = new HitResult(new Position2(x, topLeft.Y), Direction2.FromDegrees(270), f, start.Y > topLeft.Y); } } } { // bottom var f = (bottomRight.Y - start.Y) / direction.Y; if (f >= 0 && f < bestF) { var x = start.X + direction.X * f; if (x >= topLeft.X && x <= bottomRight.X) { bestF = f; result = new HitResult(new Position2(x, bottomRight.Y), Direction2.FromDegrees(90), f, start.Y < bottomRight.Y); } } } } return result; }