detectCollision method

  1. @override
void detectCollision(
  1. Shape shape1,
  2. Shape shape2,
  3. ContactManifold manifold
)
override

Detect collision of the shapes provided

Implementation

@override
void detectCollision(Shape shape1,Shape shape2,ContactManifold manifold ) {
  Vector3 n = this.n;
  Vector3 p = this.p;

  Plane pn;
  Sphere s;

  flip = shape1 is Plane;

  if(!flip){
    pn = shape2 as Plane;
    s = shape1 as Sphere;
  }
  else{
    pn = shape1 as Plane;
    s = shape2 as Sphere;
  }

  double rad = s.radius;
  double len;

  n.sub2( s.position, pn.position );
  //var h = _Math.dotVectors( pn.normal, n );

  n.x *= pn.normal.x;//+ rad;
  n.y *= pn.normal.y;
  n.z *= pn.normal.z;//+ rad;


  len = n.length2;

  if(len > 0 && len < rad * rad){//&& h > rad*rad ){
    len = math.sqrt(len);
    //len = _Math.sqrt( h );
    n..setFrom(pn.normal)..inverse();
    //n.scaleEqual( 1/len );

    //(0, -1, 0)

    //n.normalize();
    p..setFrom( s.position )..addScaled( n, rad );
    manifold.addPointVec( p, n, len - rad, flip );
  }
}