예제 #1
0
void
PhsXWorld::_addParticles(nau::render::Pass* pass, std::shared_ptr<nau::scene::IScene> &aScene, std::string name, nau::material::IBuffer* positions) {

    PxPhysics *gPhysics = &(m_pDynamicsWorld->getPhysics());

    float particleDistance = 0.01f;
    // create particle system in PhysX SDK
    particleSystem = gPhysics->createParticleFluid(MAXPARTICLE);
    //particleSystem->setGridSize(5.0f);
    particleSystem->setMaxMotionDistance(0.3f);
    //particleSystem->setRestOffset(particleDistance*0.3f);
    particleSystem->setRestOffset(0.04f);
    //particleSystem->setContactOffset(particleDistance*0.3f * 2);
    particleSystem->setContactOffset(0.036f);
    particleSystem->setDamping(0.0f);
    particleSystem->setRestitution(0.3f);
    particleSystem->setDynamicFriction(0.001f);
    particleSystem->setRestParticleDistance(particleDistance);
    particleSystem->setViscosity(60.0f);
    particleSystem->setStiffness(45.0f);
    //particleSystem->setParticleReadDataFlag(PxParticleReadDataFlag::eVELOCITY_BUFFER, true);

    particleSystem->userData = aScene.get();

    // add particle system to scene, in case creation was successful
    if (particleSystem)
        m_pDynamicsWorld->addActor(*particleSystem);

    particleIndexPool = PxParticleExt::createIndexPool(MAXPARTICLE);
    particlePass = pass;
    particlePositionBuffer = positions;
    createParticles();
}
예제 #2
0
bool PxInitVehicleSDK(PxPhysics& physics)
{
	PX_ASSERT(static_cast<Ps::Foundation*>(&physics.getFoundation()) == &Ps::Foundation::getInstance());
	Ps::Foundation::incRefCount();
	setVehicleToleranceScale(physics.getTolerancesScale());
	return true;
}
예제 #3
0
void PVDHelper::createPvdConnection(const EditableParams& params)
{
	PvdConnectionManager* pvd = mPhysics->getPvdConnectionManager();
	if(!pvd)
		return;

/*	if(0)
	{
		PxDebuggerConnectionFlags PDebuggerFlags;
		PDebuggerFlags |= PxExtensionConnectionType::Debug;
		PDebuggerFlags |= PxExtensionConnectionType::Profile;
		PDebuggerFlags |= PxExtensionConnectionType::Memory;

		PxExtensionVisualDebugger::connect( 
						pvd,
						PVD_HOST,
						5425,
						3000,
						PDebuggerFlags
						);
		return;
	}*/

	//The connection flags state overall what data is to be sent to PVD.  Currently
	//the Debug connection flag requires support from the implementation (don't send
	//the data when debug isn't set) but the other two flags, profile and memory
	//are taken care of by the PVD SDK.

	//Use these flags for a clean profile trace with minimal overhead
	//TConnectionFlagsType theConnectionFlags( PvdConnectionType::Profile )
#ifdef BETA2
	TConnectionFlagsType theConnectionFlags( PvdConnectionType::Debug | PvdConnectionType::Profile | PvdConnectionType::Memory );
	if(!params.mUseFullPvdConnection)
		theConnectionFlags = TConnectionFlagsType(PvdConnectionType::Profile);
#else
	PxVisualDebuggerConnectionFlags theConnectionFlags( PxVisualDebuggerExt::getAllConnectionFlags() );
	if(!params.mUseFullPvdConnection)
		theConnectionFlags = PxVisualDebuggerConnectionFlag::Profile;
#endif

	//Create a pvd connection that writes data straight to the filesystem.  This is
	//the fastest connection on windows for various reasons.  First, the transport is quite fast as
	//pvd writes data in blocks and filesystems work well with that abstraction.
	//Second, you don't have the PVD application parsing data and using CPU and memory bandwidth
	//while your application is running.
	//PxExtensionVisualDebugger::connect(pvd,"c:\\temp.pxd2", PxDebuggerConnectionFlags( (PxU32)theConnectionFlags));
	
	//The normal way to connect to pvd.  PVD needs to be running at the time this function is called.
	//We don't worry about the return value because we are already registered as a listener for connections
	//and thus our onPvdConnected call will take care of setting up our basic connection state.
#ifdef BETA2
	PxExtensionVisualDebugger::connect(pvd, PVD_HOST, 5425, 10, PxDebuggerConnectionFlags( (PxU32)theConnectionFlags) );
#else
	PVD::PvdConnection* theConnection = PxVisualDebuggerExt::createConnection(mPhysics->getPvdConnectionManager(), PVD_HOST, 5425, 10, theConnectionFlags );
	if(theConnection)
		theConnection->release();
#endif
}
예제 #4
0
//=============================================================================
// PRIVATE FUNCTIONS
//=============================================================================
static physx::unique_ptr<PxConvexMesh> GenerateConvexFromDXMesh(PxPhysics &iPhysics, ID3DXMesh *iMesh)
{
	//Used to retrieve information from X file
	struct Mesh_FVF {
		D3DXVECTOR3 VertexPos;
		D3DXVECTOR3 Normal;
		D3DXVECTOR2 TexCoord;
	};

	int aNumVerticies = iMesh->GetNumVertices();
	DWORD FVFSize = D3DXGetFVFVertexSize(iMesh->GetFVF());

	//Create pointer for vertices
	PxVec3* verts = new PxVec3[aNumVerticies];

	char *DXMeshPtr;
	iMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&DXMeshPtr);
	for(int i = 0; i < aNumVerticies; i++)
	{
		Mesh_FVF *DXMeshFVF = (Mesh_FVF*)DXMeshPtr;
		verts[i] = PxVec3(DXMeshFVF->VertexPos.x, DXMeshFVF->VertexPos.y, DXMeshFVF->VertexPos.z);
		DXMeshPtr += FVFSize;
	}
	iMesh->UnlockVertexBuffer();

	// Create descriptor for convex mesh
	PxConvexMeshDesc convexDesc;
	convexDesc.points.count		= aNumVerticies;
	convexDesc.points.stride	= sizeof(PxVec3);
	convexDesc.points.data		= verts;
	convexDesc.flags			= PxConvexFlag::eCOMPUTE_CONVEX;

	PxTolerancesScale toleranceScale;
	toleranceScale.length = 1.0f;
	toleranceScale.mass = 1000.0f;
	toleranceScale.speed = 9.8f;

	assert(toleranceScale.isValid());

	physx::unique_ptr<PxCooking> cooker = physx::unique_ptr<PxCooking>(
		PxCreateCooking(PX_PHYSICS_VERSION, iPhysics.getFoundation(), PxCookingParams(toleranceScale))
		);

	// Cooking from memory
	MemoryStream buf;
	physx::unique_ptr<PxConvexMesh> convexMesh;
	if(cooker->cookConvexMesh(convexDesc, buf))
	{
		convexMesh = physx::unique_ptr<PxConvexMesh>(iPhysics.createConvexMesh(buf));
	}	

	delete[] verts;

	return convexMesh;
}
예제 #5
0
	void FPhysXMesh::initialize()
	{
		if (mCookedData != nullptr && mCookedDataSize > 0)
		{
			PxPhysics* physx = gPhysX().getPhysX();

			PxDefaultMemoryInputData input(mCookedData, mCookedDataSize);
			if (mType == PhysicsMeshType::Convex)
				mConvexMesh = physx->createConvexMesh(input);
			else
				mTriangleMesh = physx->createTriangleMesh(input);
		}
	}
예제 #6
0
void
PhsXWorld::build(void) {
    PxTolerancesScale scale = PxTolerancesScale();
    PxFoundation* gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback);
    PxProfileZoneManager* profileZoneManager = &PxProfileZoneManager::createProfileZoneManager(gFoundation);
    PxPhysics*	gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, scale, true, profileZoneManager);
    if (gPhysics->getPvdConnectionManager()) {
        gPhysics->getVisualDebugger()->setVisualizeConstraints(true);
        gPhysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlag::eTRANSMIT_CONTACTS, true);
        gPhysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlag::eTRANSMIT_SCENEQUERIES, true);
        //gPhysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlag::eTRANSMIT_CONSTRAINTS, true);
        gConnection = PxVisualDebuggerExt::createConnection(gPhysics->getPvdConnectionManager(), "127.0.0.1", 5425, 100);
    }
    PxSceneDesc sceneDesc(gPhysics->getTolerancesScale());
    sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
    PxDefaultCpuDispatcher* gDispatcher = PxDefaultCpuDispatcherCreate(2);
    sceneDesc.cpuDispatcher = gDispatcher;
    sceneDesc.filterShader = PxDefaultSimulationFilterShader;
    sceneDesc.flags |= PxSceneFlag::eENABLE_ACTIVETRANSFORMS;
    m_pDynamicsWorld = gPhysics->createScene(sceneDesc);
    //m_pDynamicsWorld->setFlag(PxSceneFlag::eENABLE_ACTIVETRANSFORMS, true);

    mCooking = PxCreateCooking(PX_PHYSICS_VERSION, *gFoundation, PxCookingParams(scale));
    manager = PxCreateControllerManager(*m_pDynamicsWorld);

    std::srand(time(NULL));
}
예제 #7
0
파일: Entity.cpp 프로젝트: franaisa/Gloom
	void CEntity::deserializeFromRepXFile(const std::string &file, int group, const std::vector<int>& groupList, const Logic::IPhysics* component) {
		// Obtenemos el puntero al servidor de fisicas
		Physics::CServer* physicsServer = Physics::CServer::getSingletonPtr();
		PxScene* scene = physicsServer->getActiveScene();
		PxPhysics* physics = physicsServer->getPhysxSDK();
		PxCooking* cooking = physicsServer->getCooking();
		assert(scene);

		// Preparar parámetros para deserializar
		PxDefaultFileInputData data(file.c_str());
		PxCollection* bufferCollection = physics->createCollection();
		PxCollection* sceneCollection = physics->createCollection(); 
		PxStringTable* stringTable = &PxStringTableExt::createStringTable( CServer::getSingletonPtr()->getFoundation()->getAllocatorCallback() ); 
		PxUserReferences* externalRefs = NULL; 
		PxUserReferences* userRefs = NULL; 

		// Deserializar a partir del fichero RepX
		repx::deserializeFromRepX(data, *physics, *cooking, stringTable, externalRefs, 
								  *bufferCollection, *sceneCollection, userRefs);


		// Añadir entidades físicas a la escena
		physics->addCollection(*sceneCollection, *scene);

		// Buscar una entidad de tipo PxRigidActor. Asumimos que hay exactamente 1 en el fichero.
		_actor = NULL;
		for (unsigned int i = 0; i < sceneCollection->getNbObjects() && !_actor; ++i) {
			PxSerializable* p = sceneCollection->getObject(i);
			_actor = p->is<PxRigidActor>();
		}
		assert(_actor);

		// Anotar el componente lógico asociado a la entidad física
		_actor->userData = (void*)component;

		// Establecer el grupo de colisión
		PxSetGroup(*_actor, group);
		// Establecer los filtros de colisión
		Physics::CServer::getSingletonPtr()->setupFiltering(_actor, group, groupList);

		// Liberar recursos
		bufferCollection->release();
		sceneCollection->release();
	}
예제 #8
0
void
PhsXWorld::_addCharacter(float mass, float radius, float height, float stepHeight, std::shared_ptr<nau::scene::IScene> &aScene, std::string name) {
    PxPhysics *gPhysics = &(m_pDynamicsWorld->getPhysics());
    PxCapsuleControllerDesc desc;
    //desc.height = 1.3f;
    //desc.radius = 0.35f;
    desc.height = height;
    desc.radius = radius;
    PxVec3 pos = PxMat44(const_cast<float*> (aScene->getTransform().getMatrix())).getPosition();
    desc.position = PxExtendedVec3(pos.x, pos.y, pos.z);
    desc.material = gPhysics->createMaterial(0.5f, 0.5f, 0.6f);
    desc.userData = aScene.get();
    desc.reportCallback = this;
    desc.climbingMode = PxCapsuleClimbingMode::eCONSTRAINED;
    desc.stepOffset = stepHeight;
    desc.upDirection = PxVec3(0, 1, 0);
    //desc.slopeLimit = cosf(DegToRad(80.0f));
    controller = manager->createController(desc);
}
예제 #9
0
void PVDHelper::togglePvdConnection(const EditableParams& params)
{
	PvdConnectionManager* pvd = mPhysics->getPvdConnectionManager();
	if(!pvd)
		return;

	if(pvd->isConnected())
		pvd->disconnect();
	else
		createPvdConnection(params);
}
예제 #10
0
		void InitPhysX() {
		        gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback);
		        gPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale() );
		        if(gPhysicsSDK == NULL) {
		                cerr<<"Error create PhysX."<<endl;
		        }
		        PxSceneDesc sceneDesc(gPhysicsSDK->getTolerancesScale());
		        sceneDesc.gravity               = PxVec3(0.0f, -9.8f, 0.0f);
		        sceneDesc.cpuDispatcher = PxDefaultCpuDispatcherCreate(1);
		        sceneDesc.filterShader  = PxDefaultSimulationFilterShader;
		        gScene = gPhysicsSDK->createScene(sceneDesc);
		        PxMaterial* material = gPhysicsSDK->createMaterial(0.5,0.5,0.5);
		        PxTransform planePos =  PxTransform(PxVec3(0.0f),PxQuat(PxHalfPi, PxVec3(0.0f, 0.0f, 1.0f)));
		        PxRigidStatic* plane =  gPhysicsSDK->createRigidStatic(planePos);
		        plane->createShape(PxPlaneGeometry(), *material);
		        gScene->addActor(*plane);
		        PxTransform             boxPos(PxVec3(0.0f, 10.0f, 0.0f));
		        PxBoxGeometry   boxGeometry(PxVec3(2,2,2));
		        gBox = PxCreateDynamic(*gPhysicsSDK, boxPos, boxGeometry, *material, 1.0f);
		        gScene->addActor(*gBox);
		}
예제 #11
0
bool PxInitExtensions(PxPhysics& physics)
{
    PX_ASSERT(static_cast<Ps::Foundation*>(&physics.getFoundation()) == &Ps::Foundation::getInstance());
    Ps::Foundation::incRefCount();

    physics.registerClass(PxConcreteType::eUSER_SPHERICAL_JOINT,	Ext::SphericalJoint::createInstance);
    physics.registerClass(PxConcreteType::eUSER_REVOLUTE_JOINT,	Ext::RevoluteJoint::createInstance);
    physics.registerClass(PxConcreteType::eUSER_DISTANCE_JOINT,	Ext::DistanceJoint::createInstance);
    physics.registerClass(PxConcreteType::eUSER_D6_JOINT,			Ext::D6Joint::createInstance);
    physics.registerClass(PxConcreteType::eUSER_PRISMATIC_JOINT,	Ext::PrismaticJoint::createInstance);
    physics.registerClass(PxConcreteType::eUSER_FIXED_JOINT,		Ext::FixedJoint::createInstance);
#if PX_SUPPORT_VISUAL_DEBUGGER
    if ( physics.getPvdConnectionManager() != NULL )
        physics.getPvdConnectionManager()->addHandler( gPvdHandler );
#endif
    return true;
}
예제 #12
0
bool PxInitExtensions(PxPhysics& physics, PxPvd* pvd)
{
	PX_ASSERT(static_cast<Ps::Foundation*>(&physics.getFoundation()) == &Ps::Foundation::getInstance());
	PX_UNUSED(physics);
	PX_UNUSED(pvd);
	Ps::Foundation::incRefCount();

#if PX_SUPPORT_PVD
	if(pvd)
	{
		gPvdHandler.mPvd = static_cast<PsPvd*>(pvd);
		gPvdHandler.mPvd->addClient(&gPvdHandler);
	}
#endif

	return true;
}
예제 #13
0
bool Controller::createProxyActor(PxPhysics& sdk, const PxGeometry& geometry, const PxMaterial& material)
{
    // PT: we don't disable raycasting or CD because:
    // - raycasting is needed for visibility queries (the SDK otherwise doesn't know about the CCTS)
    // - collision is needed because the only reason we create actors there is to handle collisions with dynamic shapes
    // So it's actually wrong to disable any of those.

    PxTransform globalPose;
    globalPose.p = toVec3(mPosition);	// LOSS OF ACCURACY
    globalPose.q = mUserParams.mQuatFromUp;

    mKineActor = sdk.createRigidDynamic(globalPose);
    if(!mKineActor)
        return false;

    mKineActor->createShape(geometry, material);
    mKineActor->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC, true);

    PxRigidBodyExt::updateMassAndInertia(*mKineActor, mProxyDensity);
    mScene->addActor(*mKineActor);
    return true;
}
예제 #14
0
		void ShutdownPhysX() {
		        gPhysicsSDK->release();                 
		        gFoundation->release();                 
		}
예제 #15
0
void PxCollectForExportSDK(const PxPhysics& physics, PxCollection& collection)
{
    // Collect convexes
    {
        Ps::Array<PxConvexMesh*> objects(physics.getNbConvexMeshes());
        const PxU32 nb = physics.getConvexMeshes(objects.begin(), objects.size());
        PX_ASSERT(nb == objects.size());
        PX_UNUSED(nb);

        for(PxU32 i=0; i<objects.size(); i++)
            objects[i]->collectForExport(collection);
    }

    // Collect triangle meshes
    {
        Ps::Array<PxTriangleMesh*> objects(physics.getNbTriangleMeshes());
        const PxU32 nb = physics.getTriangleMeshes(objects.begin(), objects.size());

        PX_ASSERT(nb == objects.size());
        PX_UNUSED(nb);

        for(PxU32 i=0; i<objects.size(); i++)
            objects[i]->collectForExport(collection);
    }

    // Collect heightfields
    {
        Ps::Array<PxHeightField*> objects(physics.getNbHeightFields());
        const PxU32 nb = physics.getHeightFields(objects.begin(), objects.size());

        PX_ASSERT(nb == objects.size());
        PX_UNUSED(nb);

        for(PxU32 i=0; i<objects.size(); i++)
            objects[i]->collectForExport(collection);
    }

    // Collect materials
    {
        Ps::Array<PxMaterial*> objects(physics.getNbMaterials());
        const PxU32 nb = physics.getMaterials(objects.begin(), objects.size());

        PX_ASSERT(nb == objects.size());
        PX_UNUSED(nb);

        for(PxU32 i=0; i<objects.size(); i++)
            objects[i]->collectForExport(collection);
    }

#if PX_USE_CLOTH_API
    // Collect cloth fabrics
    {
        Ps::Array<PxClothFabric*> objects(physics.getNbClothFabrics());
        const PxU32 nb = physics.getClothFabrics(objects.begin(), objects.size());

        PX_ASSERT(nb == objects.size());
        PX_UNUSED(nb);

        for(PxU32 i=0; i<objects.size(); i++)
            objects[i]->collectForExport(collection);
    }
#endif
}
예제 #16
0
void 
PhysXRigidManager::addStaticBody(const std::string & scene, physx::PxScene * world, physx::PxCooking * mCooking, nau::physics::IPhysics::BoundingVolume shape, physx::PxMaterial * material) {
	PxPhysics *gPhysics = &(world->getPhysics());
	PxRigidStatic * staticActor;
	PxTransform trans = PxTransform(PxMat44(rigidBodies[scene].info.extInfo.transform));
	switch (shape.sceneShape)
	{
	case nau::physics::IPhysics::BOX:
	{
		staticActor = PxCreateStatic(
			world->getPhysics(),
			trans,
			PxBoxGeometry(shape.max[0], shape.max[1], shape.max[2]),
			*material
		);
	}
	break;
	case nau::physics::IPhysics::SPHERE:
	{
		staticActor = PxCreateStatic(
			world->getPhysics(),
			trans,
			PxSphereGeometry(shape.max[0]),
			*material
		);
	}
	break;
	case nau::physics::IPhysics::CAPSULE:
	{
		staticActor = PxCreateStatic(
			world->getPhysics(),
			trans,
			PxCapsuleGeometry(
				shape.max[0],
				shape.max[1]
			),
			*material
		);
	}
	break;
	default:
	{
		if (scene.compare("plane") == 0) {
			staticActor = PxCreatePlane(
				world->getPhysics(),
				PxPlane(0.0f, 1.0f, 0.0f, 0.0f),
				*material
			);
		}
		else {
			staticActor = gPhysics->createRigidStatic(trans);
			PxTriangleMeshGeometry triGeom(gPhysics->createTriangleMesh(*getTriangleMeshGeo(world, mCooking, rigidBodies[scene].info.extInfo, true)));
			//triGeom.triangleMesh = gPhysics->createTriangleMesh(*getTriangleMeshGeo(world, mCooking, rigidBodies[scene].extInfo, true));
			staticActor->createShape(triGeom, *material);
		}
	}
	break;
	}
	staticActor->userData = static_cast<void*> (new std::string(scene));
	world->addActor(*staticActor);
	rigidBodies[scene].info.actor = staticActor;
}
예제 #17
0
void PVDHelper::onPvdConnected(PvdConnection& )
{
	//setup joint visualization.  This gets piped to pvd.
	mPhysics->getVisualDebugger()->setVisualizeConstraints(true);
	mPhysics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlags::eTRANSMIT_CONTACTS, true);
}
예제 #18
0
void
PhsXWorld::_addCloth(float mass, std::shared_ptr<nau::scene::IScene> &aScene, std::string name, nau::math::vec3 aVec) {
    PxPhysics *gPhysics = &(m_pDynamicsWorld->getPhysics());

    std::shared_ptr<nau::scene::SceneObject> &aObject = aScene->getSceneObject(0);
    std::shared_ptr<VertexData> &vd = aObject->getRenderable()->getVertexData();
    std::vector<std::shared_ptr<MaterialGroup>> &matGroups = aObject->getRenderable()->getMaterialGroups();
    std::vector<std::shared_ptr<MaterialGroup>>::iterator matGroupsIter;

    PxDefaultMemoryOutputStream writeBuffer;

    int count = static_cast<int> (vd->getDataOf(VertexData::GetAttribIndex(std::string("position")))->size());
    PxClothParticle *particles = new PxClothParticle[count];

    PxClothMeshDesc meshDesc;
    matGroupsIter = matGroups.begin();
    for (; matGroupsIter != matGroups.end(); matGroupsIter++) {
        if ((*matGroupsIter)->getIndexData()->getIndexSize()) {
            std::shared_ptr<std::vector<unsigned int>> &indexes = (*matGroupsIter)->getIndexData()->getIndexData();
            PxClothParticle *ptls = particles;
            std::shared_ptr<std::vector<VertexData::Attr>> points = vd->getDataOf(VertexData::GetAttribIndex(std::string("position")));
            for (int i = 0; i < count; i++) {
                VertexData::Attr tempPoint = points->at(i);
                //ptls[i] = PxClothParticle(PxVec3(tempPoint.x, tempPoint.y, tempPoint.z), (i==0 || i==1) ? 0.0f : 1.0f);
                ptls[i] = PxClothParticle(PxVec3(tempPoint.x, tempPoint.y, tempPoint.z), i == 0 ? 0.0f : 0.1f);
            }

            meshDesc.points.data = reinterpret_cast<const unsigned char *>(&(vd->getDataOf(VertexData::GetAttribIndex(std::string("position")))->at(0)));
            meshDesc.points.count = count;
            meshDesc.points.stride = 4 * sizeof(float);

            meshDesc.invMasses.data = &particles->invWeight;
            meshDesc.invMasses.count = count;
            meshDesc.invMasses.stride = sizeof(PxClothParticle);

            meshDesc.triangles.data = reinterpret_cast<const unsigned char *>(&((*indexes)[0]));
            meshDesc.triangles.count = static_cast<int> (indexes->size() / 3);
            meshDesc.triangles.stride = 3 * sizeof(unsigned int);

        }
    }
    //float * points = reinterpret_cast<float *>(&(vd->getDataOf(VertexData::GetAttribIndex(std::string("position")))->at(0)));
    //PxU32 numParticles = static_cast<int> (vd->getDataOf(VertexData::GetAttribIndex(std::string("position")))->size());
    //PxU32 stride = 4 * sizeof(float);
    //// create particles
    //PxClothParticle* particles = new PxClothParticle[numParticles];
    //PxClothParticle* pIt = particles;
    //for (PxU32 i = 0; i<numParticles; ++i) {
    //	pIt->invWeight = i==0 ? 0.0f : 1.0f;
    //	int tempStride = i*stride;
    //	pIt->pos = PxVec3(points[tempStride], points[tempStride + 1], points[tempStride + 2]);
    //}

    PxClothFabric* fabric = PxClothFabricCreate(*gPhysics, meshDesc, PxVec3(0, -1, 0));
    PxTransform pose = PxTransform(PxMat44(const_cast<float*> (aScene->getTransform().getMatrix())));
    PxClothFlags flags = PxClothFlags();
    /*if(!flags.isSet(PxClothFlag::eSCENE_COLLISION))
    	flags.set(PxClothFlag::eSCENE_COLLISION);
    if (!flags.isSet(PxClothFlag::eGPU))
    	flags.set(PxClothFlag::eGPU);
    if (!flags.isSet(PxClothFlag::eSWEPT_CONTACT))
    	flags.set(PxClothFlag::eSWEPT_CONTACT);*/
    cloth = gPhysics->createCloth(pose, *fabric, particles, flags);
    cloth->userData = aScene.get();
    cloth->setClothFlag(PxClothFlag::eSCENE_COLLISION, true);
    cloth->setClothFlag(PxClothFlag::eGPU, true);
    cloth->setClothFlag(PxClothFlag::eSWEPT_CONTACT, true);
    cloth->setSolverFrequency(300.0f);
    cloth->setInertiaScale(0.9f);

    cloth->setStretchConfig(PxClothFabricPhaseType::eVERTICAL, PxClothStretchConfig(0.2f));
    cloth->setStretchConfig(PxClothFabricPhaseType::eHORIZONTAL, PxClothStretchConfig(0.2f));
    cloth->setStretchConfig(PxClothFabricPhaseType::eSHEARING, PxClothStretchConfig(0.75f));
    cloth->setStretchConfig(PxClothFabricPhaseType::eBENDING, PxClothStretchConfig(0.2f));
    m_pDynamicsWorld->addActor(*cloth);

}
예제 #19
0
void
PhsXWorld::_addRigid(float mass, float friction, float restitution, std::shared_ptr<nau::scene::IScene> &aScene, std::string name, nau::math::vec3 aVec) {

    PxPhysics *gPhysics = &(m_pDynamicsWorld->getPhysics());

    if (mass == 0.0f) {
        PxRigidStatic* staticActor;
        if (name.compare("plane") == 0) {
            staticActor = PxCreatePlane(*gPhysics,
                                        PxPlane(0.0f, 1.0f, 0.0f, 0.0f),
                                        *(gPhysics->createMaterial(friction, friction, restitution))
                                       );

        }
        else {
            /*if (name.compare("box") == 0) {
            	staticActor = PxCreateStatic(*gPhysics,
            		PxTransform(PxMat44(const_cast<float*> (aScene->getTransform().getMatrix()))),
            		PxBoxGeometry(1.0f,1.0f,1.0f),
            		*(gPhysics->createMaterial(1.0f, 1.0f, 0.6f))
            	);
            }
            else {*/
            staticActor = gPhysics->createRigidStatic(PxTransform(PxMat44(const_cast<float*> (aScene->getTransform().getMatrix()))));
            PxTriangleMeshGeometry triGeom;
            triGeom.triangleMesh = gPhysics->createTriangleMesh(getTriangleMeshGeo(m_pDynamicsWorld, aScene));
            staticActor->createShape(triGeom, *(gPhysics->createMaterial(friction, friction, restitution)));
            //}
        }
        staticActor->userData = aScene.get();
        m_pDynamicsWorld->addActor(*staticActor);
    }
    else {
        PxRigidDynamic* dynamic;
        //if (name.compare("ball") == 0) {
        //	dynamic = PxCreateDynamic(*gPhysics,
        //		PxTransform(PxMat44(const_cast<float*> (aScene->getTransform().getMatrix()))),
        //		PxSphereGeometry(1),
        //		*(gPhysics->createMaterial(0.5f, 0.5f, 0.6f)),
        //		10.0f
        //	);
        //	//dynamic->setLinearVelocity(PxVec3(0, -50, -100));
        //}
        //else {
        PxTransform trans = PxTransform(PxMat44(const_cast<float*> (aScene->getTransform().getMatrix())));
        dynamic = gPhysics->createRigidDynamic(trans);
        PxConvexMesh * convexMesh = gPhysics->createConvexMesh(getTriangleMeshGeo(m_pDynamicsWorld, aScene, false));
        PxConvexMeshGeometry convGeom(convexMesh);
        //PxConvexMeshGeometry convGeom(convexMesh, PxMeshScale(0.5f));
        //convGeom.convexMesh = gPhysics->createConvexMesh(getTriangleMeshGeo(m_pDynamicsWorld, aScene, false));

        //PxShape *shape = dynamic->createShape(convGeom, *(gPhysics->createMaterial(0.5f, 0.5f, 0.6f)), PxShapeFlag::eSIMULATION_SHAPE | PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE);
        PxShape *shape = dynamic->createShape(convGeom, *(gPhysics->createMaterial(friction, friction, restitution)));
        //shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, true);
        //dynamic->setRigidBodyFlag(PxRigidBodyFlag::eKINEMATIC, false);
        //}
        dynamic->userData = aScene.get();
        //dynamic->setAngularDamping(0.5f);
        //dynamic->setLinearVelocity(velocity);

        m_pDynamicsWorld->addActor(*dynamic);
    }
}
예제 #20
0
bool Ext::RevoluteJoint::attach(PxPhysics &physics, PxRigidActor* actor0, PxRigidActor* actor1)
{
    mPxConstraint = physics.createConstraint(actor0, actor1, *this, sShaders, sizeof(RevoluteJointData));
    return mPxConstraint!=NULL;
}
예제 #21
0
void
PhysXRigidManager::addDynamicBody(const std::string & scene, physx::PxScene * world, physx::PxCooking * mCooking, nau::physics::IPhysics::BoundingVolume shape, physx::PxMaterial * material) {
	PxPhysics *gPhysics = &(world->getPhysics());
	PxRigidDynamic * dynamic;

	rigidBodies[scene].scalingFactor = getScalingFactor(rigidBodies[scene].info.extInfo.transform);
	PxMeshScale scale = PxMeshScale(rigidBodies[scene].scalingFactor);
	PxMat44 aux(rigidBodies[scene].info.extInfo.transform);
	PxVec3 pos(aux.getPosition());
	aux *= (1.0f / rigidBodies[scene].scalingFactor);
	PxMat44 mat(
		PxVec3(aux.column0.x, aux.column0.y, aux.column0.z),
		PxVec3(aux.column1.x, aux.column1.y, aux.column1.z),
		PxVec3(aux.column2.x, aux.column2.y, aux.column2.z),
		pos
	);

	//PxTransform trans = PxTransform(PxMat44(rigidBodies[scene].extInfo.transform));
	PxTransform trans = PxTransform(mat);

	switch (shape.sceneShape)
	{
	case nau::physics::IPhysics::BOX:
	{
		dynamic = gPhysics->createRigidDynamic(trans);
		dynamic->createShape(
			PxBoxGeometry(
				shape.max[0] * rigidBodies[scene].scalingFactor,
				shape.max[1] * rigidBodies[scene].scalingFactor,
				shape.max[2] * rigidBodies[scene].scalingFactor),
			*material);
	}
	break;
	case nau::physics::IPhysics::SPHERE:
	{
		dynamic = gPhysics->createRigidDynamic(trans);
		dynamic->createShape(PxSphereGeometry(shape.max[0] * rigidBodies[scene].scalingFactor), *material);
	}
	break;
	case nau::physics::IPhysics::CAPSULE:
	{
		dynamic = gPhysics->createRigidDynamic(trans);
		dynamic->createShape(
			PxCapsuleGeometry(
				shape.max[0] * rigidBodies[scene].scalingFactor,
				shape.max[1] * rigidBodies[scene].scalingFactor),
			*material);
	}
	break;
	default:
	{
		dynamic = gPhysics->createRigidDynamic(trans);
		PxConvexMesh * convexMesh = gPhysics->createConvexMesh(*getTriangleMeshGeo(world, mCooking, rigidBodies[scene].info.extInfo, false));
		dynamic->createShape(PxConvexMeshGeometry(convexMesh, scale), *material);
	}
	break;
	}

	dynamic->userData = static_cast<void*> (new std::string(scene));
	rigidBodies[scene].rollingFriction = -1.0f;
	rigidBodies[scene].rollingFrictionTimeStamp = 1;
	world->addActor(*dynamic);
	rigidBodies[scene].info.actor = dynamic;
}