NxScene* plSimulationMgr::GetScene(plKey world)
{
    if (!world)
        world = GetKey();

    NxScene* scene = fScenes[world];

    if (!scene)
    {
        NxSceneDesc sceneDesc;
        sceneDesc.gravity.set(0, 0, -32.174049f);
        sceneDesc.userTriggerReport = &gSensorReport;
        sceneDesc.userContactReport = &gContactReport;
        scene = fSDK->createScene(sceneDesc);

        // See "Advancing The Simulation State" in the PhysX SDK Documentation
        // This will cause PhysX to only update for our step size. If we call simulate
        // faster than that, PhysX will return immediately. If we call it slower than that,
        // PhysX will do some extra steps for us (isn't that nice?).
        // Anyway, this should be a good way to make us independent of the framerate.
        // If not, I blame the usual suspects (Tye, eap, etc...)
        scene->setTiming(kDefaultStepSize);

        // Most physicals use the default friction and restitution values, so we
        // make them the default.
        NxMaterial* mat = scene->getMaterialFromIndex(0);
        float rest = mat->getRestitution();
        float sfriction = mat->getStaticFriction();
        float dfriction = mat->getDynamicFriction();
        mat->setRestitution(0.5);
        mat->setStaticFriction(0.5);
        mat->setDynamicFriction(0.5);

        // By default we just leave all the collision groups enabled, since
        // PhysX already makes sure that things like statics and statics don't
        // collide.  However, we do make it so the avatar and dynamic blockers
        // only block avatars and dynamics.
        for (int i = 0; i < plSimDefs::kGroupMax; i++)
        {
            scene->setGroupCollisionFlag(i, plSimDefs::kGroupAvatarBlocker, false);
            scene->setGroupCollisionFlag(i, plSimDefs::kGroupDynamicBlocker, false);
            scene->setGroupCollisionFlag(i, plSimDefs::kGroupLOSOnly, false);
            scene->setGroupCollisionFlag(plSimDefs::kGroupLOSOnly, i, false);
        }
        scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupAvatar, false);
        scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupAvatarBlocker, true);
        scene->setGroupCollisionFlag(plSimDefs::kGroupDynamic, plSimDefs::kGroupDynamicBlocker, true);
        scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupStatic, true);
        scene->setGroupCollisionFlag( plSimDefs::kGroupStatic, plSimDefs::kGroupAvatar, true);
        scene->setGroupCollisionFlag(plSimDefs::kGroupAvatar, plSimDefs::kGroupDynamic, true);
        
        // The dynamics are in actor group 1, everything else is in 0.  Request
        // a callback for whenever a dynamic touches something.
        scene->setActorGroupPairFlags(0, 1, NX_NOTIFY_ON_TOUCH);
        scene->setActorGroupPairFlags(1, 1, NX_NOTIFY_ON_TOUCH);

        fScenes[world] = scene;
    }

    return scene;
}
Beispiel #2
0
pWorld*pFactory::createWorld(CK3dEntity* referenceObject, pWorldSettings *worldSettings,pSleepingSettings *sleepSettings)
{


	using namespace vtTools::AttributeTools;
	using namespace vtTools::ParameterTools;

	
	//////////////////////////////////////////////////////////////////////////
	//sanity checks : 
	if (!referenceObject || !GetPMan() )
	{
		return NULL;
	}


	if (!getPhysicSDK())
	{
		//xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"No physic sdk loaded");
		return NULL;
	}

	int worldAtt = GetPMan()->att_world_object;
	int surfaceAttribute = GetPMan()->att_surface_props;

	//exists ? Delete it !
	pWorld *w = GetPMan()->getWorld(referenceObject->GetID());
	if (w)
	{
		GetPMan()->deleteWorld(referenceObject->GetID());
	}
		
	//our new world : 
	pWorld *result  = new pWorld(referenceObject);
	GetPMan()->getWorlds()->InsertUnique(referenceObject,result);

	result->initUserReports();



	//////////////////////////////////////////////////////////////////////////

	//there is no world settings attribute  : 
	if (!referenceObject->HasAttribute(worldAtt) )
	{
		referenceObject->SetAttribute(worldAtt);
		using namespace vtTools;
		VxVector grav = worldSettings->getGravity();
		float sWith  = worldSettings->getSkinWith();
		AttributeTools::SetAttributeValue<VxVector>(referenceObject,worldAtt,0,&grav);
		AttributeTools::SetAttributeValue<float>(referenceObject,worldAtt,1,&sWith);
	}


	if (!worldSettings)
	{
		worldSettings = pFactory::Instance()->createWorldSettings(XString("Default"),GetPMan()->getDefaultConfig());
	}
	if (!worldSettings)
	{
		worldSettings = new pWorldSettings();
	}

	//////////////////////////////////////////////////////////////////////////
	//pSDK Scene creation  : 

	// Create a scene
	NxSceneDesc sceneDesc;
	sceneDesc.gravity				= pMath::getFrom(worldSettings->getGravity());
	sceneDesc.upAxis = 1;
	sceneDesc.flags |=NX_SF_ENABLE_ACTIVETRANSFORMS;
	sceneDesc.userNotify =&myNotify;
	sceneDesc.userContactReport = result->contactReport;
    
	NxScene *scene = NULL;
	if (getPhysicSDK())
	{
		scene  = getPhysicSDK()->createScene(sceneDesc);
		if(scene == NULL) 
		{
            xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,"Couldn't create scene!");
			return NULL;
		}
	}

	result->setScene(scene);
	scene->setUserContactReport(result->contactReport);
	scene->setUserTriggerReport(result->triggerReport);

	NxMaterialDesc *materialDescr = NULL;
	NxMaterial *material = NULL;
	if (referenceObject->HasAttribute(surfaceAttribute))
	{
		materialDescr  = createMaterialFromEntity(referenceObject);
		material =  result->getScene()->createMaterial(*materialDescr);
		material->userData = (void*)GetValueFromParameterStruct<int>(referenceObject->GetAttributeParameter(surfaceAttribute) ,E_MS_XML_TYPE);
	}else{
		
		if (getDefaultDocument())
		{
			
			materialDescr = createMaterialFromXML("Default",getDefaultDocument());
		}
		
		if (materialDescr)
		{
			material = result->getScene()->createMaterial(*materialDescr);
		}

		if (!material)
		{
			materialDescr = new NxMaterialDesc();
			materialDescr->setToDefault();
			material = result->getScene()->getMaterialFromIndex(0); 
			material->loadFromDesc(*materialDescr);
		}
	}
	
	int z = (int)material->userData;
	NxMaterial *zeroMaterial  = result->getScene()->getMaterialFromIndex(0);
	zeroMaterial->setDirOfAnisotropy(material->getDirOfAnisotropy());
	zeroMaterial->setStaticFriction(material->getStaticFriction());
	zeroMaterial->setDynamicFriction(material->getDynamicFriction());
	zeroMaterial->setStaticFrictionV(material->getStaticFrictionV());
	zeroMaterial->setDynamicFrictionV(material->getDynamicFrictionV());
	zeroMaterial->setFrictionCombineMode(material->getFrictionCombineMode());
	zeroMaterial->setRestitutionCombineMode(material->getRestitutionCombineMode());
	zeroMaterial->setFlags(material->getFlags());
	zeroMaterial->userData = material->userData;




	if (!material)
	{
		xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,"Couldn't create default material!");
	}
	result->setDefaultMaterial(material);

	scene->userData = result;

	
	//NxConstraintDominance testDom(1.0, 1.0f);
	//result->getScene()->setDominanceGroupPair(1, 2,testDom );	//board - debris



	//////////////////////////////////////////////////////////////////////////
	//there is no world settings attribute  : 
	/*
	if (!referenceObject->HasAttribute(GetPMan()->att_sleep_settings) )
	{
		referenceObject->SetAttribute(GetPMan()->att_sleep_settings);
		using namespace vtTools;
		AttributeTools::SetAttributeValue<int>(referenceObject,GetPMan()->att_sleep_settings,0,&sSettings->m_SleepSteps);
		AttributeTools::SetAttributeValue<float>(referenceObject,GetPMan()->att_sleep_settings,1,&sSettings->m_AngularThresold);
		AttributeTools::SetAttributeValue<float>(referenceObject,GetPMan()->att_sleep_settings,2,&sSettings->m_LinearThresold);
		AttributeTools::SetAttributeValue<int>(referenceObject,GetPMan()->att_sleep_settings,3,&sSettings->m_AutoSleepFlag);
	}	
	*/
	

	/*
	result->SleepingSettings(sSettings);
	//////////////////////////////////////////////////////////////////////////

	result->Reference(referenceObject);
	
	result->Init();
*/


	result->_checkForDominanceConstraints();
	result->_construct();






	return result;
	

	//return NULL;

}
Beispiel #3
0
int PMaterialIterator(const CKBehaviorContext& behcontext)
{
	
	CKBehavior* beh = behcontext.Behavior;

	CKContext* ctx = behcontext.Context;

	PhysicManager *pm = GetPMan();
	
	pFactory *pf = pFactory::Instance();

	if (beh->IsInputActive(0))
	{
		beh->ActivateInput(0,FALSE);

		//////////////////////////////////////////////////////////////////////////
		//we reset our session counter
		int sessionIndex=-1;
		beh->SetOutputParameterValue(0,&sessionIndex);


		LMaterials*sResults = NULL;
		beh->GetLocalParameterValue(0,&sResults);
		if (!sResults)
		{
			sResults = new LMaterials();
		}else
			sResults->clear();


		NxScene * scene = GetPMan()->getDefaultWorld()->getScene();
		for(int i = 0 ; i < GetPMan()->getDefaultWorld()->getScene()->getNbMaterials() ; i ++)
		{
		
			NxMaterial *currentMaterial = scene->getMaterialFromIndex(i);

			sResults->push_back(currentMaterial);
		}

		beh->SetLocalParameterValue(0,&sResults);



		if (sResults->size())
		{
			beh->ActivateInput(1);
		}else
		{
			beh->ActivateOutput(0);
			return 0;
		}
	}




	if( beh->IsInputActive(1) )
	{
		beh->ActivateInput(1,FALSE);

		int currentIndex=0;	CKParameterOut *pout = beh->GetOutputParameter(0);		pout->GetValue(&currentIndex);
		currentIndex++;



		LMaterials *sResults = NULL;	beh->GetLocalParameterValue(0,&sResults);
		if (!sResults)		{			beh->ActivateOutput(0);			return 0;		}

		if (currentIndex>=sResults->size())
		{
			sResults->clear();
			beh->ActivateOutput(0);
			return 0;
		}

		NxMaterial * material =  sResults->at(currentIndex);
		if (material!=NULL)
		{

			int sIndex = currentIndex+1;
			beh->SetOutputParameterValue(0,&sIndex);

			

					
			//SetOutputParameterValue<int>(beh,O_XML,material->xmlLinkID);
			SetOutputParameterValue<float>(beh,O_DFRICTION,material->getDynamicFriction());
			SetOutputParameterValue<float>(beh,O_SFRICTION,material->getStaticFriction());

			SetOutputParameterValue<float>(beh,O_RES,material->getRestitution());

			SetOutputParameterValue<float>(beh,O_DFRICTIONV,material->getDynamicFrictionV());
			SetOutputParameterValue<float>(beh,O_SFRICTIONV,material->getStaticFrictionV());

			SetOutputParameterValue<VxVector>(beh,O_ANIS,getFrom(material->getDirOfAnisotropy()));
			SetOutputParameterValue<int>(beh,O_FCMODE,material->getFrictionCombineMode());
			SetOutputParameterValue<int>(beh,O_RCMODE,material->getFrictionCombineMode());
			SetOutputParameterValue<int>(beh,O_FLAGS,material->getFlags());
		}

		if(material->userData )
		{
			pMaterial *bMaterial  = static_cast<pMaterial*>(material->userData);

			if (bMaterial && bMaterial->xmlLinkID )
			{
			
				int xid = bMaterial->xmlLinkID;
				XString nodeName = vtAgeia::getEnumDescription(GetPMan()->GetContext()->GetParameterManager(),VTE_XML_MATERIAL_TYPE,xid);
				CKParameterOut *nameStr = beh->GetOutputParameter(O_NAME);
				nameStr->SetStringValue(nodeName.Str());
			}
		}
		//pFactory::Instance()->copyTo(beh->GetOutputParameter(O_MATERIAL),material);


		beh->ActivateOutput(0);
	}
	return 0;
}
Beispiel #4
0
	/// Retrieves the DynamicFriction value. 
	virtual Scalar  GetDynamicFriction () const { return m_pNxMaterial->getDynamicFriction(); }