Ejemplo n.º 1
0
dNewtonKinematicBody::dNewtonKinematicBody(dNewtonWorld* const world, dNewtonCollision* const collision, dMatrix matrix, dFloat mass)
	:dNewtonBody(matrix)
{
	NewtonWorld* const newton = world->m_world;
	NewtonWaitForUpdateToFinish(newton);

	m_body = NewtonCreateDynamicBody(newton, collision->m_shape, &matrix[0][0]);
	collision->DeleteShape();
	collision->SetShape(NewtonBodyGetCollision(m_body));

	NewtonBodySetMassProperties(m_body, mass, NewtonBodyGetCollision(m_body));

	NewtonBodySetUserData(m_body, this);
	NewtonBodySetTransformCallback(m_body, OnBodyTransformCallback);
	NewtonBodySetForceAndTorqueCallback(m_body, OnForceAndTorqueCallback);
}
DemoEntityManager::~DemoEntityManager(void)
{
	// is we are run asynchronous we need make sure no update in on flight.
	if (m_world) {
		NewtonWaitForUpdateToFinish (m_world);
	}

	glDeleteLists(m_font, 96);	
	ReleaseTexture(m_fontImage);

	Cleanup ();

	// destroy the empty world
	if (m_world) {
		NewtonDestroy (m_world);
		m_world = NULL;
	}
	dAssert (NewtonGetMemoryUsed () == 0);

	delete m_context;
}
Ejemplo n.º 3
0
    iPhysicsJoint* iPhysics::createJoint(iPhysicsBody* body0, iPhysicsBody* body1, int dof)
    {
        iPhysicsJoint* result = nullptr;
        con_assert(body0 != nullptr, "zero pointer");

        if (body0 != nullptr)
        {
            NewtonWaitForUpdateToFinish(static_cast<const NewtonWorld*>(_defaultWorld));
            NewtonJoint * joint = NewtonConstraintCreateUserJoint(static_cast<NewtonWorld*>(_defaultWorld), dof, reinterpret_cast<NewtonUserBilateralCallback>(SubmitConstraints), nullptr, static_cast<NewtonBody*>(body0->getNewtonBody()), body1 != nullptr ? static_cast<NewtonBody*>(body1->getNewtonBody()) : nullptr);

            result = new iPhysicsJoint(joint, body0->getID(), body1 != nullptr ? body1->getID() : 0);

            _jointListMutex.lock();
            _joints[result->getID()] = result;
            _jointListMutex.unlock();

            NewtonJointSetUserData(joint, result);
        }

        return result;
    }
Ejemplo n.º 4
0
    void iPhysics::destroyWorld(iPhysicsWorld* world)
    {
        con_assert(world != nullptr, "zero pointer");

        if (world != nullptr)
        {
            _worldListMutex.lock();
            auto iter = _worlds.find(world->getID());
            if (iter != _worlds.end())
            {
                NewtonWaitForUpdateToFinish(static_cast<const NewtonWorld*>((*iter).second->getNewtonWorld()));
                NewtonDestroy(static_cast<const NewtonWorld*>((*iter).second->getNewtonWorld()));
                delete (*iter).second;
                _worlds.erase(iter);
            }
            else
            {
                con_err("world id " << world->getID() << " not found");
            }
            _worldListMutex.unlock();
        }
    }
Ejemplo n.º 5
0
void PhysicsWorld::waitUpdate()
{
	NewtonWaitForUpdateToFinish(m_world);
}
Ejemplo n.º 6
0
void dNewton::WaitForUpdateToFinish ()
{
	NewtonWaitForUpdateToFinish(m_world);
}
Ejemplo n.º 7
0
dNewton::~dNewton()
{
	NewtonWaitForUpdateToFinish (m_world);
	NewtonDestroy (m_world);
}
Ejemplo n.º 8
0
 void iPhysics::destroyNewtonBody(void* newtonBody)
 {
     NewtonWaitForUpdateToFinish(static_cast<const NewtonWorld*>(_defaultWorld));
     NewtonBodySetUserData(static_cast<const NewtonBody*>(newtonBody), nullptr);
     NewtonDestroyBody(static_cast<const NewtonBody*>(newtonBody));
 }
dNewtonCollisionSphere::dNewtonCollisionSphere(dNewtonWorld* const world, dFloat r)
	:dNewtonCollision(world, 0)
{
	NewtonWaitForUpdateToFinish(m_myWorld->m_world);
	SetShape(NewtonCreateSphere(m_myWorld->m_world, r, 0, NULL));
}
dNewtonCollisionScene::dNewtonCollisionScene(dNewtonWorld* const world)
	:dNewtonCollision(world, 0)
{
	NewtonWaitForUpdateToFinish(m_myWorld->m_world);
	SetShape(NewtonCreateSceneCollision(m_myWorld->m_world, 0));
}
dNewtonCollisionCompound::dNewtonCollisionCompound(dNewtonWorld* const world)
	:dNewtonCollision(world, 0)
{
	NewtonWaitForUpdateToFinish(m_myWorld->m_world);
	SetShape(NewtonCreateCompoundCollision(m_myWorld->m_world, 0));
}
dNewtonCollisionConvexHull::dNewtonCollisionConvexHull(dNewtonWorld* const world, int vertexCount, const dFloat* const vertexCloud, dFloat tolerance)
	:dNewtonCollision(world, 0)
{
	NewtonWaitForUpdateToFinish(m_myWorld->m_world);
	SetShape(NewtonCreateConvexHull(m_myWorld->m_world, vertexCount, vertexCloud, 3 * sizeof (dFloat), tolerance, 0, NULL));
}
dNewtonCollisionChamferedCylinder::dNewtonCollisionChamferedCylinder(dNewtonWorld* const world, dFloat radio, dFloat height)
	:dNewtonAlignedShapes(world, 0)
{
	NewtonWaitForUpdateToFinish(m_myWorld->m_world);
	SetShape(NewtonCreateChamferCylinder(m_myWorld->m_world, radio, height, 0, NULL));
}
dNewtonCollisionCapsule::dNewtonCollisionCapsule(dNewtonWorld* const world, dFloat radio0, dFloat radio1, dFloat height)
	:dNewtonAlignedShapes(world, 0)
{
	NewtonWaitForUpdateToFinish(m_myWorld->m_world);
	SetShape(NewtonCreateCapsule(m_myWorld->m_world, radio0, radio1, height, 0, NULL));
}
dNewtonCollisionBox::dNewtonCollisionBox(dNewtonWorld* const world, dFloat x, dFloat y, dFloat z)
	:dNewtonCollision(world, 0)
{
	NewtonWaitForUpdateToFinish(m_myWorld->m_world);
	SetShape(NewtonCreateBox(m_myWorld->m_world, x, y, z, 0, NULL));
}
void DemoEntityManager::Cleanup ()
{
	// is we are run asynchronous we need make sure no update in on flight.
	if (m_world) {
		NewtonWaitForUpdateToFinish (m_world);
	}

	// destroy all remaining visual objects
	while (dList<DemoEntity*>::GetFirst()) {
		RemoveEntity (dList<DemoEntity*>::GetFirst());
	}

	m_sky = NULL;

	// destroy the Newton world
	if (m_world) {
		// get serialization call back before destroying the world
		NewtonDestroy (m_world);
		m_world = NULL;
	}

	//	memset (&demo, 0, sizeof (demo));
	// check that there are no memory leak on exit
	dAssert (NewtonGetMemoryUsed () == 0);

	// create the newton world
	m_world = NewtonCreate();

	// link the work with this user data
	NewtonWorldSetUserData(m_world, this);

	// set joint serialization call back
	CustomJoint::Initalize(m_world);

	// add all physics pre and post listeners
	//	m_preListenerManager.Append(new DemoVisualDebugerListener("visualDebuger", m_world));
	new DemoEntityListener (this);
	m_cameraManager = new DemoCameraListener(this);
	//	m_postListenerManager.Append (new DemoAIListener("aiManager"));

	// set the default parameters for the newton world
	// set the simplified solver mode (faster but less accurate)
	NewtonSetSolverModel (m_world, 4);

	// newton 300 does not have world size, this is better controlled by the client application
	//dVector minSize (-500.0f, -500.0f, -500.0f);
	//dVector maxSize ( 500.0f,  500.0f,  500.0f);
	//NewtonSetWorldSize (m_world, &minSize[0], &maxSize[0]); 

	// set the performance track function
	//NewtonSetPerformanceClock (m_world, dRuntimeProfiler::GetTimeInMicrosenconds);

	// clean up all caches the engine have saved
	NewtonInvalidateCache (m_world);

	// Set the Newton world user data
	NewtonWorldSetUserData(m_world, this);


	// we start without 2d render
	m_renderHood = NULL;
	m_renderHoodContext = NULL;
}
dNewtonCollisionNull::dNewtonCollisionNull(dNewtonWorld* const world)
	:dNewtonCollision(world, 0)
{
	NewtonWaitForUpdateToFinish(m_myWorld->m_world);
	SetShape(NewtonCreateNull(m_myWorld->m_world));
}