//-------------------------------------------------------------------------------------------------- void q3Body::RemoveBox( const q3Box* box ) { assert( box ); assert( box->body == this ); q3Box* node = m_boxes; q3Box* list = m_boxes; bool found = false; if ( node == box ) { list = node->next; found = true; } else { while ( node ) { if ( node->next == box ) { node->next = box->next; found = true; break; } node = node->next; } } // This shape was not connected to this body. assert( found ); // Remove all contacts associated with this shape q3ContactEdge* edge = m_contactList; while ( edge ) { q3ContactConstraint* contact = edge->constraint; edge = edge->next; q3Box* A = contact->A; q3Box* B = contact->B; if ( box == A || box == B ) m_scene->m_contactManager.RemoveContact( contact ); } m_scene->m_contactManager.m_broadphase.RemoveBox( box ); CalculateMassData( ); m_scene->m_heap.Free( (void*)box ); }
//-------------------------------------------------------------------------------------------------- const q3Box* q3Body::AddBox( const q3BoxDef& def ) { q3AABB aabb; q3Box* box = (q3Box*)m_scene->m_heap.Allocate( sizeof( q3Box ) ); box->local = def.m_tx; box->e = def.m_e; box->next = m_boxes; m_boxes = box; box->ComputeAABB( m_tx, &aabb ); box->body = this; box->friction = def.m_friction; box->restitution = def.m_restitution; box->density = def.m_density; box->sensor = def.m_sensor; CalculateMassData( ); m_scene->m_contactManager.m_broadphase.InsertBox( box, aabb ); m_scene->m_newBox = true; return box; }