Before you begin, you can view the previous framework analysis.
In the scenario of physical simulation, a node should first have two attributes
Physical attributes include quality, speed, inertia, acceleration, angular velocity, constraints, friction coefficient, etc.
Ry attribute shape, surrounded by volume layers, and Collision Detection type mask. World conversion.
Most physical attributes are in classes such as collosionObject and rigidObjec.
The geometric attributes are subdivided into the layer and shape of the surrounding body, and the collision detection type mask.
To further introduce Dbvt's core function btDbvt: collideTV
You must first introduce btDbvtProxy. BtDbvtProxy inherits from btBroadphaseProxy.
View plaincopy to clipboardprint?
ATTRIBUTE_ALIGNED16 (struct) btBroadphaseProxy
{
/// Optional filtering to cull potential collisions
Enum CollisionFilterGroups
{
DefaultFilter = 1,
StaticFilter = 2,
KinematicFilter = 4,
DebrisFilter = 8,
SensorTrigger = 16,
CharacterFilter = 32,
AllFilter =-1 // all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
};
Void * m_clientObject; // Usually the client btCollisionObject or Rigidbody class
Short int m_collisionFilterGroup; // collision detection type
Short int m_collisionFilterMask; // collision detection type mask
Void * m_multiSapParentProxy; // sweep and prune broadphase
Int m_uniqueId; // m_uniqueId is used in the management structure of overlapping nodes, not required
BtVector3 m_aabbMin; // store the volume
BtVector3 m_aabbMax; // store the volume
}
ATTRIBUTE_ALIGNED16 (struct) btBroadphaseProxy
{
/// Optional filtering to cull potential collisions
Enum CollisionFilterGroups
{
DefaultFilter = 1,
StaticFilter = 2,
KinematicFilter = 4,
DebrisFilter = 8,
SensorTrigger = 16,
CharacterFilter = 32,
AllFilter =-1 // all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
};
Void * m_clientObject; // Usually the client btCollisionObject or Rigidbody class
Short int m_collisionFilterGroup; // collision detection type
Short int m_collisionFilterMask; // collision detection type mask
Void * m_multiSapParentProxy; // sweep and prune broadphase
Int m_uniqueId; // m_uniqueId is used in the management structure of overlapping nodes, not required
BtVector3 m_aabbMin; // store the volume
BtVector3 m_aabbMax; // store the volume
}
The btBroadphaseProxy base class includes the most basic collision detection types and the collision detection types supported by the object itself. For details about the collision detection types, see section 5th of the bullet manual. Objects can be selected based on the supported collision detection types. It also contains pointers to physical property objects.
Let's look at btDbvtProxy.
View plaincopy to clipboardprint?
Struct btDbvtProxy: btBroadphaseProxy
{
/* Fields */
BtDbvtNode * leaf; // point to the corresponding node in Dbvt
BtDbvtProxy * links [2]; // for the front and back nodes pointing to the bidirectional list, see btDbvtBroadphase analysis.
Int stage; // For the queue, see btDbvtBroadphase analysis.
}
Struct btDbvtProxy: btBroadphaseProxy
{
/* Fields */
BtDbvtNode * leaf; // point to the corresponding node in Dbvt
BtDbvtProxy * links [2]; // for the front and back nodes pointing to the bidirectional list, see btDbvtBroadphase analysis.
Int stage; // For the queue, see btDbvtBroadphase analysis.
}
BtDbvtProxy is a node that uses the proxy design mode to connect physical attribute nodes and geometric nodes.
It is also an important part of overlapping node management. Then let's take a look at btDbvtTreeCollider.
View plaincopy to clipboardprint?
/* Tree collider */
Struct btDbvtTreeCollider: btDbvt: ICollide
{
BtDbvtBroadphase * pbp;
BtDbvtProxy * proxy;
Void Process (const btDbvtNode * n)
{
Process (n, proxy-> leaf );
}
}
/* Tree collider */
Struct btDbvtTreeCollider: btDbvt: ICollide
{
BtDbvtBroadphase * pbp;
BtDbvtProxy * proxy;
Void Process (const btDbvtNode * n)
{
Process (n, proxy-> leaf );
}
}
BtDbvtTreeCollider defines the processing method for collision between two geometric nodes in the distant state. btDbvt: ICollide defines the interface standard btDbvtTreeCollider as a specific implementation under dbvt, developers can also embed different processing logic based on their own needs. Proxy represents the master node, and n represents the compared node.
Enter the topic btDbvt: colreceivetv. The main algorithm of this function is to traverse all the leaf nodes that overlap with the target node, and then use the existing processing logic module btDbvtTreeCollider to process the two nodes. A new data structure btHashedOverlappingPairCache will be introduced. For more information, see the subsequent btDbvtBroadphase analysis.
View plaincopy to clipboardprint?
BtDbvt: collideTV (const btDbvtNode * root,
Const btDbvtVolume & vol,
DBVT_IPOLICY)
{
ATTRIBUTE_ALIGNED16 (btDbvtVolume) volume (vol );
BtAlignedObjectArray <const btDbvtNode *> stack;
Stack. resize (0 );
Stack. reserve (SIMPLE_STACKSIZE); // generate a stack to traverse Dbvt
Stack. push_back (root); // The root node is added to the stack.
Do {
Const btDbvtNode * n = stack [stack. size ()-1]; // stack top element exit stack
Stack. pop_back (); // stack top element exit stack
If (Intersect (n-> volume, volume) // if this node contains the target node
{
If (n-> isinternal () // if it is an internal node, the Child tree is traversed.
{
Stack. push_back (n-> childs [0]); // The left child enters the stack.
Stack. push_back (n-> childs [1]); // The right child enters the stack
}
Else // if it is already a leaf node
{
Policy. Process (n); // uses the existing processing policy to Process the collision nodes.
}
}
} While (stack. size ()> 0); // run until all intersect leaf node is visited.
}
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/superwiles/archive/2010/02/23/5318237.aspx