Ejemplo n.º 1
0
void Diamond::updateMotion( double deltaT )
{
	age += deltaT;
	
	// extremely realistic physics!
	
	Vect2 position = line->getPosition() + ( velocity * deltaT );
	
	if( position.getx() < SURFACE_MIN_U )
	{
		// bounce
		if( velocity.getx() < 0.0 )
		{
			velocity.Set( velocity.getx() * -1.0, velocity.gety() );
		}
		// clamp
		position.Set( SURFACE_MIN_U, position.gety() );
	}
	else if( position.getx() > SURFACE_MAX_U )
	{
		// bounce
		if( velocity.getx() > 0.0 )
		{
			velocity.Set( velocity.getx() * -1.0, velocity.gety() );
		}
		// clamp
		position.Set( SURFACE_MAX_U, position.gety() );
	}
	
	if( position.gety() < SURFACE_MIN_V )
	{
		// bounce
		if( velocity.gety() < 0.0 )
		{
			velocity.Set( velocity.getx(), velocity.gety() * -1.0 );
		}
		// clamp
		position.Set( position.getx(), SURFACE_MIN_V );
	}
	else if( position.gety() > SURFACE_MAX_V )
	{
		// bounce
		if( velocity.gety() > 0.0 )
		{
			velocity.Set( velocity.getx(), velocity.gety() * -1.0 );
		}
		// clamp
		position.Set( position.getx(), SURFACE_MAX_V );
	}
	
	line->setPosition( position );

	
/*	float rotation = line->getRotation() + ( rotationalVelocity * deltaT );
	
	// clamp
	// prevent near-infinite looping, just in case
	if( rotation < -720.0 || rotation > 720.0 )
		rotation = 0.0;
	while( rotation < 0.0 )
		rotation += 360.0;
	while( rotation > 360.0 )
		rotation -= 360.0;

	line->setRotation( rotation );*/
	
	
	float pulsePercentage = age * pulseRate;
	// need to find the decimal part of pulsePercentage
	pulsePercentage -= static_cast<int>( pulsePercentage );
	// use sine to make pulsePercentage oscillate
	//   pi*2 = full range of sine
	//   0.5 needed because results of sine range from -1 to +1
	pulsePercentage = ( sinf( pulsePercentage * M_PI * 2.0f ) + 1.0f ) * 0.5f;

	line->setScale( 
		interpolate( pulseScaleMin, pulseScaleMax, 1.0f - pulsePercentage ), 
		interpolate( pulseScaleMin, pulseScaleMax, pulsePercentage ) );
}
Ejemplo n.º 2
0
void Pinwheel::updateMotion( double deltaT )
{
	// extremely realistic physics!
	
	Vect2 position = line->getPosition() + ( velocity * deltaT );
	
	if( position.getx() < SURFACE_MIN_U )
	{
		// bounce
		if( velocity.getx() < 0.0 )
		{
			velocity.Set( velocity.getx() * -1.0, velocity.gety() );
		}
		// clamp
		position.Set( SURFACE_MIN_U, position.gety() );
	}
	else if( position.getx() > SURFACE_MAX_U )
	{
		// bounce
		if( velocity.getx() > 0.0 )
		{
			velocity.Set( velocity.getx() * -1.0, velocity.gety() );
		}
		// clamp
		position.Set( SURFACE_MAX_U, position.gety() );
	}
	
	if( position.gety() < SURFACE_MIN_V )
	{
		// bounce
		if( velocity.gety() < 0.0 )
		{
			velocity.Set( velocity.getx(), velocity.gety() * -1.0 );
		}
		// clamp
		position.Set( position.getx(), SURFACE_MIN_V );
	}
	else if( position.gety() > SURFACE_MAX_V )
	{
		// bounce
		if( velocity.gety() > 0.0 )
		{
			velocity.Set( velocity.getx(), velocity.gety() * -1.0 );
		}
		// clamp
		position.Set( position.getx(), SURFACE_MAX_V );
	}
	
	line->setPosition( position );

	
	float rotation = line->getRotation() + ( rotationalVelocity * deltaT );
	
	// clamp
	// prevent near-infinite looping, just in case
	if( rotation < -720.0 || rotation > 720.0 )
		rotation = 0.0;
	while( rotation < 0.0 )
		rotation += 360.0;
	while( rotation > 360.0 )
		rotation -= 360.0;

	line->setRotation( rotation );
}