Example #1
0
void CEntity::Render()
{
	if( !m_visible ) return;

	if( !m_orderQueue.empty() )
	{
		std::deque<CEntityOrder>::iterator it;
		CBoundingObject* destinationCollisionObject;
		float x0, y0, x, y;

		x = m_orderQueue.front().m_target_location.x;
		y = m_orderQueue.front().m_target_location.y;

		for( it = m_orderQueue.begin(); it < m_orderQueue.end(); it++ )
		{
			if( it->m_type == CEntityOrder::ORDER_PATROL )
				break;
			x = it->m_target_location.x;
			y = it->m_target_location.y;
		}
		destinationCollisionObject = GetContainingObject( CVector2D( x, y ) );

		glShadeModel( GL_FLAT );
		glBegin( GL_LINE_STRIP );

		glVertex3f( m_position.X, m_position.Y + 0.25f, m_position.Z );

		x = m_position.X;
		y = m_position.Z;

		for( it = m_orderQueue.begin(); it < m_orderQueue.end(); it++ )
		{
			x0 = x;
			y0 = y;
			x = it->m_target_location.x;
			y = it->m_target_location.y;
			rayIntersectionResults r;
			CVector2D fwd( x - x0, y - y0 );
			float l = fwd.Length();
			fwd = fwd.Normalize();
			CVector2D rgt = fwd.beta();
			if( GetRayIntersection( CVector2D( x0, y0 ), fwd, rgt, l, m_bounds->m_radius, destinationCollisionObject, &r ) )
			{
				glEnd();
				glBegin( GL_LINES );
				glColor3f( 1.0f, 0.0f, 0.0f );
				glVertex3f( x0 + fwd.x * r.distance, GetAnchorLevel( x0 + fwd.x * r.distance, y0 + fwd.y * r.distance ) + 0.25f, y0 + fwd.y * r.distance );
				glVertex3f( r.position.x, GetAnchorLevel( r.position.x, r.position.y ) + 0.25f, r.position.y );
				glEnd();
				glBegin( GL_LINE_STRIP );
				glVertex3f( x0, GetAnchorLevel( x0, y0 ), y0 );
			}
			switch( it->m_type )
			{
				case CEntityOrder::ORDER_GOTO:
				glColor3f( 1.0f, 0.0f, 0.0f );
				break;
				case CEntityOrder::ORDER_GOTO_COLLISION:
				glColor3f( 1.0f, 0.5f, 0.5f );
				break;
				case CEntityOrder::ORDER_GOTO_NOPATHING:
				case CEntityOrder::ORDER_GOTO_SMOOTHED:
				glColor3f( 0.5f, 0.5f, 0.5f );
				break;
				case CEntityOrder::ORDER_PATROL:
				glColor3f( 0.0f, 1.0f, 0.0f );
				break;
				default:
				continue;
			}

			glVertex3f( x, GetAnchorLevel( x, y ) + 0.25f, y );
		}

		glEnd();
		glShadeModel( GL_SMOOTH );
	}

	glColor3f( 1.0f, 1.0f, 1.0f );
	if( GetCollisionObject( this ) )
		glColor3f( 0.5f, 0.5f, 1.0f );
	m_bounds->Render( GetAnchorLevel( m_position.X, m_position.Z ) + 0.25f ); //m_position.Y + 0.25f );
}
Example #2
0
/// this will animate and update the state as required
void cRubikSnake::Update( float _fDeltaTime )
{
    TSRVector3 vRayStart;
    TSRVector3 vRayDirection;
            
    m_pCamera->ComputeRay( ( int ) Mouse()->m_Loc.x, ( int ) Mouse()->m_Loc.y, vRayStart, vRayDirection );

	Graphics()->SetDepthStencilState( Graphics()->m_DefaultDepthStencilState );

    m_SelectedIndex = GetRayIntersection( m_pCamera->m_Loc, vRayDirection );


    m_ArcBall.SetBounds( ( float ) Graphics()->m_uiWidth, ( float )Graphics()->m_uiHeight );

	_fDeltaTime = _fDeltaTime * m_fSpeed;
    // first calculate where the center of it will be...to make the camera be looking at it
    TSRMatrix4 currentMatrix;
    currentMatrix.MakeIdent();

    TSRGlobalConstants.PushMatrix();
    TSRGlobalConstants.LoadIdentity();
    m_Center.Assign( 0.0f, 0.0f, 0.0f );
    for ( unsigned int i = 0; i < m_Angles.size(); i++ )
    {
        TSRGlobalConstants.MultMatrix( m_Transform.d );
        TSRGlobalConstants.Rotate( m_Angles[ i ], 0.0f, 1.0f, 0.0f );
        TSRGlobalConstants.Translate( -0.5f, -0.5f, 0.0f );
        TSRGlobalConstants.GetWorldMatrix( currentMatrix.d );
        m_Center += currentMatrix.GetLoc();
    }
    TSRGlobalConstants.PopMatrix();
    m_Center = m_Center / ( float )m_Angles.size();
	if ( m_State == SnakeState_Waiting )
    {
		return;
    }

	if ( m_State == SnakeState_Resetting )
	{
		for ( unsigned int i = 0; i < m_Angles.size(); i++ )
		{
			m_Angles[ i ] -= m_ResetAngleSteps[ i ];
		}

		m_iStepsRemaining--;

		if ( m_iStepsRemaining == 0 )
		{
			m_State = SnakeState_Waiting;
		}
		return;
	}

	if ( m_State == SnakeState_Moving )
	{
		m_Angles[ m_iCurrentMoveID ] += m_fMoveStep;
		m_iStepsRemaining--;

		if ( m_iStepsRemaining == 0 )
		{
			m_State = SnakeState_Waiting;
            Save();
		}
	}
}