Esempio n. 1
0
		/**
		 * Method is used to add heightfield actor to physics scene.
		 * @param	entity is actor logic object.
		 * @param	heightData is terrain height map data.
		 * @param	params is terrain parameters: heightmap size, row/column scale, max. height.
		 * @param	filterGroup is actor own id.
		 * @param	filterMask is mask to filter pairs that trigger a contact callback.
		 */
		void PhysicsManager::addHeightFieldActor(SceneEntity* entity, unsigned char* heightData, const Vector4D& params, PxU32 filterGroup, PxU32 filterMask)
		{
			int terrainSize = static_cast<int>(params.x());

			PxHeightFieldSample* samples = new PxHeightFieldSample[terrainSize*terrainSize];
			PxHeightFieldDesc descriptor;
			descriptor.nbColumns = static_cast<int>(terrainSize);
			descriptor.nbRows = static_cast<int>(terrainSize);
	
			for(int i = 0; i < terrainSize*terrainSize; ++i)
				samples[i].height = static_cast<PxI16>(heightData[i]);

			descriptor.samples.data = samples;
			descriptor.samples.stride = sizeof(PxHeightFieldSample);

			PxHeightField* heightField = physicsSDK->createHeightField(descriptor);
			PxHeightFieldGeometry geometry(heightField, PxMeshGeometryFlags(),params.w()*0.00390625f,params.y(),params.z());
			PxTransform transformation = PxTransform(PxVec3(-terrainSize*0.5f*params.y(),0.0f,-terrainSize*0.5f*params.z()),PxQuat::createIdentity());

			PxRigidStatic* heightFieldActor = physicsSDK->createRigidStatic(transformation);
			PxShape* aHeightFieldShape = heightFieldActor->createShape(geometry,*materials[0].second);
			heightFieldActor->setName(entity->entityName.c_str());
			setupFiltering(heightFieldActor,filterGroup,filterMask);
			scene->addActor(*heightFieldActor);
			
			StaticActor* s = new StaticActor();
			s->entityLogic = entity;
			s->entityPhysics = heightFieldActor;
			staticActors.push_back(s);
		}
Esempio n. 2
0
void Physics::SetUpTutorial1()
{
	//Add a plane
	PxTransform pose = PxTransform(PxVec3(0.0f, 0, 0.0f), PxQuat(PxHalfPi*1.0f, PxVec3(0.0f, 0.0f, 1.0f)));
	PxRigidStatic* plane = PxCreateStatic(*g_Physics, pose, PxPlaneGeometry(), *g_PhysicsMaterial);
	//Add it to the physx scene
	g_PhysicsScene->addActor(*plane);
	//Add a box
	float density = 5000;
	PxBoxGeometry box(5,5,5);
	PxTransform transformS(PxVec3(0, 5, 0));
	PxRigidStatic* StaticActor = PxCreateStatic(*g_Physics, transformS, box, *g_PhysicsMaterial);
	StaticActor->setName("TriggerBox");
	setupFiltering(StaticActor, FilterGroup::eGROUND, FilterGroup::ePLAYER);
	setShapeAsTrigger(StaticActor);
	//add it to the physx scene
	g_PhysicsScene->addActor(*StaticActor);
}
Esempio n. 3
0
		/**
		 * Method is used to add new static actor to physics scene. Now only plane shape can be used.
		 * @param	entity is pointer to scene entity which will be added to physics simulation.
		 * @param	type is enumeration of shape type.
		 * @param	filterGroup is actor own id.
		 * @param	filterMask is mask to filter pairs that trigger a contact callback.
		 */
		void PhysicsManager::addStaticActor(SceneEntity* entity, ShapeType type, PxU32 filterGroup, PxU32 filterMask)
		{
			PxVec3 position;
			PxQuat orientation;
			PxTransform transformation;

			if(entity == nullptr)
			{
				 transformation = PxTransform(PxVec3(0.0f,1.0f,0.0f),PxQuat(PxHalfPi,PxVec3(0.0f, 0.0f, 1.0f)));
			}
			else
			{
				position = PxVec3(entity->entityState.position[0],entity->entityState.position[1],entity->entityState.position[2]);
				orientation = PxQuat(entity->entityState.orientation[0],entity->entityState.orientation[1],entity->entityState.orientation[2],entity->entityState.orientation[3]);
				transformation = PxTransform(position,orientation); 
			}

			PxRigidStatic* actor = nullptr;
			actor = physicsSDK->createRigidStatic(transformation);
			
			if(!actor)
				Logger::getInstance()->saveLog(Log<string>("Static Actor creation error occurred!"));
			
			PxShape* shape = nullptr;

			if(type == PLANE)
				shape = actor->createShape(PxPlaneGeometry(),*materials[0].second);
			else
				return;

			if(!shape)
				Logger::getInstance()->saveLog(Log<string>("Static Actor shape creation error occurred!"));
			
			actor->setName("World Plane");
			setupFiltering(actor,filterGroup,filterMask);
			scene->addActor(*actor);

			StaticActor* s = new StaticActor();
			s->entityLogic = entity;
			s->entityPhysics = actor;
			staticActors.push_back(s);
		}