void labscale::CreateRegolithContainer()
{
    // Geometry variables
    PxReal box_d = labscale::reg_box.diameter;
    PxReal box_h = labscale::reg_box.fillHeight*2;
    PxReal wall_dh = box_d/20;

    // We'll make the regolith container with a kinematic actor
    PxRigidDynamic* theBox = gPhysX.mPhysics->createRigidDynamic(PxTransform(PxVec3(0,0.05*wall_dh,0)));
    if (!theBox)
        ncc__error("Actor creation failed!");
    theBox->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC, true);

    // Define sides
    PxBoxGeometry box_bottom(box_d/2,wall_dh/2,box_d/2);
    PxBoxGeometry box_side(wall_dh/2,box_h/2,box_d/2);
    PxMaterial* defmat=gPhysX.mDefaultMaterial;

    // Attach the sides, making front wall invisible
    theBox->createShape(box_bottom,*defmat,PxTransform(PxVec3(0,wall_dh/2,0))); // the bottom
    theBox->createShape(box_side,*defmat,PxTransform(PxVec3(-box_d/2,box_h/2,0),PxQuat(0,PxVec3(0,1,0)))); // left wall
    theBox->createShape(box_side,*defmat,PxTransform(PxVec3( box_d/2,box_h/2,0),PxQuat(0,PxVec3(0,1,0)))); // right wall
    theBox->createShape(box_side,*defmat,PxTransform(PxVec3(0,box_h/2,-box_d/2),PxQuat(PxPi/2,PxVec3(0,1,0)))); // back wall
    PxShape* fwall =  theBox->createShape(box_side,*defmat,PxTransform(PxVec3(0,box_h/2, box_d/2),PxQuat(PxPi/2,PxVec3(0,1,0)))); // front wall
    fwall->setName("~fwall");

    // Name, color, and register the container
    theBox->setName("the_box");
    ColorActor(theBox, ncc::rgb::rRed);
    gPhysX.mScene->addActor(*theBox);
    labscale::VIPs.container = theBox;

}
Exemple #2
0
void Physics::Shoot()
{
	float densityS = 100;
	PxSphereGeometry sphere(1);
	PxTransform transformS(PxVec3(m_camera.world[3].x, m_camera.world[3].y, m_camera.world[3].z));
	PxRigidDynamic* dynamicActorS = PxCreateDynamic(*g_Physics, transformS, sphere, *g_PhysicsMaterial, densityS);
	dynamicActorS->setName("Bullet");
	setupFiltering(dynamicActorS, FilterGroup::ePLAYER, FilterGroup::eGROUND);
	//add it to the physx scene
	g_PhysicsScene->addActor(*dynamicActorS);
	dynamicActorS->addForce(PxVec3(-m_camera.world[2].x, -m_camera.world[2].y, -m_camera.world[2].z)*muzzleSpeed, PxForceMode::eIMPULSE, true);
}
PxRigidDynamic * labscale::CreateRegolithGrain()
{
    PxMaterial* glass = gPhysX.mPhysics->createMaterial(0.5, 0.5, 0.5); // "glass"
    PxReal radius = labscale::regolith.diameter/2;
    PxReal rho = labscale::regolith.materialDensity;
    PxRigidDynamic* actor = CreateRubbleGrain(PxVec3(0,1.5*labscale::reg_box.fillHeight,0),eSPHERE_GRAIN,radius,*glass,rho);
    actor->setName("regolith");

    if (!actor)
        ncc__error("actor creations failed");
    return actor;
}
		/**
		 * Method is used to add new dynamic actor to physics scene.
		 * @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::addDynamicActor(SceneEntity* entity, ShapeType type, PxU32 filterGroup, PxU32 filterMask)
		{
			PxRigidDynamic* actor = nullptr;
			
			PxVec3 position = PxVec3(entity->entityState.position[0],entity->entityState.position[1],entity->entityState.position[2]);	
			PxQuat orientation = PxQuat(entity->entityState.orientation[0],entity->entityState.orientation[1],entity->entityState.orientation[2],entity->entityState.orientation[3]);
			PxReal density = 1.0f;
			PxTransform transformation = PxTransform(position,orientation); 

			if(type == BOX)
			{
				float x = (entity->entityGeometry.geometryBox->max.x() - entity->entityGeometry.geometryBox->min.x())*entity->entityState.scale.x()*0.5f;
				float y = (entity->entityGeometry.geometryBox->max.y() - entity->entityGeometry.geometryBox->min.y())*entity->entityState.scale.y()*0.5f;
				float z = (entity->entityGeometry.geometryBox->max.z() - entity->entityGeometry.geometryBox->min.z())*entity->entityState.scale.z()*0.5f;
				
				PxVec3 dimensions(x,y,z);
				actor = PxCreateDynamic(*physicsSDK,transformation,PxBoxGeometry(dimensions),*materials[0].second,density);
				PxRigidBodyExt::updateMassAndInertia(*actor, density);
			}
			else if(type == SPHERE)
			{
				float radius = entity->entityGeometry.geometrySphere->sphereRadius;
				actor = PxCreateDynamic(*physicsSDK,transformation,PxSphereGeometry(radius),*materials[0].second,density);
			}
			else if(type == CAPSULE)
			{
				float radius = entity->entityGeometry.geometrySphere->sphereRadius;
				actor = PxCreateDynamic(*physicsSDK,transformation,PxCapsuleGeometry(radius/2, radius),*materials[0].second,density);
			}
			else if(type == CONVEX)
			{
				/*int vertsCount = entity->entityGeometry.geometryMesh->getVerticesAmount();
				AyumiUtils::Vertex<>* verts = entity->entityGeometry.geometryMesh->getVertices();
				PxVec3* convexVerts = new PxVec3[vertsCount];

				for(int i = 0; i < vertsCount; ++i)
					convexVerts[i] = PxVec3(verts[i].x,verts[i].y,verts[i].z);

				PxConvexMeshDesc convexDesc;
				convexDesc.points.count = entity->entityGeometry.geometryMesh->getVerticesAmount();
				convexDesc.points.stride = sizeof(PxVec3);
				convexDesc.points.data = convexVerts;
				convexDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX;

				MemoryWriteBuffer buf;
				if(cooking->cookConvexMesh(convexDesc, buf))
				{
					PxConvexMesh* convexMesh = physicsSDK->createConvexMesh(MemoryReadBuffer(buf.data));
					actor = PxCreateDynamic(*physicsSDK,transformation,PxConvexMeshGeometry(convexMesh,PxMeshScale()),*materials[0].second,density);
				}
				else
				{
					Logger::getInstance()->saveLog(Log<string>("Convex Mesh creation error occurred!"));
					return;
				}*/
				//delete[] convexVerts;
			}
			else
			{
				Logger::getInstance()->saveLog(Log<string>("Dynamic Actor shape creation error occurred!"));
				return;
			}

			if(!actor)
				Logger::getInstance()->saveLog(Log<string>("Static Actor creation error occurred!"));
			
			PxRigidBodyExt::updateMassAndInertia(*actor, density);
			actor->setAngularDamping(0.75);
			actor->setLinearVelocity(PxVec3(0,0,0));
			actor->setName(entity->entityName.c_str());
			setupFiltering(actor,filterGroup,filterMask);
			scene->addActor(*actor);
			
			DynamicActor* d = new DynamicActor();
			d->entityLogic = entity;
			d->entityPhysics = actor;
			d->shapesAmount = actor->getNbShapes();
			d->shapes = new PxShape*[d->shapesAmount];
			dynamicActors.push_back(d);
		}