Beispiel #1
0
void PhysStart ( void )
{
	gAllocator = new UserAllocator;
    gPhysicsSDK = NxCreatePhysicsSDK ( NX_PHYSICS_SDK_VERSION,gAllocator );

    if ( !gPhysicsSDK )
		return;

	gPhysicsSDK->setParameter ( NX_MIN_SEPARATION_FOR_PENALTY, -0.05f );

	gPhysicsSDK->setParameter ( NX_VISUALIZATION_SCALE,        1 );
	gPhysicsSDK->setParameter ( NX_VISUALIZE_COLLISION_SHAPES, 1 );
	gPhysicsSDK->setParameter ( NX_VISUALIZE_ACTOR_AXES,       1 );
	gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, 1);

    NxSceneDesc			sceneDesc;
    sceneDesc.gravity               = gDefaultGravity;
    sceneDesc.broadPhase            = NX_BROADPHASE_COHERENT;
    sceneDesc.collisionDetection    = true;
	sceneDesc.userContactReport		= carContactReport;
    gScene = gPhysicsSDK->createScene ( sceneDesc );

	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex ( 0 );
	defaultMaterial->setRestitution     ( 0.0f );
	defaultMaterial->setStaticFriction  ( 0.5f );
	defaultMaterial->setDynamicFriction ( 0.5f );

	gPhysicsSDK->setActorGroupPairFlags(0, 0, NX_NOTIFY_ON_TOUCH);
}
Beispiel #2
0
bool initNx()
{
	NxSDKCreateError error;
	gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, new ErrorStream(), NxPhysicsSDKDesc(), &error);
	if (gPhysicsSDK == NULL) {
		cout << "Physics SDK creation failed: " << PhysXUtils::getErrorString(error) << endl;
		return false;
	}

	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.2f); // 0.2 is the best I've tried

	NxSceneDesc sceneDesc;
	sceneDesc.gravity = NxVec3(0.0f, -9.81f, 0.0f);
	g_NxScene = gPhysicsSDK->createScene(sceneDesc);

	if (g_NxScene == NULL) {
		cout << "ERROR: unable to create PhysX scene" << endl;
		return false;
	}

	NxMaterial* defaultMaterial = g_NxScene->getMaterialFromIndex(0);
	defaultMaterial->setRestitution(0.0f);
	defaultMaterial->setStaticFriction(0.5f);
	defaultMaterial->setDynamicFriction(0.5f);

	NxPlaneShapeDesc planeDesc;
	NxActorDesc actorDesc;
	actorDesc.shapes.pushBack(&planeDesc);
	g_NxScene->createActor(actorDesc);

	return true;
}
	/**
	 * CreateGroundPlane(): Create Ground Plane
	 * @return
	 */
void CreateGroundPlane(){
	/*
	 *	Create Ground Plane
	 * Static Actor: has no 'NxBodyDesc'
	 */
	//actor Descriptor with Collection of Shapes.
	NxActorDesc	actorDesc;

	//Plane Shape Descriptor
	NxPlaneShapeDesc	planeDesc;
	//平面方程式: ax + by + cz + d = 0;
	planeDesc.normal = NxVec3(0, 1, 0);		//面の法線はY軸(↑)方向
	planeDesc.d = 0.0f;								//Y = 0.0fに面を作る

	actorDesc.shapes.pushBack( &planeDesc );	//ActorにPlaneを登録
	
	//NxScene Creates Actor and Returns a Pointer.
	NxActor* pActor = pScene->createActor( actorDesc);
	pActor->userData = NULL;		//PhysX上のActorと(ゲームなどの)データ上のActorを結びつける
	
	//Set the parameters for the Default Material
	//Physicsの"Material"とは目に見える表面材質ではなく,物体の物理学的特徴を表す
	NxMaterial* defaultMaterial = pScene->getMaterialFromIndex( 0 );
	defaultMaterial->setRestitution( 0.3f );			//反発係数
	defaultMaterial->setStaticFriction( 0.5f );		//静止摩擦係数
	defaultMaterial->setDynamicFriction( 0.5f );	//動摩擦係数
}
Beispiel #4
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
PhysicsProcessor::PhysicsProcessor()
{
    NxPhysicsSDKDesc desc;
    NxSDKCreateError errorCode = NXCE_NO_ERROR;

    NxPhysicsSDK* pPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, NULL, desc, &errorCode);
    if( pPhysicsSDK == NULL )
    {
        throw std::exception("Exception: Cannot create PhysX SDK Pointer.");
    }
    this->m_pPhysicsSDK = pPhysicsSDK;

    this->m_pPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.025f);

    NxSceneDesc sceneDesc;
    sceneDesc.gravity = NxVec3(0.0f, -9.81f, 0.0f);

    NxScene* pScene = this->m_pPhysicsSDK->createScene(sceneDesc);
    if( pScene == NULL )
    {
        throw std::exception("Exception: Cannot create PhysX Scene Pointer.");
    }
    this->m_pScene = pScene;

    PhysicsActorFactory* pFactory = &PhysicsActorFactory::instance();

    pFactory->setScene(this->m_pScene);

    NxMaterial * defaultMaterial = this->m_pScene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.0f);
	defaultMaterial->setStaticFriction(0.5f);
	defaultMaterial->setDynamicFriction(0.5f);
}
void InitNx()
{
    // Create the physics SDK
    gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
    if (!gPhysicsSDK)  return;

	// Set the physics parameters
	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

	// Set the debug visualization parameters
	gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
//	gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LOCAL_AXES, 1);

    // Create the scene
    NxSceneDesc sceneDesc;
    sceneDesc.gravity               = gDefaultGravity;
	sceneDesc.simType				= NX_SIMULATION_HW;
    gScene = gPhysicsSDK->createScene(sceneDesc);	
 if(!gScene){ 
		sceneDesc.simType				= NX_SIMULATION_SW; 
		gScene = gPhysicsSDK->createScene(sceneDesc);  
		if(!gScene) return;
	}

	// Create the default material
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);

	// Create the objects in the scene
	CreateGroundPlane();

	capsule1 = CreateCapsule(NxVec3(0,5,0), 1, 0.5, 10);
	capsule1->raiseBodyFlag(NX_BF_KINEMATIC);
	capsule2 = CreateCapsule(NxVec3(0,3,0), 1, 0.5, 10);
//	capsule2->setLinearDamping(0.1);
    capsule2->raiseBodyFlag(NX_BF_DISABLE_GRAVITY);

	NxVec3 globalAnchor = NxVec3(0,5,0);
	NxVec3 globalAxis = NxVec3(0,1,0);
	d6Joint = CreateD6Joint(capsule1, capsule2, globalAnchor, globalAxis);

	gSelectedActor = capsule2;
	gForceStrength = 50000;
	gCameraSpeed = 10;

	// Initialize HUD
	InitializeHUD();
	InitializeSpecialHUD();

	// Get the current time
	getElapsedTime();

	// Start the first frame of the simulation
	if (gScene)  StartPhysics();
}
int plSimulationMgr::GetMaterialIdx(NxScene* scene, float friction, float restitution)
{
    if (friction == 0.5f && restitution == 0.5f)
        return 0;

    // Use the nutty PhysX method to search for a matching material
    #define kNumMatsPerCall 32
    NxMaterial* materials[kNumMatsPerCall];
    NxU32 iterator = 0;
    bool getMore = true;
    while (getMore)
    {
        int numMats = scene->getMaterialArray(materials, kNumMatsPerCall, iterator);

        for (int i = 0; i < numMats; i++)
        {
            if (materials[i]->getDynamicFriction() == friction &&
                materials[i]->getRestitution() == restitution)
            {
                return materials[i]->getMaterialIndex();
            }
        }

        getMore = (numMats == kNumMatsPerCall);
    }

    // Couldn't find the material, so create it
    NxMaterialDesc desc;
    desc.restitution = restitution;
    desc.dynamicFriction = friction;
    desc.staticFriction = friction;
    NxMaterial* mat = scene->createMaterial(desc);
    return mat->getMaterialIndex();
}
Beispiel #7
0
//-------------------------------------------------------------------------------------------------
bool sdPhysicsSystem::LoadScene(sdMap* pkMap)
{
	if (!m_bInitialized || !pkMap)
		return false;

	sdTerrain* pkTerrain = pkMap->GetTerrain();
	NIASSERT(pkTerrain);

	// 创建空白NxScene
	CreateEmptyScene(pkTerrain->GetTerrainSize());
	NIASSERT(m_pkScene);

	float fTimeStep = 1.f / 60.f;
	m_pkScene->setTiming(fTimeStep, 6, NX_TIMESTEP_FIXED);
	m_pkScene->setUserTriggerReport(m_pkUserTriggerReport);

	NxMaterial* pkDefaultMaterial = m_pkScene->getMaterialFromIndex(0);
	NIASSERT(pkDefaultMaterial);
	pkDefaultMaterial->setRestitution(0.1f);
	pkDefaultMaterial->setStaticFriction(0.5f);
	pkDefaultMaterial->setDynamicFriction(0.5f);

	// 加载地形数据到NxScene
	CreateTerrain(pkTerrain);

	// 加载预生成的物件数据到NxScene
	

	// 生成地形的边界
	CreateTerrainBound(pkTerrain);

	return true;
}
Beispiel #8
0
//-----------------------------------------------------------------------------
//  InitScene
//-----------------------------------------------------------------------------
bool    CPhysicScene::InitScene (const TInitInfo& initInfo)
{
    // Create the scene
    m_pScene = CPhysicEngine::Ref().GetNxPhysicsSDK()->createScene (initInfo.nxInfo);
    if ( m_pScene == NULL ) return false;

    // Editar las propiedades del material por defecto
    NxMaterial* defaultMaterial = m_pScene->getMaterialFromIndex(0); 
    defaultMaterial->setRestitution (0.0f);
    defaultMaterial->setStaticFriction (0.5f);
    defaultMaterial->setDynamicFriction (0.4f);

    // CreateBox (NxVec3(0,0,0), NxVec3(10, 10, 10), 1);
    
    // Configuramos callback collisiones
	//!!
    m_pScene->setUserContactReport(this);
	m_pScene->setUserTriggerReport(this);
	m_pCollisionMng = initInfo.pCollisionMng;

    // Inicializar gestor de agua
    CPhysicWaterMgr::TInitInfo  initWaterInfo;
    initWaterInfo.pScene = this;
    initWaterInfo.fWaterLevel = Globals::g_fWaterLevel;
    initWaterInfo.fWaterDensity = 4.f;
    initWaterInfo.fFrictionAngular = 10.f;
    initWaterInfo.fFrictionLinear = 5.f;
    m_WaterMgr.Init( initWaterInfo );

	// Comprobar si debemos activar el gestor de agua
	//!!
	m_bWaterMngEnabled = initInfo.bWaterMngEnabled;

    return true;
}
void InitNx()
{
	// Create a memory allocator
    gAllocator = new UserAllocator;

    // Create the physics SDK
	gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator);
	if (!gPhysicsSDK)  return;

	// Set the physics parameters
	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

	// Set the debug visualization parameters
	gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);
	//gPhysicsSDK->setParameter(NX_VISUALIZE_CLOTH_COLLISIONS, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_CLOTH_SLEEP, 1);

	// Check available hardware
	NxHWVersion hwCheck = gPhysicsSDK->getHWVersion();
	if (hwCheck == NX_HW_VERSION_NONE) 
	{
		gHardwareCloth = false;
	}
	else 
		gHardwareCloth = true;

	// Create the scenes
    NxSceneDesc sceneDesc;
    sceneDesc.gravity = gDefaultGravity;
    sceneDesc.simType = NX_SIMULATION_HW;
    gScene = gPhysicsSDK->createScene(sceneDesc);	
	if(!gScene){ 
		sceneDesc.simType = NX_SIMULATION_SW; 
		gScene = gPhysicsSDK->createScene(sceneDesc);  
		if(!gScene) return;
	}

	// Create the default material
	NxMaterialDesc       m; 
	m.restitution        = 0.5;
	m.staticFriction     = 0.2;
	m.dynamicFriction    = 0.2;
	NxMaterial* mat = gScene->getMaterialFromIndex(0);
	mat->loadFromDesc(m); 

    SetupTearingScene();

	if (gScene->getNbActors() > 0)
		gSelectedActor = *gScene->getActors();
	else
		gSelectedActor = NULL;

	// Initialize HUD
    InitializeHUD();
	InitializeSpecialHUD();
}
void InitNx()
{
	// Create a memory allocator
    gAllocator = new UserAllocator;

    // Create the physics SDK
	gPhysicsSDK = CreatePhysics();

    // Create the scene
    NxSceneDesc sceneDesc;
    sceneDesc.gravity               = gDefaultGravity;
	sceneDesc.simType				= NX_SIMULATION_HW;
    gScene = gPhysicsSDK->createScene(sceneDesc);	
	if(!gScene){ 
		sceneDesc.simType				= NX_SIMULATION_SW; 
		gScene = gPhysicsSDK->createScene(sceneDesc);  
		if(!gScene) return;
	}

	// Create the default material
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);

    // Set Core Dump directory
	char buff[512];
	FindMediaFile(fnameCD, buff);
#ifdef WIN32
	SetCurrentDirectory(buff);
#elif LINUX
	chdir(buff);
#endif

	// Create the objects in the scene
	NxActor* groundPlane = CreateGroundPlane();

	NxActor* box = CreateBox(NxVec3(5,0,0), NxVec3(0.5,1,0.5), 20);
	NxActor* sphere = CreateSphere(NxVec3(0,0,0), 1, 10);
	NxActor* capsule = CreateCapsule(NxVec3(-5,0,0), 2, 0.5, 10);
//	pyramid = CreatePyramid(NxVec3(0,0,0), NxVec3(1,0.5,1.5), 10);

	AddUserDataToActors(gScene);

	gSelectedActor = capsule;
//	gSelectedActor = pyramid;

	// Initialize HUD
	InitializeHUD();

	// Get the current time
	getElapsedTime();

	// Start the first frame of the simulation
	if (gScene)  StartPhysics();
}
NxActor* CreateGroundPlane()
{
    // Create a plane with default descriptor
    NxPlaneShapeDesc planeDesc;
    NxActorDesc actorDesc;
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); 
	planeDesc.materialIndex	= defaultMaterial->getMaterialIndex();
    actorDesc.shapes.pushBack(&planeDesc);
    return gScene->createActor(actorDesc);
}
void InitNx()
{
	// Create a memory allocator
    gAllocator = new UserAllocator;

    // Create the physics SDK
    gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator);
    if (!gPhysicsSDK)  return;

	// Set the physics parameters
	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

	// Set the debug visualization parameters
	gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 2);
	gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1);

    // Create the scene
    NxSceneDesc sceneDesc;
    sceneDesc.gravity               = gDefaultGravity;
    sceneDesc.simType				= NX_SIMULATION_HW;
    gScene = gPhysicsSDK->createScene(sceneDesc);	
 if(!gScene){ 
		sceneDesc.simType				= NX_SIMULATION_SW; 
		gScene = gPhysicsSDK->createScene(sceneDesc);  
		if(!gScene) return;
	}

	// Create the default material
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);

	// Create the objects in the scene
	CreateGroundPlane();

	mainBox = CreateMainObject();

	gSelectedActor = mainBox;
	gCameraPos = NxVec3(0,15,-50);
	gCameraSpeed = 20;
    gForceStrength = 50000000;

	// Initialize HUD
	InitializeHUD();

	// Get the current time
	getElapsedTime();

	// Start the first frame of the simulation
	if (gScene)  StartPhysics();
}
bool CreateScenario()
{
	DestroyScenario();

	// Create the scene
	NxSceneDesc sceneDesc;
	sceneDesc.gravity = gDefaultGravity;
	sceneDesc.simType = bHWScene? NX_SIMULATION_HW : NX_SIMULATION_SW;
	gScene = gPhysicsSDK->createScene(sceneDesc);	
	if(0 == gScene)
	{ 
		bHWScene = !bHWScene;
		sceneDesc.simType = bHWScene? NX_SIMULATION_HW : NX_SIMULATION_SW;
		gScene = gPhysicsSDK->createScene(sceneDesc);  
		if(0 == gScene) return false;
	}

	// Create the default material
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);

	// Create the plane in primary scene
	groundPlane = CreateGroundPlane();

	// Create compartment(HSM, managed hardware scene) attached to this scene
	NxCompartmentDesc desc;
	desc.type = NX_SCT_RIGIDBODY;
	desc.deviceCode = NxU32(NX_DC_PPU_0);
	gCompartmentHW = gScene->createCompartment(desc);

	desc.deviceCode = NxU32(NX_DC_CPU);
	gCompartmentSW = gScene->createCompartment(desc);

	// Create objects
	boxHW = CreateManagedBox(NxVec3(6, 0, 0), NxVec3(0.5, 1, 0.5), 20, gCompartmentHW);
	boxSW = CreateManagedBox(NxVec3(3, 0, 0), NxVec3(0.5, 1, 0.5), 20, gCompartmentSW);
	sphereHW = CreateManagedSphere(NxVec3(-6,0,0), 1, 10, gCompartmentHW);
	sphereHW = CreateManagedSphere(NxVec3(-3,0,0), 1, 10, gCompartmentSW);
	capsule = CreateManagedCapsule(NxVec3(0,0,0), 2, 1, 5, 0);

	gSelectedActor = boxHW;

	// Initialize HUD
	InitializeHUD();

	// Start the first frame of the simulation
	StartPhysics();
	return true;
}
static bool InitNx()
{
	if (!gAllocator)
		gAllocator = new UserAllocator;

	// Initialize PhysicsSDK
	NxPhysicsSDKDesc desc;
	NxSDKCreateError errorCode = NXCE_NO_ERROR;
	gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator, NULL, desc, &errorCode);
	if(gPhysicsSDK == NULL) 
	{
		printf("\nSDK create error (%d - %s).\nUnable to initialize the PhysX SDK, exiting the sample.\n\n", errorCode, getNxSDKCreateError(errorCode));
		return false;
	}
#if SAMPLES_USE_VRD
	// The settings for the VRD host and port are found in SampleCommonCode/SamplesVRDSettings.h
	if (gPhysicsSDK->getFoundationSDK().getRemoteDebugger() && !gPhysicsSDK->getFoundationSDK().getRemoteDebugger()->isConnected())
		gPhysicsSDK->getFoundationSDK().getRemoteDebugger()->connect(SAMPLES_VRD_HOST, SAMPLES_VRD_PORT, SAMPLES_VRD_EVENTMASK);
#endif

	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.025f);

	// Create two scenes
	for(NxU32 i=0;i<2;i++)
	{
		NxSceneDesc sceneDesc;
		sceneDesc.gravity				= gDefaultGravity;

		gScenes[i] = gPhysicsSDK->createScene(sceneDesc);
		if(gScenes[i] == NULL) 
		{
			printf("\nError: Unable to create one of the two PhysX scenes, exiting the sample.\n\n");
			return false;
		}

		// Create ground plane
		NxPlaneShapeDesc PlaneDesc;
		NxActorDesc ActorDesc;
		ActorDesc.shapes.pushBack(&PlaneDesc);
		gScenes[i]->createActor(ActorDesc);

		//materials are no longer shared between scenes so they have to be set up for both:
		NxMaterial * defaultMaterial = gScenes[i]->getMaterialFromIndex(0); 
		defaultMaterial->setRestitution(0.0f);
		defaultMaterial->setStaticFriction(0.5f);
		defaultMaterial->setDynamicFriction(0.5f);
	}
	return true;
}
Beispiel #15
0
Cutter::Cutter(NxVec3 pos, string fname)
{
	m_cutterHeight = 0.0f;
	m_cutterRotateAngle = 0.0f;
	m_cutterON = false;
	m_cutterParams = new CutterParams;
	m_attachedTriPod = NULL;

	CfgLoader cfg(fname, m_cutterParams->getVariableList());

	//D3DXMatrixRotationYawPitchRoll(&dimm->matChassisRotation, rotateChassis.y, rotateChassis.x, rotateChassis.z);

	ObjectParams temp;
	temp.loadFromFile("Objects\\" + m_cutterParams->chassisModel);
	m_objChassis = new Surface(temp.meshName, temp.generateMaterial(), Vec3(0, 0, 0));
	temp.loadFromFile("Objects\\" + m_cutterParams->cutterModel);
	m_objCutter = new Surface(temp.meshName, temp.generateMaterial(), Vec3(0, 0, 0));

	Vec3 min = m_objChassis->boundingBox.Min;
	//min.y -= 1.0f;
	Vec3 max = m_objChassis->boundingBox.Max;
	//max.y += 0.5f;
	m_actionBox = new ActionBox(min, max);

	core.game->getWorld()->addToWorld(m_objChassis, NO_COLLISION, 0, GROUP_NON_COLLIDABLE, NULL, 1);
	core.game->getWorld()->addToWorld(m_objCutter, NO_COLLISION, 0, GROUP_NON_COLLIDABLE, NULL, 1);

	m_cutterParams->dimm = Vec3(m_objChassis->boundingBox.getWidth()/2, m_objChassis->boundingBox.getHeight()/6, m_objChassis->boundingBox.getDepth()/2);

	m_actor = core.dynamics->createBox(pos, NxVec3(m_cutterParams->dimm), m_cutterParams->density);
	SetActorCollisionGroup(m_actor, GROUP_COLLIDABLE_NON_PUSHABLE);
	NxMaterial *anisoMaterial = NULL;
	//if(!anisoMaterial)
	{
		//Create an anisotropic material
		NxMaterialDesc material; 
		//Anisotropic friction material
		material.restitution = 0.01f;
		material.staticFriction = 0.01f;
		material.dynamicFriction = 0.01f;
		material.dynamicFrictionV = 0.1f;
		material.staticFrictionV = 0.1f;
		material.dirOfAnisotropy.set(1,0,0);
		material.flags = NX_MF_ANISOTROPIC;
		anisoMaterial = core.dynamics->getScene()->createMaterial(material);
	}
	m_actor->getShapes()[0]->setMaterial(anisoMaterial->getMaterialIndex());
}
Beispiel #16
0
	bool PhysicsManager::createScene() {
		
		if(!mSDK)
			return false;

		// Create a scene
		NxSceneDesc sceneDesc;
		sceneDesc.setToDefault();
		
		//sceneDesc.timeStepMethod = NX_TIMESTEP_VARIABLE;
		sceneDesc.timeStepMethod = NX_TIMESTEP_FIXED;

		sceneDesc.gravity				= NxVec3(0.0f, -14.1f, 0.0f);

		sceneDesc.simType = NX_SIMULATION_SW;

		mScene = mSDK->createScene(sceneDesc);
		if(mScene == NULL) 
		{
			printf("\nError: Unable to create a PhysX scene, exiting the sample.\n\n");
			return false;
		}

		mScene->setActorGroupPairFlags(0,0,NX_NOTIFY_ON_START_TOUCH|NX_NOTIFY_ON_TOUCH|NX_NOTIFY_ON_END_TOUCH);

		// Set default material
		NxMaterial* defaultMaterial = mScene->getMaterialFromIndex(0);
		defaultMaterial->setRestitution(0.0f);
		defaultMaterial->setStaticFriction(0.5f);
		defaultMaterial->setDynamicFriction(0.5f);

		// Create ground plane
		//NxPlaneShapeDesc planeDesc;
		//NxActorDesc actorDesc;
		//actorDesc.shapes.pushBack(&planeDesc);
		//mScene->createActor(actorDesc);


		mScene->setUserTriggerReport(this);
		mScene->setUserContactReport(this);

		mIsSceneCreated = true;
		mIsRunningSim = true;

		mCurrentTime = 0;

		return true;
	}
		//-----------------------------------------------------------------------
		bool PhysXBridge::initNx(Real gravityY)
		{
			if (!mPhysicsSDK)
			{
				// Initialize PhysicsSDK
				NxPhysicsSDKDesc desc;
				NxSDKCreateError errorCode = NXCE_NO_ERROR;
				mPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, 0, new PhysXLogging(), desc, &errorCode);
				if(!mPhysicsSDK) 
				{
					EXCEPT(Exception::ERR_INTERNAL_ERROR, "PU: Cannot initialise the PhysX SDK.", "PhysXBridge::initNx");
				}

				mPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.05f);
			}

			// Create a scene
			if (!mScene)
			{
				NxSceneDesc sceneDesc;
				sceneDesc.gravity = NxVec3(0.0f, gravityY, 0.0f);
				mScene = mPhysicsSDK->createScene(sceneDesc);
				if(!mScene)
				{
					EXCEPT(Exception::ERR_INTERNAL_ERROR, "PU: Cannot create a PhysX Scene.", "PhysXBridge::initNx");
				}

				// Set the contact report
				mScene->setUserContactReport(&mPhysXContactReport);

				// Set default material
				NxMaterial* defaultMaterial = mScene->getMaterialFromIndex(0);
				defaultMaterial->setRestitution(0.0f);
				defaultMaterial->setStaticFriction(0.5f);
				defaultMaterial->setDynamicFriction(0.5f);

				// Create ground plane
				createPlane();
			}

			// Create a controller
			ControllerManager& controllerManager = ControllerManager::getSingleton(); 
			ControllerValueRealPtr physXBridgeUpdateValue(PU_NEW PhysXBridgeUpdateValue(this));
			mTimeController = controllerManager.createFrameTimePassthroughController(physXBridgeUpdateValue);

			return true;
		}
void InitNx()
{
	// Create a memory allocator
	gAllocator = new UserAllocator;

	// Create the physics SDK
	gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator);
	if (!gPhysicsSDK)  return;

	// Set the physics parameters
	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

	// Set the debug visualization parameters
	gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1);
	//gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	//gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);
	//gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, 1);

	// Create the scene
	NxSceneDesc sceneDesc;
	sceneDesc.simType				= NX_SIMULATION_SW;
	sceneDesc.gravity               = gDefaultGravity;
	gScene = gPhysicsSDK->createScene(sceneDesc);	

	// Create the default material
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);

	groundPlane	= CreateGroundPlane();
	//groundPlane->getShapes()[0]->setFlag(NX_SF_FLUID_DRAIN,true);

	// Create drain actors
	CreateDrainActors();

	fluidEmitter = CreateFluidEmitter(0.35, 0.35);

	// Initialize HUD
	InitializeHUD();

	// Get the current time
	getElapsedTime();

	// Start the first frame of the simulation
	if (gScene)  StartPhysics();
}
Beispiel #19
0
bool InitNx()
{
	// Initialize PhysicsSDK
	NxPhysicsSDKDesc desc;
	gMyPhysX.initPhysX(desc);

	if(isPhysXHardwarePresent())
		printf("PhysX Hardware is available in your system!\n");
	// Create a scene
	NxSceneDesc sceneDesc;
	sceneDesc.gravity				= gDefaultGravity;

	gMyPhysX.createDefaultScene(sceneDesc);

	// Create ground plane
	NxPlaneShapeDesc PlaneDesc;
	PlaneDesc.group = 2;
	NxActorDesc ActorDesc;
	ActorDesc.shapes.pushBack(&PlaneDesc);
	gMyPhysX.getScene()->createActor(ActorDesc);

	NxMaterial * defaultMaterial = gMyPhysX.getScene()->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.0f);
	defaultMaterial->setStaticFriction(0.5f);
	defaultMaterial->setDynamicFriction(0.5f);

	// Create trigger

	NxVec3 zeroV(0,0,0);

	CreateTrigger(NxVec3(0,10,0), 10);
	CreateTrigger(NxVec3(-40,10,0), 10, &zeroV, false);
	CreateCube(NxVec3(-40,10,40), 10, NULL, false, true);
	CreateCube(NxVec3(-40,10,80), 10, NULL, true, false);

	//This creates a kinematic actor with a trigger, note that kinematic
	//triggers get interactions with static objects, thus this trigger
	//(which is placed directly above the ground) will directly get an
	//enter event for the ground plane (and change it's color). 
	CreateTrigger(NxVec3(40,10,0), 10, NULL, true);
	//You can try to move it up just a little bit, and you will see 
	//that it will no longer intersect the ground plane.
	//CreateTrigger(NxVec3(40,11,0), 10, NULL, true);

	return true;
}
Beispiel #20
0
//
//	ESciVis::InitPhysX
//
void ESciVis::InitPhysX( void )
{
	LOG_INIT("PhysX");
	
	// Create the physics SDK
    nx = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
    if (!nx)  return;

	// Set the physics parameters
	nx->setParameter(NX_SKIN_WIDTH, 0.01f);

	// Set the debug visualization parameters
	nx->setParameter(NX_VISUALIZATION_SCALE, 1);
	nx->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	nx->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);

    // Create the scene
    NxSceneDesc sceneDesc;
    sceneDesc.gravity               = NxVec3(0,0,0);
	sceneDesc.simType				= NX_SIMULATION_SW;
    nx_scene = nx->createScene(sceneDesc);	
	
	if(!nx_scene) { 
		sceneDesc.simType				= NX_SIMULATION_SW; 
		nx_scene = nx->createScene(sceneDesc);  
		if(!nx_scene) return;
	}
	
	//	coocking lib :
	nx_cook	=	NxGetCookingLib(NX_PHYSICS_SDK_VERSION);
	if (!nx_cook) {
		RUNTIME_ERROR("NxGetCookingLib() failed");
	}
	nx_cook->NxInitCooking();
	

	// Create the default material
	NxMaterial* defaultMaterial = nx_scene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);
}
Beispiel #21
0
bool GraphicsClass::InitializePhysX(NxScene* scene)
{
	n_scene = scene;
	
	// plane
	NxPlaneShapeDesc plane_desc;
	plane_desc.normal = NxVec3(0,1,0);
	plane_desc.d = 0.0f;

	NxMaterial* defaultMaterial = n_scene->getMaterialFromIndex(0);
	defaultMaterial->setRestitution(0.0f);
	defaultMaterial->setStaticFriction(0.5f);
	defaultMaterial->setDynamicFriction(0.5f);
	
	NxActorDesc plane_actor;
	plane_actor.shapes.pushBack(&plane_desc);
	n_scene->createActor(plane_actor);

	return true;
}
Beispiel #22
0
void PhysScene::create(const Desc& desc) {
	Scene::create(desc);

	{
		// Access to PhysX requires CS, despite the object is not activated yet
		CriticalSectionWrapper csw(universe->getCS());

		pNxPhysicsSDK = universe->pNxPhysicsSDK;

		pNxScene = pNxPhysicsSDK->createScene(desc.physics.nxSceneDesc);
		if (pNxScene == NULL)
			throw MsgPhysSceneNxSceneCreate(Message::LEVEL_CRIT, "PhysScene::create(): Unable to create NxScene");

		// Set simulation parameters
		pNxScene->setTiming((NxReal)universe->maxTimeStep);

		NxMaterial* defaultMaterial = pNxScene->getMaterialFromIndex(0);
		defaultMaterial->setRestitution((NxReal)desc.physics.restitution);
		defaultMaterial->setStaticFriction((NxReal)desc.physics.staticFriction);
		defaultMaterial->setDynamicFriction((NxReal)desc.physics.dynamicFriction);
	}
}
Beispiel #23
0
bool PhysX::InitNx()
{

	// Initialize PhysicsSDK
	NxPhysicsSDKDesc desc;
	NxSDKCreateError errorCode = NXCE_NO_ERROR;
	m_pPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, NULL, desc, &errorCode);
	if(m_pPhysicsSDK == NULL) 
	{
		printf("Unable to initialize the PhysX SDK, exiting the sample.\n");
		return false;
	}

	m_pPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.03f);

	// Create a scene
	NxSceneDesc sceneDesc;
	sceneDesc.gravity				= NxVec3(0.0f, -9.81f, 0.0f);
	m_pScene = m_pPhysicsSDK->createScene(sceneDesc);
	if(m_pScene == NULL) 
	{
		printf("Unable to create a PhysX scene, exiting the sample.\n");
		return false;
	}

	// Set default material
	NxMaterial* defaultMaterial = m_pScene->getMaterialFromIndex(0);
	defaultMaterial->setRestitution(0.0f);
	defaultMaterial->setStaticFriction(0.5f);
	defaultMaterial->setDynamicFriction(0.5f);

	// Create ground plane
	NxPlaneShapeDesc planeDesc;
	NxActorDesc actorDesc;
	actorDesc.shapes.pushBack(&planeDesc);
	m_pScene->createActor(actorDesc);

	return true;
}
Beispiel #24
0
bool InitNx()
{
	// Initialize PhysicsSDK
	NxPhysicsSDKDesc desc;
	NxSDKCreateError errorCode = NXCE_NO_ERROR;
	gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, 0, 0, desc, &errorCode);
	if(gPhysicsSDK == NULL) 
	{
		printf("\nSDK create error (%d - %s).\nUnable to initialize the PhysX SDK, exiting the sample.\n\n", errorCode, getNxSDKCreateError(errorCode));
		return false;
	}

	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, gSkinWidth);
	gPhysicsSDK->setParameter(NX_DEFAULT_SLEEP_ENERGY, 0.01f);

	// Create a scene
	NxSceneDesc sceneDesc;
	sceneDesc.gravity				= NxVec3(0.0f, -9.81f, 0.0f);
	sceneDesc.userNotify = &g_SleepCallBack; //用户自定义事件
	sceneDesc.userContactReport		= &gMyContactReport;
	gScene = gPhysicsSDK->createScene(sceneDesc);
	if(gScene == NULL) 
	{
		printf("\nError: Unable to create a PhysX scene, exiting the sample.\n\n");
		return false;
	}
	gScene->setTiming();
	// Set default material
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0);
	defaultMaterial->setRestitution(0.0f);
	defaultMaterial->setStaticFriction(0.5f);
	defaultMaterial->setDynamicFriction(0.5f);

	CreatePhysicsTerrain();
	return true;
}
Beispiel #25
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 #26
0
void Vehicle::loadScene(const std::string &fileName)
{

	//车的父节点
	mBaseCarNode			= mSceneMgr->getRootSceneNode()->createChildSceneNode(fileName + "BaseCarNode");

	//DotSceneLoader* dsl = new DotSceneLoader();//rel
	//dsl->parseDotScene(fileName + ".scene", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mSceneMgr, mBaseCarNode);

	mVehicleRenderable = new VehicleRenderable(mSceneMgr, mBaseCarNode);
	mVehicleRenderable->load(fileName + ".vrf");

	//车身节点
	mBodyNode				= static_cast<Ogre::SceneNode*>(mBaseCarNode->getChild(fileName + "Body"));

	//轮子节点
	mWheels[TOP_LEFT].mSceneNode	= static_cast<Ogre::SceneNode*>(mBaseCarNode->getChild(fileName + "LTWheel"));
	mWheels[TOP_LEFT].mName			= fileName + "LTWheel";

	mWheels[TOP_RIGHT].mSceneNode	= static_cast<Ogre::SceneNode*>(mBaseCarNode->getChild(fileName + "RTWheel"));
	mWheels[TOP_RIGHT].mName		= fileName + "RTWheel";

	mWheels[Bottom_LEFT].mSceneNode	= static_cast<Ogre::SceneNode*>(mBaseCarNode->getChild(fileName + "LBWheel"));
	mWheels[Bottom_LEFT].mName		= fileName + "LBWheel";

	mWheels[Bottom_RIGHT].mSceneNode  = static_cast<Ogre::SceneNode*> (mBaseCarNode->getChild(fileName + "RBWheel"));
	mWheels[Bottom_RIGHT].mName		  = fileName + "RBWheel";

	//设置整体参数
	NxBodyDesc bodyDes;
	//bodyDes.wakeUpCounter	= 1E8;
	bodyDes.mass			= 12000;//mVehicleInfo.gMass;
	//bodyDes.massLocalPose.t	= NxVec3(mVehicleInfo.gMassLocalPose.x, mVehicleInfo.gMassLocalPose.y, mVehicleInfo.gMassLocalPose.z);

	bodyDes.angularDamping	= 0.03f;
	bodyDes.linearDamping	= 0.08f;

	//写入车身的shapeDesc
	mBoundingBox		= mBodyNode->getAttachedObject(0)->getBoundingBox();
	NxBoxShapeDesc boxDes;
	NxVec3 dimen		(mBoundingBox.getHalfSize().x, mBoundingBox.getHalfSize().y, mBoundingBox.getHalfSize().z);
	NxVec3 localPos		(mBodyNode->getPosition().x, mBodyNode->getPosition().y, mBodyNode->getPosition().z);

	////车身到轮子的距离
	//NxReal d1 = NxMath::abs(mBodyNode->getPosition().y - mWheels[0].mSceneNode->getPosition().y);
	////包围盒半径之和
	//NxReal d2 = mBoundingBox.getHalfSize().y + mWheels[0].mSceneNode->getAttachedObject(0)->getBoundingBox().getHalfSize().y;
	////判断轮子是否与车身的包围盒重叠
	//if(d1 < d2)
	//{
	//	//设置为最大适合高度
	//	dimen.y = (mBoundingBox.getSize().y - (d2 - d1)) / 2.0f;
	//}
	boxDes.dimensions.set(dimen);
	boxDes.localPose.t	= localPos;

	NxActorDesc actorDesc;
	actorDesc.body			= &bodyDes;
	actorDesc.globalPose.t	= NxVec3(mOriginalPos.x, mOriginalPos.y, mOriginalPos.z);
	NxQuat quat;
	quat.setWXYZ(mOriginalQuat.w, mOriginalQuat.x, mOriginalQuat.y, mOriginalQuat.z);
	actorDesc.globalPose.M.fromQuat(quat);
	actorDesc.shapes.pushBack(&boxDes);
	mActor		= mNxScene->createActor(actorDesc);
	mActor->setCMassOffsetLocalPosition(NxVec3(0, -mBoundingBox.getSize().y, 0));
	mBodyShape  = static_cast<NxBoxShape*>(mActor->getShapes()[0]);

	//写入轮子的shapeDesc

	createWheelShapeDesc(&mWheels[TOP_LEFT], true);
	createWheelShapeDesc(&mWheels[TOP_RIGHT], true);
	createWheelShapeDesc(&mWheels[Bottom_LEFT], false);
	createWheelShapeDesc(&mWheels[Bottom_RIGHT], false);

	//mWheels[TOP_LEFT].mWheelDesc.localPose.t = NxVec3(mBoundingBox.getHalfSize().x, 2, 0);
	//mWheels[TOP_RIGHT].mWheelDesc.localPose.t = NxVec3(-mBoundingBox.getHalfSize().x, 2, 0);
	//mWheels[Bottom_LEFT].mWheelDesc.localPose.t = NxVec3(mBoundingBox.getHalfSize().x, -mBoundingBox.getHalfSize().y, 0);
	//mWheels[Bottom_RIGHT].mWheelDesc.localPose.t = NxVec3(-mBoundingBox.getHalfSize().x, -mBoundingBox.getHalfSize().y, 0);

	//创建轮子
	mWheels[TOP_LEFT].mWheel = static_cast<NxWheelShape*>(mActor->createShape(mWheels[TOP_LEFT].mWheelDesc));
	mWheels[TOP_RIGHT].mWheel = static_cast<NxWheelShape*>(mActor->createShape(mWheels[TOP_RIGHT].mWheelDesc));
	mWheels[Bottom_LEFT].mWheel	= static_cast<NxWheelShape*>(mActor->createShape(mWheels[Bottom_LEFT].mWheelDesc));
	mWheels[Bottom_RIGHT].mWheel = static_cast<NxWheelShape*>(mActor->createShape(mWheels[Bottom_RIGHT].mWheelDesc));

	NxMaterial* mat = mNxScene->getMaterialFromIndex(0);
	mat->setFrictionCombineMode(NX_CM_MULTIPLY);
	mat->setStaticFriction(300.2f);
	mat->setDynamicFriction(100.5f);
}
Beispiel #27
0
int DXApp::run(HINSTANCE hInst, HWND hWnd)
{
    MSG msg;
    HACCEL hAccelTable;
    hAccelTable = LoadAccelerators(hInst, (LPCTSTR)IDC_TESTDXPROJ);
    QueryPerformanceFrequency((LARGE_INTEGER*)&Frequency);


    if(!_p_physdk) return -1;

    NxSceneDesc sceneDesc;
    sceneDesc.gravity.set(0, -9800.f, 0);
    sceneDesc.collisionDetection = true;
    sceneDesc.groundPlane = true;
    _p_scene = _p_physdk->createScene(sceneDesc);
    if(!_p_scene) return -2;

    _time_step = 1.0f/400.0f;
    _p_scene->setTiming(_time_step);

    NxMaterialDesc ParticleMaterialDesc;
    ParticleMaterialDesc.restitution = 0.80f;
    //ParticleMaterialDesc.spinFriction = 0.2f;
    ParticleMaterialDesc.staticFriction = 0.8f;
    ParticleMaterialDesc.dynamicFriction = 0.5f;
    NxMaterial* ParticleMaterial = _p_scene->createMaterial(ParticleMaterialDesc);
    _particle_material = ParticleMaterial->getMaterialIndex();


    D3DPRESENT_PARAMETERS D3DParams;
    D3DParams.Windowed = true;
    D3DParams.BackBufferWidth = width;
    D3DParams.BackBufferHeight = height;
    D3DParams.MultiSampleType = D3DMULTISAMPLE_NONE;
    D3DParams.MultiSampleQuality = 0;
    D3DParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
    D3DParams.Flags = 0;
    D3DParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    D3DParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
    D3DParams.BackBufferFormat = D3DFMT_UNKNOWN;
    D3DParams.BackBufferCount = 3;
    D3DParams.hDeviceWindow = hWnd;
    D3DParams.EnableAutoDepthStencil = true;
    D3DParams.AutoDepthStencilFormat = D3DFMT_D16;

    if(FAILED(_p_D3D->CreateDevice( D3DADAPTER_DEFAULT,
                                    D3DDEVTYPE_HAL,
                                    hWnd,
                                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                    &D3DParams,
                                    &_p_device)))
    {
        return -3;
    }

    D3DXCreateFont(_p_device, 12, 0, FW_NORMAL, 1, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Arial", &FPSFont);

    _p_device->SetFVF(particle_fvf);
    if(FAILED(D3DXCompileShaderFromFile(
                  strPixelShader,
                  NULL,
                  NULL,
                  "ps_main",
                  "ps_2_0",
                  0,
                  &_p_code,
                  NULL,
                  &_p_constant_able )))
    {
        MessageBox(hWnd, "Error compiling Script", "Pixel Shader Compile Error", MB_ICONERROR);
        return 1;
    }

    _p_device->CreatePixelShader((DWORD*)_p_code->GetBufferPointer(), &_p_shader);
    _p_code->Release();
    _p_code = NULL;

    //SHADOW Buffer Pixel Shaders
    if(FAILED(D3DXCompileShaderFromFile(
                  strShadowPS,
                  NULL,
                  NULL,
                  "ps_main",
                  "ps_2_0",
                  0,
                  &_p_code,
                  NULL,
                  &_p_SB_constant_able )))
    {
        MessageBox(hWnd, "Error compiling Script", "Pixel Shader Compile Error", MB_ICONERROR);
        return 1;
    }

    _p_device->CreatePixelShader((DWORD*)_p_code->GetBufferPointer(), &_p_SB_shader);
    _p_code->Release();
    _p_code = NULL;

    //SHADOW Buffer Vertex Shaders
    if(FAILED(D3DXCompileShaderFromFile(
                  strShadowVS,
                  NULL,
                  NULL,
                  "vs_main",
                  "vs_2_0",
                  0,
                  &_p_code,
                  NULL,
                  &_p_SB_vertex_constant_able )))
    {
        MessageBox(hWnd, "Error compiling Script", "Vertex Shader Compile Error", MB_ICONERROR);
        return 1;
    }

    _p_device->CreateVertexShader((DWORD*)_p_code->GetBufferPointer(), &_p_SB_vshader);
    _p_code->Release();
    _p_code = NULL;

    if(FAILED(D3DXCompileShaderFromFile(
                  strCombinerShader,
                  NULL,
                  NULL,
                  "ps_main",
                  "ps_2_b",
                  0,
                  &_p_code,
                  NULL,
                  &_p_constant_able )))
    {
        MessageBox(hWnd, "Error compiling Script", "Pixel Shader Compile Error", MB_ICONERROR);
        return 1;
    }

    _p_device->CreatePixelShader((DWORD*)_p_code->GetBufferPointer(), &_p_combinershader);
    _p_code->Release();
    _p_code = NULL;

    if(FAILED(D3DXCompileShaderFromFile(
                  strScreenAlignShader,
                  NULL,
                  NULL,
                  "vs_main",
                  "vs_2_0",
                  0,
                  &_p_code,
                  NULL,
                  &_p_constant_able )))
    {
        MessageBox(hWnd, "Error compiling Script", "Vertex Shader Compile Error", MB_ICONERROR);
        return 1;
    }

    _p_device->CreateVertexShader((DWORD*)_p_code->GetBufferPointer(), &_p_alignshader);
    _p_code->Release();
    _p_code = NULL;

    _p_device->SetFVF(light_fvf);
    if(FAILED(D3DXCompileShaderFromFile(
                  strLightShader,
                  NULL,
                  NULL,
                  "ps_main",
                  "ps_2_0",
                  0,
                  &_p_code,
                  NULL,
                  &_p_constant_able )))
    {
        MessageBox(hWnd, "Error compiling Script", "Pixel Shader Compile Error", MB_ICONERROR);
        return 1;
    }

    _p_device->CreatePixelShader((DWORD*)_p_code->GetBufferPointer(), &_p_lightshader);
    _p_code->Release();
    _p_code = NULL;

    _p_device->SetFVF(particle_fvf);
    if(FAILED(D3DXCompileShaderFromFile(
                  strVertexShader,
                  NULL,
                  NULL,
                  "vs_main",
                  "vs_2_0",
                  0,
                  &_p_code,
                  NULL,
                  &_p_vertex_constant_able )))
    {
        MessageBox(hWnd, "Error compiling Script", "Vertex Shader Compile Error", MB_ICONERROR);
        return 1;
    }

    _p_device->CreateVertexShader((DWORD*)_p_code->GetBufferPointer(), &_p_vshader);
    _p_code->Release();
    _p_code = NULL;

    hMatProjection = _p_vertex_constant_able->GetConstantByName(NULL, strMatProjection);
    hMatView = _p_vertex_constant_able->GetConstantByName(NULL, strMatView);
    hMatTexture = _p_vertex_constant_able->GetConstantByName(NULL, strMatTexture);
    hMatWorld = _p_vertex_constant_able->GetConstantByName(NULL, strMatWorld);
    hLightPosition = _p_vertex_constant_able->GetConstantByName(NULL, strLightPosition);
    hDeltaPos = _p_vertex_constant_able->GetConstantByName(NULL, strDeltaPos);
    hSBMatProjection = _p_SB_vertex_constant_able->GetConstantByName(NULL, strMatProjection);
    hSBMatWorld = _p_SB_vertex_constant_able->GetConstantByName(NULL, strMatWorld);

    //Setup our particle mesh.
    {
        LPD3DXMESH _tmp_mesh;
        if(FAILED(D3DXLoadMeshFromX(strCubeMesh, D3DXMESH_VB_MANAGED, _p_device, NULL, NULL, NULL, NULL, &_tmp_mesh)))
        {
            MessageBox(hWnd, "Error Loading Cube Model", "Mesh Load Error", MB_ICONERROR);
            return 1;
        }
        _tmp_mesh->CloneMeshFVF(D3DXMESH_VB_MANAGED, particle_fvf, _p_device, &_particle_Mesh);
        _tmp_mesh->Release();
    }

    // We now have _p_physdk, _p_scene, _p_D3D, _p_device initialized

    // Setup the Camera
    CameraAngleX = (D3DX_PI/4)*3;
    CameraAngleY = 0;

    // Light Setup
    DrawLight.location = NxVec3(500, 500, 50);
    DrawLight.point_size = _particle_size;
    DrawLight.diffuse = (((_particle_color & 0xFF000000)>>24))<<24
                        | (((_particle_color & 0x00FF0000)>>16))<<16
                        | (((_particle_color & 0x0000FF00)>>8))<<8
                        | ((_particle_color & 0x000000FF));

    D3DCAPS9 DevCaps;
    _p_device->GetDeviceCaps(&DevCaps);
    if(FAILED(_p_device->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &_screen_buffer, NULL)))
    {
        MessageBox(hWnd, "Error Creating Texture", "Texture Error", MB_ICONERROR);
        return 1;
    }

    if(DevCaps.NumSimultaneousRTs > 1)
    {
        bMotionBlur = true;
        if(FAILED(_p_device->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &_blur_buffer, NULL)))
        {
            MessageBox(hWnd, "Error Creating BLUR Texture", "Texture Error", MB_ICONERROR);
            return 1;
        }
        if(FAILED(_p_device->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &_old_blur_buffer, NULL)))
        {
            MessageBox(hWnd, "Error Creating BLUR Texture", "Texture Error", MB_ICONERROR);
            return 1;
        }
        //_p_device->CreateRenderTarget(width, height, D3DFMT_D32, D3DMULTISAMPLE_NONE , 0, false, &_blur_buffer, NULL);
    }
    else
        bMotionBlur = false;


    if(FAILED(_p_device->CreateTexture(ShadowMapSize, ShadowMapSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R32F, D3DPOOL_DEFAULT, &ShadowBuffer, NULL)))
    {
        MessageBox(hWnd, "Error Creating Shadow Buffer", "Texture Error", MB_ICONERROR);
        return 1;
    }


    while(loop_continue)
    {
        Frame();
        if(PeekMessage(&msg, NULL, 0, 0, 1))
        {
            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    }

    return (int) msg.wParam;
}
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 #29
0
void plPXPhysical::Write(hsStream* stream, hsResMgr* mgr)
{
    plPhysical::Write(stream, mgr);

    hsAssert(fActor, "nil actor");  
    hsAssert(fActor->getNbShapes() == 1, "Can only write actors with one shape. Writing first only.");
    NxShape* shape = fActor->getShapes()[0];

    NxMaterialIndex matIdx = shape->getMaterial();
    NxScene* scene = plSimulationMgr::GetInstance()->GetScene(fWorldKey);
    NxMaterial* mat = scene->getMaterialFromIndex(matIdx);
    float friction = mat->getStaticFriction();
    float restitution = mat->getRestitution();

    stream->WriteLEScalar(fActor->getMass());
    stream->WriteLEScalar(friction);
    stream->WriteLEScalar(restitution);
    stream->WriteByte(fBoundsType);
    stream->WriteByte(fGroup);
    stream->WriteLE32(fReportsOn);
    stream->WriteLE16(fLOSDBs);
    mgr->WriteKey(stream, fObjectKey);
    mgr->WriteKey(stream, fSceneNode);
    mgr->WriteKey(stream, fWorldKey);
    mgr->WriteKey(stream, fSndGroup);

    hsPoint3 pos;
    hsQuat rot;
    IGetPositionSim(pos);
    IGetRotationSim(rot);
    pos.Write(stream);
    rot.Write(stream);

    fProps.Write(stream);

    if (fBoundsType == plSimDefs::kSphereBounds)
    {
        const NxSphereShape* sphereShape = shape->isSphere();
        stream->WriteLEScalar(sphereShape->getRadius());
        hsPoint3 localPos = plPXConvert::Point(sphereShape->getLocalPosition());
        localPos.Write(stream);
    }
    else if (fBoundsType == plSimDefs::kBoxBounds)
    {
        const NxBoxShape* boxShape = shape->isBox();
        hsPoint3 dim = plPXConvert::Point(boxShape->getDimensions());
        dim.Write(stream);
        hsPoint3 localPos = plPXConvert::Point(boxShape->getLocalPosition());
        localPos.Write(stream);
    }
    else
    {
        if (fBoundsType == plSimDefs::kHullBounds)
            hsAssert(shape->isConvexMesh(), "Hull shape isn't a convex mesh");
        else
            hsAssert(shape->isTriangleMesh(), "Exact shape isn't a trimesh");

        // We hide the stream we used to create this mesh away in the shape user data.
        // Pull it out and write it to disk.
        hsVectorStream* vecStream = (hsVectorStream*)shape->userData;
        stream->Write(vecStream->GetEOF(), vecStream->GetData());
        delete vecStream;
    }
}
Beispiel #30
0
	Data(bool useHardware, bool useHardwareOnly, bool useMultithreading, PhysicsParams *params)
	:	sdk(0),
		scene(0),
		crashed(false),

		statsNumActors(0),
		statsNumDynamicActors(0),
		statsNumDynamicActorsInAwakeGroups(0),
		statsMaxDynamicActorsInAwakeGroups(0),
		statsSimulationTime(0),
		statsSimulationWaitTime(0),
		statsSimulationStartWaitTime(0),
		startSimulationTime(0),

		statsContacts(0),
		ccd(false),
		ccdMaxThickness(0.5f),

		runningInHardware(false),
		physicslib_fluid_containment_actor(0),
		physicslib_fluid_containment_shape(0),
		physicslib_fluid_containment_sphere_actor(0),
		physicslib_fluid_containment_sphere_shape(0)
	{
		if (params == NULL)
		{
			params = &physics_defaultParams;
			::Logger::getInstance()->debug("PhysicsLib - No physics params given, using defaults.");
		}

		if (params->scriptRunner == NULL)
		{
			::Logger::getInstance()->warning("PhysicsLib - No script runner given, collision groups, etc. will be initialized to default values.");
		}

		NxPhysicsSDKDesc sdkDesc;
		if(!useHardware)
			sdkDesc.flags |= NX_SDKF_NO_HARDWARE;

		sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, 0, getLogger(), sdkDesc);
		//sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);

		// HACK: ...
		physxSDK = sdk;

		if(sdk)
		{
			if(sdk->getHWVersion() == NX_HW_VERSION_NONE)
				useHardware = false;

			if (params->ccd)
			{
				sdk->setParameter(NX_CONTINUOUS_CD, true);
				sdk->setParameter(NX_CCD_EPSILON, 0.001f);
			}
			this->ccd = params->ccd;
			this->ccdMaxThickness = params->ccdMaxThickness;

			NxSceneDesc sceneDesc;
			sceneDesc.gravity = NxVec3(params->gravity.x, params->gravity.y, params->gravity.z);	
			sceneDesc.userContactReport = &contactReport;
			//sceneDesc.userNotify = &userNotify;

			if(useHardware)
			{
				sceneDesc.simType = NX_SIMULATION_HW;
				if (useHardwareOnly)
				{
					sceneDesc.flags |= NX_SF_RESTRICTED_SCENE;
				}
			}
			else
			{
				sceneDesc.simType = NX_SIMULATION_SW;
			}

			if (!useMultithreading)
			{
				// Disable threading
				sceneDesc.flags = 0;
			}

			runningInHardware = useHardware;

			sceneDesc.flags |= NX_SF_ENABLE_ACTIVETRANSFORMS;
			scene = sdk->createScene(sceneDesc);
			if(scene)
			{
				NxMaterial *defaultMaterial = scene->getMaterialFromIndex(0);
				defaultMaterial->setStaticFriction(params->defaultStaticFriction);
				defaultMaterial->setDynamicFriction(params->defaultDynamicFriction);
				defaultMaterial->setRestitution(params->defaultRestitution);

#ifdef PROJECT_CLAW_PROTO
				// Create material for cops (larger friction, no restitution)
				NxMaterialDesc materialDesc;
				materialDesc.restitution = 0.0f;   
				materialDesc.restitutionCombineMode = NX_CM_MIN;
				materialDesc.staticFriction = 10.0f;
				materialDesc.dynamicFriction = 10.0f;
				unitMaterial = scene->createMaterial(materialDesc);
#endif

				sdk->setParameter(NX_VISUALIZATION_SCALE, 1.f);

#ifndef PROJECT_SHADOWGROUNDS
				sdk->setParameter(NX_SKIN_WIDTH, 0.01f);
#endif

				// NEW: the new scriptable collision/contact group initialization
				int contactFlags1 = NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_TOUCH | NX_NOTIFY_FORCES;
#ifdef PHYSICS_FEEDBACK
				int contactFlags2 = NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_TOUCH | NX_NOTIFY_FORCES;
#else
				int contactFlags2 = NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_FORCES;
#endif
				if (params->scriptRunner != NULL)
				{
					bool ok = params->scriptRunner->runPhysicsLibScript("physics_init", "set_contacts");
					if (!ok)
						::Logger::getInstance()->error("PhysicsLib - Failed to run physics_init:set_contacts script (script/sub may not be loaded or did not return expected value).");
				}

				for (int i = 0; i < PHYSICS_MAX_COLLISIONGROUPS; i++)
				{
					for (int j = 0; j < PHYSICS_MAX_COLLISIONGROUPS; j++)
					{
						if (physicslib_group_cont[i][j] != physicslib_group_cont[j][i])
						{
							::Logger::getInstance()->error("PhysicsLib - Improperly mirrored physics contacts data (group1 -> group2 does not have same flag as group2 -> group1).");
							::Logger::getInstance()->debug("contacts data group numbers follow:");
							::Logger::getInstance()->debug(int2str(i));
							::Logger::getInstance()->debug(int2str(j));
						}
						if (physicslib_group_cont[i][j] == PHYSICSLIB_GROUP_CONTACT_FLAGS1)
							scene->setActorGroupPairFlags(i, j, contactFlags1);
						else if (physicslib_group_cont[i][j] == PHYSICSLIB_GROUP_CONTACT_FLAGS2)
							scene->setActorGroupPairFlags(i, j, contactFlags2);
					}
				}

				if (params->scriptRunner != NULL)
				{
					bool ok = params->scriptRunner->runPhysicsLibScript("physics_init", "set_collisions");
					if (!ok)
						::Logger::getInstance()->error("PhysicsLib - Failed to run physics_init:set_collision script (script/sub may not be loaded or did not return expected value).");
				}

				for (int i = 0; i < PHYSICS_MAX_COLLISIONGROUPS; i++)
				{
					for (int j = 0; j < PHYSICS_MAX_COLLISIONGROUPS; j++)
					{
						if (physicslib_group_coll[i][j] != physicslib_group_coll[j][i])
						{
							::Logger::getInstance()->error("PhysicsLib - Improperly mirrored physics collision data (group1 -> group2 does not have same flag as group2 -> group1).");
							::Logger::getInstance()->debug("collision data group numbers follow:");
							::Logger::getInstance()->debug(int2str(i));
							::Logger::getInstance()->debug(int2str(j));
						}
						scene->setGroupCollisionFlag(i, j, physicslib_group_coll[i][j]);
					}
				}

// OLD SCHEISSE...
/*
				// Contact groups
				{
					int contactFlags1 = NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_TOUCH | NX_NOTIFY_FORCES;
#ifdef PHYSICS_FEEDBACK
					int contactFlags2 = NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_TOUCH | NX_NOTIFY_FORCES;
#else
					int contactFlags2 = NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_FORCES;
#endif
					//int contactFlags3 = NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_FORCES;

					scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_STATIC, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, contactFlags2);
					scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_STATIC, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, contactFlags2);
					scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_STATIC, PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, contactFlags1);
					scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, contactFlags2);
					scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, contactFlags2);
					//scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, contactFlags2);
scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, contactFlags1);
					scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, PHYSICS_COLLISIONGROUP_UNITS, contactFlags2);
scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_STATIC, PHYSICS_COLLISIONGROUP_UNITS, contactFlags2);
scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_CLAW, PHYSICS_COLLISIONGROUP_STATIC, contactFlags1);
					//scene->setActorGroupPairFlags(PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, PHYSICS_COLLISIONGROUP_UNITS, contactFlags3);
				}

				// Collision groups
				{
					// claw
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_CLAW, PHYSICS_COLLISIONGROUP_CLAW, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_CLAW, PHYSICS_COLLISIONGROUP_NOCOLLISION, false);
scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_CLAW, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_CLAW, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_CLAW, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_CLAW, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_CLAW, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_CLAW, PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, false);

					// Model particles
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, false);

					// Doors
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_DOORS, PHYSICS_COLLISIONGROUP_DOORS, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_DOORS, PHYSICS_COLLISIONGROUP_STATIC, false);

					// Units and model particles
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_UNITS, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_UNITS, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, false);

					// Fluids
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUIDS, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUIDS, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUIDS, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUIDS, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, false);

					// Fluids w/ detailed collision
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUIDS_DETAILED, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUIDS_DETAILED, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUIDS_DETAILED, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUIDS_DETAILED, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, false);

					// Fluid containment
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_STATIC, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_UNITS, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_DOORS, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, PHYSICS_COLLISIONGROUP_FLUIDS_DETAILED, false);

					// No collision
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_STATIC, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_WO_UNIT_COLL_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_MODEL_PARTICLES_NO_SOUND, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_UNITS, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_DOORS, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_DYNAMIC_TERRAINOBJECTS, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_FLUID_CONTAINMENT_PLANES, false);
					scene->setGroupCollisionFlag(PHYSICS_COLLISIONGROUP_NOCOLLISION, PHYSICS_COLLISIONGROUP_NOCOLLISION, false);
				}
*/
			}
		}
	}