void RigidBodyWorld::UpdatePhysics () { RigidBodyWorldDesc* const desc = (RigidBodyWorldDesc*) RigidBodyWorldDesc::GetDescriptor(); float timestep = 1.0f / desc->m_minFps; if (timestep > 1.0f / 60.0f) { timestep = 1.0f / 60.0f; } desc->m_updateRigidBodyMatrix = false; NewtonUpdate(desc->m_newton, timestep); TimeValue t (GetCOREInterface()->GetTime()); float scale = 1.0f / float (GetMasterScale(UNITS_METERS)); for (NewtonBody* body = NewtonWorldGetFirstBody(desc->m_newton); body; body = NewtonWorldGetNextBody(desc->m_newton, body)) { dMatrix matrix; INode* const node = (INode*)NewtonBodyGetUserData(body); NewtonBodyGetMatrix(body, &matrix[0][0]); matrix = desc->m_systemMatrix * matrix * desc->m_systemMatrixInv; matrix.m_posit = matrix.m_posit.Scale (scale); Matrix3 maxMatrix (GetMatrixFromdMatrix (matrix)); node->SetNodeTM(t, maxMatrix); } UpdateViewPorts (); desc->m_updateRigidBodyMatrix = true; }
void Import::LoadNode (dScene& scene, INode* maxParent, dScene::dTreeNode* node, const GeometryCache& meshCache, Mtl *mtl, MaxNodeChache& maxNodeCache) { dScene::dTreeNode* geometryNode = NULL; for (void* ptr = scene.GetFirstChild(node); ptr; ptr = scene.GetNextChild(node, ptr) ) { dScene::dTreeNode* node = scene.GetNodeFromLink(ptr); dNodeInfo* info = scene.GetInfoFromNode(node); if (info->IsType(dGeometryNodeInfo::GetRttiType())) { geometryNode = node; break; } } INode* maxNode = NULL; if (geometryNode) { // maxNode = CreateMaxMeshNode (mtl, &geom[0]->GetInfo(), meshCache); maxNode = CreateMaxMeshNode (scene, mtl, geometryNode, meshCache); maxNodeCache.Insert (maxNode, geometryNode); } else { maxNode = CreateMaxHelperNode (); } _ASSERTE (maxNode); maxNodeCache.Insert (maxNode, node); if (maxParent) { maxParent->AttachChild(maxNode, 1); } dSceneNodeInfo* sceneInfo = (dSceneNodeInfo*)scene.GetInfoFromNode(node); TCHAR name[128]; TCHAR tmp[128]; strcpy (tmp, sceneInfo->GetName()); for (int i = 0; tmp[i]; i ++) { if (isspace(tmp[i])) { tmp[i] = '_'; } } strcpy (name, tmp); for (int i = 1; m_ip->GetINodeByName(name); i ++) { sprintf (name, "%s_%02d", tmp, i); // node->SetNameID(name); } maxNode->SetName(name); dMatrix transform (sceneInfo->GetTransform()); dMatrix matrix; for (int i = 0; i < 4; i ++) { for (int j = 0; j < 4; j ++) { matrix[i][j] = transform[i][j]; } } Matrix3 maxMatrix (GetMatrixFromdMatrix (matrix)); // maxMatrix.SetRow (0, *((Point3*) &matrix[0])); // maxMatrix.SetRow (1, *((Point3*) &matrix[1])); // maxMatrix.SetRow (2, *((Point3*) &matrix[2])); // maxMatrix.SetRow (3, *((Point3*) &matrix[3])); maxNode->SetNodeTM(0, maxMatrix); for (void* ptr = scene.GetFirstChild(node); ptr; ptr = scene.GetNextChild(node, ptr) ) { dScene::dTreeNode* node = scene.GetNodeFromLink(ptr); dNodeInfo* info = scene.GetInfoFromNode(node); if (info->IsType(dSceneNodeInfo::GetRttiType())) { LoadNode (scene, maxNode, node, meshCache, mtl, maxNodeCache); } } }