load TextureOffset values from .ani file for texture frame animation on models

This commit is contained in:
Chris Danford
2005-05-01 00:02:08 +00:00
parent 4144d28bf2
commit d291eda3f8
3 changed files with 60 additions and 27 deletions
+3 -8
View File
@@ -379,14 +379,9 @@ void Model::DrawPrimitives()
DISPLAY->SetMaterial( Emissive, Ambient, Diffuse, mat.Specular, mat.fShininess ); DISPLAY->SetMaterial( Emissive, Ambient, Diffuse, mat.Specular, mat.fShininess );
if( mat.diffuse.m_fTexVelocityX != 0 || mat.diffuse.m_fTexVelocityY != 0 ) RageVector2 vTexTranslate = mat.diffuse.GetTextureTranslate();
{ if( vTexTranslate.x != 0 || vTexTranslate.y != 0 )
float fScrollX = mat.diffuse.m_fTexVelocityX * mat.diffuse.GetSecondsIntoAnimation() / mat.diffuse.GetAnimationLengthSeconds(); DISPLAY->TextureTranslate( vTexTranslate.x, vTexTranslate.y, 0 );
fScrollX += mat.diffuse.m_fTexOffsetX;
float fScrollY = mat.diffuse.m_fTexVelocityY * mat.diffuse.GetSecondsIntoAnimation() / mat.diffuse.GetAnimationLengthSeconds();
fScrollY += mat.diffuse.m_fTexOffsetY;
DISPLAY->TextureTranslate( fScrollX, fScrollY, 0 );
}
/* There's some common code that could be folded out here, but it seems /* There's some common code that could be folded out here, but it seems
* clearer to keep it separate. */ * clearer to keep it separate. */
+42 -15
View File
@@ -15,10 +15,8 @@ AnimatedTexture::AnimatedTexture()
m_iCurState = 0; m_iCurState = 0;
m_fSecsIntoFrame = 0; m_fSecsIntoFrame = 0;
m_bSphereMapped = false; m_bSphereMapped = false;
m_fTexVelocityX = 0; m_vTexOffset = RageVector2(0,0);
m_fTexVelocityY = 0; m_vTexVelocity = RageVector2(0,0);
m_fTexOffsetX = 0;
m_fTexOffsetY = 0;
m_BlendMode = BLEND_NORMAL; m_BlendMode = BLEND_NORMAL;
} }
@@ -47,10 +45,10 @@ void AnimatedTexture::Load( CString sTexOrIniPath )
if( pAnimatedTexture == NULL ) if( pAnimatedTexture == NULL )
RageException::Throw( "The animated texture file '%s' doesn't contain a section called 'AnimatedTexture'.", sTexOrIniPath.c_str() ); RageException::Throw( "The animated texture file '%s' doesn't contain a section called 'AnimatedTexture'.", sTexOrIniPath.c_str() );
pAnimatedTexture->GetAttrValue( "TexVelocityX", m_fTexVelocityX ); pAnimatedTexture->GetAttrValue( "TexVelocityX", m_vTexVelocity.x );
pAnimatedTexture->GetAttrValue( "TexVelocityY", m_fTexVelocityY ); pAnimatedTexture->GetAttrValue( "TexVelocityY", m_vTexVelocity.y );
pAnimatedTexture->GetAttrValue( "TexOffsetX", m_fTexOffsetX ); pAnimatedTexture->GetAttrValue( "TexOffsetX", m_vTexOffset.x );
pAnimatedTexture->GetAttrValue( "TexOffsetY", m_fTexOffsetY ); pAnimatedTexture->GetAttrValue( "TexOffsetY", m_vTexOffset.y );
for( int i=0; i<1000; i++ ) for( int i=0; i<1000; i++ )
{ {
@@ -62,21 +60,31 @@ void AnimatedTexture::Load( CString sTexOrIniPath )
if( pAnimatedTexture->GetAttrValue( sFileKey, sFileName ) && if( pAnimatedTexture->GetAttrValue( sFileKey, sFileName ) &&
pAnimatedTexture->GetAttrValue( sDelayKey, fDelay ) ) pAnimatedTexture->GetAttrValue( sDelayKey, fDelay ) )
{ {
CString sTranslateXKey = ssprintf( "TranslateX%04d", i );
CString sTranslateYKey = ssprintf( "TranslateY%04d", i );
RageVector2 vOffset(0,0);
pAnimatedTexture->GetAttrValue( sTranslateXKey, vOffset.x );
pAnimatedTexture->GetAttrValue( sTranslateYKey, vOffset.y );
RageTextureID ID; RageTextureID ID;
ID.filename = Dirname(sTexOrIniPath) + sFileName; ID.filename = Dirname(sTexOrIniPath) + sFileName;
ID.bStretch = true; ID.bStretch = true;
ID.bHotPinkColorKey = true; ID.bHotPinkColorKey = true;
ID.bMipMaps = true; // use mipmaps in Models ID.bMipMaps = true; // use mipmaps in Models
AnimatedTextureState state = { AnimatedTextureState state(
TEXTUREMAN->LoadTexture( ID ), TEXTUREMAN->LoadTexture( ID ),
fDelay fDelay,
}; vOffset
);
vFrames.push_back( state ); vFrames.push_back( state );
} }
else else
{
break; break;
} }
} }
}
else else
{ {
RageTextureID ID; RageTextureID ID;
@@ -84,10 +92,11 @@ void AnimatedTexture::Load( CString sTexOrIniPath )
ID.bHotPinkColorKey = true; ID.bHotPinkColorKey = true;
ID.bStretch = true; ID.bStretch = true;
ID.bMipMaps = true; // use mipmaps in Models ID.bMipMaps = true; // use mipmaps in Models
AnimatedTextureState state = { AnimatedTextureState state(
TEXTUREMAN->LoadTexture( ID ), TEXTUREMAN->LoadTexture( ID ),
1 1,
}; RageVector2(0,0)
);
vFrames.push_back( state ); vFrames.push_back( state );
} }
} }
@@ -141,11 +150,15 @@ void AnimatedTexture::SetSecondsIntoAnimation( float fSeconds )
for( unsigned i=0; i<vFrames.size(); i++ ) for( unsigned i=0; i<vFrames.size(); i++ )
{ {
AnimatedTextureState& ats = vFrames[i]; AnimatedTextureState& ats = vFrames[i];
if( fSeconds > ats.fDelaySecs ) if( fSeconds >= ats.fDelaySecs )
{ {
fSeconds -= ats.fDelaySecs; fSeconds -= ats.fDelaySecs;
m_iCurState = i+1; m_iCurState = i+1;
} }
else
{
break;
}
} }
m_fSecsIntoFrame = fSeconds; // remainder m_fSecsIntoFrame = fSeconds; // remainder
} }
@@ -175,6 +188,20 @@ void AnimatedTexture::Unload()
m_fSecsIntoFrame = 0; m_fSecsIntoFrame = 0;
} }
RageVector2 AnimatedTexture::GetTextureTranslate()
{
float fPercentIntoAnimation = GetSecondsIntoAnimation() / GetAnimationLengthSeconds();
RageVector2 v = m_vTexVelocity * fPercentIntoAnimation + m_vTexOffset;
if( vFrames.empty() )
return v;
ASSERT( m_iCurState < (int)vFrames.size() );
v += vFrames[m_iCurState].vTranslate;
return v;
}
msMesh::msMesh() msMesh::msMesh()
{ {
ZERO( szName ); ZERO( szName );
+15 -4
View File
@@ -51,24 +51,35 @@ public:
float GetAnimationLengthSeconds() const; float GetAnimationLengthSeconds() const;
void SetSecondsIntoAnimation( float fSeconds ); void SetSecondsIntoAnimation( float fSeconds );
float GetSecondsIntoAnimation() const; float GetSecondsIntoAnimation() const;
RageVector2 GetTextureTranslate();
bool m_bSphereMapped; bool m_bSphereMapped;
float m_fTexOffsetX;
float m_fTexOffsetY;
float m_fTexVelocityX;
float m_fTexVelocityY;
BlendMode m_BlendMode; BlendMode m_BlendMode;
bool NeedsNormals() const { return m_bSphereMapped; } bool NeedsNormals() const { return m_bSphereMapped; }
private: private:
RageVector2 m_vTexOffset;
RageVector2 m_vTexVelocity;
int m_iCurState; int m_iCurState;
float m_fSecsIntoFrame; float m_fSecsIntoFrame;
struct AnimatedTextureState struct AnimatedTextureState
{ {
AnimatedTextureState(
RageTexture* pTexture_,
float fDelaySecs_,
RageVector2 vTranslate_
)
{
pTexture = pTexture_;
fDelaySecs = fDelaySecs_;
vTranslate = vTranslate_;
}
RageTexture* pTexture; RageTexture* pTexture;
float fDelaySecs; float fDelaySecs;
RageVector2 vTranslate;
}; };
vector<AnimatedTextureState> vFrames; vector<AnimatedTextureState> vFrames;
}; };