The convexSweepTest feature

Software: Away3D 4.x

Rope, Newbie
Posted: 16 April 2012 12:07 PM   Total Posts: 5

Hello,
I tried to add the interface for convexSweepTest in awayphysics.swc
but it seems not work. It’s time-consuming and get the wrong result.

source as below(awayPhysics.c)

==================================================
AS3_Val sweptSphereTest(void* data, AS3_Val args){
 btCollisionObject
* obj;
 
double fromx, fromy, fromz;
 
double tox, toy, toz;
 
double radius;
 
AS3_ArrayValue(args, "PtrType,DoubleType,DoubleType,DoubleType,DoubleType,DoubleType,DoubleType,DoubleType", &obj;, &fromx;, &fromy;, &fromz;, &tox;, &toy;, &toz;, &radius;);
 
 if(
collisionWorld)
 
{
  btSphereShape
* sweptShape =  new btSphereShape(radius);
  
btVector3 source(fromx, fromy, fromz);
  
btVector3 dest(tox, toy, toz); 
  
btCollisionWorld::ClosestConvexResultCallback cb(source, dest);
  
btTransform from;
  
from.setIdentity();
  
from.setOrigin(source);
  
btTransform to;
  
to.setIdentity();
  
from.setOrigin(dest);

  
btVector3 hit_surface;
  
btVector3 hit_com;
  
btVector3 normal;
  
double hit_fraction;

  
collisionWorld->convexSweepTest (sweptShape, from, to, cb);
  
  if (
cb.hasHit ())
  
{
   hit_surface 
= cb.m_hitPointWorld;
   
hit_com.setInterpolate3(source, dest, cb.m_closestHitFraction);
   
hit_fraction = cb.m_closestHitFraction;
   
normal = cb.m_hitNormalWorld;
   
normal.normalize ();
   
   
//get rigid body from collision object
   
btRigidBody* body = btRigidBody::upcast(cb.m_hitCollisionObject);
   
//clone result
   
SphereSweptInfo out(hit_surface, hit_com, normal, hit_fraction, body);
   
return_as3_ptr(&out;);
  
} else {
   hit_com 
= dest;
   
hit_surface = dest;
   
hit_fraction = 1.0f;
   
normal = btVector3(1.0, 0.0, 0.0);
   return 
AS3_Null();
  
}
 }
 
return AS3_Null();
}
================================================== 

I have check the out struct(SphereSweptInfo) in as3 source pointer.
Is it wrong?

   

Rope, Newbie
Posted: 19 April 2012 01:13 AM   Total Posts: 5   [ # 1 ]

I have solved it.

It’s caused by the AWPBase member _scaling

We need to scaling the swept source, destination and shape too.

So… the code above is work fine.

   
   
‹‹ advice/link need it

X

Away3D Forum

Member Login

Username

Password

Remember_me



X