UNPKG

@rpgjs/physic

Version:

A deterministic 2D top-down physics library for RPG, sandbox and MMO games

82 lines 2.14 kB
import { Entity } from './Entity'; import { Vector2 } from '../core/math/Vector2'; /** * Integration method type */ export declare enum IntegrationMethod { /** Semi-implicit Euler (default, stable and fast) */ Euler = "euler", /** Verlet integration (more stable, better energy conservation) */ Verlet = "verlet" } /** * Configuration for physics integration */ export interface IntegratorConfig { /** Integration method to use */ method?: IntegrationMethod; /** Time step (usually 1/60 for 60 FPS) */ deltaTime: number; /** Gravity vector (optional, for top-down usually zero) */ gravity?: Vector2; } /** * Physics integrator * * Handles numerical integration of physical entities. * Supports multiple integration methods for different stability requirements. * * @example * ```typescript * const integrator = new Integrator({ deltaTime: 1/60 }); * integrator.integrate(entity); * ``` */ export declare class Integrator { private config; private gravity; /** * Creates a new integrator * * @param config - Integrator configuration */ constructor(config: IntegratorConfig); /** * Integrates an entity's motion * * Updates position, velocity, and rotation based on forces and torques. * * @param entity - Entity to integrate */ integrate(entity: Entity): void; /** * Semi-implicit Euler integration * * Updates velocity first, then position. More stable than explicit Euler. * * @param entity - Entity to integrate */ private integrateEuler; /** * Verlet integration * * More stable than Euler, better energy conservation. * Requires storing previous position. * * @param entity - Entity to integrate */ private integrateVerlet; /** * Updates the gravity vector * * @param gravity - New gravity vector */ setGravity(gravity: Vector2): void; /** * Gets the current gravity vector * * @returns Gravity vector */ getGravity(): Vector2; } //# sourceMappingURL=integrator.d.ts.map