Ejemplo n.º 1
0
void QuatTestComp::EndUpdate( GActorHandle i_actor )
{
	if ( m_keyDown )
	{
		// Attempt 1.  Works, but weird...
		/*
		float totalRot = fabs(acosf(m_quat.DotProduct(m_targetQuat)));
		// time / (rot speed / totalRot).
		if (totalRot > 0.0f)
			m_quat.Slerp(m_quat, m_targetQuat, g_Clock::Get().SecondsSinceLastFrame() * (GMath::Deg2Rad(30.0f) / totalRot));

		m_quat.Normalize();
		*/

		// Attempt 2.
		GVector3 target = m_targetQuat * GVector3::Forward;
		target.Normalize();
		GVector3 current = m_quat * GVector3::Forward;
		current.Normalize();
		float dot = target.Dot( current );
		if (dot < 0.99999f)
		{
			GVector3 cross = current.Cross( target );
			float sign = GMath::Sign( cross.y() );
			cross.Normalize();
			GQuat delta;
			delta.FromAngleAxis( GMath::Deg2Rad( 30.0f ) * g_Clock::Get().SecondsSinceLastFrame(), cross );
			m_quat = m_quat * delta;
			if( GMath::Sign( ( m_quat * GVector3::Forward ).Cross( m_targetQuat * GVector3::Forward ).y() ) != sign )
				m_quat = m_targetQuat;
		}

	}

	GActor* actor = GActor::FromHandle( i_actor );
	assert( actor );

	GVector3 vStartPoint = actor->m_position;
	GVector3 vEndPoint = actor->m_position + ( m_quat * GVector3::Forward * 100.0f );
	GDebugDraw::DrawLine( vStartPoint, vEndPoint, 0.002f, 0.002f, GDebugDraw::RED );

	GVector3 vEndTargetPoint = actor->m_position + ( m_targetQuat * GVector3( 0.0f, 0.0f, 100.0f ) );
	GDebugDraw::DrawLine( vStartPoint, vEndTargetPoint, 0.002f, 0.002f, GDebugDraw::BLUE );
}
Ejemplo n.º 2
0
void QuatTestComp::ResetCalculation( GActorHandle i_Handle )
{
	GActor* actor = GActor::FromHandle( i_Handle );
	GVector3 facing = -actor->m_rotation.Dir(); // TODO: Fix the z-hack soon..
	GVector3 worldZ( 0.0f, 0.0f, 1.0f );
	float angle = acosf( worldZ.Dot( facing ) );
	GVector3 ortho = worldZ.Cross( facing );
	if( ortho.LengthSquared() > 0.0f )
	{
		ortho.Normalize();
		m_quat.FromAngleAxis( angle, ortho );
	}
}
Ejemplo n.º 3
0
void QuatTestComp::NewRandomVector( )
{
	m_targetQuat.Identify();
	GVector3 randomVector( 0.0f, 0.5f, 0.0f );
	randomVector.x( static_cast<float>( rand() % 100) / 100.0f - 0.5f );
	randomVector.z( static_cast<float>( rand() % 100 ) / 100.0f - 0.5f );
	randomVector.Normalize();

	float angle = acosf( randomVector.Dot( GVector3::Forward ) );
	GVector3 cross = GVector3::Forward.Cross( randomVector );
	cross.Normalize();
	m_targetQuat.FromAngleAxis( angle, cross );
}
Ejemplo n.º 4
0
// alright.  this is the "state machine" :(
void CtfAiPlayerComp::Update( GActorHandle i_actor )
{
	GActor* actor = GActor::FromHandle( i_actor );

	// make sure the player is valid every frame.
	if( !m_Player )
	{
		m_Player = g_World::Get().GetActorByName( "PlayerOne" );
		if( !m_Player )
			return;
	}

	g_AudioManager.UpdateChannelPosition( m_walkOnGroundSlow, actor->m_position );

	StaminaBrain( i_actor );

	if( m_usingStamina )
		m_staminaMeter -= g_Clock::Get().SecondsSinceLastFrame() * 5.0f;
	else
		m_staminaMeter += g_Clock::Get().SecondsSinceLastFrame() * 1.66667f;

	GMath::Clamp( &m_staminaMeter, 0.0f, 10.0f );

	switch( m_State )
	{
		case SEEK:
			Seek( i_actor );
		break;
		case CAPTURE:
			Capture( i_actor );
		break;
		case PURSUE:
			Pursue( i_actor );
		break;
	}

	if( m_PathToTarget.m_pathFound )
	{
		GGroundFollowerComp* gFollower = GetComponent<GGroundFollowerComp>( i_actor );
		assert( gFollower ); // you f****d up.

		GVector3 velocity;

		if( m_PathToTarget.m_PathNodes.size() <= 1 && m_State == PURSUE )
		{
			GActorHandle playerHandle = g_World::Get().GetActorByName( "PlayerOne" );
			GActor* player = GActor::FromHandle( playerHandle );
			if( !player )
				velocity = GVector3( 0.0f, 0.0f, 0.0f ); 
			else
				velocity = player->m_position - actor->m_position;	
		}
		else
		{
			velocity = m_TargetNodePos - actor->m_position;
		}

		velocity.Normalize();
		if( m_usingStamina )
			velocity *= 1000.0f;
		else
			velocity *= 500.0f;

		m_LastVelocity = velocity;

		gFollower->m_velocity = velocity;
	}
}