1 /** 2 * The Render Engine 3 * CollisionData 4 * 5 * @fileoverview Data object which holds collision relevant information. 6 * 7 * @author: Brett Fattori (brettf@renderengine.com) 8 * 9 * @author: $Author: bfattori $ 10 * @version: $Revision: 1555 $ 11 * 12 * Copyright (c) 2011 Brett Fattori (brettf@renderengine.com) 13 * 14 * Permission is hereby granted, free of charge, to any person obtaining a copy 15 * of this software and associated documentation files (the "Software"), to deal 16 * in the Software without restriction, including without limitation the rights 17 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 * copies of the Software, and to permit persons to whom the Software is 19 * furnished to do so, subject to the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be included in 22 * all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 * THE SOFTWARE. 31 * 32 */ 33 34 // The class this file defines and its required classes 35 R.Engine.define({ 36 "class":"R.struct.CollisionData", 37 "requires":[ 38 "R.engine.PooledObject" 39 ] 40 }); 41 42 /** 43 * @class An object which contains information about a collision. The values of the 44 * collision data are read directly. 45 * 46 * @param o {Number} Overlap 47 * @param u {R.math.Vector2D} The collision normal 48 * @param s1 {R.engine.GameObject} Game object 1 49 * @param s2 {R.engine.GameObject} Game object 2 50 * @param i {R.math.Vector2D} Impulse vector to separate shapes 51 * @param wt {Number} World time 52 * @param dt {Number} Time since last frame redraw (delta time) 53 * 54 * @extends R.engine.PooledObject 55 * @constructor 56 * @description Creates a collision data structure. 57 */ 58 R.struct.CollisionData = function () { 59 return R.engine.PooledObject.extend(/** @scope R.struct.CollisionData.prototype */{ 60 61 /** 62 * The overlap in pixels 63 * @type {Number} 64 */ 65 overlap:0, 66 67 /** 68 * The collision normal 69 * @type {R.math.Vector2D} 70 */ 71 unitVector:null, 72 73 /** 74 * The game object which collided 75 * @type {R.engine.GameObject} 76 */ 77 shape1:null, 78 79 /** 80 * The game object that was collided with 81 * @type {R.engine.GameObject} 82 */ 83 shape2:null, 84 85 /** 86 * A vector which can be used to move the two objects apart so they aren't colliding 87 * @type {R.math.Vector2D} 88 */ 89 impulseVector:null, 90 91 /** 92 * The world time at the time of the collision 93 * @type {Number} 94 */ 95 worldTime:0, 96 97 /** 98 * The time delta between the world time and the last time the engine was updated 99 * @type {Number} 100 */ 101 delta:0, 102 103 /** @private */ 104 constructor:function (o, u, s1, s2, i, wt, dt) { 105 this.overlap = o; 106 this.unitVector = u; 107 this.shape1 = s1; 108 this.shape2 = s2; 109 this.impulseVector = i; 110 this.worldTime = wt; 111 this.delta = dt; 112 113 //if (Object.freeze) { 114 // Object.freeze(this); 115 //} 116 117 this.base("CollisionData"); 118 }, 119 120 /** 121 * Destroy the collision data object. 122 */ 123 destroy:function () { 124 if (this.impulseVector) { 125 this.impulseVector.destroy(); 126 } 127 if (this.unitVector) { 128 this.unitVector.destroy(); 129 } 130 this.base(); 131 }, 132 133 /** 134 * Release the collision data object back into the pool for reuse. 135 */ 136 release:function () { 137 this.base(); 138 this.overlap = 0; 139 this.unitVector = null; 140 this.shape1 = null; 141 this.shape2 = null; 142 this.impulseVector = null; 143 this.worldTime = 0; 144 this.delta = 0; 145 } 146 }, { 147 getClassName:function () { 148 return "R.struct.CollisionData"; 149 } 150 }); 151 };