MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / _createFragments

Method _createFragments

Engine/source/T3D/physics/physicsDebris.cpp:620–683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

618}
619
620void PhysicsDebris::_createFragments()
621{
622 _deleteFragments();
623
624 mWorld = PHYSICSMGR->getWorld( "client" );
625 if ( !mWorld )
626 return;
627
628 TSShape *shape = mDataBlock->mShape;
629
630 mShapeInstance = new TSShapeInstance( shape, true );
631 mShapeInstance->animate();
632
633 Vector< CollisionShapeInfo > infoList;
634 shape->buildColShapes( false, Point3F::One, &infoList );
635
636 mFragments.setSize( infoList.size() );
637 dMemset( mFragments.address(), 0, mFragments.memSize() );
638
639 const Point3F damageDir( 0, 0, 1 );
640
641 MatrixF bodyMat( true );
642 bodyMat = getTransform();
643
644 const U32 bodyFlags = PhysicsBody::BF_DEBRIS;
645 mWorldBox = Box3F::Invalid;
646
647 for ( S32 i = 0; i < infoList.size(); i++ )
648 {
649 const CollisionShapeInfo &info = infoList[i];
650
651 Fragment &fragment = mFragments[i];
652
653 if ( info.colNode == -1 )
654 Con::errorf( "PhysicsDebris::_createFragments, Missing or couldnt find a colNode." );
655 else
656 _findNodes( info.colNode, fragment.nodeIds );
657
658 PhysicsBody *body = PHYSICSMGR->createBody();
659 body->init( info.colShape, mDataBlock->mass, bodyFlags, this, mWorld );
660 body->setMaterial( mDataBlock->restitution, mDataBlock->dynamicFriction, mDataBlock->staticFriction );
661 body->setDamping( mDataBlock->linearDamping, mDataBlock->angularDamping );
662 body->setSleepThreshold( mDataBlock->linearSleepThreshold, mDataBlock->angularSleepThreshold );
663 body->setTransform( bodyMat );
664 body->setLinVelocity( mInitialLinVel );
665 fragment.body = body;
666
667 // Set the initial delta state.
668 fragment.pos = bodyMat.getPosition();
669 fragment.rot.set( bodyMat );
670 fragment.lastPos = fragment.pos;
671 fragment.lastRot = fragment.rot;
672
673 // Update the bounds.
674 mWorldBox.intersect( body->getWorldBounds() );
675 }
676
677 // Finish up updating the bounds.

Callers

nothing calls this directly

Calls 15

buildColShapesMethod · 0.80
memSizeMethod · 0.80
dMemsetFunction · 0.50
errorfFunction · 0.50
getWorldMethod · 0.45
animateMethod · 0.45
setSizeMethod · 0.45
sizeMethod · 0.45
addressMethod · 0.45
createBodyMethod · 0.45
initMethod · 0.45
setMaterialMethod · 0.45

Tested by

no test coverage detected