mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-09-03 20:39:39 +02:00
Merge from V2: Fix flipper animation and angle calculation (#150)
This commit is contained in:
parent
7f3bee15f0
commit
20032b0893
@ -137,7 +137,7 @@ void TFlipper::TimerExpired(int timerId, void* caller)
|
|||||||
auto flip = static_cast<TFlipper*>(caller);
|
auto flip = static_cast<TFlipper*>(caller);
|
||||||
int bmpCountSub1 = flip->ListBitmap->GetCount() - 1;
|
int bmpCountSub1 = flip->ListBitmap->GetCount() - 1;
|
||||||
|
|
||||||
auto newBmpIndex = static_cast<int>(floor((pb::time_now - flip->InputTime) / flip->TimerTime));
|
auto newBmpIndex = static_cast<int>(floor(flip->FlipperEdge->flipper_angle(pb::time_now) / flip->FlipperEdge->AngleMax * bmpCountSub1 + 0.5));
|
||||||
if (newBmpIndex > bmpCountSub1)
|
if (newBmpIndex > bmpCountSub1)
|
||||||
newBmpIndex = bmpCountSub1;
|
newBmpIndex = bmpCountSub1;
|
||||||
if (newBmpIndex < 0)
|
if (newBmpIndex < 0)
|
||||||
@ -155,7 +155,7 @@ void TFlipper::TimerExpired(int timerId, void* caller)
|
|||||||
}
|
}
|
||||||
if (flip->MessageField == 2)
|
if (flip->MessageField == 2)
|
||||||
{
|
{
|
||||||
flip->BmpIndex = bmpCountSub1 - newBmpIndex;
|
flip->BmpIndex = newBmpIndex;
|
||||||
if (flip->BmpIndex <= 0)
|
if (flip->BmpIndex <= 0)
|
||||||
{
|
{
|
||||||
flip->BmpIndex = 0;
|
flip->BmpIndex = 0;
|
||||||
|
@ -419,19 +419,17 @@ float TFlipperEdge::flipper_angle(float timeNow)
|
|||||||
{
|
{
|
||||||
if (!FlipperFlag)
|
if (!FlipperFlag)
|
||||||
return Angle1;
|
return Angle1;
|
||||||
float angle = (Angle1 - Angle2) / AngleMax * AngleMult;
|
|
||||||
if (angle < 0.0f)
|
|
||||||
angle = -angle;
|
|
||||||
|
|
||||||
if (angle >= 0.0000001f)
|
float currentAngleDuration = fabsf((Angle1 - Angle2) / AngleMax * AngleMult);
|
||||||
angle = (timeNow - InputTime) / angle;
|
float currentAngleRatio;
|
||||||
|
|
||||||
|
if (currentAngleDuration >= 0.0000001f)
|
||||||
|
currentAngleRatio = (timeNow - InputTime) / currentAngleDuration;
|
||||||
else
|
else
|
||||||
angle = 1.0;
|
currentAngleRatio = 1.0;
|
||||||
|
|
||||||
angle = min(1, max(angle, 0));
|
currentAngleRatio = min(1.0f, max(currentAngleRatio, 0.0f));
|
||||||
if (FlipperFlag == 2)
|
return currentAngleRatio * (Angle1 - Angle2) + Angle2;
|
||||||
angle = 1.0f - angle;
|
|
||||||
return angle * AngleMax;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TFlipperEdge::is_ball_inside(float x, float y)
|
int TFlipperEdge::is_ball_inside(float x, float y)
|
||||||
@ -483,8 +481,7 @@ void TFlipperEdge::SetMotion(int code, float value)
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FlipperFlag)
|
InputTime = value;
|
||||||
InputTime = value;
|
|
||||||
FlipperFlag = code;
|
FlipperFlag = code;
|
||||||
AngleStopTime = AngleMult + InputTime;
|
AngleStopTime = AngleMult + InputTime;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user