Animation in SDL

This is a discussion on Animation in SDL within the Game Programming forums, part of the General Programming Boards category; I'm just using BSP's in 3d. I didn't even know you could use them in 2d!?!...

  1. #16
    Registered User
    Join Date
    Jun 2006
    Posts
    9
    I'm just using BSP's in 3d. I didn't even know you could use them in 2d!?!

  2. #17
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Of course you can. AFAIK it's just splitting up a large area into a tree.
    I don't fully understand it but I guess you can apply it to 2D.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #18
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291
    I don't fully understand it but I guess you can apply it to 2D.
    Sorta like, oh, I dunno, DOOM?
    Last edited by Cheeze-It; 06-05-2006 at 03:44 AM.
    Staying away from General.

  4. #19
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Oh yeah.
    DOOM used raycasting right? I was reading an article about that and Wolf3D the other day.

    EDIT: That being raycasting and I know it has nothing to do with BSP. Meh.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  5. #20
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Animation is just changing textures in a quad at a certain rate. That SDL code looks hideous compared to actually just using ID3DXSprite or coding your own.

    What you need:

    CAnimFrame - a class to wrap one frame of animation
    CAnimSeq - a class to wrap one full sequence

    Each CAnimSeq resides in an array. You will need an object factory of sorts that can return a new instance of CAnimSeq so you can have as many objects using the same animation as you want and yet they won't conflict. Your animations act as a template that can be used anywhere in the game and on any poly, be it a quad, triangle, or something else.

    Hopefully that might break it down better for you.

    I use a system of ID's where the ID represent the index into the array for CAnimFrame's and for CAnimSeq's. If you take this approach animation can be done like this:

    Code:
    void CAnimSeq::Update(float fTimeDelta)
    {
      m_fTimeElapsed+=fTimeDelta;
    
      int iNumFramesToAdvance=static_cast<int>(m_fTimeElapsed/m_fFrameTime);
    
      m_iCurrentFrame+=iNumFramesToAdvance;
    
      if (m_iCurrentFrame>m_iMaxFrames)
      {
         if (m_bLooping)
         {
            m_iCurrentFrame-=m_iMaxFrames;
         } else m_bActive=0;
       }
    }
    
    void CAnimSeq::Render(void)
    {
      ...
      if (!m_bActive) return;
    
      DWORD dwTextureID=m_pFrames[m_iCurrentFrame];
    
      m_pDevice->SetTexture(m_pTextureMgr->GetTexture(dwTextureID));
      ...
      //Draw the quad
    }
    Not sure about the data type cast there and haven't tested this as is, but I'm sure you can figure that part out.

    Now if you want to make the textures accessible w/o having to call the texture manager then just use a method by which you get pointers to them (CAnimFrame's), and/or their actual textures (IDirect3DTexture9) at run-time. Then instead of calling texture manager you just do an array access inside of your render and it should work. So keep and array like this:

    Code:
     ...
     IDirect3DTexture9 *m_pFrameImages;

    You can also bypass CAnimFrame since it's really just an ID in the texture manager's array, but you may want to keep it around to add functionality to frames later on.

    I'm not sure what SDL is doing there, but according to that website, it's more of a hassle than just coding your own in pure D3D.

    Also, GetTickCount() seems to work just fine for me but I've also used QueryPerformanceCounter().

    I'll give you the vertex structure you will need for simple textured quad's with color support at the vertices.

    Code:
    //MSVC 6 style
    #ifndef AnimVertex_h
    #define AnimVertex_h
    
    #include "d3dx9.h"
    
    #define AnimVertexFVF D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;
    
    struct AnimVertex
    {
      D3DXVECTOR3  Pos;
      float RHW;
      D3DXCOLOR Diffuse;
      float u,v;
    
      AnimVertex(float x,float y,float z, D3DXCOLOR _diffuse,float _u,float _v):Pos(&D3DXVECTOR3(x,y,z)),RHW(1.0f),Diffuse(_diffuse),
    u(_u),v(_v) { }
    
      AnimVertex(void):Pos(&D3DXVECTOR3(0.0f,0.0f,0.0f)),RHW(1.0f),Diffuse(0),u(0.0f),v(0.0f) { }
    };
    
    #endif
    Use #pragma once for MSVC .NET 2005 instead of that #ifndef gobbly gook.
    Last edited by VirtualAce; 06-05-2006 at 05:22 AM.

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

    The way I'm doing it in SDL isn't that bad but I don't really like it either. I load the animation sheet into a surface then move an SDL_Rect across it in increments equal to the width of each frame.

    I'm going to drop SDL starting from today and start over with D3D.

    Then I can use DirectInput too, which I like but it has problems with SDL (or SDL has problems with DI). SDL input is really crappy.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #22
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291
    Quote Originally Posted by ahluka
    Oh yeah.
    DOOM used raycasting right? I was reading an article about that and Wolf3D the other day.

    EDIT: That being raycasting and I know it has nothing to do with BSP. Meh.
    Wolf3d used Raycasting. Doom didn't. As far as I
    know, anyway. I could be wrong.
    Last edited by Cheeze-It; 06-05-2006 at 03:30 PM.
    Staying away from General.

  8. #23
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Apparently DOOM did but the engine is more advanced, allowing for different height walls of arbitary shape.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  9. #24
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    DOOM used heightmap based raycasting but it was still raycasting. More like voxels than anything, but not true voxels. It heightmapped walls to produce layers and the did floor and sky mapping to fill in the gaps between the heights. This is how they got steps in the floor or indentations in the floor. Notice in DOOM when you look up or down the view really begins to fall apart.

    The only complete 3D 6 DOF heightmapped engines I've seen are from Novalogic's Delta Force 1, 2; Armored Fist 1,2; and Comanche 1,2. How they got 6 DOF in a heightmapped voxel engine is beyond me. They probably made use of vertical ray coherence as well as a host of other tricks to get it to look right. But it does look right and it looked good for the day it was made in. Outcast tried to do this type of engine but in my opinion failed as it's framerates are not good, visuals don't look nearly as good as Novalogic's, and it's res is limited to a very odd size.

    I believe Descent 1 was raycasted but I'm not sure of the method. Dark Forces 1 from LucasArts was also raycasted using a more DOOM-like technology. The non-ortho raycasting is done via line-segments representing walls and doing a ray to line intersection test. The BSP is used to weed out all of the lines in the world that are not in the frustum. Otherwise the thing would crawl.

    It's a simple test by taking 2 equations of a line, making them equal to each other, eliminating knowns since you have 2 unknowns (can eliminate x or y depending on casting type since you know the cellsize of your world), and solving the equation both for x and y. You can also raycast using tangents.

    Gamedev has a paper about non-ortho raycasting.
    Last edited by VirtualAce; 06-06-2006 at 05:35 AM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems compiling this SDL app
    By Rider in forum C++ Programming
    Replies: 3
    Last Post: 03-27-2007, 12:22 PM
  2. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 05:48 AM
  3. SDL and MinGW Studio
    By Vicious in forum Tech Board
    Replies: 0
    Last Post: 07-30-2004, 09:59 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. sdl in c++
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-07-2002, 07:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21