planck-js
Version:
2D physics engine for JavaScript/HTML5 game development
151 lines (125 loc) • 4.92 kB
JavaScript
/*
* Copyright (c) 2016 Ali Shakiba http://shakiba.me/planck.js
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
var Settings = exports;
/**
* Tuning constants based on meters-kilograms-seconds (MKS) units.
*/
// Collision
/**
* The maximum number of contact points between two convex shapes. Do not change
* this value.
*/
Settings.maxManifoldPoints = 2;
/**
* The maximum number of vertices on a convex polygon. You cannot increase this
* too much because BlockAllocator has a maximum object size.
*/
Settings.maxPolygonVertices = 8;
/**
* This is used to fatten AABBs in the dynamic tree. This allows proxies to move
* by a small amount without triggering a tree adjustment. This is in meters.
*/
Settings.aabbExtension = 0.1;
/**
* This is used to fatten AABBs in the dynamic tree. This is used to predict the
* future position based on the current displacement. This is a dimensionless
* multiplier.
*/
Settings.aabbMultiplier = 2.0;
/**
* A small length used as a collision and constraint tolerance. Usually it is
* chosen to be numerically significant, but visually insignificant.
*/
Settings.linearSlop = 0.005;
Settings.linearSlopSquared = Settings.linearSlop * Settings.linearSlop;
/**
* A small angle used as a collision and constraint tolerance. Usually it is
* chosen to be numerically significant, but visually insignificant.
*/
Settings.angularSlop = (2.0 / 180.0 * Math.PI);
/**
* The radius of the polygon/edge shape skin. This should not be modified.
* Making this smaller means polygons will have an insufficient buffer for
* continuous collision. Making it larger may create artifacts for vertex
* collision.
*/
Settings.polygonRadius = (2.0 * Settings.linearSlop);
/**
* Maximum number of sub-steps per contact in continuous physics simulation.
*/
Settings.maxSubSteps = 8;
// Dynamics
/**
* Maximum number of contacts to be handled to solve a TOI impact.
*/
Settings.maxTOIContacts = 32;
/**
* A velocity threshold for elastic collisions. Any collision with a relative
* linear velocity below this threshold will be treated as inelastic.
*/
Settings.velocityThreshold = 1.0;
/**
* The maximum linear position correction used when solving constraints. This
* helps to prevent overshoot.
*/
Settings.maxLinearCorrection = 0.2;
/**
* The maximum angular position correction used when solving constraints. This
* helps to prevent overshoot.
*/
Settings.maxAngularCorrection = (8.0 / 180.0 * Math.PI);
/**
* The maximum linear velocity of a body. This limit is very large and is used
* to prevent numerical problems. You shouldn't need to adjust this.
*/
Settings.maxTranslation = 2.0;
Settings.maxTranslationSquared = (Settings.maxTranslation * Settings.maxTranslation);
/**
* The maximum angular velocity of a body. This limit is very large and is used
* to prevent numerical problems. You shouldn't need to adjust this.
*/
Settings.maxRotation = (0.5 * Math.PI)
Settings.maxRotationSquared = (Settings.maxRotation * Settings.maxRotation)
/**
* This scale factor controls how fast overlap is resolved. Ideally this would
* be 1 so that overlap is removed in one time step. However using values close
* to 1 often lead to overshoot.
*/
Settings.baumgarte = 0.2;
Settings.toiBaugarte = 0.75;
// Sleep
/**
* The time that a body must be still before it will go to sleep.
*/
Settings.timeToSleep = 0.5;
/**
* A body cannot sleep if its linear velocity is above this tolerance.
*/
Settings.linearSleepTolerance = 0.01;
Settings.linearSleepToleranceSqr = Math.pow(Settings.linearSleepTolerance, 2);
/**
* A body cannot sleep if its angular velocity is above this tolerance.
*/
Settings.angularSleepTolerance = (2.0 / 180.0 * Math.PI);
Settings.angularSleepToleranceSqr = Math.pow(Settings.angularSleepTolerance, 2);
Assert = function(statement, msg) {
if (!statement) {
throw new Error(msg);
}
}