Exemple #1
0
BcBool MaAABB::boxIntersect( const MaAABB& AABB, MaAABB* pIntersectionBox ) const
{
	// Check for no overlap.
	if( ( Min_.x() > AABB.Max_.x() ) ||
		( Max_.x() < AABB.Min_.x() ) ||
		( Min_.y() > AABB.Max_.y() ) ||
		( Max_.y() < AABB.Min_.y() ) ||
		( Min_.z() > AABB.Max_.z() ) ||
		( Max_.z() < AABB.Min_.z() ) )
	{
		return BcFalse;
	}

	// Overlap, compute AABB of intersection.
	if( pIntersectionBox != NULL )
	{
		pIntersectionBox->Min_.x( BcMax( Min_.x(), AABB.Min_.x() ) );
		pIntersectionBox->Max_.x( BcMin( Max_.x(), AABB.Max_.x() ) );
		pIntersectionBox->Min_.y( BcMax( Min_.y(), AABB.Min_.y() ) );
		pIntersectionBox->Max_.y( BcMin( Max_.y(), AABB.Max_.y() ) );
		pIntersectionBox->Min_.z( BcMax( Min_.z(), AABB.Min_.z() ) );
		pIntersectionBox->Max_.z( BcMin( Max_.z(), AABB.Max_.z() ) );
	}

	return BcTrue;
}
Exemple #2
0
void MaAABB::expandBy( const MaAABB& AABB )
{
	Min_.x( BcMin( Min_.x(), AABB.Min_.x() ) );
	Min_.y( BcMin( Min_.y(), AABB.Min_.y() ) );
	Min_.z( BcMin( Min_.z(), AABB.Min_.z() ) );

	Max_.x( BcMax( Max_.x(), AABB.Max_.x() ) );
	Max_.y( BcMax( Max_.y(), AABB.Max_.y() ) );
	Max_.z( BcMax( Max_.z(), AABB.Max_.z() ) );
}
Exemple #3
0
void MaAABB::expandBy( const MaVec3d& Point )
{
	Min_.x( BcMin( Min_.x(), Point.x() ) );
	Min_.y( BcMin( Min_.y(), Point.y() ) );
	Min_.z( BcMin( Min_.z(), Point.z() ) );

	Max_.x( BcMax( Max_.x(), Point.x() ) );
	Max_.y( BcMax( Max_.y(), Point.y() ) );
	Max_.z( BcMax( Max_.z(), Point.z() ) );
}
Exemple #4
0
//////////////////////////////////////////////////////////////////////////
// execute
//virtual
void SysKernel::execute()
{
	// Set main thread.
	extern void BcSetGameThread();
	BcSetGameThread();

	// Run until there are no more systems to run.
	do
	{
		// Mark main timer.
		MainTimer_.mark();
		
		// Tick systems.
		tick();
		
		// Sleep if we have a fixed rate specified, otherwise just yield.
		if( TickRate_ > 0.0f )
		{
			BcReal TimeSpent = MainTimer_.time();
			SleepAccumulator_ += BcMax( ( TickRate_ ) - TimeSpent, 0.0f );
		
			if( SleepAccumulator_ > 0.0f )
			{
				BcReal SleepTime = SleepAccumulator_;
				SleepAccumulator_ -= SleepTime;
				BcSleep( BcMin( SleepTime, TickRate_ ) );
			}
		}
		else
		{
			BcYield();
		}

		// Store frame time.
		FrameTime_ = BcMin( MainTimer_.time(), TickRate_ * 4.0f );

		BcAssert( FrameTime_ >= 0.0f );
	}
	while( SystemList_.size() > 0 );
}
//////////////////////////////////////////////////////////////////////////
// setMaterialParameters
void ScnLightingVisitor::setMaterialParameters( class ScnMaterialComponent* MaterialComponent ) const
{
	BcU32 Count = BcMin( (BcU32)4, (BcU32)LightComponents_.size() );
	for( BcU32 Idx = 0; Idx < Count; ++Idx )
	{
		ScnLightComponent* LightComponent = LightComponents_[ Idx ];
		LightComponent->setMaterialParameters( Idx, MaterialComponent );

	}	

	for( BcU32 Idx = Count; Idx < 4; ++Idx )
	{
		/*
		MaterialComponent->setLightParameters( Idx,
	                                           MaVec3d( 0.0f, 0.0f, 0.0f ),
	                                           MaVec3d( 0.0f, 0.0f, 0.0f ),
	                                           RsColour::BLACK,
	                                           RsColour::BLACK,
	                                           0.0f,
	                                           0.0f,
	                                           0.0f );
	                                           */
	}
}
Exemple #6
0
////////////////////////////////////////////////////////////////////////////////
// setNoofUpdateVertices
//virtual
void RsVertexBufferGL::setNoofUpdateVertices( BcU32 NoofVertices )
{
	NoofUpdateVertices_ = BcMin( NoofVertices, Desc_.NoofVertices_ );
}
Exemple #7
0
//////////////////////////////////////////////////////////////////////////
// tickBehaviour
void GaGameUnit::tickBehaviour( BcFixed Delta )
{
#if PSY_DEBUG
	static BcU32 BreakID = BcErrorCode;
	if( ID_ == BreakID )
	{
		BcBreakpoint;
	}
#endif

	switch( Behaviour_ )
	{
	case BEHAVIOUR_IDLE:
		{
			CurrState_.Velocity_ = BcFixedVec2d( 0.0f, 0.0f );
			BcU32 NearestUnit = pSimulator_->findNearestUnit( CurrState_.Position_, ID_, 1 << ( 1 - TeamID_ ) );
			if( NearestUnit != BcErrorCode )
			{
				doAttack( NearestUnit );
			}
		}
		break;

	case BEHAVIOUR_GUARD:
		{
			CurrState_.Velocity_ = BcFixedVec2d( 0.0f, 0.0f );
			BcU32 NearestUnit = pSimulator_->findNearestUnit( CurrState_.Position_, ID_, 1 << ( 1 - TeamID_ ) );
			if( NearestUnit != BcErrorCode )
			{
				doAttack( NearestUnit );
			}
		}
		break;

	case BEHAVIOUR_MOVE:
		{
			BcU32 NearestUnit = pSimulator_->findNearestUnit( CurrState_.Position_, ID_, 1 << ( 1 - TeamID_ ) );
			if( IsAttackMove_ && inRangeForAttack( NearestUnit ) == RANGE_IN )
			{
				CurrState_.Velocity_ = BcFixedVec2d( 0.0f, 0.0f );

				doAttack( NearestUnit );
			}
			else
			{
				// Reset attack timer.
				AttackTimer_ = BcMax( AttackTimer_,  BcFixed( Desc_.CoolDownMultiplier_ ) / Desc_.RateOfAttack_ );
				
				// Make longer whe moving.
				AttackTimer_ = BcMin( BcFixed( 1.0f ) / Desc_.RateOfAttack_, AttackTimer_ + ( BcFixed( 1.0f ) / Desc_.RateOfAttack_ ) * ( Delta * 0.05f ) );

				// Calculate velocity vector.
				CurrState_.Velocity_ = BcFixedVec2d( MoveTargetPosition_ - CurrState_.Position_ ).normal() * Desc_.MoveSpeed_;
				BcFixed MoveDistance = Desc_.MoveSpeed_ * Delta;
				if( ( CurrState_.Position_ - MoveTargetPosition_ ).magnitudeSquared() < ( MoveDistance * MoveDistance ) )
				{
					CurrState_.Position_ = MoveTargetPosition_;
					setBehaviourIdle();
				}
			}
		}
		break;

	case BEHAVIOUR_ATTACK:
		{
			TRange Range = inRangeForAttack( TargetUnitID_ );
			if( Range == RANGE_IN )
			{
				doAttack( TargetUnitID_ );
			}
			else
			{
				// Reset attack timer.
				AttackTimer_ = BcMax( AttackTimer_,  BcFixed( Desc_.CoolDownMultiplier_ ) / ( Desc_.RateOfAttack_ ) );

				// Make longer whe moving.
				AttackTimer_ = BcMin( BcFixed( 1.0f ) / Desc_.RateOfAttack_, AttackTimer_ + ( BcFixed( 1.0f ) / Desc_.RateOfAttack_ ) * ( Delta * 0.05f ) );

				// Get unit position.
				GaGameUnit* pUnit = pSimulator_->getUnit( TargetUnitID_ );
				if( pUnit != NULL )
				{
					BcFixedVec2d Direction = ( getPosition() - pUnit->getPosition() ).normal() * ( ( Desc_.MinRange_ + Desc_.Range_ ) * 0.5f );
					MoveTargetPosition_ = pUnit->getPosition() + Direction;
				}
				else
				{
					// Attack move to previous target.
					IsAttackMove_ = BcTrue;
					Behaviour_ = BEHAVIOUR_MOVE;
				}

				// Calculate velocity vector.
				CurrState_.Velocity_ = BcFixedVec2d( MoveTargetPosition_ - CurrState_.Position_ ).normal() * Desc_.MoveSpeed_;

				// If we moved further away, then stop and set target.
				BcFixed CurrMagnitudeSquared = ( CurrState_.Position_ - MoveTargetPosition_ ).magnitudeSquared();
				BcFixed PrevMagnitudeSquared = ( PrevState_.Position_ - MoveTargetPosition_ ).magnitudeSquared();
				if( CurrMagnitudeSquared > PrevMagnitudeSquared )
				{
					setBehaviourIdle();
				}
			}
		}
		break;

	case BEHAVIOUR_DAMAGE:
		{
			// Calculate velocity vector.
			CurrState_.Velocity_ = BcFixedVec2d( MoveTargetPosition_ - CurrState_.Position_ ).normal() * Desc_.MoveSpeed_;
			BcFixed MoveDistance = Desc_.MoveSpeed_ * Delta;
			if( ( CurrState_.Position_ - MoveTargetPosition_ ).magnitudeSquared() < ( MoveDistance * MoveDistance ) )
			{
				CurrState_.Position_ = MoveTargetPosition_;

				// Cause damage.
				pSimulator_->applyDamage( MoveTargetPosition_, Desc_.Range_, Desc_.Health_ );

				// Debug point!
				pSimulator_->addDebugPoint( getPosition(), Desc_.Range_, RsColour::YELLOW );

				if( Desc_.pHitSound_ != NULL )
				{
					GaTopState::pImpl()->playSound( Desc_.pHitSound_, MoveTargetPosition_ );
				}

				// Set as dead.
				setBehaviourDead();
			}
		}
		break;
	}

	// Attack timer.
	if( AttackTimer_ > 0.0f )
	{
		AttackTimer_ -= Delta;
	}
	else if( AttackTimer_ < 0.0f )
	{
		AttackTimer_ = 0.0f;
	}

	// Death.
	if( Health_ <= 0.0f )
	{
		Health_ = 0.0f;
		Behaviour_ = BEHAVIOUR_DEAD;
	}
}