void CParticle::update( NxReal fDeltaTime )
{
	
	Alpha -= 4;

	// アクターを削除する
	if( Alpha < 0 )
	{
		Alpha = 0; 
		m_pParticleEmitter->removeParticle();
		return;
	}

	// Use our down-caster to get a sphere pointer (and make sure it is a sphere)
	NxSphereShape* pSphere = _pActor->getShapes()[0]->isSphere();
	const NxReal fMaxRadius = 0.01f;
	const NxReal fGrowthRate = 0.6f;
	if( pSphere )
	{
		// Grow the radius at growth rate fGrowthRate m/s, until it reaches fMaxRadius meters
		NxReal fCurrentRadius = pSphere->getRadius();
		if ( fCurrentRadius < fMaxRadius )
		{
			pSphere->setRadius( pSphere->getRadius() + fGrowthRate*fDeltaTime );
			if( pSphere->getRadius() > fMaxRadius )
				pSphere->setRadius( fMaxRadius );
		}
	}
}
示例#2
0
void Particle::update(NxReal fDeltaTime)
{
	// particles have a false, thermodynamic force applied which pushes them up every frame
	_pActor->addForce(_vThermoDynamicForce);

	// Use our down-caster to get a sphere pointer (and make sure it is a sphere)
	NxSphereShape* pSphere = _pActor->getShapes()[0]->isSphere();
	const NxReal fMaxRadius = 3.0f;
	const NxReal fGrowthRate = 0.6f;
	if (pSphere)
	{
		// Grow the radius at growth rate fGrowthRate m/s, until it reaches fMaxRadius meters
		NxReal fCurrentRadius = pSphere->getRadius();
		if (fCurrentRadius < fMaxRadius)
		{
			pSphere->setRadius(pSphere->getRadius() + fGrowthRate*fDeltaTime);
			if (pSphere->getRadius() > fMaxRadius)
				pSphere->setRadius(fMaxRadius);
		}
	}
}
void CPhysicsActor::SetScale( Vec3& scale )
{
	// do not scale if scale is currently 1:1 or if the scale
	// has not changed
	if( scale.x == 1 && scale.y == 1 && scale.z == 1 ||
		scale == m_CurrentScale )
	{
		return;
	}

	// make sure the scale is valid
	// No 0 scales or negative scales!
	if( scale.x <= 0 && scale.y <= 0 && scale.z <= 0 )
	{
		m_ToolBox->Log( LOGWARNING, _T("CPhysicsActor::SetScale() Invalid scale!\n" ) );
		return;
	}

	NxVec3 newScale( scale.x, scale.y, scale.z );

	// unscale the old scale
	// Loop through shapes in the actor
	unsigned int numShapes = m_Actor->getNbShapes();
	NxShape*const* shapes = m_Actor->getShapes();
   	NxShape* currentShape;

	NxVec3 shapeLocalPosition;

	// for each shape type scale its dimensions
	while( numShapes-- >= 1 )
	{
		currentShape = shapes[numShapes];

		// get the shape's type
		NxShapeType type = currentShape->getType();

		switch( type )
		{
			case NX_SHAPE_BOX:
				{
					// do something
					NxBoxShape* shape = (NxBoxShape*)currentShape;
					// rescale box dimensions
					NxVec3 dimensions = shape->getDimensions();
					
					Vec3 newDimensions(dimensions.x, dimensions.y, dimensions.z);
					RescaleVector( newDimensions, scale );

					// set the shape data with the newly rescaled dimensions
					shape->setDimensions( NxVec3(newDimensions.x, newDimensions.y, newDimensions.z) );
					break;
				}
			case NX_SHAPE_SPHERE:
				{
					// do something
					NxSphereShape* shape = (NxSphereShape*)currentShape;
					float radius = shape->getRadius();
					radius /= m_CurrentScale.x;
					radius *= newScale.x;
					// set the shape data with the newly rescaled dimensions
					shape->setRadius( radius );
					break;
				}
			case NX_SHAPE_CAPSULE:
				{
					// do something
					NxCapsuleShape* shape;
					shape = (NxCapsuleShape*)currentShape;
					// rescale radius
					float radius = shape->getRadius();
					radius /= m_CurrentScale.x;
					radius *= newScale.x;
					// rescale height
					float height = shape->getHeight();
					height /= m_CurrentScale.z;
					height *= newScale.z;
					// set the shape data with the newly rescaled dimensions
					shape->setRadius( radius );
					shape->setHeight( height );
					break;
				}
			default:
				m_ToolBox->Log( LOGWARNING, _T("CPhysicsObject::SetScale() Attempting to scale on unsupported shape!\n" ) );
				return;
		}

		// get the shape's local position and rescale it
		shapeLocalPosition = currentShape->getLocalPosition();

		Vec3 newShapeLocalPosition(shapeLocalPosition.x, shapeLocalPosition.y, shapeLocalPosition.z);
		RescaleVector( newShapeLocalPosition, scale );

		currentShape->setLocalPosition( NxVec3(newShapeLocalPosition.x, newShapeLocalPosition.y, newShapeLocalPosition.z) );
	}

	// Set the current scale to the new scale so we can unscale the scale
	m_CurrentScale = scale;
}