Example #1
0
void Level::addPlatform(const b2AABB& platform)
{
    b2BodyDef platformBodyDef;
    platformBodyDef.position = platform.GetCenter();
    b2Body* platformBody = mWorld->CreateBody(&platformBodyDef);
    platformBody->SetType(b2_staticBody);

    b2PolygonShape platformBox;
    b2Vec2 platformHalfSize = platform.GetExtents();
    platformBox.SetAsBox(platformHalfSize.x, platformHalfSize.y);

    platformBody->CreateFixture(&platformBox, 0.f);
}
Example #2
0
// Create a proxy in the tree as a leaf node. We return the index
// of the node instead of a pointer so that we can grow
// the node pool.
uint16 b2DynamicTree::CreateProxy(const b2AABB& aabb, void* userData)
{
	uint16 node = AllocateNode();

	// Fatten the aabb.
	b2Vec2 center = aabb.GetCenter();
	b2Vec2 extents = b2_fatAABBFactor * aabb.GetExtents();
	m_nodes[node].aabb.lowerBound = center - extents;
	m_nodes[node].aabb.upperBound = center + extents;
	m_nodes[node].userData = userData;

	InsertLeaf(node);

	return node;
}
Example #3
0
void b2DynamicTree::MoveProxy(uint16 proxyId, const b2AABB& aabb)
{
	b2Assert(proxyId < m_nodeCount);

	b2Assert(m_nodes[proxyId].IsLeaf());

	if (m_nodes[proxyId].aabb.Contains(aabb))
	{
		return;
	}

	RemoveLeaf(proxyId);

	b2Vec2 center = aabb.GetCenter();
	b2Vec2 extents = b2_fatAABBFactor * aabb.GetExtents();

	m_nodes[proxyId].aabb.lowerBound = center - extents;
	m_nodes[proxyId].aabb.upperBound = center + extents;

	InsertLeaf(proxyId);
}