Esempio n. 1
0
void KeyboardUpCallback(unsigned char key, int x, int y)
{
	gKeys[key] = false;

	switch (key)
	{
		case 'p': { bPause = !bPause; 
					if (bPause)
						hud.SetDisplayString(2, "Paused - Hit \"p\" to Unpause", 0.3f, 0.55f);
					else
						hud.SetDisplayString(2, "", 0.0f, 0.0f);	
					break; }
		case 'x': { bShadows = !bShadows; break; }
		case 'b': { bDebugWireframeMode = !bDebugWireframeMode; break; }		
		case 'f': { bForceMode = !bForceMode; break; }

		case 'o': 
		{     
			NxCloth** cloths = gScene->getCloths();
			for (NxU32 i = 0; i < gScene->getNbCloths(); i++) 
			{
				cloths[i]->setFlags(cloths[i]->getFlags() ^ NX_CLF_BENDING_ORTHO);
			}
			break;
		}

		case 'g': 
		{     
			NxCloth** cloths = gScene->getCloths();
			for (NxU32 i = 0; i < gScene->getNbCloths(); i++) 
			{
				cloths[i]->setFlags(cloths[i]->getFlags() ^ NX_CLF_GRAVITY);
			}
			break;
		}

		case 'y': 
		{
			NxCloth** cloths = gScene->getCloths();
			for (NxU32 i = 0; i < gScene->getNbCloths(); i++) 
			{
				cloths[i]->setFlags(cloths[i]->getFlags() ^ NX_CLF_BENDING);
			}	            
			break;
		}
		case ' ': 
		{
			NxActor* sphere = CreateSphere(gCameraPos, 1, 1);
			sphere->setLinearVelocity(gCameraForward * 20);
			break; 
		}
		case 27 : { exit(0); break; }
		default : { break; }
	}
}
Esempio n. 2
0
void ParticleEmitter::addParticle()
{

	if ((_iTailIndex == _iHeadIndex) && (_iParticleCount != 0)) // FIFO is full
	{
		removeParticle();
		// Now there is a slot free
	}

	// Add a single-shape actor to the scene
	NxActorDesc actorDesc;
	NxBodyDesc bodyDesc;

	NxSphereShapeDesc sphereDesc;
	sphereDesc.radius = 1.0f;
	sphereDesc.group = cParticleCollisionGroup; // this group does not collide with itself
	actorDesc.shapes.pushBack(&sphereDesc);

	actorDesc.body = &bodyDesc;
	actorDesc.density = 10.0f;
	actorDesc.globalPose.t = _vStartingPos;

	NxActor* pNewActor =  _pScene->createActor(actorDesc);

	// Give it an initial linear velocity, scaled by _fStartingVelScale
	NxVec3 vRandVec(NxReal(rand()*_fStartingVelScale), NxReal(rand()*_fStartingVelScale), NxReal(rand()*_fStartingVelScale));
	pNewActor->setLinearVelocity(vRandVec);

	// Turn off gravity for smoke
	pNewActor->raiseBodyFlag(NX_BF_DISABLE_GRAVITY);

	_aParticleArray[_iHeadIndex] = new Particle(pNewActor, _vThermoDynamicAcceleration);

	_iHeadIndex = (_iHeadIndex+1) % ciMaxParticles;
	++_iParticleCount;
}
Esempio n. 3
0
pRigidBody*pFactory::cloneRigidBody(CK3dEntity *src,CK3dEntity *dst,CKDependencies *deps,int copyFlags,int bodyFlags/* =0 */)
{
	//src->Rest
	pRigidBody *result = GetPMan()->getBody(dst);
	pRigidBody *srcBody = GetPMan()->getBody(src);
	CK3dEntity *referenceObject = dst;

	XString errMsg;
	pObjectDescr oDescr;

	//----------------------------------------------------------------
	//
	// sanity checks
	//
	#ifdef _DEBUG
		assert(src);
		assert(dst);
	#endif // _DEBUG

	if (!(copyFlags & PB_CF_PHYSICS))
	{
		errMsg.Format("Nothing to copy, aborting");
		xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,errMsg.Str());
		return NULL;
	}

	//iAssertW(!result,"","Object :%s already physicalized");
		
	//----------------------------------------------------------------
	//
	// fill object description
	//
	if (!result && IParameter::Instance()->copyTo(oDescr,src,copyFlags))
	{
		pWorld *world  = GetPMan()->getWorld(oDescr.worlReference) ? GetPMan()->getWorld(oDescr.worlReference) : GetPMan()->getDefaultWorld();
		if(world)
		{

			if ( (copyFlags && PB_CF_OVRRIDE_BODY_FLAGS) )
				oDescr.flags  = (BodyFlags)bodyFlags;
			
			//now create the final rigid body : 
			result  = pFactory::Instance()->createRigidBody(dst,oDescr);
		}
	}

	if (!result){
		xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,"cloning failed");
		return NULL;
	}

	//----------------------------------------------------------------
	//
	// clone joints
	//
	if ( (copyFlags & PB_CF_JOINTS) )
	{
		pFactory::cloneJoints(src,dst,copyFlags);

	}

	//----------------------------------------------------------------
	//
	// copy velocities
	//
	if ( (copyFlags & PB_CF_VELOCITIES) )
	{
		NxActor *actorSrc  = srcBody->getActor();
		NxActor *actorDst  = result->getActor();

		actorDst->setLinearVelocity( actorSrc->getLinearVelocity() );
		actorDst->setAngularVelocity( actorSrc->getAngularVelocity() );
	}

	//----------------------------------------------------------------
	//
	// copy forces
	//
	if ( (copyFlags & PB_CF_FORCE) )
	{
		NxActor *actorSrc  = srcBody->getActor();
		NxActor *actorDst  = result->getActor();
		actorDst->setLinearMomentum( actorSrc->getLinearMomentum() );
		actorDst->setAngularMomentum( actorSrc->getAngularMomentum() );
	}
	
	//----------------------------------------------------------------
	//
	// copy sub shapes if : 
	//
	//		"Copy Children In Dependencies" &&
	//		( copyFlags::OverrideBodyFlags & hierarchy &&  newBodyFlags & hierarchy  ) ||		
	//		( oldBodyFlags & hierarchy )
	if ( ((*deps->At(CKCID_3DENTITY)) & CK_DEPENDENCIES_COPY_3DENTITY_CHILDREN)  && 
		  ( (( copyFlags & PB_CF_OVRRIDE_BODY_FLAGS ) && (bodyFlags & BF_Hierarchy)) ||
		  ( oDescr.flags & BF_Hierarchy) )
		)
	{
		int dCount = dst->GetChildrenCount();
		CK3dEntity* subEntity = NULL;
		while (subEntity= dst->HierarchyParser(subEntity) )
		{
			if (subEntity==dst)
				continue;

			CK3dEntity *orginalObject = findSimilarInSourceObject(src,dst,subEntity);
			if (orginalObject)
			{
				iAssertW(cloneShape(orginalObject,subEntity,dst,copyFlags,bodyFlags),"","clone of sub shape failed");
			}
		}
	}
	return NULL;
}