API Documentation
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_core_glge_placeable.js.html, line: 199 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_core_glge_placeable.js.html, line: 199 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_core_glge_placeable.js.html, line: 199 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_core_glge_placeable.js.html, line: 199 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29
1 /* 2 GLGE WebGL Graphics Engine 3 Copyright (c) 2010, 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_placeable.js 32 * @author me@paulbrunt.co.uk 33 */ 34 35 36 (function(GLGE){ 37 38 39 GLGE.ZUP=[0,0,1]; 40 GLGE.YUP=[0,1,0]; 41 GLGE.XUP=[1,0,0]; 42 43 44 /** 45 * @class Abstract class to agument objects that requires position, rotation and scale. 46 */ 47 GLGE.Placeable=function(){ 48 } 49 GLGE.Placeable.prototype.locX=0; 50 GLGE.Placeable.prototype.locY=0; 51 GLGE.Placeable.prototype.locZ=0; 52 GLGE.Placeable.prototype.dLocX=0; 53 GLGE.Placeable.prototype.dLocY=0; 54 GLGE.Placeable.prototype.dLocZ=0; 55 GLGE.Placeable.prototype.quatX=0; 56 GLGE.Placeable.prototype.quatY=0; 57 GLGE.Placeable.prototype.quatZ=0; 58 GLGE.Placeable.prototype.quatW=0; 59 GLGE.Placeable.prototype.rotX=0; 60 GLGE.Placeable.prototype.rotY=0; 61 GLGE.Placeable.prototype.rotZ=0; 62 GLGE.Placeable.prototype.dRotX=0; 63 GLGE.Placeable.prototype.dRotY=0; 64 GLGE.Placeable.prototype.dRotZ=0; 65 GLGE.Placeable.prototype.scaleX=1; 66 GLGE.Placeable.prototype.scaleY=1; 67 GLGE.Placeable.prototype.scaleZ=1; 68 GLGE.Placeable.prototype.dScaleX=0; 69 GLGE.Placeable.prototype.dScaleY=0; 70 GLGE.Placeable.prototype.dScaleZ=0; 71 GLGE.Placeable.prototype.matrix=null; 72 GLGE.Placeable.prototype.rotOrder=GLGE.ROT_XYZ; 73 GLGE.Placeable.prototype.lookAt=null; 74 GLGE.Placeable.prototype.mode=GLGE.P_EULER; 75 GLGE.Placeable.prototype.upAxis=GLGE.ZUP; 76 77 /** 78 * @name GLGE.Placeable#appened 79 * @event fires when all the object is appened as a child to another 80 * @param {object} event 81 */ 82 83 /** 84 * @name GLGE.Placeable#removed 85 * @event fires when all the object is removed as a child to another 86 * @param {object} event 87 */ 88 89 /** 90 * @name GLGE.Placeable#matrixUpdate 91 * @event fires when this object has its transform changed supplies the target object as event.obj 92 * @param {object} event 93 */ 94 95 96 /** 97 * @name GLGE.Placeable#childMatrixUpdate 98 * @event fires when any child objects have there transform changed supplies the target object as event.obj 99 * @param {object} event 100 */ 101 102 /** 103 * Gets the root node object 104 * @returns {object} 105 */ 106 GLGE.Placeable.prototype.getRoot=function(){ 107 if(this.type==GLGE.G_ROOT){ 108 return this; 109 }else if(this.parent){ 110 var value=this.parent.getRoot(); 111 if(!value) return this; 112 else return value; 113 }else{ 114 return this; 115 } 116 } 117 /** 118 * Gets the id string of this text 119 * @returns {string} 120 */ 121 GLGE.Placeable.prototype.getRef=function(){ 122 if(this.id){ 123 return this.id; 124 }else if(this.parent){ 125 return this.parent.getRef(); 126 }else{ 127 return null; 128 } 129 } 130 /** 131 * Sets the id string 132 * @param {string} id The id string 133 */ 134 GLGE.Placeable.prototype.setId=function(id){ 135 this.id=id; 136 return this; 137 } 138 /** 139 * Gets the id string of this text 140 * @returns {string} 141 */ 142 GLGE.Placeable.prototype.getId=function(){ 143 return this.id 144 } 145 /** 146 * gets the object or poisition being looking at 147 * @param {array|object} value the location/object 148 */ 149 GLGE.Placeable.prototype.getLookat=function(){ 150 return this.lookAt; 151 } 152 /** 153 * sets the look at for this object, will be updated every frame 154 * @param {array|object} value the location/objec to look at 155 */ 156 GLGE.Placeable.prototype.setLookat=function(value){ 157 this.lookAt=value; 158 return this; 159 } 160 161 /** 162 * gets the up axis of the object 163 */ 164 GLGE.Placeable.prototype.getUpAxis=function(){ 165 return this.upAxis; 166 } 167 /** 168 * sets the upAxis for this object 169 * @param {array} value the up axis for the object 170 */ 171 GLGE.Placeable.prototype.setUpAxis=function(value){ 172 this.upAxis=value; 173 return this; 174 } 175 176 /** 177 * Points the object in the direction of the coords or placeable value 178 * @param {array|object} value the location/objec to look at 179 */ 180 GLGE.Placeable.prototype.Lookat=function(value){ 181 var objpos; 182 var pos=this.getPosition(); 183 if(value.getPosition){ 184 objpos=value.getPosition(); 185 }else{ 186 objpos={x:value[0],y:value[1],z:value[2]}; 187 } 188 var coord=[pos.x-objpos.x,pos.y-objpos.y,pos.z-objpos.z]; 189 var zvec=GLGE.toUnitVec3(coord); 190 var xvec=GLGE.toUnitVec3(GLGE.crossVec3(this.upAxis,zvec)); 191 192 if(xvec[0]==0 && xvec[1]==0 && xvec[2]==0) xvec[1]=1; 193 194 var yvec=GLGE.toUnitVec3(GLGE.crossVec3(zvec,xvec)); 195 this.setRotMatrix(GLGE.Mat4([xvec[0], yvec[0], zvec[0], 0, 196 xvec[1], yvec[1], zvec[1], 0, 197 xvec[2], yvec[2], zvec[2], 0, 198 0, 0, 0, 1])); 199 } 200 /** 201 * Sets the transform mode 202 * @param {mode} value the transform mode 203 */ 204 GLGE.Placeable.prototype.setTransformMode=function(value){ 205 this.mode=value; 206 this.matrix=null; 207 return this; 208 } 209 /** 210 * Gets the euler rotation order 211 * @returns {number} the objects rotation matrix 212 */ 213 GLGE.Placeable.prototype.getRotOrder=function(){ 214 return this.rotOrder; 215 } 216 /** 217 * Sets the euler rotation order 218 * @param {number} value the order to rotate GLGE.ROT_XYZ,GLGE.ROT_XZY,etc.. 219 */ 220 GLGE.Placeable.prototype.setRotOrder=function(value){ 221 this.rotOrder=value; 222 this.matrix=null; 223 this.rotmatrix=null; 224 return this; 225 } 226 /** 227 * Gets the rotaion matrix 228 * @returns {matrix} the objects rotation matrix 229 */ 230 GLGE.Placeable.prototype.getRotMatrix=function(){ 231 if(!this.rotmatrix){ 232 var rotation=this.getRotation(); 233 if(this.mode==GLGE.P_EULER) this.rotmatrix=GLGE.rotateMatrix(rotation.x,rotation.y,rotation.z,this.rotOrder); 234 if(this.mode==GLGE.P_QUAT) this.rotmatrix=GLGE.quatRotation(rotation.x,rotation.y,rotation.z,rotation.w); 235 } 236 return this.rotmatrix; 237 } 238 /** 239 * Sets the rotation matrix 240 * @param {matrix} the objects rotation matrix 241 */ 242 GLGE.Placeable.prototype.setRotMatrix=function(matrix){ 243 this.mode=GLGE.P_MATRIX; 244 this.rotmatrix=matrix; 245 this.updateMatrix(); 246 return this; 247 } 248 /** 249 * Sets the x location of the object 250 * @param {number} value The value to assign to the x position 251 */ 252 GLGE.Placeable.prototype.setLocX=function(value){this.locX=value; this.translateMatrix=null;this.staticMatrix=null;this.updateMatrix();return this;} 253 /** 254 * Sets the y location of the object 255 * @param {number} value The value to assign to the y position 256 */ 257 GLGE.Placeable.prototype.setLocY=function(value){this.locY=value; this.translateMatrix=null;this.staticMatrix=null;this.updateMatrix();return this;} 258 /** 259 * Sets the z location of the object 260 * @param {number} value The value to assign to the z position 261 */ 262 GLGE.Placeable.prototype.setLocZ=function(value){this.locZ=value; this.translateMatrix=null;this.staticMatrix=null;this.updateMatrix();return this;} 263 /** 264 * Sets the location of the object 265 * @param {number} x The value to assign to the x position 266 * @param {number} y The value to assign to the y position 267 * @param {number} z The value to assign to the z position 268 */ 269 GLGE.Placeable.prototype.setLoc=function(x,y,z){this.locX=x;this.locY=y;this.locZ=z; this.translateMatrix=null;this.staticMatrix=null;this.updateMatrix();return this;} 270 /** 271 * Sets the x location displacement of the object, usefull for animation 272 * @param {number} value The value to assign to the x displacement 273 */ 274 GLGE.Placeable.prototype.setDLocX=function(value){this.dLocX=value;this.translateMatrix=null;this.staticMatrix=null;this.updateMatrix();return this;} 275 /** 276 * Sets the y location displacement of the object, usefull for animation 277 * @param {number} value The value to assign to the y displacement 278 */ 279 GLGE.Placeable.prototype.setDLocY=function(value){this.dLocY=value; this.translateMatrix=null;this.staticMatrix=null;this.updateMatrix();return this;} 280 /** 281 * Sets the z location displacement of the object, usefull for animation 282 * @param {number} value The value to assign to the z displacement 283 */ 284 GLGE.Placeable.prototype.setDLocZ=function(value){this.dLocZ=value;this.translateMatrix=null;this.staticMatrix=null;this.updateMatrix();return this;} 285 /** 286 * Sets the location displacement of the object, useful for animation 287 * @param {number} x The value to assign to the x position 288 * @param {number} y The value to assign to the y position 289 * @param {number} z The value to assign to the z position 290 */ 291 GLGE.Placeable.prototype.setDLoc=function(x,y,z){this.dLocX=x;this.dLocY=y;this.dLocZ=z; this.translateMatrix=null;this.staticMatrix=null;this.updateMatrix();return this;} 292 /** 293 * Sets the x quat value 294 * @param {number} value the x quat value 295 */ 296 GLGE.Placeable.prototype.setQuatX=function(value){this.mode=GLGE.P_QUAT;this.quatX=parseFloat(value);this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 297 /** 298 * Sets the y quat value 299 * @param {number} value the y quat value 300 */ 301 GLGE.Placeable.prototype.setQuatY=function(value){this.mode=GLGE.P_QUAT;this.quatY=parseFloat(value);this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 302 /** 303 * Sets the z quat value 304 * @param {number} value the z quat value 305 */ 306 GLGE.Placeable.prototype.setQuatZ=function(value){this.mode=GLGE.P_QUAT;this.quatZ=parseFloat(value);this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 307 /** 308 * Sets the w quat value 309 * @param {number} value the w quat value 310 */ 311 GLGE.Placeable.prototype.setQuatW=function(value){this.mode=GLGE.P_QUAT;this.quatW=parseFloat(value);this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 312 /** 313 * Sets the quaternions 314 * @param {number} x The value to assign to the x 315 * @param {number} y The value to assign to the y 316 * @param {number} z The value to assign to the z 317 * @param {number} w The value to assign to the w 318 */ 319 GLGE.Placeable.prototype.setQuat=function(x,y,z,w){this.mode=GLGE.P_QUAT;this.quatX=x;this.quatY=y;this.quatZ=z;this.quatW=w;this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 320 321 /** 322 * Sets the x rotation of the object 323 * @param {number} value The value to assign to the x rotation 324 */ 325 GLGE.Placeable.prototype.setRotX=function(value){this.mode=GLGE.P_EULER;this.rotX=value;this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 326 /** 327 * Sets the y rotation of the object 328 * @param {number} value The value to assign to the y rotation 329 */ 330 GLGE.Placeable.prototype.setRotY=function(value){this.mode=GLGE.P_EULER;this.rotY=value;this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 331 /** 332 * Sets the z rotation of the object 333 334 * @param {number} value The value to assign to the z rotation 335 */ 336 GLGE.Placeable.prototype.setRotZ=function(value){this.mode=GLGE.P_EULER;this.rotZ=value;this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 337 /** 338 * Sets the rotation of the object 339 * @param {number} x The value to assign to the x rotation 340 * @param {number} y The value to assign to the y rotation 341 * @param {number} z The value to assign to the z rotation 342 */ 343 GLGE.Placeable.prototype.setRot=function(x,y,z){this.mode=GLGE.P_EULER;this.rotX=x;this.rotY=y;this.rotZ=z;this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 344 /** 345 * Sets the x rotation displacement of the object, usefull for animation 346 * @param {number} value The value to assign to the x displacement 347 */ 348 GLGE.Placeable.prototype.setDRotX=function(value){this.mode=GLGE.P_EULER;this.dRotX=value;this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 349 /** 350 * Sets the y rotation displacement of the object, usefull for animation 351 * @param {number} value The value to assign to the y displacement 352 */ 353 GLGE.Placeable.prototype.setDRotY=function(value){this.mode=GLGE.P_EULER;this.dRotY=value;this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 354 /** 355 * Sets the z rotation displacement of the object, usefull for animation 356 * @param {number} value The value to assign to the z displacement 357 */ 358 359 GLGE.Placeable.prototype.setDRotZ=function(value){this.mode=GLGE.P_EULER;this.dRotZ=value;this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 360 /** 361 * Sets the rotation displacement of the object, useful for animation 362 * @param {number} x The value to assign to the x rotation 363 * @param {number} y The value to assign to the y rotation 364 * @param {number} z The value to assign to the z rotation 365 */ 366 GLGE.Placeable.prototype.setDRot=function(x,y,z){this.mode=GLGE.P_EULER;this.dRotX=x;this.dRotY=y;this.dRotZ=z;this.staticMatrix=null;this.rotmatrix=null;this.updateMatrix();return this;} 367 /** 368 * Sets the x scale of the object 369 * @param {number} value The value to assign to the x scale 370 */ 371 GLGE.Placeable.prototype.setScaleX=function(value){if(this.ScaleX==value) return this;this.scaleX=value;this.staticMatrix=null;this.scaleMatrix=null;this.updateMatrix();return this;} 372 /** 373 * Sets the y scale of the object 374 * @param {number} value The value to assign to the y scale 375 */ 376 GLGE.Placeable.prototype.setScaleY=function(value){if(this.ScaleY==value) return this;this.scaleY=value;this.staticMatrix=null;this.scaleMatrix=null;this.updateMatrix();return this;} 377 /** 378 * Sets the z scale of the object 379 * @param {number} value The value to assign to the z scale 380 */ 381 GLGE.Placeable.prototype.setScaleZ=function(value){if(this.ScaleZ==value) return this;this.scaleZ=value;this.staticMatrix=null;this.scaleMatrix=null;this.updateMatrix();return this;} 382 /** 383 * Sets the scale of the object 384 * @param {number} x The value to assign to the x scale 385 * @param {number} y The value to assign to the y scale 386 * @param {number} z The value to assign to the z scale 387 */ 388 GLGE.Placeable.prototype.setScale=function(x,y,z){if(!y){y=x;z=x}; this.scaleX=x;this.scaleY=y;this.scaleZ=z;this.staticMatrix=null;this.scaleMatrix=null;this.updateMatrix();return this;} 389 /** 390 * Sets the x scale displacement of the object, usefull for animation 391 * @param {number} value The value to assign to the x displacement 392 */ 393 GLGE.Placeable.prototype.setDScaleX=function(value){if(this.dScaleX==value) return this;this.dScaleX=value;this.staticMatrix=null;this.scaleMatrix=null;this.updateMatrix();return this;} 394 /** 395 * Sets the y scale displacement of the object, usefull for animation 396 * @param {number} value The value to assign to the y displacement 397 */ 398 GLGE.Placeable.prototype.setDScaleY=function(value){if(this.dScaleY==value) return this;this.dScaleY=value;this.staticMatrix=null;this.scaleMatrix=null;this.updateMatrix();return this;} 399 /** 400 * Sets the z scale displacement of the object, usefull for animation 401 * @param {number} value The value to assign to the z displacement 402 */ 403 GLGE.Placeable.prototype.setDScaleZ=function(value){if(this.dScaleZ==value) return this;this.dScaleZ=value;this.staticMatrix=null;this.scaleMatrix=null;this.updateMatrix();return this;} 404 /** 405 * Sets the scale displacement of the object, useful for animation 406 * @param {number} x The value to assign to the x scale 407 * @param {number} y The value to assign to the y scale 408 * @param {number} z The value to assign to the z scale 409 */ 410 GLGE.Placeable.prototype.setDScale=function(x,y,z){this.dScaleX=x;this.dScaleY=y;this.dScaleZ=z;this.staticMatrix==null;this.scaleMatrix=null;this.updateMatrix();return this;} 411 /** 412 * Gets the x location of the object 413 * @returns {number} 414 */ 415 GLGE.Placeable.prototype.getLocX=function(){return this.locX;} 416 /** 417 * Gets the y location of the object 418 * @returns {number} 419 */ 420 GLGE.Placeable.prototype.getLocY=function(){return this.locY;} 421 /** 422 * Gets the z location of the object 423 * @returns {number} 424 */ 425 GLGE.Placeable.prototype.getLocZ=function(){return this.locZ;} 426 /** 427 * Gets the x location displacement of the object 428 * @returns {number} 429 */ 430 GLGE.Placeable.prototype.getDLocX=function(){return this.dLocX;} 431 /** 432 * Gets the y location displacement of the object 433 * @returns {number} 434 */ 435 GLGE.Placeable.prototype.getDLocY=function(){return this.dLocY;} 436 /** 437 * Gets the z location displacement of the object 438 * @returns {number} 439 */ 440 GLGE.Placeable.prototype.getDLocZ=function(){return this.dLocZ;} 441 /** 442 * Gets the x quat of the rotation 443 * @returns {number} 444 */ 445 GLGE.Placeable.prototype.getQuatX=function(){return this.quatX;} 446 /** 447 * Gets the y quat of the rotation 448 * @returns {number} 449 */ 450 GLGE.Placeable.prototype.getQuatY=function(){return this.quatY;} 451 /** 452 * Gets the z quat of the rotation 453 * @returns {number} 454 */ 455 GLGE.Placeable.prototype.getQuatZ=function(){return this.quatZ;} 456 /** 457 * Gets the w quat of the rotation 458 * @returns {number} 459 */ 460 GLGE.Placeable.prototype.getQuatW=function(){return this.quatW;} 461 /** 462 * Gets the x rotation of the object 463 * @returns {number} 464 */ 465 GLGE.Placeable.prototype.getRotX=function(){return this.rotX;} 466 /** 467 * Gets the y rotation of the object 468 * @returns {number} 469 */ 470 GLGE.Placeable.prototype.getRotY=function(){return this.rotY;} 471 /** 472 * Gets the z rotation of the object 473 * @returns {number} 474 */ 475 GLGE.Placeable.prototype.getRotZ=function(){return this.rotZ;} 476 /** 477 * Gets the x rotaional displacement of the object 478 * @returns {number} 479 */ 480 GLGE.Placeable.prototype.getDRotX=function(){return this.dRotX;} 481 /** 482 * Gets the y rotaional displacement of the object 483 * @returns {number} 484 */ 485 GLGE.Placeable.prototype.getDRotY=function(){return this.dRotY;} 486 /** 487 * Gets the z rotaional displacement of the object 488 * @returns {number} 489 */ 490 GLGE.Placeable.prototype.getDRotZ=function(){return this.dRotZ;} 491 /** 492 * Gets the x scale of the object 493 * @returns {number} 494 */ 495 GLGE.Placeable.prototype.getScaleX=function(){return this.scaleX;} 496 /** 497 * Gets the y scale of the object 498 * @returns {number} 499 */ 500 GLGE.Placeable.prototype.getScaleY=function(){return this.scaleY;} 501 /** 502 * Gets the z scale of the object 503 * @returns {number} 504 */ 505 GLGE.Placeable.prototype.getScaleZ=function(){return this.scaleZ;} 506 /** 507 * Gets the x scale displacement of the object 508 * @returns {number} 509 */ 510 GLGE.Placeable.prototype.getDScaleX=function(){return this.dScaleX;} 511 /** 512 * Gets the y scale displacement of the object 513 * @returns {number} 514 */ 515 GLGE.Placeable.prototype.getDScaleY=function(){return this.dScaleY;} 516 /** 517 * Gets the z scale displacement of the object 518 * @returns {number} 519 */ 520 GLGE.Placeable.prototype.getDScaleZ=function(){return this.dScaleZ;} 521 /** 522 * Gets the position of the object 523 * @returns {array} 524 */ 525 GLGE.Placeable.prototype.getPosition=function(){ 526 var position={}; 527 position.x=parseFloat(this.locX)+parseFloat(this.dLocX); 528 position.y=parseFloat(this.locY)+parseFloat(this.dLocY); 529 position.z=parseFloat(this.locZ)+parseFloat(this.dLocZ); 530 return position; 531 } 532 /** 533 * Gets the rotation of the object 534 * @returns {object} 535 */ 536 GLGE.Placeable.prototype.getRotation=function(){ 537 var rotation={}; 538 if(this.mode==GLGE.P_EULER){ 539 rotation.x=parseFloat(this.rotX)+parseFloat(this.dRotX); 540 rotation.y=parseFloat(this.rotY)+parseFloat(this.dRotY); 541 rotation.z=parseFloat(this.rotZ)+parseFloat(this.dRotZ); 542 } 543 if(this.mode==GLGE.P_QUAT){ 544 rotation.x=parseFloat(this.quatX); 545 rotation.y=parseFloat(this.quatY); 546 rotation.z=parseFloat(this.quatZ); 547 rotation.w=parseFloat(this.quatW); 548 } 549 return rotation; 550 } 551 /** 552 * Gets the scale of the object 553 * @returns {object} 554 */ 555 GLGE.Placeable.prototype.getScale=function(){ 556 var scale={}; 557 scale.x=parseFloat(this.scaleX)+parseFloat(this.dScaleX); 558 scale.y=parseFloat(this.scaleY)+parseFloat(this.dScaleY); 559 scale.z=parseFloat(this.scaleZ)+parseFloat(this.dScaleZ); 560 return scale; 561 } 562 /** 563 * Gets the scale matrix 564 * @returns {object} 565 */ 566 GLGE.Placeable.prototype.getScaleMatrix=function(){ 567 if(!this.scaleMatrix){ 568 this.scaleMatrix=GLGE.scaleMatrix(parseFloat(this.scaleX)+parseFloat(this.dScaleX),parseFloat(this.scaleY)+parseFloat(this.dScaleY),parseFloat(this.scaleZ)+parseFloat(this.dScaleZ)); 569 } 570 return this.scaleMatrix; 571 } 572 /** 573 * Gets the translate matrix 574 * @returns {object} 575 */ 576 GLGE.Placeable.prototype.getTranslateMatrix=function(){ 577 if(!this.tmatrix) this.tmatrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]; 578 if(!this.translateMatrix){ 579 this.tmatrix[3]=+this.locX+this.dLocX; 580 this.tmatrix[7]=+this.locY+this.dLocY; 581 this.tmatrix[11]=+this.locZ+this.dLocZ; 582 this.translateMatrix=this.tmatrix; 583 } 584 return this.translateMatrix; 585 } 586 587 /** 588 * Gets the local transform matrix 589 * @returns {object} 590 */ 591 GLGE.Placeable.prototype.getLocalMatrix=function(){ 592 this.getModelMatrix(); 593 return this.localMatrix; 594 } 595 596 /** 597 * Sets a static transfrom matrix, overrides any rotations and translation that may be set 598 * @returns {object} 599 */ 600 GLGE.Placeable.prototype.setStaticMatrix=function(matrix){ 601 this.staticMatrix=matrix; 602 this.updateMatrix(); 603 return this; 604 } 605 606 /** 607 * Clears the static matrix if one is set 608 * @returns {object} 609 */ 610 GLGE.Placeable.prototype.clearStaticMatrix=function(){ 611 this.staticMatrix=null; 612 this.updateMatrix(); 613 return this; 614 } 615 616 /** 617 * Updates the model matrix 618 * @private 619 */ 620 GLGE.Placeable.prototype.updateMatrix=function(){ 621 this.matrix=null; 622 if(this.children){ 623 for(var i=0;i<this.children.length;i++){ 624 this.children[i].updateMatrix(); 625 } 626 } 627 var o=obj=this; 628 obj.fireEvent("matrixUpdate",{obj:o}); 629 if(obj=obj.parent) obj.fireEvent("childMatrixUpdate",{obj:o}); 630 } 631 /** 632 * Gets the model matrix to transform the model within the world 633 */ 634 GLGE.Placeable.prototype.getModelMatrix=function(){ 635 if(!this.matrix){ 636 GLGE.reuseMatrix4(this.invmatrix); 637 GLGE.reuseMatrix4(this.transmatrix); 638 GLGE.reuseMatrix4(this.transinvmatrix); 639 this.invmatrix=null; 640 this.transmatrix=null; 641 this.transinvmatrix=null; 642 if(this.staticMatrix){ 643 var matrix=this.staticMatrix; 644 this.localMatrix=this.staticMatrix; 645 if(this.parent) matrix=GLGE.mulMat4(this.parent.getModelMatrix(),matrix); 646 this.matrix=matrix; 647 }else{ 648 var translate=this.getTranslateMatrix(); 649 var scale=this.getScaleMatrix(); 650 var M1=GLGE.mulMat4(this.getRotMatrix(),scale); 651 var matrix=GLGE.mulMat4(translate,M1); 652 //GLGE.reuseMatrix4(M1); 653 this.localMatrix=matrix; 654 if(this.parent) matrix=GLGE.mulMat4(this.parent.getModelMatrix(),matrix); 655 this.matrix=matrix; 656 } 657 } 658 return this.matrix; 659 } 660 /** 661 * Gets the model inverse matrix to transform the model within the world 662 */ 663 GLGE.Placeable.prototype.getInverseModelMatrix=function(){ 664 if(!this.matrix){ 665 this.getModelMatrix(); 666 } 667 if(!this.invmatrix){ 668 this.invmatrix=GLGE.transposeMat4(this.matrix); 669 } 670 return this.invmatrix; 671 } 672 /** 673 * Gets the model transposed matrix to transform the model within the world 674 */ 675 GLGE.Placeable.prototype.getTransposeModelMatrix=function(){ 676 if(!this.matrix){ 677 this.getModelMatrix(); 678 } 679 if(!this.transmatrix){ 680 this.transmatrix=GLGE.transposeMat4(this.matrix); 681 } 682 return this.transmatrix; 683 } 684 /** 685 * Gets the model inverse transposed matrix to transform the model within the world 686 */ 687 GLGE.Placeable.prototype.getTransposeInverseModelMatrix=function(){ 688 if(!this.matrix){ 689 this.getModelMatrix(); 690 } 691 if(!this.transinvmatrix){ 692 this.invtransmatrix=GLGE.transposeMat4(this.getInverseModelMatrix()); 693 } 694 return this.transinvmatrix; 695 } 696 /** 697 * Moves the object 698 * @returns {array} amount array [x,y,z] to move 699 * @returns {number} reference move with respecct to GLGE.GLOBAL or GLGE.LOCAL 700 */ 701 GLGE.Placeable.prototype.move=function(amount,reference){ 702 if(!reference) reference=GLGE.GLOBAL; 703 switch(reference){ 704 case GLGE.GLOBAL: 705 this.setLocX(+this.locX+amount[0]); 706 this.setLocY(+this.locY+amount[1]); 707 this.setLocZ(+this.locZ+amount[2]); 708 break; 709 case GLGE.LOCAL: 710 var matrix=this.getModelMatrix(); 711 var xAxis=GLGE.toUnitVec3([matrix[0],matrix[1],matrix[2]]); 712 var yAxis=GLGE.toUnitVec3([matrix[4],matrix[5],matrix[6]]); 713 var zAxis=GLGE.toUnitVec3([matrix[8],matrix[9],matrix[10]]); 714 var x=xAxis[0]*amount[0]+xAxis[1]*amount[1]+xAxis[2]*amount[2]; 715 var y=yAxis[0]*amount[0]+yAxis[1]*amount[1]+yAxis[2]*amount[2]; 716 var z=zAxis[0]*amount[0]+zAxis[1]*amount[1]+zAxis[2]*amount[2]; 717 this.setLocX(+this.locX+x); 718 this.setLocY(+this.locY+y); 719 this.setLocZ(+this.locZ+z); 720 break; 721 } 722 return this; 723 } 724 725 })(GLGE);