2001-11-03 10:52:42 +00:00
|
|
|
#include "stdafx.h" // testing updates
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
File: Actor.h
|
|
|
|
|
|
|
|
|
|
Desc: Base class for all objects that appear on the screen.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001 Chris Danford. All rights reserved.
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
#include "Actor.h"
|
|
|
|
|
#include <math.h>
|
2001-11-28 20:26:45 +00:00
|
|
|
#include "RageScreen.h"
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Actor::Actor()
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Actor::Init()
|
|
|
|
|
{
|
2001-11-28 20:26:45 +00:00
|
|
|
m_size = m_start_pos = m_end_pos = D3DXVECTOR2( 0, 0 );
|
|
|
|
|
m_pos = m_start_pos = m_end_pos = D3DXVECTOR2( 0, 0 );
|
|
|
|
|
m_rotation = m_start_rotation = m_end_rotation = D3DXVECTOR3( 0, 0, 0 );
|
|
|
|
|
m_scale = m_start_scale = m_end_scale = D3DXVECTOR2( 1, 1 );
|
|
|
|
|
m_colorDiffuse = m_start_colorDiffuse = m_end_colorDiffuse= D3DXCOLOR( 1, 1, 1, 1 );
|
|
|
|
|
m_colorAdd = m_start_colorAdd = m_end_colorAdd = D3DXCOLOR( 0, 0, 0, 0 );
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
m_TweenType = no_tween;
|
|
|
|
|
m_fTweenTime = 0.0f;
|
|
|
|
|
m_fTimeIntoTween = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-28 20:26:45 +00:00
|
|
|
void Actor::Draw()
|
|
|
|
|
{
|
|
|
|
|
D3DXVECTOR2 pos = m_pos;
|
|
|
|
|
D3DXVECTOR3 rotation = m_rotation;
|
|
|
|
|
D3DXVECTOR2 scale = m_scale;
|
|
|
|
|
|
|
|
|
|
// update properties based on SpriteEffects
|
|
|
|
|
switch( m_Effect )
|
|
|
|
|
{
|
|
|
|
|
case no_effect:
|
|
|
|
|
break;
|
|
|
|
|
case blinking:
|
|
|
|
|
break;
|
|
|
|
|
case camelion:
|
|
|
|
|
break;
|
|
|
|
|
case glowing:
|
|
|
|
|
break;
|
|
|
|
|
case wagging:
|
|
|
|
|
rotation.z = m_fWagRadians * (float)sin(
|
|
|
|
|
(m_fWagTimer / m_fWagPeriod) // percent through wag
|
|
|
|
|
* 2.0 * D3DX_PI );
|
|
|
|
|
break;
|
|
|
|
|
case spinning:
|
|
|
|
|
// nothing special needed
|
|
|
|
|
break;
|
|
|
|
|
case vibrating:
|
|
|
|
|
pos.x += m_fVibrationDistance * randomf(-1.0f, 1.0f) * GetZoom();
|
|
|
|
|
pos.y += m_fVibrationDistance * randomf(-1.0f, 1.0f) * GetZoom();
|
|
|
|
|
break;
|
|
|
|
|
case flickering:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LPDIRECT3DDEVICE8 pd3dDevice = SCREEN->GetDevice();
|
|
|
|
|
|
|
|
|
|
// calculate and apply world transform
|
|
|
|
|
D3DXMATRIX matWorld, matTemp;
|
|
|
|
|
D3DXMatrixIdentity( &matWorld ); // pass this along to each thing we draw and let it set it's own world matrix
|
|
|
|
|
D3DXMatrixScaling( &matTemp, scale.x, scale.y, 1 ); // add in the zoom
|
|
|
|
|
matWorld *= matTemp;
|
|
|
|
|
D3DXMatrixRotationYawPitchRoll( &matTemp, rotation.y, rotation.x, rotation.z ); // add in the rotation
|
|
|
|
|
matWorld *= matTemp;
|
|
|
|
|
D3DXMatrixTranslation( &matTemp, pos.x, pos.y, 0 ); // add in the translation
|
|
|
|
|
matWorld *= matTemp;
|
|
|
|
|
D3DXMatrixTranslation( &matTemp, -0.5f, -0.5f, 0 ); // shift to align texels with pixels
|
|
|
|
|
matWorld *= matTemp;
|
|
|
|
|
pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-28 01:26:58 +00:00
|
|
|
void Actor::Update( const float &fDeltaTime )
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
|
|
|
|
// RageLog( "Actor::Update( %f )", fDeltaTime );
|
|
|
|
|
|
2001-11-28 20:26:45 +00:00
|
|
|
// update effect
|
|
|
|
|
switch( m_Effect )
|
|
|
|
|
{
|
|
|
|
|
case no_effect:
|
|
|
|
|
break;
|
|
|
|
|
case blinking:
|
|
|
|
|
case camelion:
|
|
|
|
|
case glowing:
|
|
|
|
|
if( m_bTweeningTowardEndColor ) {
|
|
|
|
|
m_fPercentBetweenColors += m_fDeltaPercentPerSecond * fDeltaTime;
|
|
|
|
|
if( m_fPercentBetweenColors > 1.0f ) {
|
|
|
|
|
m_fPercentBetweenColors = 1.0f;
|
2001-11-29 06:49:26 +00:00
|
|
|
|
2001-11-28 20:26:45 +00:00
|
|
|
m_bTweeningTowardEndColor = FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { // !m_bTweeningTowardEndColor
|
|
|
|
|
m_fPercentBetweenColors -= m_fDeltaPercentPerSecond * fDeltaTime;
|
|
|
|
|
if( m_fPercentBetweenColors < 0.0f ) {
|
|
|
|
|
m_fPercentBetweenColors = 0.0f;
|
|
|
|
|
m_bTweeningTowardEndColor = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RageLog( "Actor::m_fPercentBetweenColors %f", m_fPercentBetweenColors );
|
|
|
|
|
break;
|
|
|
|
|
case wagging:
|
|
|
|
|
m_fWagTimer += fDeltaTime;
|
|
|
|
|
if( m_fWagTimer > m_fWagPeriod )
|
|
|
|
|
m_fWagTimer -= m_fWagPeriod;
|
|
|
|
|
break;
|
|
|
|
|
case spinning:
|
|
|
|
|
float rotation;
|
|
|
|
|
rotation = GetRotation();
|
|
|
|
|
rotation += m_fSpinSpeed * fDeltaTime;
|
|
|
|
|
if( rotation > 2.0f * D3DX_PI )
|
|
|
|
|
rotation -= 2.0f * D3DX_PI;
|
|
|
|
|
else if( rotation < 0.0f )
|
|
|
|
|
rotation += 2.0f * D3DX_PI;
|
|
|
|
|
SetRotation( rotation );
|
|
|
|
|
break;
|
|
|
|
|
case vibrating:
|
|
|
|
|
break;
|
|
|
|
|
case flickering:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
// update tweening
|
|
|
|
|
if( m_TweenType != no_tween ) // we are performing some type of tweening
|
|
|
|
|
{
|
|
|
|
|
m_fTimeIntoTween += fDeltaTime;
|
|
|
|
|
|
|
|
|
|
if( m_fTimeIntoTween > m_fTweenTime ) // The tweening is over. Stop the tweening
|
|
|
|
|
{
|
|
|
|
|
m_pos = m_end_pos;
|
|
|
|
|
m_scale = m_end_scale;
|
|
|
|
|
m_rotation = m_end_rotation;
|
2001-11-28 20:26:45 +00:00
|
|
|
m_colorDiffuse = m_end_colorDiffuse;
|
|
|
|
|
m_colorAdd = m_end_colorAdd;
|
2001-11-03 10:52:42 +00:00
|
|
|
m_TweenType = no_tween;
|
|
|
|
|
}
|
|
|
|
|
else // Tweening. Recalcute the curent position.
|
|
|
|
|
{
|
2001-11-28 20:26:45 +00:00
|
|
|
float fPercentThroughTween = m_fTimeIntoTween / m_fTweenTime;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
// distort the percentage if appropriate
|
|
|
|
|
if( m_TweenType == tween_bias_begin )
|
2001-11-28 20:26:45 +00:00
|
|
|
fPercentThroughTween = (float) sqrt( fPercentThroughTween );
|
2001-11-03 10:52:42 +00:00
|
|
|
else if( m_TweenType == tweening_bias_end )
|
|
|
|
|
fPercentThroughTween = fPercentThroughTween * fPercentThroughTween;
|
|
|
|
|
|
|
|
|
|
|
2001-11-28 20:26:45 +00:00
|
|
|
m_pos = m_start_pos + (m_end_pos - m_start_pos )*fPercentThroughTween;
|
|
|
|
|
m_scale = m_start_scale + (m_end_scale - m_start_scale )*fPercentThroughTween;
|
|
|
|
|
m_rotation = m_start_rotation+ (m_end_rotation - m_start_rotation)*fPercentThroughTween;
|
|
|
|
|
m_colorDiffuse = m_start_colorDiffuse*(1.0f-fPercentThroughTween) + m_end_colorDiffuse*(fPercentThroughTween);
|
|
|
|
|
m_colorAdd = m_start_colorAdd *(1.0f-fPercentThroughTween) + m_end_colorAdd *(fPercentThroughTween);
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // end if m_TweenType != no_tween
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-28 20:26:45 +00:00
|
|
|
void Actor::TweenTo( float time, float x, float y, float zoom, float rot, D3DXCOLOR col, TweenType tt )
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
|
|
|
|
// set our tweeen starting values to the current position
|
|
|
|
|
m_start_pos = m_pos;
|
|
|
|
|
m_start_scale = m_scale;
|
|
|
|
|
m_start_rotation = m_rotation;
|
2001-11-28 20:26:45 +00:00
|
|
|
m_start_colorDiffuse = m_colorDiffuse;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
// set the ending tweening position to what the user asked for
|
2001-11-28 20:26:45 +00:00
|
|
|
m_end_pos.x = (float)x;
|
|
|
|
|
m_end_pos.y = (float)y;
|
2001-11-03 10:52:42 +00:00
|
|
|
m_end_scale.x = zoom;
|
|
|
|
|
m_end_scale.y = zoom;
|
|
|
|
|
m_end_rotation.z = rot;
|
2001-11-28 20:26:45 +00:00
|
|
|
m_end_colorDiffuse = col;
|
2001-11-03 10:52:42 +00:00
|
|
|
m_TweenType = tt;
|
|
|
|
|
m_fTweenTime = time;
|
|
|
|
|
m_fTimeIntoTween = 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-20 11:49:10 +00:00
|
|
|
|
2001-11-28 20:26:45 +00:00
|
|
|
void Actor::BeginTweening( float time, TweenType tt )
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
|
|
|
|
// set our tweeen starting and ending values to the current position
|
2001-11-28 20:26:45 +00:00
|
|
|
m_start_pos = m_end_pos = m_pos;
|
|
|
|
|
m_start_scale = m_end_scale = m_scale;
|
|
|
|
|
m_start_rotation = m_end_rotation = m_rotation;
|
|
|
|
|
m_start_colorDiffuse = m_end_colorDiffuse = m_colorDiffuse;
|
|
|
|
|
m_start_colorAdd = m_end_colorAdd = m_colorAdd;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
m_TweenType = tt;
|
|
|
|
|
m_fTweenTime = time;
|
|
|
|
|
m_fTimeIntoTween = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-28 20:26:45 +00:00
|
|
|
void Actor::SetTweenX( float x ) { m_end_pos.x = x; }
|
|
|
|
|
void Actor::SetTweenY( float y ) { m_end_pos.y = y; }
|
|
|
|
|
void Actor::SetTweenXY( float x, float y ) { SetTweenX(x); SetTweenY(y); }
|
|
|
|
|
void Actor::SetTweenZoom( float zoom ) { m_end_scale.x = zoom; m_end_scale.y = zoom; }
|
|
|
|
|
void Actor::SetTweenRotationX( float r ) { m_end_rotation.x = r; }
|
|
|
|
|
void Actor::SetTweenRotationY( float r ) { m_end_rotation.y = r; }
|
|
|
|
|
void Actor::SetTweenRotationZ( float r ) { m_end_rotation.z = r; }
|
|
|
|
|
void Actor::SetTweenDiffuseColor( D3DXCOLOR c ) { m_end_colorDiffuse = c; }
|
|
|
|
|
void Actor::SetTweenAddColor( D3DXCOLOR c ) { m_end_colorAdd = c; }
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void Actor::ScaleTo( LPRECT pRect, StretchType st )
|
|
|
|
|
{
|
|
|
|
|
// width and height of rectangle
|
2001-11-25 04:31:44 +00:00
|
|
|
float rect_width = RECTWIDTH(*pRect);
|
|
|
|
|
float rect_height = RECTHEIGHT(*pRect);
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-25 10:49:31 +00:00
|
|
|
if( rect_width < 0 ) SetRotationY( D3DX_PI );
|
|
|
|
|
if( rect_height < 0 ) SetRotationX( D3DX_PI );
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
// center of the rectangle
|
2001-11-25 04:31:44 +00:00
|
|
|
float rect_cx = pRect->left + rect_width/2;
|
|
|
|
|
float rect_cy = pRect->top + rect_height/2;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
// zoom factor needed to scale the Actor to fill the rectangle
|
2001-11-25 04:31:44 +00:00
|
|
|
float fNewZoomX = (float)fabs(rect_width / m_size.x);
|
|
|
|
|
float fNewZoomY = (float)fabs(rect_height / m_size.y);
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-25 04:31:44 +00:00
|
|
|
float fNewZoom;
|
2001-11-03 10:52:42 +00:00
|
|
|
switch( st )
|
|
|
|
|
{
|
|
|
|
|
case cover:
|
|
|
|
|
fNewZoom = fNewZoomX>fNewZoomY ? fNewZoomX : fNewZoomY; // use larger zoom
|
|
|
|
|
break;
|
|
|
|
|
case fit_inside:
|
|
|
|
|
fNewZoom = fNewZoomX>fNewZoomY ? fNewZoomY : fNewZoomX; // use smaller zoom
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-25 04:31:44 +00:00
|
|
|
SetXY( rect_cx, rect_cy );
|
2001-11-03 10:52:42 +00:00
|
|
|
SetZoom( fNewZoom );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Actor::StretchTo( LPRECT pRect )
|
|
|
|
|
{
|
|
|
|
|
// width and height of rectangle
|
|
|
|
|
int rect_width = RECTWIDTH(*pRect);
|
|
|
|
|
int rect_height = RECTHEIGHT(*pRect);
|
|
|
|
|
|
2001-11-25 10:49:31 +00:00
|
|
|
if( rect_width < 0 ) SetRotationY( D3DX_PI );
|
|
|
|
|
if( rect_height < 0 ) SetRotationX( D3DX_PI );
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
// center of the rectangle
|
|
|
|
|
int rect_cx = pRect->left + rect_width/2;
|
|
|
|
|
int rect_cy = pRect->top + rect_height/2;
|
|
|
|
|
|
|
|
|
|
// zoom factor needed to scale the Actor to fill the rectangle
|
2001-11-28 20:26:45 +00:00
|
|
|
float fNewZoomX = (float)fabs(rect_width / m_size.x);
|
|
|
|
|
float fNewZoomY = (float)fabs(rect_height / m_size.y);
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-28 20:26:45 +00:00
|
|
|
SetXY( (float)rect_cx, (float)rect_cy );
|
2001-11-03 10:52:42 +00:00
|
|
|
m_scale.x = fNewZoomX;
|
|
|
|
|
m_scale.y = fNewZoomY;
|
|
|
|
|
}
|
2001-11-28 20:26:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// effects
|
|
|
|
|
|
|
|
|
|
void Actor::SetEffectNone()
|
|
|
|
|
{
|
|
|
|
|
m_Effect = no_effect;
|
|
|
|
|
//m_color = D3DXCOLOR( 1.0,1.0,1.0,1.0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Actor::SetEffectBlinking( float fDeltaPercentPerSecond, D3DXCOLOR Color, D3DXCOLOR Color2 )
|
|
|
|
|
{
|
|
|
|
|
m_Effect = blinking;
|
|
|
|
|
m_start_colorDiffuse = Color;
|
|
|
|
|
m_end_colorDiffuse = Color2;
|
|
|
|
|
//m_fPercentBetweenColors = 0.0;
|
|
|
|
|
//m_bTweeningTowardEndColor = TRUE;
|
|
|
|
|
m_fDeltaPercentPerSecond = fDeltaPercentPerSecond;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Actor::SetEffectCamelion( float fDeltaPercentPerSecond, D3DXCOLOR Color, D3DXCOLOR Color2 )
|
|
|
|
|
{
|
|
|
|
|
m_Effect = camelion;
|
|
|
|
|
m_start_colorDiffuse = Color;
|
|
|
|
|
m_end_colorDiffuse = Color2;
|
|
|
|
|
//m_fPercentBetweenColors = 0.0;
|
|
|
|
|
//m_bTweeningTowardEndColor = TRUE;
|
|
|
|
|
m_fDeltaPercentPerSecond = fDeltaPercentPerSecond;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Actor::SetEffectGlowing( float fDeltaPercentPerSecond, D3DXCOLOR Color, D3DXCOLOR Color2 )
|
|
|
|
|
{
|
|
|
|
|
m_Effect = glowing;
|
|
|
|
|
m_start_colorAdd = Color;
|
|
|
|
|
m_end_colorAdd = Color2;
|
|
|
|
|
//m_fPercentBetweenColors = 0.0;
|
|
|
|
|
//m_bTweeningTowardEndColor = TRUE;
|
|
|
|
|
m_fDeltaPercentPerSecond = fDeltaPercentPerSecond;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Actor::SetEffectWagging( float fWagRadians, float fWagPeriod )
|
|
|
|
|
{
|
|
|
|
|
m_Effect = wagging;
|
|
|
|
|
m_fWagRadians = fWagRadians;
|
|
|
|
|
m_fWagPeriod = fWagPeriod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Actor::SetEffectSpinning( float fSpinSpeed /*radians per second*/ )
|
|
|
|
|
{
|
|
|
|
|
m_Effect = spinning;
|
|
|
|
|
m_fSpinSpeed = fSpinSpeed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Actor::SetEffectVibrating( float fVibrationDistance )
|
|
|
|
|
{
|
|
|
|
|
m_Effect = vibrating;
|
|
|
|
|
m_fVibrationDistance = fVibrationDistance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Actor::SetEffectFlickering()
|
|
|
|
|
{
|
|
|
|
|
m_Effect = flickering;
|
|
|
|
|
}
|