Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthormp
    • CommentTimeOct 28th 2008 edited
     
    Hi!

    i search about it, but i'll put the question...it's possible have a boundingBox circular, or construct it based on polygon?

    thanks.
    mp
    • CommentAuthorRichard
    • CommentTimeOct 30th 2008
     
    Not at the moment but I hope to have this in a later version.
  1.  
    Seconded. This feature would be really useful.
    • CommentAuthorpsilos
    • CommentTimeNov 18th 2008
     
    +1
    • CommentAuthortlp
    • CommentTimeJan 15th 2009
     
    or something like a BoundingZone!
    I tried to implement it for 3DZones, but sadly i failed, at least so far! ;)
    Would be so nice to see something like that in next Version soon! ;)

    regards

    Timo
    • CommentAuthorRichard
    • CommentTimeJan 18th 2009
     
    It will, indeed, be various physics related to Zones. There's a branch in SVN called LinesAndCollisions where I've started developing it.
    • CommentAuthortlp
    • CommentTimeJan 18th 2009
     
    how nice! looking forward to that!
    I will try to check out the branch!
    Thanks so much!
    • CommentAuthorPiwie
    • CommentTimeNov 3rd 2011
     
    Hello!

    Is there a way to create a boundingSphere, or others 3d bounding shapes? any workaround?
    Iv'e looked into the boundingBox class, but i don't see how to achieve this...

    Thanks a lot!
    • CommentAuthorRichard
    • CommentTimeNov 5th 2011
     
    Hi

    For a general solution, you need a 3d equivalent of the 2d CollisionZone action. But you could also create a specific custom action just for the shape you need.
    • CommentAuthorPiwie
    • CommentTimeNov 5th 2011
     
    Hey Richard,
    Thank you for your suggestions. I guess create a 3d CollisionZone might be the best solution.
    So, in the SphereZone class, i've added a new method in SphereZone , collideParticle, it's code is a copy/paste from 2d DiscZone in which i've add the z dimensions. But, of course, it's not working as i hoped : some particles are bouncing fine, some are juste going outside of my spherezone, and others are bouncing from 10 to 20 pixels. I will be very gratefull if you can take a look at this code!

    Thanks so much
    <code>
    public function collideParticle(particle:Particle3D, bounce:Number = 1):Boolean
    {
    var outerLimit:Number;
    var innerLimit:Number;
    var outerLimitSq:Number;
    var innerLimitSq:Number;
    var distanceSq:Number;
    var distance:Number;
    var pdx:Number;
    var pdy:Number;
    var pdz:Number;
    var pDistanceSq:Number;
    var adjustSpeed:Number;
    var positionRatio:Number;
    var epsilon:Number = 0.001;
    var dx:Number = particle.position.x - _center.x;
    var dy:Number = particle.position.y - _center.y;
    var dz:Number = particle.position.z - _center.z;
    var dotProduct:Number = particle.velocity.x * dx + particle.velocity.y * dy + particle.velocity.z * dz;
    if( dotProduct < 0 ) // moving towards center
    {
    outerLimit = _outerRadius + particle.collisionRadius;
    if( Math.abs( dx ) > outerLimit ) return false;
    if( Math.abs( dy ) > outerLimit ) return false;
    if( Math.abs( dz ) > outerLimit ) return false;
    distanceSq = dx * dx + dy * dy + dz * dz;
    outerLimitSq = outerLimit * outerLimit;
    if( distanceSq > outerLimitSq ) return false;
    // Particle is inside outer circle

    pdx = (particle.position.x - particle.velocity.x) - _center.x;
    pdy = (particle.position.y - particle.velocity.y) - _center.y;
    pdz = (particle.position.z - particle.velocity.z) - _center.z;
    pDistanceSq = pdx * pdx + pdy * pdy + pdz * pdz;
    if( pDistanceSq > outerLimitSq )
    {
    // particle was outside outer circle
    adjustSpeed = ( 1 + bounce ) * dotProduct / distanceSq;
    particle.velocity.x -= adjustSpeed * dx;
    particle.velocity.y -= adjustSpeed * dy;
    particle.velocity.z -= adjustSpeed * dz;
    distance = Math.sqrt( distanceSq );
    positionRatio = ( 2 * outerLimit - distance ) / distance + epsilon;
    particle.position.x = _center.x + dx * positionRatio;
    particle.position.y = _center.y + dy * positionRatio;
    particle.position.z = _center.z + dz * positionRatio;
    return true;
    }

    if( _innerRadius != 0 && innerRadius != _outerRadius )
    {
    innerLimit = _innerRadius + particle.collisionRadius;
    if( Math.abs( dx ) > innerLimit ) return false;
    if( Math.abs( dy ) > innerLimit ) return false;
    if( Math.abs( dz ) > innerLimit ) return false;
    innerLimitSq = innerLimit * innerLimit;
    if( distanceSq > innerLimitSq ) return false;
    // Particle is inside inner circle

    if( pDistanceSq > innerLimitSq )
    {
    // particle was outside inner circle
    adjustSpeed = ( 1 + bounce ) * dotProduct / distanceSq;
    particle.velocity.x -= adjustSpeed * dx;
    particle.velocity.y -= adjustSpeed * dy;
    particle.velocity.z -= adjustSpeed * dz;
    distance = Math.sqrt( distanceSq );
    positionRatio = ( 2 * innerLimit - distance ) / distance + epsilon;
    particle.position.x = _center.x + dx * positionRatio;
    particle.position.y = _center.y + dy * positionRatio;
    particle.position.z = _center.z + dz * positionRatio;
    return true;
    }
    }
    return false;
    }
    else // moving away from center
    {
    outerLimit = _outerRadius - particle.collisionRadius;
    //pdx = particle.previousX - _center.x;
    pdx = (particle.position.x - particle.velocity.x) - _center.x;
    pdy = (particle.position.y - particle.velocity.y) - _center.y;
    pdy = (particle.position.z - particle.velocity.z) - _center.z;
    if( Math.abs( pdx ) > outerLimit ) return false;
    if( Math.abs( pdy ) > outerLimit ) return false;
    if( Math.abs( pdz ) > outerLimit ) return false;
    pDistanceSq = pdx * pdx + pdy * pdy + pdz * pdz;
    outerLimitSq = outerLimit * outerLimit;
    if( pDistanceSq > outerLimitSq ) return false;
    // particle was inside outer circle

    distanceSq = dx * dx + dy * dy + dz * dz;

    if( _innerRadius != 0 && innerRadius != _outerRadius )
    {
    innerLimit = _innerRadius - particle.collisionRadius;
    innerLimitSq = innerLimit * innerLimit;
    if( pDistanceSq < innerLimitSq && distanceSq >= innerLimitSq )
    {
    // particle was inside inner circle and is outside it
    adjustSpeed = ( 1 + bounce ) * dotProduct / distanceSq;
    particle.velocity.x -= adjustSpeed * dx;
    particle.velocity.y -= adjustSpeed * dy;
    particle.velocity.z -= adjustSpeed * dz;
    distance = Math.sqrt( distanceSq );
    positionRatio = ( 2 * innerLimit - distance ) / distance - epsilon;
    particle.position.x = _center.x + dx * positionRatio;
    particle.position.y = _center.y + dy * positionRatio;
    particle.position.z = _center.z + dz * positionRatio;
    return true;
    }
    }

    if( distanceSq >= outerLimitSq )
    {
    // Particle is inside outer circle
    adjustSpeed = ( 1 + bounce ) * dotProduct / distanceSq;
    particle.velocity.x -= adjustSpeed * dx;
    particle.velocity.y -= adjustSpeed * dy;
    particle.velocity.z -= adjustSpeed * dz;
    distance = Math.sqrt( distanceSq );
    positionRatio = ( 2 * outerLimit - distance ) / distance - epsilon;
    particle.position.x = _center.x + dx * positionRatio;
    particle.position.y = _center.y + dy * positionRatio;
    particle.position.z = _center.z + dz * positionRatio;
    return true;
    }
    return false;
    }
    }
    </code>