use sin lookup table to fix terrible performance with float and tipsy performance on some archs
This commit is contained in:
+11
-11
@@ -193,7 +193,7 @@ void Actor::BeginDraw() // set the world matrix and calculate actor properties
|
||||
ssprintf("%f", fPercentThroughEffect) );
|
||||
|
||||
bool bBlinkOn = fPercentThroughEffect > 0.5f;
|
||||
float fPercentBetweenColors = sinf( (fPercentThroughEffect + 0.25f) * 2 * PI ) / 2 + 0.5f;
|
||||
float fPercentBetweenColors = RageFastSin( (fPercentThroughEffect + 0.25f) * 2 * PI ) / 2 + 0.5f;
|
||||
ASSERT_M( fPercentBetweenColors >= 0 && fPercentBetweenColors <= 1,
|
||||
ssprintf("%f, %f", fPercentBetweenColors, fPercentThroughEffect) );
|
||||
float fOriginalAlpha = m_tempState.diffuse[0].a;
|
||||
@@ -225,15 +225,15 @@ void Actor::BeginDraw() // set the world matrix and calculate actor properties
|
||||
break;
|
||||
case rainbow:
|
||||
m_tempState.diffuse[0] = RageColor(
|
||||
cosf( fPercentBetweenColors*2*PI ) * 0.5f + 0.5f,
|
||||
cosf( fPercentBetweenColors*2*PI + PI * 2.0f / 3.0f ) * 0.5f + 0.5f,
|
||||
cosf( fPercentBetweenColors*2*PI + PI * 4.0f / 3.0f) * 0.5f + 0.5f,
|
||||
RageFastCos( fPercentBetweenColors*2*PI ) * 0.5f + 0.5f,
|
||||
RageFastCos( fPercentBetweenColors*2*PI + PI * 2.0f / 3.0f ) * 0.5f + 0.5f,
|
||||
RageFastCos( fPercentBetweenColors*2*PI + PI * 4.0f / 3.0f) * 0.5f + 0.5f,
|
||||
fOriginalAlpha );
|
||||
for( int i=1; i<4; i++ )
|
||||
m_tempState.diffuse[i] = m_tempState.diffuse[0];
|
||||
break;
|
||||
case wag:
|
||||
m_tempState.rotation += m_vEffectMagnitude * sinf( fPercentThroughEffect * 2.0f * PI );
|
||||
m_tempState.rotation += m_vEffectMagnitude * RageFastSin( fPercentThroughEffect * 2.0f * PI );
|
||||
break;
|
||||
case spin:
|
||||
// nothing needs to be here
|
||||
@@ -245,7 +245,7 @@ void Actor::BeginDraw() // set the world matrix and calculate actor properties
|
||||
break;
|
||||
case bounce:
|
||||
{
|
||||
float fPercentOffset = sinf( fPercentThroughEffect*PI );
|
||||
float fPercentOffset = RageFastSin( fPercentThroughEffect*PI );
|
||||
m_tempState.pos += m_vEffectMagnitude * fPercentOffset;
|
||||
m_tempState.pos.x = roundf( m_tempState.pos.x );
|
||||
m_tempState.pos.y = roundf( m_tempState.pos.y );
|
||||
@@ -254,7 +254,7 @@ void Actor::BeginDraw() // set the world matrix and calculate actor properties
|
||||
break;
|
||||
case bob:
|
||||
{
|
||||
float fPercentOffset = sinf( fPercentThroughEffect*PI*2 );
|
||||
float fPercentOffset = RageFastSin( fPercentThroughEffect*PI*2 );
|
||||
m_tempState.pos += m_vEffectMagnitude * fPercentOffset;
|
||||
m_tempState.pos.x = roundf( m_tempState.pos.x );
|
||||
m_tempState.pos.y = roundf( m_tempState.pos.y );
|
||||
@@ -265,7 +265,7 @@ void Actor::BeginDraw() // set the world matrix and calculate actor properties
|
||||
{
|
||||
float fMinZoom = m_vEffectMagnitude[0];
|
||||
float fMaxZoom = m_vEffectMagnitude[1];
|
||||
float fPercentOffset = sinf( fPercentThroughEffect*PI );
|
||||
float fPercentOffset = RageFastSin( fPercentThroughEffect*PI );
|
||||
float fZoom = SCALE( fPercentOffset, 0.f, 1.f, fMinZoom, fMaxZoom );
|
||||
m_tempState.scale *= fZoom;
|
||||
|
||||
@@ -392,9 +392,9 @@ void Actor::UpdateTweening( float fDeltaTime )
|
||||
case TWEEN_LINEAR: fPercentAlongPath = fPercentThroughTween; break;
|
||||
case TWEEN_ACCELERATE: fPercentAlongPath = fPercentThroughTween * fPercentThroughTween; break;
|
||||
case TWEEN_DECELERATE: fPercentAlongPath = 1 - (1-fPercentThroughTween) * (1-fPercentThroughTween); break;
|
||||
case TWEEN_BOUNCE_BEGIN:fPercentAlongPath = 1 - sinf( 1.1f + fPercentThroughTween*(PI-1.1f) ) / 0.89f; break;
|
||||
case TWEEN_BOUNCE_END: fPercentAlongPath = sinf( 1.1f + (1-fPercentThroughTween)*(PI-1.1f) ) / 0.89f; break;
|
||||
case TWEEN_SPRING: fPercentAlongPath = 1 - cosf( fPercentThroughTween*PI*2.5f )/(1+fPercentThroughTween*3); break;
|
||||
case TWEEN_BOUNCE_BEGIN:fPercentAlongPath = 1 - RageFastSin( 1.1f + fPercentThroughTween*(PI-1.1f) ) / 0.89f; break;
|
||||
case TWEEN_BOUNCE_END: fPercentAlongPath = RageFastSin( 1.1f + (1-fPercentThroughTween)*(PI-1.1f) ) / 0.89f; break;
|
||||
case TWEEN_SPRING: fPercentAlongPath = 1 - RageFastCos( fPercentThroughTween*PI*2.5f )/(1+fPercentThroughTween*3); break;
|
||||
default: ASSERT(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ float ArrowEffects::GetYOffset( const PlayerState* pPlayerState, int iCol, float
|
||||
fYAdjust += fBrakeYAdjust;
|
||||
}
|
||||
if( fAccels[PlayerOptions::ACCEL_WAVE] > 0 )
|
||||
fYAdjust += fAccels[PlayerOptions::ACCEL_WAVE] * 20.0f*sinf( fYOffset/38.0f );
|
||||
fYAdjust += fAccels[PlayerOptions::ACCEL_WAVE] * 20.0f*RageFastSin( fYOffset/38.0f );
|
||||
|
||||
fYOffset += fYAdjust;
|
||||
|
||||
@@ -113,7 +113,7 @@ float ArrowEffects::GetYOffset( const PlayerState* pPlayerState, int iCol, float
|
||||
g_fExpandSeconds += timerExpand.GetDeltaTime();
|
||||
else
|
||||
timerExpand.GetDeltaTime(); // throw away
|
||||
float fExpandMultiplier = SCALE( cosf(g_fExpandSeconds*3), -1, 1, 0.5f, 1.5f );
|
||||
float fExpandMultiplier = SCALE( RageFastCos(g_fExpandSeconds*3), -1, 1, 0.5f, 1.5f );
|
||||
fScrollSpeed *= SCALE( fAccels[PlayerOptions::ACCEL_EXPAND], 0.f, 1.f, 1.f, fExpandMultiplier );
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ float ArrowEffects::GetYPos( const PlayerState* pPlayerState, int iCol, float fY
|
||||
const float* fEffects = pPlayerState->m_CurrentPlayerOptions.m_fEffects;
|
||||
|
||||
if( fEffects[PlayerOptions::EFFECT_TIPSY] > 0 )
|
||||
f += fEffects[PlayerOptions::EFFECT_TIPSY] * ( cosf( RageTimer::GetTimeSinceStartFast()*1.2f + iCol*1.8f) * ARROW_SIZE*0.4f );
|
||||
f += fEffects[PlayerOptions::EFFECT_TIPSY] * ( RageFastCos( RageTimer::GetTimeSinceStartFast()*1.2f + iCol*1.8f) * ARROW_SIZE*0.4f );
|
||||
return f;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ float ArrowEffects::GetYOffsetFromYPos( const PlayerState* pPlayerState, int iCo
|
||||
|
||||
const float* fEffects = pPlayerState->m_CurrentPlayerOptions.m_fEffects;
|
||||
if( fEffects[PlayerOptions::EFFECT_TIPSY] > 0 )
|
||||
f -= fEffects[PlayerOptions::EFFECT_TIPSY] * ( cosf( RageTimer::GetTimeSinceStartFast()*1.2f + iCol*2.f) * ARROW_SIZE*0.4f );
|
||||
f -= fEffects[PlayerOptions::EFFECT_TIPSY] * ( RageFastCos( RageTimer::GetTimeSinceStartFast()*1.2f + iCol*2.f) * ARROW_SIZE*0.4f );
|
||||
|
||||
float fShift, fScale;
|
||||
ArrowGetReverseShiftAndScale( pPlayerState, iCol, fYReverseOffsetPixels, fShift, fScale );
|
||||
@@ -212,13 +212,13 @@ float ArrowEffects::GetXPos( const PlayerState* pPlayerState, int iColNum, float
|
||||
float fRads = acosf( fPositionBetween );
|
||||
fRads += fYOffset * 6 / SCREEN_HEIGHT;
|
||||
|
||||
const float fAdjustedPixelOffset = SCALE( cosf(fRads), -1, 1, fMinX, fMaxX );
|
||||
const float fAdjustedPixelOffset = SCALE( RageFastCos(fRads), -1, 1, fMinX, fMaxX );
|
||||
|
||||
fPixelOffsetFromCenter += (fAdjustedPixelOffset - fRealPixelOffset) * fEffects[PlayerOptions::EFFECT_TORNADO];
|
||||
}
|
||||
|
||||
if( fEffects[PlayerOptions::EFFECT_DRUNK] > 0 )
|
||||
fPixelOffsetFromCenter += fEffects[PlayerOptions::EFFECT_DRUNK] * ( cosf( RageTimer::GetTimeSinceStartFast() + iColNum*0.2f + fYOffset*10/SCREEN_HEIGHT) * ARROW_SIZE*0.5f );
|
||||
fPixelOffsetFromCenter += fEffects[PlayerOptions::EFFECT_DRUNK] * ( RageFastCos( RageTimer::GetTimeSinceStartFast() + iColNum*0.2f + fYOffset*10/SCREEN_HEIGHT) * ARROW_SIZE*0.5f );
|
||||
if( fEffects[PlayerOptions::EFFECT_FLIP] > 0 )
|
||||
{
|
||||
// TODO: Don't index by PlayerNumber.
|
||||
@@ -270,7 +270,7 @@ float ArrowEffects::GetXPos( const PlayerState* pPlayerState, int iColNum, float
|
||||
if( bEvenBeat )
|
||||
fAmount *= -1;
|
||||
|
||||
const float fShift = 20.0f*fAmount*sinf( fYOffset / 15.0f + PI/2.0f );
|
||||
const float fShift = 20.0f*fAmount*RageFastSin( fYOffset / 15.0f + PI/2.0f );
|
||||
fPixelOffsetFromCenter += fEffects[PlayerOptions::EFFECT_BEAT] * fShift;
|
||||
} while(0);
|
||||
|
||||
@@ -377,7 +377,7 @@ float ArrowGetPercentVisible( const PlayerState* pPlayerState, int iCol, float f
|
||||
fVisibleAdjust -= fAppearances[PlayerOptions::APPEARANCE_STEALTH];
|
||||
if( fAppearances[PlayerOptions::APPEARANCE_BLINK] > 0 )
|
||||
{
|
||||
float f = sinf(RageTimer::GetTimeSinceStartFast()*10);
|
||||
float f = RageFastSin(RageTimer::GetTimeSinceStartFast()*10);
|
||||
f = Quantize( f, 0.3333f );
|
||||
fVisibleAdjust += SCALE( f, 0, 1, -1, 0 );
|
||||
}
|
||||
@@ -432,7 +432,7 @@ float ArrowEffects::GetZPos( const PlayerState* pPlayerState, int iCol, float fY
|
||||
const float* fEffects = pPlayerState->m_CurrentPlayerOptions.m_fEffects;
|
||||
|
||||
if( fEffects[PlayerOptions::EFFECT_BUMPY] > 0 )
|
||||
fZPos += fEffects[PlayerOptions::EFFECT_BUMPY] * 40*sinf( fYOffset/16.0f );
|
||||
fZPos += fEffects[PlayerOptions::EFFECT_BUMPY] * 40*RageFastSin( fYOffset/16.0f );
|
||||
|
||||
return fZPos;
|
||||
}
|
||||
|
||||
@@ -144,8 +144,8 @@ void GrooveRadar::GrooveRadarValueMap::DrawPrimitives()
|
||||
const float fDistFromCenter =
|
||||
( m_fValuesOld[p][c] * (1-m_PercentTowardNew[p]) + m_fValuesNew[p][c] * m_PercentTowardNew[p] + 0.07f ) * fRadius;
|
||||
const float fRotation = RADAR_VALUE_ROTATION(i);
|
||||
const float fX = cosf(fRotation) * fDistFromCenter;
|
||||
const float fY = -sinf(fRotation) * fDistFromCenter;
|
||||
const float fX = RageFastCos(fRotation) * fDistFromCenter;
|
||||
const float fY = -RageFastSin(fRotation) * fDistFromCenter;
|
||||
|
||||
v[1+i].p = RageVector3( fX, fY, 0 );
|
||||
v[1+i].c = v[0].c;
|
||||
@@ -162,8 +162,8 @@ void GrooveRadar::GrooveRadarValueMap::DrawPrimitives()
|
||||
const float fDistFromCenter =
|
||||
( m_fValuesOld[p][c] * (1-m_PercentTowardNew[p]) + m_fValuesNew[p][c] * m_PercentTowardNew[p] + 0.07f ) * fRadius;
|
||||
const float fRotation = RADAR_VALUE_ROTATION(i);
|
||||
const float fX = cosf(fRotation) * fDistFromCenter;
|
||||
const float fY = -sinf(fRotation) * fDistFromCenter;
|
||||
const float fX = RageFastCos(fRotation) * fDistFromCenter;
|
||||
const float fY = -RageFastSin(fRotation) * fDistFromCenter;
|
||||
|
||||
v[i].p = RageVector3( fX, fY, 0 );
|
||||
v[i].c = PLAYER_COLOR.GetValue( p );
|
||||
|
||||
@@ -514,7 +514,7 @@ void LifeMeterBar::DrawPrimitives()
|
||||
m_pStream->m_fPassingAlpha = m_fPassingAlpha;
|
||||
m_pStream->m_fHotAlpha = m_fHotAlpha;
|
||||
|
||||
float fPercentRed = (m_fTrailingLifePercentage<DANGER_THRESHOLD) ? sinf( RageTimer::GetTimeSinceStartFast()*PI*4 )/2+0.5f : 0;
|
||||
float fPercentRed = (m_fTrailingLifePercentage<DANGER_THRESHOLD) ? RageFastSin( RageTimer::GetTimeSinceStartFast()*PI*4 )/2+0.5f : 0;
|
||||
m_quadBlackBackground.SetDiffuse( RageColor(fPercentRed*0.8f,0,0,1) );
|
||||
|
||||
ActorFrame::DrawPrimitives();
|
||||
|
||||
@@ -785,16 +785,16 @@ void MusicWheel::GetItemPosition( float fPosOffsetsFromMiddle, float& fX_out, fl
|
||||
{
|
||||
const float curve = CIRCLE_PERCENT*2*PI;
|
||||
fRotationX_out = SCALE(fPosOffsetsFromMiddle,-NUM_WHEEL_ITEMS/2.0f,+NUM_WHEEL_ITEMS/2.0f,-curve/2.f,+curve/2.f);
|
||||
fX_out = (1-cosf(fPosOffsetsFromMiddle/PI))*ITEM_CURVE_X;
|
||||
fY_out = WHEEL_3D_RADIUS*sinf(fRotationX_out);
|
||||
fZ_out = -100+WHEEL_3D_RADIUS*cosf(fRotationX_out);
|
||||
fX_out = (1-RageFastCos(fPosOffsetsFromMiddle/PI))*ITEM_CURVE_X;
|
||||
fY_out = WHEEL_3D_RADIUS*RageFastSin(fRotationX_out);
|
||||
fZ_out = -100+WHEEL_3D_RADIUS*RageFastCos(fRotationX_out);
|
||||
fRotationX_out *= 180.f/PI; // to degrees
|
||||
|
||||
// printf( "fRotationX_out = %f\n", fRotationX_out );
|
||||
}
|
||||
else if(!USE_LINEAR_WHEEL)
|
||||
{
|
||||
fX_out = (1-cosf(fPosOffsetsFromMiddle/PI))*ITEM_CURVE_X;
|
||||
fX_out = (1-RageFastCos(fPosOffsetsFromMiddle/PI))*ITEM_CURVE_X;
|
||||
fY_out = fPosOffsetsFromMiddle*ITEM_SPACING_Y;
|
||||
fZ_out = 0;
|
||||
fRotationX_out = 0;
|
||||
|
||||
@@ -284,7 +284,7 @@ void NoteField::DrawBPMText( const float fBeat, const float fBPM )
|
||||
|
||||
m_textMeasureNumber.SetHorizAlign( Actor::align_right );
|
||||
m_textMeasureNumber.SetDiffuse( RageColor(1,0,0,1) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,cosf(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,RageFastCos(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetText( ssprintf("%.2f", fBPM) );
|
||||
m_textMeasureNumber.SetXY( -GetWidth()/2.f - 60, fYPos );
|
||||
m_textMeasureNumber.Draw();
|
||||
@@ -297,7 +297,7 @@ void NoteField::DrawFreezeText( const float fBeat, const float fSecs )
|
||||
|
||||
m_textMeasureNumber.SetHorizAlign( Actor::align_right );
|
||||
m_textMeasureNumber.SetDiffuse( RageColor(0.8f,0.8f,0,1) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,cosf(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,RageFastCos(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetText( ssprintf("%.2f", fSecs) );
|
||||
m_textMeasureNumber.SetXY( -GetWidth()/2.f - 10, fYPos );
|
||||
m_textMeasureNumber.Draw();
|
||||
@@ -310,7 +310,7 @@ void NoteField::DrawBGChangeText( const float fBeat, const CString sNewBGName )
|
||||
|
||||
m_textMeasureNumber.SetHorizAlign( Actor::align_left );
|
||||
m_textMeasureNumber.SetDiffuse( RageColor(0,1,0,1) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,cosf(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,RageFastCos(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetText( sNewBGName );
|
||||
m_textMeasureNumber.SetXY( +GetWidth()/2.f, fYPos );
|
||||
m_textMeasureNumber.Draw();
|
||||
@@ -525,7 +525,7 @@ void NoteField::DrawPrimitives()
|
||||
// draw in big batches.
|
||||
//
|
||||
|
||||
float fSelectedRangeGlow = SCALE( cosf(RageTimer::GetTimeSinceStartFast()*2), -1, 1, 0.1f, 0.3f );
|
||||
float fSelectedRangeGlow = SCALE( RageFastCos(RageTimer::GetTimeSinceStartFast()*2), -1, 1, 0.1f, 0.3f );
|
||||
|
||||
for( int c=0; c<m_pNoteData->GetNumTracks(); c++ ) // for each arrow column
|
||||
{
|
||||
|
||||
@@ -166,8 +166,8 @@ void RageDisplay::DrawCircleInternal( const RageSpriteVertex &p, float radius )
|
||||
for(int i = 0; i < subdivisions+1; ++i)
|
||||
{
|
||||
const float fRotation = float(i) / subdivisions * 2*PI;
|
||||
const float fX = cosf(fRotation) * radius;
|
||||
const float fY = -sinf(fRotation) * radius;
|
||||
const float fX = RageFastCos(fRotation) * radius;
|
||||
const float fY = -RageFastSin(fRotation) * radius;
|
||||
v[1+i] = v[0];
|
||||
v[1+i].p.x += fX;
|
||||
v[1+i].p.y += fY;
|
||||
|
||||
+82
-39
@@ -196,10 +196,10 @@ void RageMatrixRotationX( RageMatrix* pOut, float theta )
|
||||
theta *= PI/180;
|
||||
|
||||
RageMatrixIdentity(pOut);
|
||||
pOut->m[1][1] = cosf(theta);
|
||||
pOut->m[1][1] = RageFastCos(theta);
|
||||
pOut->m[2][2] = pOut->m[1][1];
|
||||
|
||||
pOut->m[2][1] = sinf(theta);
|
||||
pOut->m[2][1] = RageFastSin(theta);
|
||||
pOut->m[1][2] = -pOut->m[2][1];
|
||||
}
|
||||
|
||||
@@ -208,10 +208,10 @@ void RageMatrixRotationY( RageMatrix* pOut, float theta )
|
||||
theta *= PI/180;
|
||||
|
||||
RageMatrixIdentity(pOut);
|
||||
pOut->m[0][0] = cosf(theta);
|
||||
pOut->m[0][0] = RageFastCos(theta);
|
||||
pOut->m[2][2] = pOut->m[0][0];
|
||||
|
||||
pOut->m[0][2] = sinf(theta);
|
||||
pOut->m[0][2] = RageFastSin(theta);
|
||||
pOut->m[2][0] = -pOut->m[0][2];
|
||||
}
|
||||
|
||||
@@ -220,10 +220,10 @@ void RageMatrixRotationZ( RageMatrix* pOut, float theta )
|
||||
theta *= PI/180;
|
||||
|
||||
RageMatrixIdentity(pOut);
|
||||
pOut->m[0][0] = cosf(theta);
|
||||
pOut->m[0][0] = RageFastCos(theta);
|
||||
pOut->m[1][1] = pOut->m[0][0];
|
||||
|
||||
pOut->m[0][1] = sinf(theta);
|
||||
pOut->m[0][1] = RageFastSin(theta);
|
||||
pOut->m[1][0] = -pOut->m[0][1];
|
||||
}
|
||||
|
||||
@@ -236,12 +236,12 @@ void RageMatrixRotationXYZ( RageMatrix* pOut, float rX, float rY, float rZ )
|
||||
rY *= PI/180;
|
||||
rZ *= PI/180;
|
||||
|
||||
const float cX = cosf(rX);
|
||||
const float sX = sinf(rX);
|
||||
const float cY = cosf(rY);
|
||||
const float sY = sinf(rY);
|
||||
const float cZ = cosf(rZ);
|
||||
const float sZ = sinf(rZ);
|
||||
const float cX = RageFastCos(rX);
|
||||
const float sX = RageFastSin(rX);
|
||||
const float cY = RageFastCos(rY);
|
||||
const float sY = RageFastSin(rY);
|
||||
const float cZ = RageFastCos(rZ);
|
||||
const float sZ = RageFastSin(rZ);
|
||||
|
||||
/*
|
||||
* X*Y:
|
||||
@@ -309,8 +309,8 @@ RageVector4 RageQuatFromH(float theta )
|
||||
theta *= PI/180.0f;
|
||||
theta /= 2.0f;
|
||||
theta *= -1;
|
||||
const float c = cosf(theta);
|
||||
const float s = sinf(theta);
|
||||
const float c = RageFastCos(theta);
|
||||
const float s = RageFastSin(theta);
|
||||
|
||||
return RageVector4(0, s, 0, c);
|
||||
}
|
||||
@@ -320,8 +320,8 @@ RageVector4 RageQuatFromP(float theta )
|
||||
theta *= PI/180.0f;
|
||||
theta /= 2.0f;
|
||||
theta *= -1;
|
||||
const float c = cosf(theta);
|
||||
const float s = sinf(theta);
|
||||
const float c = RageFastCos(theta);
|
||||
const float s = RageFastSin(theta);
|
||||
|
||||
return RageVector4(s, 0, 0, c);
|
||||
}
|
||||
@@ -331,8 +331,8 @@ RageVector4 RageQuatFromR(float theta )
|
||||
theta *= PI/180.0f;
|
||||
theta /= 2.0f;
|
||||
theta *= -1;
|
||||
const float c = cosf(theta);
|
||||
const float s = sinf(theta);
|
||||
const float c = RageFastCos(theta);
|
||||
const float s = RageFastSin(theta);
|
||||
|
||||
return RageVector4(0, 0, s, c);
|
||||
}
|
||||
@@ -347,12 +347,12 @@ void RageQuatFromHPR(RageVector4* pOut, RageVector3 hpr )
|
||||
hpr /= 180.0f;
|
||||
hpr /= 2.0f;
|
||||
|
||||
const float sX = sinf(hpr.x);
|
||||
const float cX = cosf(hpr.x);
|
||||
const float sY = sinf(hpr.y);
|
||||
const float cY = cosf(hpr.y);
|
||||
const float sZ = sinf(hpr.z);
|
||||
const float cZ = cosf(hpr.z);
|
||||
const float sX = RageFastSin(hpr.x);
|
||||
const float cX = RageFastCos(hpr.x);
|
||||
const float sY = RageFastSin(hpr.y);
|
||||
const float cY = RageFastCos(hpr.y);
|
||||
const float sZ = RageFastSin(hpr.z);
|
||||
const float cZ = RageFastCos(hpr.z);
|
||||
|
||||
pOut->w = cX * cY * cZ + sX * sY * sZ;
|
||||
pOut->x = sX * cY * cZ - cX * sY * sZ;
|
||||
@@ -375,12 +375,12 @@ void RageQuatFromPRH(RageVector4* pOut, RageVector3 prh )
|
||||
/* Set cX to the cosine of the angle we want to rotate on the X axis,
|
||||
* and so on. Here, hpr.z (roll) rotates on the Z axis, hpr.x (heading)
|
||||
* on Y, and hpr.y (pitch) on X. */
|
||||
const float sX = sinf(prh.y);
|
||||
const float cX = cosf(prh.y);
|
||||
const float sY = sinf(prh.x);
|
||||
const float cY = cosf(prh.x);
|
||||
const float sZ = sinf(prh.z);
|
||||
const float cZ = cosf(prh.z);
|
||||
const float sX = RageFastSin(prh.y);
|
||||
const float cX = RageFastCos(prh.y);
|
||||
const float sY = RageFastSin(prh.x);
|
||||
const float cY = RageFastCos(prh.x);
|
||||
const float sZ = RageFastSin(prh.z);
|
||||
const float cZ = RageFastCos(prh.z);
|
||||
|
||||
pOut->w = cX * cY * cZ + sX * sY * sZ;
|
||||
pOut->x = sX * cY * cZ - cX * sY * sZ;
|
||||
@@ -439,9 +439,9 @@ void RageQuatSlerp(RageVector4 *pOut, const RageVector4 &from, const RageVector4
|
||||
{
|
||||
// standard case (slerp)
|
||||
float omega = acosf(cosom);
|
||||
float sinom = sinf(omega);
|
||||
scale0 = sinf((1.0f - t) * omega) / sinom;
|
||||
scale1 = sinf(t * omega) / sinom;
|
||||
float sinom = RageFastSin(omega);
|
||||
scale0 = RageFastSin((1.0f - t) * omega) / sinom;
|
||||
scale1 = RageFastSin(t * omega) / sinom;
|
||||
} else {
|
||||
// "from" and "to" quaternions are very close
|
||||
// ... so we can do a linear interpolation
|
||||
@@ -497,12 +497,12 @@ void RageMatrixAngles( RageMatrix* pOut, const RageVector3 &angles )
|
||||
{
|
||||
const RageVector3 angles_radians( angles * 2*PI / 360 );
|
||||
|
||||
const float sy = sinf( angles_radians[2] );
|
||||
const float cy = cosf( angles_radians[2] );
|
||||
const float sp = sinf( angles_radians[1] );
|
||||
const float cp = cosf( angles_radians[1] );
|
||||
const float sr = sinf( angles_radians[0] );
|
||||
const float cr = cosf( angles_radians[0] );
|
||||
const float sy = RageFastSin( angles_radians[2] );
|
||||
const float cy = RageFastCos( angles_radians[2] );
|
||||
const float sp = RageFastSin( angles_radians[1] );
|
||||
const float cp = RageFastCos( angles_radians[1] );
|
||||
const float sr = RageFastSin( angles_radians[0] );
|
||||
const float cr = RageFastCos( angles_radians[0] );
|
||||
|
||||
RageMatrixIdentity( pOut );
|
||||
|
||||
@@ -526,6 +526,49 @@ void RageMatrixTranspose( RageMatrix* pOut, const RageMatrix* pIn )
|
||||
pOut->m[j][i] = pIn->m[i][j];
|
||||
}
|
||||
|
||||
float RageFastSin( float x )
|
||||
{
|
||||
// from 0 to PI
|
||||
// sizeof(table) == 4096 == one page of memory in Windows
|
||||
static float table[1024];
|
||||
|
||||
static bool bInited = false;
|
||||
if( !bInited )
|
||||
{
|
||||
bInited = true;
|
||||
for( int i=0; i<ARRAYSIZE(table); i++ )
|
||||
{
|
||||
float x = SCALE(i,0,ARRAYSIZE(table),0.0f,PI);
|
||||
table[i] = sinf(x);
|
||||
}
|
||||
}
|
||||
|
||||
int i = (int)SCALE( x, 0.0f, PI*2, 0, ARRAYSIZE(table)*2 );
|
||||
i %= ARRAYSIZE(table) * 2;
|
||||
|
||||
DEBUG_ASSERT( i>=0 && i<ARRAYSIZE(table)*2 );
|
||||
|
||||
float fRet;
|
||||
if( i >= ARRAYSIZE(table) ) // PI <= i < 2*PI
|
||||
{
|
||||
// sin(x) == -sin(2*PI-x)
|
||||
i = ARRAYSIZE(table)*2 - 1 - i; // mirror about ARRAYSIZE(table)
|
||||
DEBUG_ASSERT( i>=0 && i<ARRAYSIZE(table) );
|
||||
fRet = -table[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
fRet = table[i];
|
||||
}
|
||||
|
||||
return fRet;
|
||||
}
|
||||
|
||||
float RageFastCos( float x )
|
||||
{
|
||||
return RageFastSin( x + 0.5f*PI );
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Chris Danford
|
||||
* All rights reserved.
|
||||
|
||||
@@ -45,6 +45,9 @@ RageMatrix RageLookAt(
|
||||
void RageMatrixAngles( RageMatrix* pOut, const RageVector3 &angles );
|
||||
void RageMatrixTranspose( RageMatrix* pOut, const RageMatrix* pIn );
|
||||
|
||||
float RageFastSin( float x );
|
||||
float RageFastCos( float x );
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user