UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

69 lines (68 loc) 2.3 kB
import { vec2 } from "gl-matrix"; import RigidBody from "../rigidbody"; import kdTree from "./kdTree"; export default class Particle extends RigidBody { private radius; density: number; densityNear: number; pressure: number; pressureNear: number; dx: vec2; posPrev: vec2; neighbours: Particle[]; /** * Creates a {@link Particle}. * * @param radius The radius of the particle * @param mass The mass of the particle */ constructor(radius: number, mass: number); /** * Finds particles which are closer to this particle than the fluid's smoothing radius. * * Particles which are closer than this distance are added to this particle's neighbours array. * * @param kdTree The {@link kdTree} of the fluid * @param smoothingRadius The fluid's smoothing radius * @param smoothingRadiusSqr The fluid's smoothing radius squared */ findNeighbours(kdTree: kdTree, smoothingRadius: number, smoothingRadiusSqr: number): void; /** * Computes the density and density near of the particle based on it's neighbours. * * @param smoothingRadius The smoothing radius of the fluid */ computeDoubleDensityRelaxation(smoothingRadius: number): void; /** * Calculate the pressure the particle based on it's neighbours. * * @param restDensity The rest density of the fluid */ computePressure(stiffness: number, stiffnessNear: number, restDensity: number): void; /** * Advanced the particle's position. * * @param delta The time since the last update * @param smoothingRadius The smoothing radius of the fluid */ advancePosition(delta: number, smoothingRadius: number): void; /** * Comptues the particle's new velocity and performs the second force solving pass. * * @param delta The time since the last update * @param gravity The physics world's gravity vector */ computeNewVelocity(delta: number, gravity: vec2): void; /** * Sets the particle's radius. * * @param radius The particle's new radius */ setRadius(radius: number): void; /** * Gets the radius of the particle. * * @returns The particle's radius */ getRadius(): number; }