bool CStage::InitPhysicsManager() { static TestContactReport s_TCR; static TestTriggerReport s_TTR; // initialize physics scene CSceneDesc phys_scene_desc; m_pPhysicsScene = PhysicsEngine().CreateScene( phys_scene_desc ); if( m_pPhysicsScene == NULL ) return false; m_pPhysicsScene->SetUserContactReport( &s_TCR ); m_pPhysicsScene->SetActorGroupPairFlags(0,0,ContactPairFlag::NOTIFY_ALL); // m_pPhysicsScene->SetActorGroupPairFlags(0,0,NX_NOTIFY_ON_START_TOUCH|NX_NOTIFY_ON_TOUCH|NX_NOTIFY_ON_END_TOUCH); m_pPhysicsScene->SetUserTriggerReport( &s_TTR ); // set pairs that don't collide with each other /* m_pPhysicsManager->SetCollisionGroupState( ENTITY_COLL_GROUP_STATICGEOMETRY,ENTITY_COLL_GROUP_STATICGEOMETRY, false ); m_pPhysicsManager->SetCollisionGroupState( ENTITY_COLL_GROUP_PLAYER, ENTITY_COLL_GROUP_ITEM, false ); m_pPhysicsManager->SetCollisionGroupState( ENTITY_COLL_GROUP_DOOR, ENTITY_COLL_GROUP_STATICGEOMETRY, false ); m_pPhysicsManager->SetCollisionGroupState( ENTITY_COLL_GROUP_DOOR, ENTITY_COLL_GROUP_DOOR, false ); m_pPhysicsManager->SetCollisionGroupState( ENTITY_COLL_GROUP_PLAYER, ENTITY_COLL_GROUP_PLAYER, false ); m_pPhysicsManager->SetCollisionGroupState( ENTITY_COLL_GROUP_NOCLIP, false ); */ int default_material_index = 0; CMaterial *pDefaultMaterial = m_pPhysicsScene->GetMaterial( default_material_index ); float default_static_friction = 1.5f; float default_dynamic_friction = 1.2f; float default_restitution = 0.5f; float rc = 0; if( pDefaultMaterial ) { // Peek at some default parameter values of the default material float sf = pDefaultMaterial->GetStaticFriction(); float df = pDefaultMaterial->GetDynamicFriction(); float rc = pDefaultMaterial->GetRestitution(); pDefaultMaterial->SetStaticFriction( default_static_friction ); pDefaultMaterial->SetDynamicFriction( default_dynamic_friction ); pDefaultMaterial->SetRestitution( default_restitution ); } // Register another material as a fallback CMaterialDesc mat_desc; mat_desc.StaticFriction = default_static_friction; mat_desc.DynamicFriction = default_dynamic_friction; mat_desc.Restitution = default_restitution; physics::CMaterial *pFallbackMaterial = m_pPhysicsScene->CreateMaterial( mat_desc ); int mat_id = pFallbackMaterial->GetMaterialID(); return true; }
CMaterial::CMaterial(const CMaterial& Other) :CNamed(Other.GetName()+"_copy") ,m_CurrentParameterData(0) ,m_Offset(0) { m_RenderableObjectTechnique = Other.GetRenderableObjectTechnique(); m_StaticFriction = Other.GetStaticFriction(); m_DynamicFriction = Other.GetDynamicFriction(); m_Restitution = Other.GetRestitution(); for (size_t i = 0; i < Other.GetTextures().size(); ++i) { m_Textures.push_back(Other.GetTextures()[i]); } for (size_t i = 0; i < Other.GetParameters().size(); ++i) { CMaterialParameter* l_OtherMaterialParameter = Other.GetParameters()[i]; CMaterialParameter::TMaterialType l_MaterialType = l_OtherMaterialParameter->GetMaterialType(); std::string l_OtherDescription = l_OtherMaterialParameter->GetDescription(); std::string l_OtherName = l_OtherMaterialParameter->GetName(); CMaterialParameter* l_MaterialParameter = nullptr; if (l_MaterialType == CMaterialParameter::TMaterialType::FLOAT) { l_MaterialType = CMaterialParameter::FLOAT; float l_Value = *((float*)l_OtherMaterialParameter->GetValueAddress()); l_MaterialParameter = new CTemplatedMaterialParameter<float>(this, l_OtherName, l_OtherDescription, l_Value, l_MaterialType); } else if (l_MaterialType == CMaterialParameter::TMaterialType::VECT2F) { l_MaterialType = CMaterialParameter::VECT2F; Vect2f l_Value = *((Vect2f*)l_OtherMaterialParameter->GetValueAddress()); l_MaterialParameter = new CTemplatedMaterialParameter<Vect2f>(this, l_OtherName, l_OtherDescription, l_Value, l_MaterialType); } else if (l_MaterialType == CMaterialParameter::TMaterialType::VECT3F) { l_MaterialType = CMaterialParameter::VECT3F; Vect3f l_Value = *((Vect3f*)l_OtherMaterialParameter->GetValueAddress()); l_MaterialParameter = new CTemplatedMaterialParameter<Vect3f>(this, l_OtherName, l_OtherDescription, l_Value, l_MaterialType); } else if (l_MaterialType == CMaterialParameter::TMaterialType::VECT4F) { l_MaterialType = CMaterialParameter::VECT4F; Vect4f l_Value = *((Vect4f*)l_OtherMaterialParameter->GetValueAddress()); l_MaterialParameter = new CTemplatedMaterialParameter<Vect4f>(this, l_OtherName, l_OtherDescription, l_Value, l_MaterialType); } m_Parameters.push_back(l_MaterialParameter); } }