Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Feb 2, 2014
1 parent 01a3879 commit d7d01b7
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/collision/ObjectCollisionMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ObjectCollisionMatrix.prototype.reset = function() {

/**
* Set max number of objects
* @method setNumObjects
* @param {Number} n
*/
ObjectCollisionMatrix.prototype.setNumObjects = function(n) {
Expand Down
2 changes: 1 addition & 1 deletion src/collision/Ray.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Ray.prototype.constructor = Ray;
var v1 = new Vec3(),
v2 = new Vec3();

/**
/*
* As per "Barycentric Technique" as named here http://www.blackpawn.com/texts/pointinpoly/default.html But without the division
*/
function pointInTriangle( p, a, b, c ) {
Expand Down
8 changes: 7 additions & 1 deletion src/constraints/ContactEquation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ function ContactEquation(bi,bj){
this.restitution = 0.0; // "bounciness": u1 = -e*u0

/**
* World-oriented vector that goes from the center of bi to the contact point in bi.
* World-oriented vector that goes from the center of bi to the contact point.
* @property {Vec3} ri
*/
this.ri = new Vec3();

/**
* World-oriented vector that starts in body j position and goes to the contact point.
* @property {Vec3} rj
*/
this.rj = new Vec3();

this.penetrationVec = new Vec3();

/**
* Contact normal, pointing out of body i.
* @property {Vec3} ni
*/
this.ni = new Vec3();

this.rixn = new Vec3();
this.rjxn = new Vec3();

Expand Down
5 changes: 5 additions & 0 deletions src/constraints/RotationalMotorEquation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ function RotationalMotorEquation(bodyA, bodyB, maxForce){

this.invIi = new Mat3();
this.invIj = new Mat3();

/**
* Motor velocity
* @property {Number} targetVelocity
*/
this.targetVelocity = 0;
};

Expand Down
40 changes: 35 additions & 5 deletions src/material/ContactMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,52 @@ module.exports = ContactMaterial;
*/
function ContactMaterial(m1, m2, friction, restitution){

/// Contact material index in the world, -1 until added to the world
/**
* Identifier of this material
* @property {Number} id
*/
this.id = -1;

/// The two materials participating in the contact
/**
* Participating materials
* @property {Array} materials
*/
this.materials = [m1,m2];

/// Kinetic friction
/**
* Friction coefficient
* @property {Number} friction
*/
this.friction = friction!==undefined ? Number(friction) : 0.3;

/// Restitution
/**
* Restitution coefficient
* @property {Number} restitution
*/
this.restitution = restitution !== undefined ? Number(restitution) : 0.3;

// Parameters to pass to the constraint when it is created
/**
* Stiffness of the produced contact equations
* @property {Number} contactEquationStiffness
*/
this.contactEquationStiffness = 1e7;

/**
* Regularization of the produced contact equations
* @property {Number} contactEquationRegularizationTime
*/
this.contactEquationRegularizationTime = 3;

/**
* Stiffness of the produced friction equations
* @property {Number} frictionEquationStiffness
*/
this.frictionEquationStiffness = 1e7;

/**
* Regularization of the produced friction equations
* @property {Number} frictionEquationRegularizationTime
*/
this.frictionEquationRegularizationTime = 3;
};

6 changes: 5 additions & 1 deletion src/math/Mat3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Vec3 = require('./Vec3')
function Mat3(elements){
/**
* A vector of length 9, containing all matrix elements
* @property Array elements
* @property {Array} elements
*/
if(elements){
this.elements = elements;
Expand Down Expand Up @@ -41,6 +41,10 @@ Mat3.prototype.identity = function(){
this.elements[8] = 1;
};

/**
* Set all elements to zero
* @method setZero
*/
Mat3.prototype.setZero = function(){
var e = this.elements;
e[0] = 0;
Expand Down
9 changes: 8 additions & 1 deletion src/math/Quaternion.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ Quaternion.prototype.toEuler = function(target,order){
target.x = bank;
};

// http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
/**
* See http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
* @method setFromEuler
* @param {Number} x
* @param {Number} y
* @param {Number} z
* @param {String} order The order to apply angles: 'XYZ' or 'YXZ' or any other combination
*/
Quaternion.prototype.setFromEuler = function ( x, y, z, order ) {
var c1 = Math.cos( x / 2 );
var c2 = Math.cos( y / 2 );
Expand Down
7 changes: 6 additions & 1 deletion src/math/Vec3.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var Mat3 = require('./Mat3')
* @param {Number} z
* @author schteppe
*/
var numVecs = 0;
function Vec3(x,y,z){
/**
* @property x
Expand Down Expand Up @@ -178,6 +177,12 @@ Vec3.prototype.norm2 = function(){
return this.dot(this);
};

/**
* Get distance from this point to another point
* @method distanceTo
* @param {Vec3} p
* @return {Number}
*/
Vec3.prototype.distanceTo = function(p){
var x=this.x, y=this.y, z=this.z;
var px=p.x, py=p.y, pz=p.z;
Expand Down
11 changes: 11 additions & 0 deletions src/objects/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,20 @@ function Body(type){

this.vlambda = new Vec3();

/**
* @property {Number} collisionFilterGroup
*/
this.collisionFilterGroup = 1;

/**
* @property {Number} collisionFilterMask
*/
this.collisionFilterMask = 1;

/**
* Whether to produce contact forces
* @property {Number} collisionResponse
*/
this.collisionResponse = true;
};

Expand Down
9 changes: 8 additions & 1 deletion src/objects/Box.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ var Shape = require('./Shape')
function Box(halfExtents){
Shape.call(this);

this.type = Shape.types.BOX;

/**
* @property halfExtents
* @type {Vec3}
*/
this.halfExtents = halfExtents;
this.type = Shape.types.BOX;

/**
* Used by the contact generator to make contacts with other convex polyhedra for example
Expand Down Expand Up @@ -68,6 +69,12 @@ Box.prototype.updateConvexPolyhedronRepresentation = function(){
this.convexPolyhedronRepresentation = h;
};

/**
* @method calculateLocalInertia
* @param {Number} mass
* @param {Vec3} target
* @return {Vec3}
*/
Box.prototype.calculateLocalInertia = function(mass,target){
target = target || new Vec3();
var e = this.halfExtents;
Expand Down
14 changes: 13 additions & 1 deletion src/objects/Compound.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ var Shape = require('./Shape')
/**
* A shape made of several other shapes.
* @class Compound
* @extends Shape
* @extends {Shape}
* @author schteppe
*/
function Compound(){
Shape.call(this);
this.type = Shape.types.COMPOUND;

/**
* @property {Array} childShapes
*/
this.childShapes = [];

/**
* @property {Array} childOffsets
*/
this.childOffsets = [];

/**
* @property {Array} childOrientations
*/
this.childOrientations = [];
};
Compound.prototype = new Shape();
Expand Down
4 changes: 4 additions & 0 deletions src/objects/RigidBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ function RigidBody(mass,shape,material){
RigidBody.prototype = new Particle(0);
RigidBody.prototype.constructor = RigidBody;

/**
* Updates the .aabbmin and .aabbmax properties
* @method computeAABB
*/
RigidBody.prototype.computeAABB = function(){
this.shape.calculateWorldAABB(this.position,
this.quaternion,
Expand Down
3 changes: 1 addition & 2 deletions src/objects/Sphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ function Sphere(radius){
Shape.call(this);

/**
* @property radius
* @type {Number}
* @property {Number} radius
*/
this.radius = radius!==undefined ? Number(radius) : 1.0;
this.type = Shape.types.SPHERE;
Expand Down
26 changes: 24 additions & 2 deletions src/solver/Solver.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,38 @@ module.exports = Solver;
* @author schteppe / https://github.com/schteppe
*/
function Solver(){
// All equations to be solved
/**
* All equations to be solved
* @property {Array} equations
*/
this.equations = [];
};

// Should be implemented in subclasses!
/**
* Should be implemented in subclasses!
* @method solve
* @param {Number} dt
* @param {World} world
*/
Solver.prototype.solve = function(dt,world){
// Should return the number of iterations done!
return 0;
};

/**
* Add an equation
* @method addEquation
* @param {Equation} eq
*/
Solver.prototype.addEquation = function(eq){
this.equations.push(eq);
};

/**
* Remove an equation
* @method removeEquation
* @param {Equation} eq
*/
Solver.prototype.removeEquation = function(eq){
var eqs = this.equations;
var i = eqs.indexOf(eq);
Expand All @@ -29,6 +47,10 @@ Solver.prototype.removeEquation = function(eq){
}
};

/**
* Add all equations
* @method removeAllEquations
*/
Solver.prototype.removeAllEquations = function(){
this.equations.length = 0;
};
Expand Down
14 changes: 14 additions & 0 deletions src/solver/SplitSolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ var Vec3 = require('../math/Vec3')
, Solver = require('./Solver')
, Body = require('../objects/Body')

/**
* Splits the equations into islands and solves them independently. Can improve performance.
* @class SplitSolver
* @constructor
* @extends {Solver}
* @param {Solver} subsolver
*/
function SplitSolver(subsolver){
Solver.call(this);
this.subsolver = subsolver;
Expand All @@ -16,6 +23,13 @@ var SplitSolver_solve_nodes = []; // All allocated node objects
var SplitSolver_solve_eqs = []; // Temp array
var SplitSolver_solve_bds = []; // Temp array
var SplitSolver_solve_dummyWorld = {bodies:null}; // Temp object

/**
* Solve the subsystems
* @method solve
* @param {Number} dt
* @param {World} world
*/
SplitSolver.prototype.solve = function(dt,world){
var nodes=SplitSolver_solve_nodes,
bodies=world.bodies,
Expand Down
20 changes: 20 additions & 0 deletions src/utils/EventTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ module.exports = EventTarget;
*/
function EventTarget() {
var listeners = {};

/**
* Add an event listener
* @method addEventListener
* @param {String} type
* @param {Function} listener
*/
this.addEventListener = function ( type, listener ) {
if ( listeners[ type ] === undefined ) {
listeners[ type ] = [];
Expand All @@ -15,11 +22,24 @@ function EventTarget() {
listeners[ type ].push( listener );
}
};

/**
* Dispatch an event
* @method dispatchEvent
* @param {Object} event
*/
this.dispatchEvent = function ( event ) {
for ( var listener in listeners[ event.type ] ) {
listeners[ event.type ][ listener ]( event );
}
};

/**
* Remove an event listener
* @method removeEventListener
* @param {String} type
* @param {Function} listener
*/
this.removeEventListener = function ( type, listener ) {
var index = listeners[ type ].indexOf( listener );
if ( index !== - 1 ) {
Expand Down
Loading

0 comments on commit d7d01b7

Please sign in to comment.