Exemple #1
0
void CtfAiPlayerComp::HandlePathFound( GActorHandle i_actor )
{
	GActor* actor = GActor::FromHandle( i_actor );
	m_LastNodePos = actor->m_position;

	// the closest node could be behind us.  make sure that's not the case. this could be breaking some rules...
	u16 selected = m_PathToTarget.m_PathNodes[0];
	if( m_PathToTarget.m_PathNodes.size() > 1 )
	{
		u16 second = m_PathToTarget.m_PathNodes[1];
		GVector3 firstNode, secondNode;
		g_WayPointManager.NodePosition( m_PathToTarget.m_PathNodes[0], firstNode);
		g_WayPointManager.NodePosition( m_PathToTarget.m_PathNodes[1], secondNode );
		GVector3 nodeDir = secondNode - firstNode;
		GVector3 toFirst = firstNode - m_LastNodePos;
		if( nodeDir.Dot( toFirst ) < 0.0f )
		{
			m_PathIndex = 1;
			selected = m_PathToTarget.m_PathNodes[1];
			m_TargetNodePos = secondNode;
			if( m_PathToTarget.m_PathNodes.size() > 2 )
				g_WayPointManager.NodePosition( m_PathToTarget.m_PathNodes[2], m_NextTargetNodePos );
			else
				m_NextTargetNodePos = secondNode;
		}
		else
		{
			m_PathIndex = 0;
			m_TargetNodePos = firstNode;
			m_NextTargetNodePos = secondNode;
			//m_CurrentPathNode = selected;
		}

	}
	else
	{
		m_PathIndex = 0;
		//m_CurrentPathNode = selected;
		g_WayPointManager.NodePosition( selected, m_TargetNodePos );
		if( m_PathToTarget.m_PathNodes.size() > 1 )
			g_WayPointManager.NodePosition( m_PathToTarget.m_PathNodes[1], m_NextTargetNodePos );
		else
			m_NextTargetNodePos = m_TargetNodePos;
	}

	m_CurrentPathNode = selected;
}
Exemple #2
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 );
}