Exemplo n.º 1
0
DemoListenerBase::DemoListenerBase(DemoEntityManager* const scene, const char* const listenerName)
{
	NewtonWorld* const world = scene->GetNewton();
	void* const prelistener = NewtonWorldAddPreListener (world, listenerName, this, PreUpdate, NULL);
	NewtonWorldAddPostListener (world, listenerName, this, PostUpdate, Destroy);

	NewtonWorldListenerSetBodyDestroyCallback (world, prelistener, OnBodyDetroy);
}
Exemplo n.º 2
0
Error PhysicsWorld::create(AllocAlignedCallback allocCb, void* allocCbData)
{
	Error err = ErrorCode::NONE;

	m_alloc = HeapAllocator<U8>(allocCb, allocCbData);

	// Set allocators
	gAlloc = &m_alloc;
	NewtonSetMemorySystem(newtonAlloc, newtonFree);

	// Initialize world
	m_world = NewtonCreate();
	if(!m_world)
	{
		ANKI_LOGE("NewtonCreate() failed");
		return ErrorCode::FUNCTION_FAILED;
	}

	// Set the simplified solver mode (faster but less accurate)
	NewtonSetSolverModel(m_world, 1);

	// Create scene collision
	m_sceneCollision = NewtonCreateSceneCollision(m_world, 0);
	Mat4 trf = Mat4::getIdentity();
	m_sceneBody = NewtonCreateDynamicBody(m_world, m_sceneCollision, &trf[0]);
	NewtonBodySetMaterialGroupID(m_sceneBody, NewtonMaterialGetDefaultGroupID(m_world));

	NewtonDestroyCollision(m_sceneCollision); // destroy old scene
	m_sceneCollision = NewtonBodyGetCollision(m_sceneBody);

	// Set the post update listener
	NewtonWorldAddPostListener(m_world, "world", this, postUpdateCallback, destroyCallback);

	// Set callbacks
	NewtonMaterialSetCollisionCallback(m_world,
		NewtonMaterialGetDefaultGroupID(m_world),
		NewtonMaterialGetDefaultGroupID(m_world),
		nullptr,
		onAabbOverlapCallback,
		onContactCallback);

	return err;
}