topical media & game development

talk show tell print

mobile-query-three-plugins-cannonjs-vendor-cannon.js-src-objects-Shape.js / js



  /*global CANNON:true */
  
  
@class CANNON.Shape
author: schteppe @brief Base class for shapes

  
  CANNON.Shape = function(){
  
      
@property int type @memberof CANNON.Shape @brief The type of this shape. Must be set to an int > 0 by subclasses.
see: CANNON.Shape.types

  
      this.type = 0;
  
      // Local AABB's
      this.aabbmin = new CANNON.Vec3();
      this.aabbmax = new CANNON.Vec3();
  };
  CANNON.Shape.prototype.constructor = CANNON.Shape;
  
  
@method boundingSphereRadius @memberof CANNON.Shape @brief Get the bounding sphere radius from this shape
returns: float

  
  CANNON.Shape.prototype.boundingSphereRadius = function(){
    throw "boundingSphereRadius() not implemented for shape type "+this.type;
  };
  
  
@method volume @memberof CANNON.Shape @brief Get the volume of this shape
returns: float

  
  CANNON.Shape.prototype.volume = function(){
    throw "volume() not implemented for shape type "+this.type;
  };
  
  
@method calculateLocalInertia @memberof CANNON.Shape @brief Calculates the inertia in the local frame for this shape.
returns: CANNON.Vec3
see: en.wikipedia.org/wiki/List_of_moments_of_inertia

  
  CANNON.Shape.prototype.calculateLocalInertia = function(mass,target){
    throw "calculateLocalInertia() not implemented for shape type "+this.type;
  };
  
  
@method calculateTransformedInertia @memberof CANNON.Shape @brief Calculates inertia in a specified frame for this shape.
returns: CANNON.Vec3

  
  CANNON.Shape.prototype.calculateTransformedInertia = function(mass,quat,target){
    if(target==undefined)
      target = new CANNON.Vec3();
  
    // Compute inertia in the world frame
    quat.normalize();
    var localInertia = this.calculateLocalInertia(mass);
  
    // @todo Is this rotation OK? Check!
    var worldInertia = quat.vmult(localInertia);
    target.x = Math.abs(worldInertia.x);
    target.y = Math.abs(worldInertia.y);
    target.z = Math.abs(worldInertia.z);
    return target;
    //throw "calculateInertia() not implemented for shape type "+this.type;
  };
  
  // Calculates the local aabb and sets the result to .aabbmax and .aabbmin
  CANNON.Shape.calculateLocalAABB = function(){
      throw new Error(".calculateLocalAABB is not implemented for this Shape yet!");
  };
  
  
@property Object types @memberof CANNON.Shape @brief The available shape types.

  
  CANNON.Shape.types = {
    SPHERE:1,
    PLANE:2,
    BOX:4,
    COMPOUND:8,
    CONVEXPOLYHEDRON:16
  };
  
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.