Fork me on GitHub

API Documentation


Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 103 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 103 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 103 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 103 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 103 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 103 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 105 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 105 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 110 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_physics_glge_physicsconstraintpoint.js.html, line: 110 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29
  1 /*
  2 GLGE WebGL Graphics Engine
  3 Copyright (c) 2011, Paul Brunt
  4 All rights reserved.
  5 
  6 Redistribution and use in source and binary forms, with or without
  7 modification, are permitted provided that the following conditions are met:
  8     * Redistributions of source code must retain the above copyright
  9       notice, this list of conditions and the following disclaimer.
 10     * Redistributions in binary form must reproduce the above copyright
 11       notice, this list of conditions and the following disclaimer in the
 12       documentation and/or other materials provided with the distribution.
 13     * Neither the name of GLGE nor the
 14       names of its contributors may be used to endorse or promote products
 15       derived from this software without specific prior written permission.
 16 
 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 20 DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY
 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 */
 28 
 29 /**
 30  * @fileOverview
 31  * @name glge_constraintpoint.js
 32  * @author me@paulbrunt.co.uk
 33  */
 34 
 35 
 36 (function(GLGE){
 37 
 38 /**
 39 * @class A wrapping class for jiglib constraint point
 40 * @augments GLGE.QuickNotation
 41 * @augments GLGE.JSONLoader
 42 */
 43 GLGE.PhysicsConstraintPoint=function(){
 44 }
 45 GLGE.augment(GLGE.QuickNotation,GLGE.PhysicsConstraintPoint);
 46 GLGE.augment(GLGE.JSONLoader,GLGE.PhysicsConstraintPoint);
 47 
 48 GLGE.PhysicsConstraintPoint.constraint=null;
 49 GLGE.PhysicsConstraintPoint.prototype.className="PhysicsConstraintPoint";
 50 
 51 
 52 /**
 53 * Sets the first body to use with this constraint
 54 * @param {GLGE.PhysicsAbstract} body1 The first body
 55 */
 56 GLGE.PhysicsConstraintPoint.prototype.setBody1=function(body1){
 57 	this.body1=body1;
 58 	this.updateConstraint();
 59 	return this;
 60 }
 61 /**
 62 * Sets the second body to use with this constraint
 63 * @param {GLGE.PhysicsAbstract} body2 The second body
 64 */
 65 GLGE.PhysicsConstraintPoint.prototype.setBody2=function(body2){
 66 	this.body2=body2;
 67 	this.updateConstraint();
 68 	return this;
 69 }
 70 /**
 71 * Sets the constraing point on the first body
 72 * @param {array} bodypos1 The first body constraint point
 73 */
 74 GLGE.PhysicsConstraintPoint.prototype.setBodyPos1=function(bodypos1){
 75 	if(typeof(bodypos1)=="string") bodypos1=bodypos1.split(",");
 76 	this.bodypos1=[parseFloat(bodypos1[0]),parseFloat(bodypos1[1]),parseFloat(bodypos1[2])];
 77 	this.updateConstraint();
 78 	return this;
 79 }
 80 /**
 81 * Sets the constraing point on the second body
 82 * @param {array} bodypos2 The second body constraint point
 83 */
 84 GLGE.PhysicsConstraintPoint.prototype.setBodyPos2=function(bodypos2){
 85 	if(typeof(bodypos2)=="string") bodypos2=bodypos2.split(",");
 86 	this.bodypos2=[parseFloat(bodypos2[0]),parseFloat(bodypos2[1]),parseFloat(bodypos2[2])];
 87 	this.updateConstraint();
 88 	return this;
 89 }
 90 
 91 /**
 92 * Updates the jiglib constraint
 93 * @private
 94 */
 95 GLGE.PhysicsConstraintPoint.prototype.updateConstraint=function(){
 96 	if(this.body1 && this.body2 && this.bodypos1 && this.bodypos2){
 97 		if(this.constraint){
 98 			if(this.parent && this.parent.physicsSystem) this.parent.physicsSystem.removeConstraint(this.constraint);
 99 			this.body1.removeConstraint(this.constraint);
100 			this.body2.removeConstraint(this.constraint);
101 		}
102 		this.constraint=new jigLib.JConstraintPoint(this.body1.jigLibObj,this.bodypos1,this.body2.jigLibObj,this.bodypos2);
103 		if(this.parent && this.parent.physicsSystem) this.parent.physicsSystem.addConstraint(this.constraint);
104 	}
105 }
106 
107 /**
108 * Add a new physics constraint to the scene
109 * @param {GLGE.PhysicsConstraintPoint} constraint The constraint to add to the scene
110 */
111 GLGE.Scene.prototype.addPhysicsConstraintPoint=function(constraint){
112 	if(!this.constraints) this.constraints=[];
113 	this.constraints.push(constraint);
114 	if(this.physicsSystem) this.physicsSystem.addConstraint(constraint.constraint);
115 	return this;
116 }
117 
118 /**
119 * Removes a physics constraint to the scene
120 * @param {GLGE.PhysicsConstraintPoint} constraint The constraint to remove from the scene
121 */
122 GLGE.Scene.prototype.removePhysicsConstraintPoint=function(constraint){
123 	if(!this.constraints) this.constraints=[];
124 	if(this.constraints.indexOf(constraint)>-1){
125 		this.constraints.push(constraint);
126 		if(this.physicsSystem) this.physicsSystem.removeConstraint(constraint.constraint);
127 	}
128 	return this;
129 }
130 
131 
132 })(GLGE);