Ejemplo n.º 1
0
void
Entity::UpdateDebug()
{
    int debug = cv_debug_entity.GetI();

    m_DirectionNode->setVisible( debug > 0 );
    m_SolidCollisionNode->setVisible( debug > 0 && m_Solid );
    m_TalkCollisionNode->setVisible( debug > 0 && m_Talkable );

    // debug output
    if( debug > 0 )
    {
        DEBUG_DRAW.SetColour( Ogre::ColourValue::White );
        DEBUG_DRAW.SetScreenSpace( true );
        DEBUG_DRAW.SetTextAlignment( DEBUG_DRAW.CENTER );
        DEBUG_DRAW.SetFadeDistance( 40, 50 );

        Ogre::Vector3 entity_pos = GetPosition();

        DEBUG_DRAW.Text( entity_pos, 0, 0, m_Name );
        DEBUG_DRAW.Text( entity_pos, 0, 12, m_AnimationCurrentName );

        if( debug > 1 )
        {
            static Ogre::String move_state_string[] = { "NONE", "WALKMESH", "LINEAR", "JUMP" };

            DEBUG_DRAW.Text( entity_pos, 0, 24, Ogre::StringConverter::toString( entity_pos ) );
            DEBUG_DRAW.Text( entity_pos, 0, 36, "Triangle: " + Ogre::StringConverter::toString( m_MoveTriangleId ) );
            DEBUG_DRAW.Text( entity_pos, 0, 48, "Move state: " + move_state_string[ m_State ] );
            switch( m_State )
            {
                case Entity::WALKMESH:
                {
                    DEBUG_DRAW.Line3d( entity_pos, m_MovePosition );
                }
                break;

                case Entity::LINEAR:
                {
                    DEBUG_DRAW.Text( m_LinearStart, 0, 0, "Start: " + Ogre::StringConverter::toString( m_LinearStart ) );
                    DEBUG_DRAW.Text( m_LinearEnd, 0, 0, "End: " + Ogre::StringConverter::toString( m_LinearEnd ) );
                    DEBUG_DRAW.Line3d( m_LinearStart, m_LinearEnd );
                }
                break;

                case Entity::JUMP:
                {
                    DEBUG_DRAW.Text( m_JumpStart, 0, 0, "Start: " + Ogre::StringConverter::toString( m_JumpStart ) );
                    DEBUG_DRAW.Text( m_JumpEnd, 0, 0, "End: " + Ogre::StringConverter::toString( m_JumpEnd ) );
                    Ogre::Vector3 distance = m_JumpEnd - m_JumpStart;
                    Ogre::Vector3 pos1, pos2, pos3;
                    pos1.x = m_JumpStart.x + distance.x * 0.25f;
                    pos1.y = m_JumpStart.y + distance.y * 0.25f;
                    float current1 = m_JumpSeconds / 4;
                    pos1.z = current1 * current1 * -13.08f + current1 * ( ( distance.z ) / m_JumpSeconds + m_JumpSeconds * 13.08f ) + m_JumpStart.z;
                    pos2.x = m_JumpStart.x + distance.x * 0.5f;
                    pos2.y = m_JumpStart.y + distance.y * 0.5f;
                    float current2 = current1 * 2;
                    pos2.z = current2 * current2 * -13.08f + current2 * ( ( distance.z ) / m_JumpSeconds + m_JumpSeconds * 13.08f ) + m_JumpStart.z;
                    pos3.x = m_JumpStart.x + distance.x * 0.75f;
                    pos3.y = m_JumpStart.y + distance.y * 0.75f;
                    float current3 = current1 * 3;
                    pos3.z = current3 * current3 * -13.08f + current3 * ( ( distance.z ) / m_JumpSeconds + m_JumpSeconds * 13.08f ) + m_JumpStart.z;
                    DEBUG_DRAW.Line3d( m_JumpStart, pos1 );
                    DEBUG_DRAW.Line3d( pos1, pos2 );
                    DEBUG_DRAW.Line3d( pos2, pos3 );
                    DEBUG_DRAW.Line3d( pos3, m_JumpEnd );
                }
                break;
            }
        }
    }
}
Ejemplo n.º 2
0
void
UiWidget::Update()
{
    if(m_Visible != true)
    {
        return;
    }

    if(m_AnimationCurrent != nullptr)
    {
        float delta_time = Timer::getSingleton().GetGameTimeDelta();
        float time = m_AnimationCurrent->GetTime();

        // if animation ended
        if(time + delta_time >= m_AnimationEndTime)
        {
            if(time != m_AnimationEndTime)
            {
                m_AnimationCurrent->AddTime(m_AnimationEndTime - time);
            }

            for(unsigned int i = 0; i < m_AnimationSync.size(); ++i)
            {
                ScriptManager::getSingleton().ContinueScriptExecution(m_AnimationSync[i]);
            }
            m_AnimationSync.clear();

            if(m_AnimationState == UiAnimation::DEFAULT && m_AnimationDefault != "")
            {
                // in case of cycled default we need to sync with end
                time = time + delta_time - m_AnimationCurrent->GetLength();
                PlayAnimation(m_AnimationDefault, UiAnimation::DEFAULT, time, -1);
            }
            else
            {
                m_AnimationCurrent = NULL;
            }
        }
        else
        {
            m_AnimationCurrent->AddTime(delta_time);
        }
    }
    else if( m_AnimationCurrent == NULL && m_AnimationState == UiAnimation::DEFAULT && m_AnimationDefault != "" )
    {
        PlayAnimation( m_AnimationDefault, UiAnimation::DEFAULT, 0, -1 );
    }



    if( m_UpdateTransformation == true )
    {
        UpdateTransformation();
    }



    for( unsigned int i = 0; i < m_Children.size(); ++i )
    {
        m_Children[ i ]->Update();
    }


    // debug output
    if(cv_debug_ui.GetI() >= 1)
    {
        float local_x1 = -m_FinalOrigin.x;
        float local_y1 = -m_FinalOrigin.y;
        float local_x2 = m_FinalSize.x + local_x1;
        float local_y2 = m_FinalSize.y + local_y1;
        float x = m_FinalTranslate.x;
        float y = m_FinalTranslate.y;

        DEBUG_DRAW.SetScreenSpace(true);

        DEBUG_DRAW.SetColour(Ogre::ColourValue(1, 0, 0, 1));

        int x1, y1, x2, y2, x3, y3, x4, y4;

        if(m_FinalRotation != 0)
        {
            float cos = Ogre::Math::Cos(Ogre::Radian(Ogre::Degree(m_FinalRotation)));
            float sin = Ogre::Math::Sin(Ogre::Radian(Ogre::Degree(m_FinalRotation)));

            x1 = static_cast<int>(local_x1 * cos - local_y1 * sin + x);
            y1 = static_cast<int>(local_x1 * sin + local_y1 * cos + y);
            x2 = static_cast<int>(local_x2 * cos - local_y1 * sin + x);
            y2 = static_cast<int>(local_x2 * sin + local_y1 * cos + y);
            x3 = static_cast<int>(local_x2 * cos - local_y2 * sin + x);
            y3 = static_cast<int>(local_x2 * sin + local_y2 * cos + y);
            x4 = static_cast<int>(local_x1 * cos - local_y2 * sin + x);
            y4 = static_cast<int>(local_x1 * sin + local_y2 * cos + y);
        }
        else
        {
            x1 = static_cast<int>(local_x1 + x);
            y1 = static_cast<int>(local_y1 + y);
            x2 = static_cast<int>(local_x2 + x);
            y2 = static_cast<int>(local_y1 + y);
            x3 = static_cast<int>(local_x2 + x);
            y3 = static_cast<int>(local_y2 + y);
            x4 = static_cast<int>(local_x1 + x);
            y4 = static_cast<int>(local_y2 + y);
        }

        // slightly modify to let show things that are on board of screen
        DEBUG_DRAW.Line(static_cast<float>(x1), static_cast<float>(y1 + 1), static_cast<float>(x2), static_cast<float>(y2 + 1));
        DEBUG_DRAW.Line(static_cast<float>(x2 - 1), static_cast<float>(y2), static_cast<float>(x3 - 1), static_cast<float>(y3));
        DEBUG_DRAW.Line(static_cast<float>(x3), static_cast<float>(y3), static_cast<float>(x4), static_cast<float>(y4));
        DEBUG_DRAW.Line(static_cast<float>(x4), static_cast<float>(y4), static_cast<float>(x1), static_cast<float>(y1));

        // draw translation
        DEBUG_DRAW.SetColour(Ogre::ColourValue(0, 1, 0, 1));
        Ogre::Vector2 area_origin = (m_Parent != nullptr) ? m_Parent->GetFinalOrigin() : Ogre::Vector2::ZERO;
        Ogre::Vector2 area_translate = (m_Parent != nullptr) ? m_Parent->GetFinalTranslate() : Ogre::Vector2::ZERO;
        Ogre::Vector2 pos = area_translate - area_origin;
        DEBUG_DRAW.Line(pos.x, pos.y, x, y);
        DEBUG_DRAW.Quad(x - 2, y - 2, x + 2, y - 2, x + 2, y + 2, x - 2, y + 2);

        if(cv_debug_ui.GetI() >= 2)
        {
            DEBUG_DRAW.SetColour(Ogre::ColourValue::White);
            DEBUG_DRAW.SetTextAlignment(DEBUG_DRAW.LEFT);
            DEBUG_DRAW.Text(static_cast<float>(x1 + 3), static_cast<float>(y1), m_PathName);
            DEBUG_DRAW.Text(static_cast<float>(x1 + 3), static_cast<float>(y1 + 12), GetCurrentAnimationName());
        }

        // draw origin
        DEBUG_DRAW.SetColour(Ogre::ColourValue(1, 0, 0, 1));
        DEBUG_DRAW.Line(x, y, static_cast<float>(x1), static_cast<float>(y1 + 1));
    }
}