load TextureOffset values from .ani file for texture frame animation on models
This commit is contained in:
@@ -379,14 +379,9 @@ void Model::DrawPrimitives()
|
||||
|
||||
DISPLAY->SetMaterial( Emissive, Ambient, Diffuse, mat.Specular, mat.fShininess );
|
||||
|
||||
if( mat.diffuse.m_fTexVelocityX != 0 || mat.diffuse.m_fTexVelocityY != 0 )
|
||||
{
|
||||
float fScrollX = mat.diffuse.m_fTexVelocityX * mat.diffuse.GetSecondsIntoAnimation() / mat.diffuse.GetAnimationLengthSeconds();
|
||||
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 );
|
||||
}
|
||||
RageVector2 vTexTranslate = mat.diffuse.GetTextureTranslate();
|
||||
if( vTexTranslate.x != 0 || vTexTranslate.y != 0 )
|
||||
DISPLAY->TextureTranslate( vTexTranslate.x, vTexTranslate.y, 0 );
|
||||
|
||||
/* There's some common code that could be folded out here, but it seems
|
||||
* clearer to keep it separate. */
|
||||
|
||||
@@ -15,10 +15,8 @@ AnimatedTexture::AnimatedTexture()
|
||||
m_iCurState = 0;
|
||||
m_fSecsIntoFrame = 0;
|
||||
m_bSphereMapped = false;
|
||||
m_fTexVelocityX = 0;
|
||||
m_fTexVelocityY = 0;
|
||||
m_fTexOffsetX = 0;
|
||||
m_fTexOffsetY = 0;
|
||||
m_vTexOffset = RageVector2(0,0);
|
||||
m_vTexVelocity = RageVector2(0,0);
|
||||
m_BlendMode = BLEND_NORMAL;
|
||||
}
|
||||
|
||||
@@ -47,10 +45,10 @@ void AnimatedTexture::Load( CString sTexOrIniPath )
|
||||
if( pAnimatedTexture == NULL )
|
||||
RageException::Throw( "The animated texture file '%s' doesn't contain a section called 'AnimatedTexture'.", sTexOrIniPath.c_str() );
|
||||
|
||||
pAnimatedTexture->GetAttrValue( "TexVelocityX", m_fTexVelocityX );
|
||||
pAnimatedTexture->GetAttrValue( "TexVelocityY", m_fTexVelocityY );
|
||||
pAnimatedTexture->GetAttrValue( "TexOffsetX", m_fTexOffsetX );
|
||||
pAnimatedTexture->GetAttrValue( "TexOffsetY", m_fTexOffsetY );
|
||||
pAnimatedTexture->GetAttrValue( "TexVelocityX", m_vTexVelocity.x );
|
||||
pAnimatedTexture->GetAttrValue( "TexVelocityY", m_vTexVelocity.y );
|
||||
pAnimatedTexture->GetAttrValue( "TexOffsetX", m_vTexOffset.x );
|
||||
pAnimatedTexture->GetAttrValue( "TexOffsetY", m_vTexOffset.y );
|
||||
|
||||
for( int i=0; i<1000; i++ )
|
||||
{
|
||||
@@ -62,19 +60,29 @@ void AnimatedTexture::Load( CString sTexOrIniPath )
|
||||
if( pAnimatedTexture->GetAttrValue( sFileKey, sFileName ) &&
|
||||
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;
|
||||
ID.filename = Dirname(sTexOrIniPath) + sFileName;
|
||||
ID.bStretch = true;
|
||||
ID.bHotPinkColorKey = true;
|
||||
ID.bMipMaps = true; // use mipmaps in Models
|
||||
AnimatedTextureState state = {
|
||||
AnimatedTextureState state(
|
||||
TEXTUREMAN->LoadTexture( ID ),
|
||||
fDelay
|
||||
};
|
||||
fDelay,
|
||||
vOffset
|
||||
);
|
||||
vFrames.push_back( state );
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -84,10 +92,11 @@ void AnimatedTexture::Load( CString sTexOrIniPath )
|
||||
ID.bHotPinkColorKey = true;
|
||||
ID.bStretch = true;
|
||||
ID.bMipMaps = true; // use mipmaps in Models
|
||||
AnimatedTextureState state = {
|
||||
AnimatedTextureState state(
|
||||
TEXTUREMAN->LoadTexture( ID ),
|
||||
1
|
||||
};
|
||||
1,
|
||||
RageVector2(0,0)
|
||||
);
|
||||
vFrames.push_back( state );
|
||||
}
|
||||
}
|
||||
@@ -141,11 +150,15 @@ void AnimatedTexture::SetSecondsIntoAnimation( float fSeconds )
|
||||
for( unsigned i=0; i<vFrames.size(); i++ )
|
||||
{
|
||||
AnimatedTextureState& ats = vFrames[i];
|
||||
if( fSeconds > ats.fDelaySecs )
|
||||
if( fSeconds >= ats.fDelaySecs )
|
||||
{
|
||||
fSeconds -= ats.fDelaySecs;
|
||||
m_iCurState = i+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_fSecsIntoFrame = fSeconds; // remainder
|
||||
}
|
||||
@@ -175,6 +188,20 @@ void AnimatedTexture::Unload()
|
||||
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()
|
||||
{
|
||||
ZERO( szName );
|
||||
|
||||
@@ -51,24 +51,35 @@ public:
|
||||
float GetAnimationLengthSeconds() const;
|
||||
void SetSecondsIntoAnimation( float fSeconds );
|
||||
float GetSecondsIntoAnimation() const;
|
||||
RageVector2 GetTextureTranslate();
|
||||
|
||||
bool m_bSphereMapped;
|
||||
float m_fTexOffsetX;
|
||||
float m_fTexOffsetY;
|
||||
float m_fTexVelocityX;
|
||||
float m_fTexVelocityY;
|
||||
BlendMode m_BlendMode;
|
||||
|
||||
bool NeedsNormals() const { return m_bSphereMapped; }
|
||||
|
||||
private:
|
||||
RageVector2 m_vTexOffset;
|
||||
RageVector2 m_vTexVelocity;
|
||||
|
||||
int m_iCurState;
|
||||
float m_fSecsIntoFrame;
|
||||
struct AnimatedTextureState
|
||||
{
|
||||
AnimatedTextureState(
|
||||
RageTexture* pTexture_,
|
||||
float fDelaySecs_,
|
||||
RageVector2 vTranslate_
|
||||
)
|
||||
{
|
||||
pTexture = pTexture_;
|
||||
fDelaySecs = fDelaySecs_;
|
||||
vTranslate = vTranslate_;
|
||||
}
|
||||
|
||||
RageTexture* pTexture;
|
||||
float fDelaySecs;
|
||||
RageVector2 vTranslate;
|
||||
};
|
||||
vector<AnimatedTextureState> vFrames;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user