#

API Docs for: 0.6.0
Show: Inherited Protected Private Deprecated

# File: src/constraints/Constraint.js

    module.exports = Constraint;

    var Utils = require('../utils/Utils');

    /**
     * Constraint base class
     * @class Constraint
     * @author schteppe
     * @constructor
     * @param {Body} bodyA
     * @param {Body} bodyB
     */
    function Constraint(bodyA, bodyB, options){
        options = Utils.defaults(options,{
            collideConnected : true,
            wakeUpBodies : true,
        });

        /**
         * Equations to be solved in this constraint
         * @property equations
         * @type {Array}
         */
        this.equations = [];

        /**
         * @property {Body} bodyA
         */
        this.bodyA = bodyA;

        /**
         * @property {Body} bodyB
         */
        this.bodyB = bodyB;

        /**
         * @property {Number} id
         */
        this.id = Constraint.idCounter++;

        /**
         * Set to true if you want the bodies to collide when they are connected.
         * @property collideConnected
         * @type {boolean}
         */
        this.collideConnected = options.collideConnected;

        if(options.wakeUpBodies){
            if(bodyA){
                bodyA.wakeUp();
            }
            if(bodyB){
                bodyB.wakeUp();
            }
        }
    }

    /**
     * @method update
     */
    Constraint.prototype.update = function(){
        throw new Error("method update() not implmemented in this Constraint subclass!");
    };

    Constraint.idCounter = 0;