Unit Breakout.Physics

Description

Continuous circle sweeps and velocity response in logical coordinates.

Source: src/Breakout.Physics.pas (line 2).

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TPhysicsRect Axis-aligned bounds; screen Y grows downward.
Record TCircleHit Earliest contact: Time in seconds, outward unit normal and initial overlap depth in logical units.

Functions and Procedures

function SweepCircleRect(CX, CY, Radius, VX, VY, MaxTime: Double; const Rect: TPhysicsRect; out Hit: TCircleHit): Boolean;
function SweepCirclePaddle(CX, CY, Radius, VX, VY, MaxTime: Double; const Rect: TPhysicsRect; out Hit: TCircleHit): Boolean;
procedure ReflectVelocity(var VX, VY: Double; NX, NY: Double);
procedure PaddleVelocity(Offset, Speed, IncomingVX, MinAngle, MaxAngle: Double; out VX, VY: Double);

Constants

PositionEpsilon = 1.0E-6;
TimeEpsilon = 1.0E-10;

Description

Functions and Procedures

function SweepCircleRect(CX, CY, Radius, VX, VY, MaxTime: Double; const Rect: TPhysicsRect; out Hit: TCircleHit): Boolean;

Sweeps a circle against a rectangle over [0, MaxTime]. Tests four face segments and four circular corner arcs, including initial overlap.

Parameters
CX
Circle center X in logical units.
CY
Circle center Y in logical units.
Radius
Positive circle radius.
VX
Horizontal velocity in units per second.
VY
Vertical velocity in units per second.
MaxTime
Nonnegative interval in seconds.
Rect
Static solid bounds.
Hit
Earliest inward contact, reset to zero if none is found.
Returns

True when contact is found in the interval.

Source: src/Breakout.Physics.pas (line 36).

function SweepCirclePaddle(CX, CY, Radius, VX, VY, MaxTime: Double; const Rect: TPhysicsRect; out Hit: TCircleHit): Boolean;

Sweeps against a horizontal capsule with cap radius half its height. Reduces to the center segment dilated by ball radius plus cap radius. Coordinates, velocity, time and Hit follow SweepCircleRect.

Source: src/Breakout.Physics.pas (line 41).

procedure ReflectVelocity(var VX, VY: Double; NX, NY: Double);

Applies v := v - 2*dot(v,n)*n only when approaching the surface. NX/NY must form an outward unit normal; separating velocity is unchanged.

Source: src/Breakout.Physics.pas (line 45).

procedure PaddleVelocity(Offset, Speed, IncomingVX, MinAngle, MaxAngle: Double; out VX, VY: Double);

Maps normalized horizontal impact offset to an upward velocity.

Parameters
Offset
Contact-center offset divided by paddle half-width; clamped to [-1,1].
Speed
Preserved velocity magnitude in logical units per second.
IncomingVX
Selects left/right at the exact paddle center.
MinAngle
Minimum absolute deflection from vertical, in degrees.
MaxAngle
Edge deflection from vertical, in degrees.
VX
Resulting horizontal velocity.
VY
Resulting negative vertical velocity.

Source: src/Breakout.Physics.pas (line 54).

Constants

PositionEpsilon = 1.0E-6;

Spatial tolerance and post-contact separation in logical units.

Source: src/Breakout.Physics.pas (line 21).

TimeEpsilon = 1.0E-10;

Temporal tolerance for contact times in seconds.

Source: src/Breakout.Physics.pas (line 23).


Generated by PasDoc 1.0.4.