You have to make the animation update through the class, I made an object class to play and loop animations like GDK used to.
CObject.h
#pragma once
class CObject
{
public:
struct sObjectData
{
char* szModel,
*szTexture_D, *szTexture_N, *szTexture_S,
*szEffect;
int iObjectID,
iTexture_D_ID, iTexture_N_ID, iTexture_S_ID,
iEffectID;
float fPositionX, fPositionY, fPositionZ,
fRotationX, fRotationY, fRotationZ,
fScaleX, fScaleY, fScaleZ;
short bAnimate;
};
sObjectData sData;
CObject();
~CObject();
void Load(char* szModel);
void Load(char* szModel, char* szTexture_D);
void Load(char* szModel, char* szTexture_D, char* szTexture_N);
void Load(char* szModel, char* szTexture_D, char* szTexture_N, char* szTexture_S);
void Instance(int iObjectID);
void SetFPS(float framesPerSec);
void animateObject(int curTime);
int GetID();
short GetAnimState();
short PlayAnimation(int startFrame, int endFrame);
short LoopAnimation(int startFrame, int endFrame);
private:
int m_ID;
int m_startFrame, m_endFrame, m_numFrames;
float m_curFrame, m_fPerSec;
int m_prevTime;
};
CObject.cpp
#include "CObject.h"
#include "DarkGDK.h"
CObject::CObject()
{
sData.bAnimate = 0;
m_fPerSec = 60; // Default to 60 fps
}
CObject::~CObject()
{
}
void CObject::Load(char* szModel)
{
sData.iObjectID = ObjectResource->Pop();
sData.szModel = szModel;
dbLoadObject(sData.szModel, sData.iObjectID);
}
void CObject::Load(char* szModel, char* szTexture_D)
{
sData.iObjectID = ObjectResource->Pop();
sData.szModel = szModel;
dbLoadObject(sData.szModel, sData.iObjectID);
sData.iTexture_D_ID = ImageResource->Pop();
sData.szTexture_D = szTexture_D;
dbLoadImage(sData.szTexture_D, sData.iTexture_D_ID);
dbTextureObject(sData.iObjectID, sData.iTexture_D_ID);
}
void CObject::Load(char* szModel, char* szTexture_D, char* szTexture_N)
{
}
void CObject::Load(char* szModel, char* szTexture_D, char* szTexture_N, char* szTexture_S)
{
}
void CObject::Instance(int iObjectID)
{
sData.iObjectID = ObjectResource->Pop();
dbInstanceObject(sData.iObjectID, iObjectID);
}
void CObject::SetFPS(float framesPerSec)
{
m_ID = sData.iObjectID;
m_fPerSec = framesPerSec;
m_prevTime = dbTimer();
}
void CObject::animateObject(int curTime)
{
if (sData.bAnimate == 1)
{
float frameProgress = float(curTime - m_prevTime) * m_fPerSec / 1000.0;
m_curFrame += frameProgress;
m_curFrame = m_curFrame - m_startFrame;
float end = m_endFrame - m_startFrame;
m_curFrame = (m_curFrame - floor(m_curFrame/end) * end) + m_startFrame;
m_prevTime = curTime;
dbSetObjectFrame(m_ID, int(m_curFrame + 0.5));
if ((int)m_curFrame == (m_endFrame - 1))
{
sData.bAnimate = 0;
dbSetObjectFrame(GetID(), m_startFrame);
}
}
if (sData.bAnimate == 2)
{
float frameProgress = float(curTime - m_prevTime) * m_fPerSec / 1000.0;
m_curFrame += frameProgress;
m_curFrame = m_curFrame - m_startFrame;
float end = m_endFrame - m_startFrame;
m_curFrame = (m_curFrame - floor(m_curFrame/end) * end) + m_startFrame;
m_prevTime = curTime;
dbSetObjectFrame(m_ID, int(m_curFrame + 0.5));
}
}
int CObject::GetID()
{
return sData.iObjectID;
}
short CObject::GetAnimState()
{
return sData.bAnimate;
}
short CObject::PlayAnimation(int startFrame, int endFrame)
{
sData.bAnimate = 1;
m_startFrame = startFrame;
m_curFrame = startFrame;
m_endFrame = endFrame;
m_numFrames = m_endFrame - m_startFrame;
dbSetObjectFrame(m_ID, startFrame);
return sData.bAnimate;
}
short CObject::LoopAnimation(int startFrame, int endFrame)
{
sData.bAnimate = 2;
m_startFrame = startFrame;
m_curFrame = startFrame;
m_endFrame = endFrame;
m_numFrames = m_endFrame - m_startFrame;
dbSetObjectFrame(m_ID, startFrame);
return sData.bAnimate;
}
It uses a struct to hold info about the model it is using. It is far from complete but the play and loop animation fuctions should work. You have to call CObject.animateObject(curTime) in the loop. Using it should look like this:
#include "DarkGDK.h"
#include "CObject.h"
void DarkGDK()
{
dbSyncOn();
dbSyncRate(60);
dbSetDisplayMode(1024, 768, 32);
CObject BadGuy;
BadGuy.Load("BadGuy.x", "BadGuy.dds");
BadGuy.SetFPS(60);
BadGuy.LoopAnimation(0, 100);
while (LoopGDK)
{
int curTime = dbTimer();
BadGuy.animateObject(curTIme);
dbSync();
}
return;
}
You will have to replace "ObjectResource->Pop();" and "ImageResource->Pop();" with your own resource mangment function or you can also use techlords:
http://forum.thegamecreators.com/?m=forum_view&t=166572&b=22&msg=1970286#m1970286