Changeset 471 for cafu/trunk/Games

Show
Ignore:
Timestamp:
01/22/12 11:33:07 (4 months ago)
Author:
Carsten
Message:

Game code:
Added the new model blending feature also to static detail entities:
Those that are animated and change their animation sequence are now smoothly blended from the first sequence to the next.
(This is nicely demonstrated in map Kidney with the Skeleton and the Face Hugger.)

Location:
cafu/trunk/Games/DeathMatch
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/Games/DeathMatch/Code/CompanyBot.cpp

    r470 r471  
    421421        } 
    422422 
    423         m_LastStdAE=m_CompanyBotModel->GetAnimExprPool().GetStandard(State.ModelSequNr, State.ModelFrameNr); 
     423        m_LastStdAE=m_CompanyBotModel->GetAnimExprPool().GetStandard(State.ModelSequNr, 0.0f); 
    424424        m_AnimExpr =m_CompanyBotModel->GetAnimExprPool().GetBlend(m_AnimExpr, m_LastStdAE, BlendTime); 
    425425    } 
  • cafu/trunk/Games/DeathMatch/Code/StaticDetailModel.cpp

    r469 r471  
    136136      m_PlayAnim(State.Flags), 
    137137      m_SequNr(State.ModelSequNr), 
    138       m_FrameNr(0.0f), 
     138      m_AnimExpr(),     // Inited in the ctor body below. 
     139      m_LastStdAE(), 
    139140      GuiName(), 
    140141      Gui(NULL) 
     
    191192 
    192193 
     194    m_LastStdAE=m_Model->GetAnimExprPool().GetStandard(m_SequNr, 0.0f); 
     195    m_AnimExpr =m_LastStdAE; 
     196    m_SequNr   =m_LastStdAE->GetSequNr();   // Set m_SequNr to the m_LastStdAE's "normalized" value. 
     197 
     198 
    193199    // Set the proper Dimensions bounding box for this model. 
    194200    // Note that the bounding box depends on the current model sequence, 
    195201    // and it must be properly scaled and rotated for world space. 
    196202    VectorT V[8]; 
    197     m_Model->GetSharedPose(m_Model->GetAnimExprPool().GetStandard(m_SequNr, 0.0f))->GetBB().AsBoxOfDouble().GetCornerVertices(V); 
     203    m_Model->GetSharedPose(m_AnimExpr)->GetBB().AsBoxOfDouble().GetCornerVertices(V); 
    198204 
    199205    for (unsigned int VertexNr=0; VertexNr<8; VertexNr++) 
     
    262268    { 
    263269        case EventID_RestartSequ: 
    264             m_FrameNr=0.0f; 
     270            m_LastStdAE->SetFrameNr(0.0f); 
    265271            break; 
    266272    } 
     
    288294 
    289295 
    290     AnimPoseT* Pose=m_Model->GetSharedPose(m_Model->GetAnimExprPool().GetStandard(m_SequNr, m_FrameNr)); 
     296    AnimPoseT* Pose=m_Model->GetSharedPose(m_AnimExpr); 
    291297    Pose->Draw(-1 /*default skin*/, LodDist); 
    292298 
     
    334340void EntStaticDetailModelT::PostDraw(float FrameTime, bool /*FirstPersonView*/) 
    335341{ 
     342    const int SequNr=(m_SequNr==255) ? -1 : m_SequNr;   // This is a hack, because m_SequNr actually has the wrong (unsigned) datatype... 
     343 
     344    if (SequNr != m_LastStdAE->GetSequNr()) 
     345    { 
     346        if (m_PlayAnim) 
     347        { 
     348            m_LastStdAE=m_Model->GetAnimExprPool().GetStandard(SequNr, 0.0f); 
     349            m_AnimExpr =m_Model->GetAnimExprPool().GetBlend(m_AnimExpr, m_LastStdAE, 3.0f); 
     350        } 
     351        else 
     352        { 
     353            m_LastStdAE->SetSequNr(m_SequNr); 
     354        } 
     355 
     356        m_SequNr=m_LastStdAE->GetSequNr();  // Set m_SequNr to the m_LastStdAE's "normalized" value. 
     357    } 
     358 
    336359    if (Gui!=NULL) 
    337360    { 
     
    346369    { 
    347370        // Advance the client-local animation. 
    348         IntrusivePtrT<AnimExprStandardT> StdAE=m_Model->GetAnimExprPool().GetStandard(m_SequNr, m_FrameNr); 
    349  
    350         StdAE->AdvanceTime(FrameTime, true); 
    351         m_FrameNr=StdAE->GetFrameNr(); 
    352     } 
    353  
    354  
    355     /* glColor3f(1.0, 0.0, 0.0); 
    356  
    357     VectorT V1=VectorT(State.Dimensions.Min.x, State.Dimensions.Min.y, State.Dimensions.Min.z)+State.Origin; 
    358     VectorT V2=VectorT(State.Dimensions.Min.x, State.Dimensions.Min.y, State.Dimensions.Max.z)+State.Origin; 
    359     VectorT V3=VectorT(State.Dimensions.Min.x, State.Dimensions.Max.y, State.Dimensions.Min.z)+State.Origin; 
    360     VectorT V4=VectorT(State.Dimensions.Min.x, State.Dimensions.Max.y, State.Dimensions.Max.z)+State.Origin; 
    361     VectorT V5=VectorT(State.Dimensions.Max.x, State.Dimensions.Min.y, State.Dimensions.Min.z)+State.Origin; 
    362     VectorT V6=VectorT(State.Dimensions.Max.x, State.Dimensions.Min.y, State.Dimensions.Max.z)+State.Origin; 
    363     VectorT V7=VectorT(State.Dimensions.Max.x, State.Dimensions.Max.y, State.Dimensions.Min.z)+State.Origin; 
    364     VectorT V8=VectorT(State.Dimensions.Max.x, State.Dimensions.Max.y, State.Dimensions.Max.z)+State.Origin; 
    365  
    366     glBegin(GL_LINES); 
    367         glVertex3f(V1.x, V1.z, -V1.y); glVertex3f(V2.x, V2.z, -V2.y); 
    368         glVertex3f(V3.x, V3.z, -V3.y); glVertex3f(V4.x, V4.z, -V4.y); 
    369         glVertex3f(V5.x, V5.z, -V5.y); glVertex3f(V6.x, V6.z, -V6.y); 
    370         glVertex3f(V7.x, V7.z, -V7.y); glVertex3f(V8.x, V8.z, -V8.y); 
    371  
    372         glVertex3f(V1.x, V1.z, -V1.y); glVertex3f(V3.x, V3.z, -V3.y); 
    373         glVertex3f(V3.x, V3.z, -V3.y); glVertex3f(V7.x, V7.z, -V7.y); 
    374         glVertex3f(V7.x, V7.z, -V7.y); glVertex3f(V5.x, V5.z, -V5.y); 
    375         glVertex3f(V5.x, V5.z, -V5.y); glVertex3f(V1.x, V1.z, -V1.y); 
    376  
    377         glVertex3f(V2.x, V2.z, -V2.y); glVertex3f(V4.x, V4.z, -V4.y); 
    378         glVertex3f(V4.x, V4.z, -V4.y); glVertex3f(V8.x, V8.z, -V8.y); 
    379         glVertex3f(V8.x, V8.z, -V8.y); glVertex3f(V6.x, V6.z, -V6.y); 
    380         glVertex3f(V6.x, V6.z, -V6.y); glVertex3f(V2.x, V2.z, -V2.y); 
    381     glEnd(); */ 
     371        m_AnimExpr->AdvanceTime(FrameTime, true); 
     372    } 
    382373} 
    383374 
     
    418409bool EntStaticDetailModelT::GetGuiPlane(unsigned int GFNr, Vector3fT& GuiOrigin, Vector3fT& GuiAxisX, Vector3fT& GuiAxisY) const 
    419410{ 
    420     if (!m_Model->GetSharedPose(m_Model->GetAnimExprPool().GetStandard(m_SequNr, m_FrameNr))->GetGuiPlane(GFNr, GuiOrigin, GuiAxisX, GuiAxisY)) return false; 
     411    if (!m_Model->GetSharedPose(m_AnimExpr)->GetGuiPlane(GFNr, GuiOrigin, GuiAxisX, GuiAxisY)) return false; 
    421412 
    422413    // Okay, got the plane. Now transform it from model space into world space. 
     
    471462    EntStaticDetailModelT* Ent=(EntStaticDetailModelT*)cf::GameSys::ScriptStateT::GetCheckedObjectParam(LuaState, 1, TypeInfo); 
    472463 
    473     lua_pushinteger(LuaState, Ent->m_SequNr); 
     464    lua_pushinteger(LuaState, Ent->m_LastStdAE->GetSequNr()); 
    474465    return 1; 
    475466} 
     
    480471    EntStaticDetailModelT* Ent=(EntStaticDetailModelT*)cf::GameSys::ScriptStateT::GetCheckedObjectParam(LuaState, 1, TypeInfo); 
    481472 
    482     Ent->m_SequNr=std::max(0, luaL_checkinteger(LuaState, 2)); 
    483     Ent->m_FrameNr=0.0f; 
    484     Ent->State.Events^=(1 << EventID_RestartSequ); 
    485  
    486     if (Ent->m_SequNr >= int(Ent->m_Model->GetAnims().Size())) Ent->m_SequNr=0; 
     473    Ent->m_LastStdAE->SetSequNr(std::max(0, luaL_checkinteger(LuaState, 2))); 
     474    Ent->m_LastStdAE->SetFrameNr(0.0f); 
     475    Ent->m_SequNr=Ent->m_LastStdAE->GetSequNr();    // Set m_SequNr to the m_LastStdAE's "normalized" value. 
    487476    return 0; 
    488477} 
     
    493482    EntStaticDetailModelT* Ent=(EntStaticDetailModelT*)cf::GameSys::ScriptStateT::GetCheckedObjectParam(LuaState, 1, TypeInfo); 
    494483 
    495     Ent->m_FrameNr=0.0f; 
     484    Ent->m_LastStdAE->SetFrameNr(0.0f); 
    496485    Ent->State.Events^=(1 << EventID_RestartSequ); 
    497486    return 0; 
  • cafu/trunk/Games/DeathMatch/Code/StaticDetailModel.hpp

    r457 r471  
    2424 
    2525#include "../../BaseEntity.hpp" 
     26#include "Models/AnimExpr.hpp" 
    2627 
    2728 
     
    7576    char&             m_PlayAnim;   ///< If 1, play the animation, i.e. advance the frames over time. If 0, keep still. This is a reference to State.Flags to have it sync'ed over the network. 
    7677    char&             m_SequNr;     ///< The number of the animation sequence to play. This is a reference to State.ModelSequNr to have it sync'ed over the network. 
    77     float             m_FrameNr;    ///< The current frame of the played animation sequence. Used <em>independently</em> on the server and the clients; only a <em>restart</em> of a sequence is sync'ed over the network via the EventID_RestartSequ event. 
     78 
     79    mutable IntrusivePtrT<AnimExpressionT>   m_AnimExpr;    ///< The state of the currently playing animation sequence. Used <em>independently</em> on the server and the clients; only a <em>restart</em> of a sequence is sync'ed over the network via the EventID_RestartSequ event. 
     80    mutable IntrusivePtrT<AnimExprStandardT> m_LastStdAE;   ///< The most recent standard expression that we set (as a subexpression of m_AnimExpr). 
     81 
    7882    std::string       GuiName;      ///< If our "gui" entity key is set, store the value here. 
    7983    cf::GuiSys::GuiI* Gui;          ///< If the model has GUI fixtures, we load the GUI here, *both* on the server- as well as on the client-side. 
  • cafu/trunk/Games/DeathMatch/GUIs/TechDemo/gui1.cgui

    r40 r471  
    6161    self:set("rect", 43, 91, 558, 324); 
    6262    self:set("backColor", 1, 1, 1, 0);      -- Set alpha value to zero! 
    63     self:set("text", "Planned features for the next (autumn '08) release:\n".. 
     63    self:set("text", "Planned features for the next release:\n".. 
    6464             "    1) Vegetation for the island\n".. 
    6565             "    2) better model support\n".. 
  • cafu/trunk/Games/DeathMatch/Worlds/Kidney.lua

    r253 r471  
    1111end 
    1212 
    13 Skeleton.delay=5 
     13Skeleton.delay=6 
    1414thread(CycleAnimSequences, Skeleton); 
    1515 
    16 FaceHugger.delay=3 
     16FaceHugger.delay=4 
    1717thread(CycleAnimSequences, FaceHugger);