forgot to check in ModelTypes.*
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
#ifndef ModelOrSprite_H
|
||||||
|
#define ModelOrSprite_H
|
||||||
|
/*
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
Class: ModelOrSprite
|
||||||
|
|
||||||
|
Desc: A 3D ModelOrSprite.
|
||||||
|
|
||||||
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
||||||
|
Chris Danford
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Actor.h"
|
||||||
|
|
||||||
|
|
||||||
|
class ModelOrSprite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ModelOrSprite () { m_pModel = NULL; m_pSprite = NULL; }
|
||||||
|
virtual ~ModelOrSprite () { delete m_pModel; delete m_pSprite; }
|
||||||
|
|
||||||
|
virtual void Update( float fDelta ) { ASSERT(m_pModel||m_pSprite); if(m_pModel) m_pModel->Update(fDelta); else m_pModel->Update(fDelta); }
|
||||||
|
virtual void DrawPrimitives() { ASSERT(m_pModel||m_pSprite); if(m_pModel) m_pModel->Update(fDelta); else m_pModel->Update(fDelta); }
|
||||||
|
|
||||||
|
void Load( CString sFile )
|
||||||
|
{
|
||||||
|
ASSERT( !m_pModel && !m_pSprite );
|
||||||
|
if( sFile.Right(3)=="txt" )
|
||||||
|
{
|
||||||
|
m_pModel = new Model();
|
||||||
|
m_pModel->Load( sFile );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_pSprite = new Sprite();
|
||||||
|
m_pSprite->Load( sFile );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Model* m_pModel;
|
||||||
|
Sprite* m_pSprite;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
#include "global.h"
|
||||||
|
/*
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
Class: ModelTypes
|
||||||
|
|
||||||
|
Desc: See header.
|
||||||
|
|
||||||
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
||||||
|
Chris Danford
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ModelTypes.h"
|
||||||
|
#include "IniFile.h"
|
||||||
|
#include "RageUtil.h"
|
||||||
|
#include "RageTexture.h"
|
||||||
|
#include "RageTextureManager.h"
|
||||||
|
|
||||||
|
AnimatedTexture::AnimatedTexture()
|
||||||
|
{
|
||||||
|
iCurState = 0;
|
||||||
|
fSecsIntoFrame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimatedTexture::Load( CString sTexOrIniPath )
|
||||||
|
{
|
||||||
|
ASSERT( vFrames.empty() ); // don't load more than once
|
||||||
|
|
||||||
|
CString sDir, sThrowAway;
|
||||||
|
splitrelpath( sTexOrIniPath, sDir, sThrowAway, sThrowAway );
|
||||||
|
|
||||||
|
bool bIsIni = sTexOrIniPath.Right(3).CompareNoCase("ini")== 0;
|
||||||
|
if( bIsIni )
|
||||||
|
{
|
||||||
|
IniFile ini;
|
||||||
|
ini.SetPath( sTexOrIniPath );
|
||||||
|
ini.ReadFile();
|
||||||
|
if( !ini.GetKey("AnimatedTexture") )
|
||||||
|
RageException::Throw( "The animated texture file '%s' doesn't contain a section called 'AnimatedTexture'.", sTexOrIniPath.c_str() );
|
||||||
|
for( int i=0; i<1000; i++ )
|
||||||
|
{
|
||||||
|
CString sFileKey = ssprintf( "Frame%04d", i );
|
||||||
|
CString sDelayKey = ssprintf( "Delay%04d", i );
|
||||||
|
|
||||||
|
CString sFileName;
|
||||||
|
float fDelay = 0;
|
||||||
|
if( ini.GetValue( "AnimatedTexture", sFileKey, sFileName ) &&
|
||||||
|
ini.GetValueF( "AnimatedTexture", sDelayKey, fDelay ) )
|
||||||
|
{
|
||||||
|
RageTextureID ID;
|
||||||
|
ID.filename = sDir+sFileName;
|
||||||
|
ID.bStretch = true;
|
||||||
|
AnimatedTextureState state = {
|
||||||
|
TEXTUREMAN->LoadTexture( ID ),
|
||||||
|
fDelay
|
||||||
|
};
|
||||||
|
vFrames.push_back( state );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RageTextureID ID;
|
||||||
|
ID.filename = sTexOrIniPath;
|
||||||
|
ID.bStretch = true;
|
||||||
|
AnimatedTextureState state = {
|
||||||
|
TEXTUREMAN->LoadTexture( ID ),
|
||||||
|
10
|
||||||
|
};
|
||||||
|
vFrames.push_back( state );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AnimatedTexture::Update( float fDelta )
|
||||||
|
{
|
||||||
|
if( vFrames.empty() )
|
||||||
|
return;
|
||||||
|
ASSERT( iCurState < (int)vFrames.size() );
|
||||||
|
fSecsIntoFrame += fDelta;
|
||||||
|
if( fSecsIntoFrame > vFrames[iCurState].fDelaySecs )
|
||||||
|
iCurState = (iCurState+1) % vFrames.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
RageTexture* AnimatedTexture::GetCurrentTexture()
|
||||||
|
{
|
||||||
|
if( vFrames.empty() )
|
||||||
|
return NULL;
|
||||||
|
ASSERT( iCurState < (int)vFrames.size() );
|
||||||
|
return vFrames[iCurState].pTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimatedTexture::SetState( int iState )
|
||||||
|
{
|
||||||
|
CLAMP( iState, 0, GetNumStates()-1 );
|
||||||
|
iCurState = iState;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AnimatedTexture::GetNumStates()
|
||||||
|
{
|
||||||
|
return vFrames.size();
|
||||||
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
#ifndef ModelTypes_H
|
||||||
|
#define ModelTypes_H
|
||||||
|
/*
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
Class: ModelTypes
|
||||||
|
|
||||||
|
Desc: Types defined in msLib.h. C arrays converted to use std::vector
|
||||||
|
|
||||||
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
||||||
|
Chris Danford
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
*
|
||||||
|
* Constants
|
||||||
|
*
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#define MS_MAX_NAME 32
|
||||||
|
#define MS_MAX_PATH 256
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
*
|
||||||
|
* Types
|
||||||
|
*
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef byte
|
||||||
|
typedef unsigned char byte;
|
||||||
|
#endif /* byte */
|
||||||
|
|
||||||
|
#ifndef word
|
||||||
|
typedef unsigned short word;
|
||||||
|
#endif /* word */
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct msVec2 {
|
||||||
|
float v[2];
|
||||||
|
operator float* () { return v; };
|
||||||
|
operator const float* () const { return v; };
|
||||||
|
} msVec2;
|
||||||
|
typedef struct msVec3 {
|
||||||
|
float v[3];
|
||||||
|
operator float* () { return v; };
|
||||||
|
operator const float* () const { return v; };
|
||||||
|
} msVec3;
|
||||||
|
typedef struct msVec4 {
|
||||||
|
float v[4];
|
||||||
|
operator float* () { return v; };
|
||||||
|
operator const float* () const { return v; };
|
||||||
|
} msVec4;
|
||||||
|
|
||||||
|
|
||||||
|
/* msFlag */
|
||||||
|
typedef enum {
|
||||||
|
eSelected = 1, eSelected2 = 2, eHidden = 4, eDirty = 8, eAveraged = 16, eUnused = 32
|
||||||
|
} msFlag;
|
||||||
|
|
||||||
|
/* msVertex */
|
||||||
|
typedef struct msVertex
|
||||||
|
{
|
||||||
|
// byte nFlags;
|
||||||
|
msVec3 Vertex;
|
||||||
|
msVec2 uv;
|
||||||
|
msVec3 Normal;
|
||||||
|
char nBoneIndex;
|
||||||
|
} msVertex;
|
||||||
|
|
||||||
|
/* msTriangle */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
// word nFlags;
|
||||||
|
word nVertexIndices[3];
|
||||||
|
// word nNormalIndices[3];
|
||||||
|
// msVec3 Normal;
|
||||||
|
// byte nSmoothingGroup;
|
||||||
|
} msTriangle;
|
||||||
|
|
||||||
|
/* msMesh */
|
||||||
|
typedef struct msMesh
|
||||||
|
{
|
||||||
|
// byte nFlags;
|
||||||
|
char szName[MS_MAX_NAME];
|
||||||
|
char nMaterialIndex;
|
||||||
|
|
||||||
|
vector<msVertex> Vertices;
|
||||||
|
|
||||||
|
// vector<msVec3> Normals;
|
||||||
|
|
||||||
|
vector<msTriangle> Triangles;
|
||||||
|
} msMesh;
|
||||||
|
|
||||||
|
/* msMaterial */
|
||||||
|
class RageTexture;
|
||||||
|
|
||||||
|
struct AnimatedTexture
|
||||||
|
{
|
||||||
|
AnimatedTexture();
|
||||||
|
|
||||||
|
void Load( CString sTexOrIniFile );
|
||||||
|
void Update( float fDelta );
|
||||||
|
|
||||||
|
RageTexture* GetCurrentTexture();
|
||||||
|
|
||||||
|
void SetState( int iState );
|
||||||
|
int GetNumStates();
|
||||||
|
|
||||||
|
int iCurState;
|
||||||
|
float fSecsIntoFrame;
|
||||||
|
struct AnimatedTextureState
|
||||||
|
{
|
||||||
|
RageTexture* pTexture;
|
||||||
|
float fDelaySecs;
|
||||||
|
};
|
||||||
|
vector<AnimatedTextureState> vFrames;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct msMaterial
|
||||||
|
{
|
||||||
|
int nFlags;
|
||||||
|
char szName[MS_MAX_NAME];
|
||||||
|
msVec4 Ambient;
|
||||||
|
msVec4 Diffuse;
|
||||||
|
msVec4 Specular;
|
||||||
|
msVec4 Emissive;
|
||||||
|
float fShininess;
|
||||||
|
float fTransparency;
|
||||||
|
char szDiffuseTexture[MS_MAX_PATH];
|
||||||
|
char szAlphaTexture[MS_MAX_PATH]; // not used in SM. Use alpha in diffuse texture instead
|
||||||
|
int nName; // not used in SM. What is this for anyway?
|
||||||
|
AnimatedTexture aniTexture;
|
||||||
|
} msMaterial;
|
||||||
|
|
||||||
|
/* msPositionKey */
|
||||||
|
typedef struct msPositionKey
|
||||||
|
{
|
||||||
|
float fTime;
|
||||||
|
msVec3 Position;
|
||||||
|
} msPositionKey;
|
||||||
|
|
||||||
|
/* msRotationKey */
|
||||||
|
typedef struct msRotationKey
|
||||||
|
{
|
||||||
|
float fTime;
|
||||||
|
msVec3 Rotation;
|
||||||
|
} msRotationKey;
|
||||||
|
|
||||||
|
/* msBone */
|
||||||
|
typedef struct msBone
|
||||||
|
{
|
||||||
|
int nFlags;
|
||||||
|
char szName[MS_MAX_NAME];
|
||||||
|
char szParentName[MS_MAX_NAME];
|
||||||
|
msVec3 Position;
|
||||||
|
msVec3 Rotation;
|
||||||
|
|
||||||
|
vector<msPositionKey> PositionKeys;
|
||||||
|
|
||||||
|
int nNumRotationKeys;
|
||||||
|
int nNumAllocedRotationKeys;
|
||||||
|
vector<msRotationKey> RotationKeys;
|
||||||
|
} msBone;
|
||||||
|
|
||||||
|
/* msModel */
|
||||||
|
typedef struct msModel
|
||||||
|
{
|
||||||
|
vector<msMesh> Meshes;
|
||||||
|
|
||||||
|
vector<msMaterial> Materials;
|
||||||
|
|
||||||
|
vector<msBone> Bones;
|
||||||
|
|
||||||
|
int FindBoneByName( const char* szName )
|
||||||
|
{
|
||||||
|
for( unsigned i=0; i<Bones.size(); i++ )
|
||||||
|
if( strcmp(Bones[i].szName, szName)==0 )
|
||||||
|
return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nFrame;
|
||||||
|
int nTotalFrames;
|
||||||
|
|
||||||
|
msVec3 Position;
|
||||||
|
msVec3 Rotation;
|
||||||
|
} msModel;
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user