Thread: Animation

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Animation

    This is an area where I really need some help. Really really.

    For animated map tiles (water etc) I was thinking about having one image file per frame, loading them in at load time then cycling through them during the render loop. Does this sound about right?

    The biggy is character animation. Big in that I have absolutely no idea how to make a start with it.

    Vital info:

    OpenGL, using orthographic mode.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Depending on what you're animating for the tiles, you may be able to get away with UV scrolling. If not, cycling through different images is probably your best option. The only other option would be to animate them procedurally, which means creating the texture based on some coded algorithm.

    Character animation can be done the same way. It might be worth it to look into setting up characters in tree like structure, so you only have to animate certain areas. However, the overhead of managing the tree and the headaches of writing it could make it completely not worth the time.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Yeah I am looking for something relatively simple - tis my first game after all. I've taken oath with myself to actually finish this one too

    EDIT: I mean first game using a graphics API.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You can do animation several ways as skorman has said.

    It depends on how you are managing your resources. Using the u,v method is extremely fast, yet requires you to have the texture set to the texture that contains these images. If you are only storing one sprite sequence per image, you won't gain any performance over switching images to do animation.

    UV based
    Code:
    class CAnimSeq;
    
    class CAnimFrame
    {
      friend class CAnimSeq;
      float m_fU,m_fV;
    
      float m_fFrameTime;
      float m_fOffsetX,m_fOffsetY;
      ....
    };
    
    class CAnimSeq
    {
      CAnimFrame *m_pFrames;
      DWORD m_dwCurFrame;
      DWORD m_dwNumFrames;
      DWORD m_dwTexID;
      bool m_bActive;
    
      float m_fElapsedTime;
      float m_fPosX,m_fPosY
    
      public:
        CAnimSeq(void):m_pFrames(NULL),m_dwCurFrame(0),m_fElapsedTime(0.0f),m_fPosX(0.0f),m_fPosY(0.0f),m_dwTexID(0) {}
    
        void Create(DWORD dwNumFrames)
        {
           m_pFrames=new CAnimFrame[dwNumFrames];
           m_bActive=true;
        }
           
       .... 
       void Update(float fTimeDelta)
        {
           m_fElapsedTime+=fTimeDelta;
           if (m_fElapsedTime>m_pFrames[m_dwCurFrame])
           {
              m_fElapsedTime=0.0f;
              m_dwCurFrame++;
              if (m_dwCurFrame>m_dwNumFrames) m_bActive=false;
           }
        }
        ....
    
    };
    
    class CAnimSeqContainer
    {
      CAnimSeq *m_pSeqs;
      ....
    };
    To render, render the current frame image at m_fPosX+m_pFrames[dwCurFrame]->m_fOffsetX,m_fPosY+m_pFrames[dwCurFrame]->m_fOffsetY.

    Set the texture to CAnimSeq::m_dwTexID prior to rendering.

    You will need more functions to get this working, but it should help.

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Thanks Bubba
    I'll have a fiddle with this and if I have any problems, I'll post them here (oh happy happy joy joy joy).
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Opengl walking leg animation
    By Bobby230 in forum C Programming
    Replies: 3
    Last Post: 03-05-2006, 03:41 PM
  2. Threads in MFC
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 12-28-2005, 06:03 PM
  3. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM
  4. animation timing
    By Eber Kain in forum Game Programming
    Replies: 2
    Last Post: 06-29-2004, 06:32 PM
  5. 3D animation (difficult?)
    By maes in forum Game Programming
    Replies: 3
    Last Post: 09-08-2003, 10:44 PM