当前位置: 首页>>代码示例>>C++>>正文


C++ Fixture::IsSensor方法代码示例

本文整理汇总了C++中Fixture::IsSensor方法的典型用法代码示例。如果您正苦于以下问题:C++ Fixture::IsSensor方法的具体用法?C++ Fixture::IsSensor怎么用?C++ Fixture::IsSensor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Fixture的用法示例。


在下文中一共展示了Fixture::IsSensor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FindAllCollisions

void PhysicsWorld::FindAllCollisions() {
	contactManager.numOldContacts = contactManager.numContacts;
	assert(contactManager.numOldContacts < MaxNumContacts );
	memcpy(contactManager.oldContacts, contactManager.contacts, contactManager.numOldContacts * sizeof(Contact));
	contactManager.numContacts = 0;
	/*
		O(n^2) collsion detection ( or worse LOL )
		Check all fixtures vs all fixtures for collisions, 
		We dont collide fixtures that are from the same body
	*/ 
	for ( size_t i = 0; i < numBodies; i++ ) {
		for ( size_t j = i + 1; j < numBodies; j++ ) {
			if ( (bodies[i]->type != eDynamic && bodies[j]->type != eDynamic) ) {
				continue;
			}
			if ( contactManager.contactFilter && !contactManager.contactFilter->ShouldCollide(bodies[i], bodies[j]) ) {
				continue;
			}
			Fixture *fi = bodies[i]->GetFixtureList();
			while ( fi ) {
				Fixture *fj = bodies[j]->GetFixtureList();
				while ( fj ) {
					if ( fi->IsSensor( ) || fj->IsSensor( ) ) {
						if ( CheckOverlap(fi->GetShape(), bodies[i]->GetPosition(), fj->GetShape(), bodies[j]->GetPosition()) )	{
							contactManager.contactListener->OnSensor(fi, fj);
						}
					} else {
						// check collision and add to the contact list if they intersect
						contactManager.AddPair(fi, fj);
					}
					fj = fj->GetNext();
				}
				fi = fi->GetNext();
			}
		}
	}
	contactManager.MergeContacts();
}		
开发者ID:robert-porter,项目名称:SideScroller,代码行数:38,代码来源:PhysicsWorld.cpp

示例2: Destroy

void Contact::Destroy(Contact* contact, BlockAllocator* allocator)
{
    assert(s_initialized == true);

    Fixture* fixtureA = contact->m_fixtureA;
    Fixture* fixtureB = contact->m_fixtureB;

    if (contact->m_manifold.pointCount > 0 &&
            fixtureA->IsSensor() == false &&
            fixtureB->IsSensor() == false)
    {
        fixtureA->GetBody()->SetAwake(true);
        fixtureB->GetBody()->SetAwake(true);
    }

    Shape::Type typeA = fixtureA->GetType();
    Shape::Type typeB = fixtureB->GetType();

    assert(0 <= typeA && typeB < Shape::e_typeCount);
    assert(0 <= typeA && typeB < Shape::e_typeCount);

    ContactDestroyFcn* destroyFcn = s_registers[typeA][typeB].destroyFcn;
    destroyFcn(contact, allocator);
}
开发者ID:ZhuangChun,项目名称:Box2D,代码行数:24,代码来源:Contact.cpp

示例3: AddPair


//.........这里部分代码省略.........
	// TODO_ERIN use a hash table to remove a potential bottleneck when both
	// bodies have a lot of contacts.
	// Does a contact already exist?
	ContactEdge* edge = bodyB->GetContactList();
	while (edge)
	{
		if (edge->other == bodyA)
		{
			Fixture* fA = edge->contact->GetFixtureA();
			Fixture* fB = edge->contact->GetFixtureB();
			s32 iA = edge->contact->GetChildIndexA();
			s32 iB = edge->contact->GetChildIndexB();

			if (fA == fixtureA && fB == fixtureB && iA == indexA && iB == indexB)
			{
				// A contact already exists.
				return;
			}

			if (fA == fixtureB && fB == fixtureA && iA == indexB && iB == indexA)
			{
				// A contact already exists.
				return;
			}
		}

		edge = edge->next;
	}

	// Does a joint override collision? Is at least one body dynamic?
	if (bodyB->ShouldCollide(bodyA) == false)
	{
		return;
	}

	// Check user filtering.
	if (m_contactFilter && m_contactFilter->ShouldCollide(fixtureA, fixtureB) == false)
	{
		return;
	}

	// Call the factory.
	Contact* c = Contact::Create(fixtureA, indexA, fixtureB, indexB, m_allocator);
	if (c == NULL)
	{
		return;
	}

	// Contact creation may swap fixtures.
	fixtureA = c->GetFixtureA();
	fixtureB = c->GetFixtureB();
	indexA = c->GetChildIndexA();
	indexB = c->GetChildIndexB();
	bodyA = fixtureA->GetBody();
	bodyB = fixtureB->GetBody();

	// Insert into the world.
	c->m_prev = NULL;
	c->m_next = m_contactList;
	if (m_contactList != NULL)
	{
		m_contactList->m_prev = c;
	}
	m_contactList = c;

	// Connect to island graph.

	// Connect to body A
	c->m_nodeA.contact = c;
	c->m_nodeA.other = bodyB;

	c->m_nodeA.prev = NULL;
	c->m_nodeA.next = bodyA->m_contactList;
	if (bodyA->m_contactList != NULL)
	{
		bodyA->m_contactList->prev = &c->m_nodeA;
	}
	bodyA->m_contactList = &c->m_nodeA;

	// Connect to body B
	c->m_nodeB.contact = c;
	c->m_nodeB.other = bodyA;

	c->m_nodeB.prev = NULL;
	c->m_nodeB.next = bodyB->m_contactList;
	if (bodyB->m_contactList != NULL)
	{
		bodyB->m_contactList->prev = &c->m_nodeB;
	}
	bodyB->m_contactList = &c->m_nodeB;

	// Wake up the bodies
	if (fixtureA->IsSensor() == false && fixtureB->IsSensor() == false)
	{
		bodyA->SetAwake(true);
		bodyB->SetAwake(true);
	}

	++m_contactCount;
}
开发者ID:BreakEngine,项目名称:Break-0.1,代码行数:101,代码来源:ContactManager.cpp


注:本文中的Fixture::IsSensor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。