コード例 #1
0
Import::Import(const char* pathName, Interface* ip, ImpInterface* impip)
{
    // set the path for textures
    char* ptr = NULL;
    sprintf (m_path, "%s", pathName);
    for (int i = 0; m_path[i]; i ++) {
        if ((m_path[i] == '\\') || (m_path[i] == '/') ) {
            ptr = &m_path[i];
        }
    }
    *ptr = 0;


    m_ip = ip;
    m_impip = impip;
    m_succes = TRUE;
    MaterialCache materialCache (NewDefaultMultiMtl());

    SetSceneParameters();

    dFloat scale;
    scale = float (GetMasterScale(UNITS_METERS));
    dMatrix scaleMatrix (GetIdentityMatrix());
    scaleMatrix[0][0] = 1.0f / scale;
    scaleMatrix[1][1] = 1.0f / scale;
    scaleMatrix[2][2] = 1.0f / scale;
    dMatrix globalRotation (scaleMatrix * dPitchMatrix(3.14159265f * 0.5f) * dRollMatrix(3.14159265f * 0.5f));

    NewtonWorld* newton = NewtonCreate();
    dScene scene (newton);

    scene.Deserialize (pathName);
//	dScene::Iterator iter (scene);
//	for (iter.Begin(); iter; iter ++) {
//		dScene::dTreeNode* node = iter.GetNode();
//		dNodeInfo* info = scene.GetInfoFromNode(node);
//		if (info->GetTypeId() == dMeshNodeInfo::GetRttiType()) {
//			dMeshNodeInfo* mesh = (dMeshNodeInfo*) scene.GetInfoFromNode(node);
//			mesh->ConvertToTriangles();
//		}
//	}
    scene.BakeTransform (globalRotation);

    GeometryCache geometryCache;
    MaxNodeChache maxNodeCache;

    LoadMaterials (scene, materialCache);
    LoadGeometries (scene, geometryCache, materialCache);
    LoadNodes (scene, geometryCache, materialCache.m_multiMat, maxNodeCache);
    ApplyModifiers (scene, maxNodeCache);

    scene.CleanUp();
    NewtonDestroy(newton);
}
コード例 #2
0
bool Physics::reinitialize()
{
    // free up bodies
    NewtonDestroyAllBodies( _p_world );
    // free all materials
    NewtonMaterialDestroyAllGroupID( _p_world );
    // destroy the existing physics world and initialize things again
    NewtonDestroy( _p_world );
    _p_world = NULL;

    // clear the material cache
    _materials.clear();

    log_verbose << "Physics: remaining non-freed bytes: " <<  allocBytesSum - freedBytesSum << std::endl;

    return initialize();
}
コード例 #3
0
ファイル: main.cpp プロジェクト: Kaoswerk/newton-dynamics
// on termination the application must destroy the Newton world 
void ShutDown ()
{
#ifdef USE_VISUAL_DEBUGGER
	// destroy the debugger server
	NewtonDebuggerDestroyServer (g_newtonDebugger);
#endif

	// destroy all rigid bodies, this is no necessary because Newton Destroy world will also destroy all bodies
	// but if you want to change level and restart you can call this function to clean the world without destroying the world.
	NewtonDestroyAllBodies (g_world);

	// finally destroy the newton world 
	NewtonDestroy (g_world);

	// now we need to destroy the Graphics entities
	delete g_sceneManager;
}
コード例 #4
0
ファイル: OgreNewt_World.cpp プロジェクト: akadjoker/gmogre3d
// Destructor
World::~World()
{
    if (m_debugger)
    {
        delete m_debugger;
        m_debugger = NULL;
    }

    if (m_defaultMatID)
    {
        delete m_defaultMatID;
        m_defaultMatID = NULL;
    }

    if (m_world)
    {
        NewtonDestroy( m_world );
        m_world = NULL;
    }
}
コード例 #5
0
void Physics::shutdown()
{
    log_info << "Physics: shutting down" << std::endl;

    if ( _p_world )
    {
        // free up bodies
        NewtonDestroyAllBodies( _p_world );
        // free all materials
        NewtonMaterialDestroyAllGroupID( _p_world );
        // destroy the existing physics world and initialize things again
        NewtonDestroy( _p_world );
        _p_world = NULL;
    }

    log_verbose << "Physics: remaining non-freed bytes: " <<  allocBytesSum - freedBytesSum << std::endl;

    // destroy singleton
    destroy();
}
コード例 #6
0
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;
}
コード例 #7
0
ファイル: iPhysics.cpp プロジェクト: tanzfisch/Igor
    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();
        }
    }
コード例 #8
0
PhysicsWorld::~PhysicsWorld()
{
	cleanupMarkedForDeletion();

	if(m_sceneBody)
	{
		NewtonDestroyBody(m_sceneBody);
		m_sceneBody = nullptr;
	}

	if(m_sceneCollision)
	{
		NewtonDestroyCollision(m_sceneCollision);
		m_sceneCollision = nullptr;
	}

	if(m_world)
	{
		NewtonDestroy(m_world);
		m_world = nullptr;
	}

	gAlloc = nullptr;
}
コード例 #9
0
pyScene::~pyScene(void)
{
	NewtonDestroy (m_scene->GetNewtonWorld());
}
コード例 #10
0
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;
}
コード例 #11
0
ファイル: dNewton.cpp プロジェクト: Kaoswerk/newton-dynamics
dNewton::~dNewton()
{
	NewtonWaitForUpdateToFinish (m_world);
	NewtonDestroy (m_world);
}
コード例 #12
0
	PhysWorld3D::~PhysWorld3D()
	{
		NewtonDestroy(m_world);
	}
コード例 #13
0
ファイル: Zone.cpp プロジェクト: pixelbound/equilibre
Zone::~Zone()
{
    clear(NULL);
    NewtonDestroy(m_collisionWorld);
}
コード例 #14
0
ファイル: tutorial.cpp プロジェクト: brettminnie/BDBGame
// destroy the world and every thing in it
void CleanUp ()
{
	// destroy the Newton world
	NewtonDestroy (nWorld);
}
コード例 #15
0
ファイル: cm_physics.cpp プロジェクト: DerSaidin/OpenWolf
/*
=============
CMod_PhysicsShutdown
=============
*/
void CMod_PhysicsShutdown() {
	if ( g_world != NULL ) {
		NewtonDestroy (g_world);
		g_world = NULL;
	}
}
コード例 #16
0
void ConvexApproximationObject::BuildMesh()
{

	// since max does no provide the iNode that will own this mesh I have no choice bu to apply the root matrix to all vertex
	ConvexApproximationClassDesc* const desc = (ConvexApproximationClassDesc*) ConvexApproximationClassDesc::GetDescriptor();
	INode* const sourceNode = desc->m_sourceNode;
	//dMatrix rootMatrix1 (GetMatrixFromMaxMatrix (sourceNode->GetNodeTM (0)));
	dMatrix rootMatrix (GetMatrixFromMaxMatrix (sourceNode->GetObjectTM(0)));

	dVector scale;
	dMatrix stretchAxis;
	dMatrix orthogonalRootTransform;
	rootMatrix.PolarDecomposition (orthogonalRootTransform, scale, stretchAxis);
	orthogonalRootTransform = orthogonalRootTransform.Inverse();

	// create a Newton world, as a manager of everything Newton related stuff
	NewtonWorld* const world = NewtonCreate ();

	// create an empty mesh and load the max mesh to it
	NewtonMesh* const sourceMesh = NewtonMeshCreate (world);

	// load all faces
	NewtonMeshBeginFace(sourceMesh);
	LoadGeometries (sourceMesh, orthogonalRootTransform);
	NewtonMeshEndFace(sourceMesh);


	// make a convex approximation form this newton mesh effect
	desc->m_progress = -1;
	Interface* const inteface = desc->m_currentInterface;
	
	inteface->ProgressStart("Creation Convex approx ...", TRUE, ConvexApproximationClassDesc::ReportMaxProgress, NULL);
	NewtonMesh* approximationMesh = NewtonMeshApproximateConvexDecomposition (sourceMesh, m_currentConcavity, 0.2f, m_currentMaxCount, 1000, ConvexApproximationClassDesc::ReportProgress);
	inteface->ProgressEnd();

	NewtonMeshDestroy (sourceMesh);



	// now convert the new mesh to a max poly Object
	MNMesh& maxMesh = GetMesh();
	maxMesh.ClearAndFree();

	int faceCount = 0;
	int vertexCount = NewtonMeshGetVertexCount(approximationMesh);
	for (void* face = NewtonMeshGetFirstFace(approximationMesh); face; face = NewtonMeshGetNextFace(approximationMesh, face)) {
		if (!NewtonMeshIsFaceOpen(approximationMesh, face)) {
			faceCount ++;
		}
	}

	//maxMesh.Clear();
	maxMesh.setNumVerts(vertexCount);
	maxMesh.setNumFaces(faceCount);

	// add all vertex
	int vertexStride = NewtonMeshGetVertexStrideInByte(approximationMesh) / sizeof (dFloat64);
	dFloat64* const vertex = NewtonMeshGetVertexArray (approximationMesh); 
	for (int j = 0; j < vertexCount; j ++) {
		dVector p (orthogonalRootTransform.TransformVector(dVector (float (vertex[vertexStride * j + 0]), float (vertex[vertexStride * j + 1]), float (vertex[vertexStride * j + 2]), float(1.0f))));
		maxMesh.P(j) = Point3 (p.m_x, p.m_y, p.m_z);
	}

	// count the number of face and make a face map
	int faceIndex = 0;
	for (void* face = NewtonMeshGetFirstFace(approximationMesh); face; face = NewtonMeshGetNextFace(approximationMesh, face)) {
		if (!NewtonMeshIsFaceOpen(approximationMesh, face)) {
			int faceIndices[256];
			int indexCount = NewtonMeshGetFaceIndexCount (approximationMesh, face);

			NewtonMeshGetFaceIndices (approximationMesh, face, faceIndices);
			MNFace* const face = maxMesh.F(faceIndex);
			face->MakePoly(indexCount, faceIndices, NULL, NULL);
			face->material = 0;
			faceIndex ++;
		}
	}

	maxMesh.InvalidateGeomCache();
	maxMesh.InvalidateTopoCache();
	maxMesh.FillInMesh();
	maxMesh.AutoSmooth(45.0f * 3.1416f / 160.0f, false, false);


	NewtonMeshDestroy (approximationMesh);
	NewtonDestroy (world);
}
コード例 #17
0
NzPhysWorld::~NzPhysWorld()
{
	NewtonDestroy(m_world);
}
コード例 #18
0
ファイル: world.cpp プロジェクト: Zarius/pseudoform
 world::~world()
 {
     NewtonDestroy(_world);
 }