2021-01-09 17:11:03 +01:00
|
|
|
#include "pch.h"
|
|
|
|
#include "TFlipperEdge.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "TLine.h"
|
|
|
|
#include "TPinballTable.h"
|
|
|
|
#include "TTableLayer.h"
|
|
|
|
|
|
|
|
float TFlipperEdge::flipper_sin_angle, TFlipperEdge::flipper_cos_angle;
|
2022-05-11 15:47:13 +02:00
|
|
|
vector2 TFlipperEdge::A1, TFlipperEdge::A2, TFlipperEdge::B1, TFlipperEdge::B2, TFlipperEdge::T1;
|
2021-01-09 17:11:03 +01:00
|
|
|
line_type TFlipperEdge::lineA, TFlipperEdge::lineB;
|
|
|
|
circle_type TFlipperEdge::circlebase, TFlipperEdge::circleT1;
|
|
|
|
|
2021-01-28 16:01:26 +01:00
|
|
|
TFlipperEdge::TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, TPinballTable* table,
|
2022-05-11 15:42:45 +02:00
|
|
|
vector3* origin, vector3* vecT1, vector3* vecT2, float extendTime, float retractTime,
|
2021-01-28 16:01:26 +01:00
|
|
|
float collMult, float elasticity, float smoothness): TEdgeSegment(collComp, activeFlag, collisionGroup)
|
2021-01-09 17:11:03 +01:00
|
|
|
{
|
2022-05-11 15:42:45 +02:00
|
|
|
vector3 crossProd{}, vecDir1{}, vecDir2{};
|
2021-01-09 17:11:03 +01:00
|
|
|
|
2021-01-23 11:33:30 +01:00
|
|
|
Elasticity = elasticity;
|
|
|
|
Smoothness = smoothness;
|
2021-10-07 07:01:34 +02:00
|
|
|
ExtendTime = extendTime;
|
|
|
|
RetractTime = retractTime;
|
2021-01-10 13:22:06 +01:00
|
|
|
CollisionMult = collMult;
|
2021-01-09 17:11:03 +01:00
|
|
|
|
2022-05-13 10:15:30 +02:00
|
|
|
T1Src = static_cast<vector2>(*vecT1);
|
|
|
|
T2Src = static_cast<vector2>(*vecT2);
|
2021-01-09 17:11:03 +01:00
|
|
|
RotOrigin.X = origin->X;
|
|
|
|
RotOrigin.Y = origin->Y;
|
|
|
|
|
|
|
|
CirclebaseRadius = origin->Z + table->CollisionCompOffset;
|
|
|
|
CirclebaseRadiusMSq = CirclebaseRadius * 1.01f * (CirclebaseRadius * 1.01f);
|
|
|
|
CirclebaseRadiusSq = CirclebaseRadius * CirclebaseRadius;
|
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
CircleT1Radius = vecT1->Z + table->CollisionCompOffset;
|
2021-01-09 17:11:03 +01:00
|
|
|
CircleT1RadiusMSq = CircleT1Radius * 1.01f * (CircleT1Radius * 1.01f);
|
|
|
|
CircleT1RadiusSq = CircleT1Radius * CircleT1Radius;
|
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
vecDir1.X = vecT1->X - origin->X;
|
|
|
|
vecDir1.Y = vecT1->Y - origin->Y;
|
2021-01-09 17:11:03 +01:00
|
|
|
vecDir1.Z = 0.0;
|
2022-05-13 10:15:30 +02:00
|
|
|
maths::normalize_2d(vecDir1);
|
2021-01-09 17:11:03 +01:00
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
vecDir2.X = vecT2->X - origin->X;
|
|
|
|
vecDir2.Y = vecT2->Y - origin->Y;
|
2021-01-09 17:11:03 +01:00
|
|
|
vecDir2.Z = 0.0;
|
2022-05-13 10:15:30 +02:00
|
|
|
maths::normalize_2d(vecDir2);
|
2021-01-09 17:11:03 +01:00
|
|
|
|
2022-05-13 10:15:30 +02:00
|
|
|
AngleMax = acos(maths::DotProduct(vecDir1, vecDir2));
|
|
|
|
maths::cross(vecDir1, vecDir2, crossProd);
|
2021-02-18 10:53:25 +01:00
|
|
|
if (crossProd.Z < 0.0f)
|
2021-01-09 17:11:03 +01:00
|
|
|
AngleMax = -AngleMax;
|
|
|
|
FlipperFlag = 0;
|
|
|
|
Angle1 = 0.0;
|
|
|
|
|
|
|
|
auto dirX1 = vecDir1.X;
|
|
|
|
auto dirY1 = -vecDir1.Y;
|
|
|
|
A2Src.X = dirY1 * CirclebaseRadius + origin->X;
|
|
|
|
A2Src.Y = dirX1 * CirclebaseRadius + origin->Y;
|
2021-01-10 13:22:06 +01:00
|
|
|
A1Src.X = dirY1 * CircleT1Radius + vecT1->X;
|
|
|
|
A1Src.Y = dirX1 * CircleT1Radius + vecT1->Y;
|
2021-01-09 17:11:03 +01:00
|
|
|
|
|
|
|
dirX1 = -dirX1;
|
|
|
|
dirY1 = -dirY1;
|
|
|
|
B1Src.X = dirY1 * CirclebaseRadius + origin->X;
|
|
|
|
B1Src.Y = dirX1 * CirclebaseRadius + origin->Y;
|
2021-01-10 13:22:06 +01:00
|
|
|
B2Src.X = dirY1 * CircleT1Radius + vecT1->X;
|
|
|
|
B2Src.Y = dirX1 * CircleT1Radius + vecT1->Y;
|
2021-01-09 17:11:03 +01:00
|
|
|
|
2021-02-18 10:53:25 +01:00
|
|
|
if (AngleMax < 0.0f)
|
2021-01-09 17:11:03 +01:00
|
|
|
{
|
2022-05-13 10:15:30 +02:00
|
|
|
std::swap(A1Src, B1Src);
|
|
|
|
std::swap(A2Src, B2Src);
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
auto dx = vecT1->X - RotOrigin.X;
|
|
|
|
auto dy = vecT1->Y - RotOrigin.Y;
|
|
|
|
auto distance1 = sqrt(dy * dy + dx * dx) + table->CollisionCompOffset + vecT1->Z;
|
2021-01-09 17:11:03 +01:00
|
|
|
DistanceDivSq = distance1 * distance1;
|
|
|
|
|
2021-10-07 07:01:34 +02:00
|
|
|
float minMoveTime = std::min(ExtendTime, RetractTime);
|
2022-05-13 10:15:30 +02:00
|
|
|
auto distance = maths::Distance(*vecT1, *vecT2);
|
2021-10-07 07:01:34 +02:00
|
|
|
CollisionTimeAdvance = minMoveTime / (distance / CircleT1Radius + distance / CircleT1Radius);
|
2021-01-09 17:11:03 +01:00
|
|
|
|
|
|
|
TFlipperEdge::place_in_grid();
|
2021-01-10 13:22:06 +01:00
|
|
|
EdgeCollisionFlag = 0;
|
|
|
|
InputTime = 0.0;
|
|
|
|
CollisionFlag1 = 0;
|
|
|
|
AngleStopTime = 0.0;
|
2021-01-09 17:11:03 +01:00
|
|
|
AngleMult = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFlipperEdge::port_draw()
|
|
|
|
{
|
2021-01-10 13:22:06 +01:00
|
|
|
set_control_points(InputTime);
|
2021-01-09 17:11:03 +01:00
|
|
|
build_edges_in_motion();
|
|
|
|
}
|
|
|
|
|
|
|
|
float TFlipperEdge::FindCollisionDistance(ray_type* ray)
|
|
|
|
{
|
|
|
|
auto ogRay = ray;
|
2021-01-10 13:22:06 +01:00
|
|
|
ray_type dstRay{}, srcRay{};
|
2021-01-09 17:11:03 +01:00
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
if (ogRay->TimeNow > AngleStopTime)
|
|
|
|
{
|
|
|
|
FlipperFlag = 0;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
if (EdgeCollisionFlag == 0)
|
|
|
|
{
|
|
|
|
if (FlipperFlag == 0)
|
|
|
|
{
|
|
|
|
CollisionFlag1 = 0;
|
|
|
|
CollisionFlag2 = 0;
|
|
|
|
set_control_points(ogRay->TimeNow);
|
2021-01-09 17:11:03 +01:00
|
|
|
build_edges_in_motion();
|
2021-01-10 13:22:06 +01:00
|
|
|
auto ballInside = is_ball_inside(ogRay->Origin.X, ogRay->Origin.Y);
|
|
|
|
srcRay.MinDistance = ogRay->MinDistance;
|
|
|
|
if (ballInside == 0)
|
|
|
|
{
|
|
|
|
srcRay.Direction = ogRay->Direction;
|
|
|
|
srcRay.MaxDistance = ogRay->MaxDistance;
|
|
|
|
srcRay.Origin = ogRay->Origin;
|
2022-05-16 08:28:35 +02:00
|
|
|
auto distance = maths::distance_to_flipper(srcRay, dstRay);
|
2021-02-18 10:53:25 +01:00
|
|
|
if (distance == 0.0f)
|
2021-01-10 13:22:06 +01:00
|
|
|
{
|
|
|
|
NextBallPosition = dstRay.Origin;
|
|
|
|
NextBallPosition.X -= srcRay.Direction.X * 1e-05f;
|
|
|
|
NextBallPosition.Y -= srcRay.Direction.Y * 1e-05f;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
NextBallPosition = dstRay.Origin;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
CollisionDirection = dstRay.Direction;
|
|
|
|
return distance;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
|
|
|
|
if (maths::Distance_Squared(ogRay->Origin, RotOrigin) >= CirclebaseRadiusMSq)
|
|
|
|
{
|
|
|
|
if (maths::Distance_Squared(ogRay->Origin, T1) >= CircleT1RadiusMSq)
|
|
|
|
{
|
2022-05-13 10:15:30 +02:00
|
|
|
srcRay.Direction.Y = lineB.PerpendicularC.Y;
|
|
|
|
srcRay.Direction.X = lineB.PerpendicularC.X;
|
2021-01-10 13:22:06 +01:00
|
|
|
if (ballInside == 4)
|
|
|
|
{
|
2022-05-13 10:15:30 +02:00
|
|
|
srcRay.Direction.Y = lineA.PerpendicularC.Y;
|
|
|
|
srcRay.Direction.X = lineA.PerpendicularC.X;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
srcRay.Direction.X = -srcRay.Direction.X;
|
|
|
|
srcRay.Direction.Y = -srcRay.Direction.Y;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
srcRay.Direction.X = T1.X - ogRay->Origin.X;
|
|
|
|
srcRay.Direction.Y = T1.Y - ogRay->Origin.Y;
|
2022-05-13 10:15:30 +02:00
|
|
|
maths::normalize_2d(srcRay.Direction);
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
srcRay.Direction.X = RotOrigin.X - ogRay->Origin.X;
|
|
|
|
srcRay.Direction.Y = RotOrigin.Y - ogRay->Origin.Y;
|
2022-05-13 10:15:30 +02:00
|
|
|
maths::normalize_2d(srcRay.Direction);
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
|
|
|
|
srcRay.Origin.X = ogRay->Origin.X - srcRay.Direction.X * 5.0f;
|
|
|
|
srcRay.Origin.Y = ogRay->Origin.Y - srcRay.Direction.Y * 5.0f;
|
|
|
|
srcRay.MaxDistance = ogRay->MaxDistance + 10.0f;
|
2022-05-16 08:28:35 +02:00
|
|
|
if (maths::distance_to_flipper(srcRay, dstRay) >= 1e+09f)
|
2021-01-10 13:22:06 +01:00
|
|
|
{
|
|
|
|
srcRay.Direction.X = RotOrigin.X - ogRay->Origin.X;
|
|
|
|
srcRay.Direction.Y = RotOrigin.Y - ogRay->Origin.Y;
|
2022-05-13 10:15:30 +02:00
|
|
|
maths::normalize_2d(srcRay.Direction);
|
2021-01-10 13:22:06 +01:00
|
|
|
srcRay.Origin.X = ogRay->Origin.X - srcRay.Direction.X * 5.0f;
|
|
|
|
srcRay.Origin.Y = ogRay->Origin.Y - srcRay.Direction.Y * 5.0f;
|
2022-05-16 08:28:35 +02:00
|
|
|
if (maths::distance_to_flipper(srcRay, dstRay) >= 1e+09f)
|
2021-01-10 13:22:06 +01:00
|
|
|
{
|
2021-01-09 17:11:03 +01:00
|
|
|
return 1e+09;
|
|
|
|
}
|
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
|
|
|
|
NextBallPosition = dstRay.Origin;
|
|
|
|
CollisionDirection = dstRay.Direction;
|
|
|
|
NextBallPosition.X -= srcRay.Direction.X * 1e-05f;
|
|
|
|
NextBallPosition.Y -= srcRay.Direction.Y * 1e-05f;
|
2021-01-09 17:11:03 +01:00
|
|
|
return 0.0;
|
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
|
|
|
|
auto posX = ogRay->Origin.X;
|
|
|
|
auto posY = ogRay->Origin.Y;
|
|
|
|
auto posXAdvance = ogRay->Direction.X * CollisionTimeAdvance;
|
|
|
|
auto posYAdvance = ogRay->Direction.Y * CollisionTimeAdvance;
|
|
|
|
auto rayMaxDistance = ogRay->MaxDistance * CollisionTimeAdvance;
|
|
|
|
auto timeNow = ogRay->TimeNow;
|
|
|
|
auto stopTime = ogRay->TimeDelta + ogRay->TimeNow;
|
|
|
|
while (timeNow < stopTime)
|
|
|
|
{
|
|
|
|
set_control_points(timeNow);
|
2021-01-09 17:11:03 +01:00
|
|
|
build_edges_in_motion();
|
2021-01-10 13:22:06 +01:00
|
|
|
auto ballInside = is_ball_inside(posX, posY);
|
|
|
|
if (ballInside != 0)
|
|
|
|
{
|
2022-05-11 15:47:13 +02:00
|
|
|
vector2* linePtr;
|
2021-01-10 13:22:06 +01:00
|
|
|
if (FlipperFlag == 1 && ballInside != 5)
|
|
|
|
{
|
2022-05-13 10:15:30 +02:00
|
|
|
linePtr = &lineA.PerpendicularC;
|
|
|
|
srcRay.Direction.Y = lineA.PerpendicularC.Y;
|
|
|
|
srcRay.Direction.X = lineA.PerpendicularC.X;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FlipperFlag != 2 || ballInside == 4)
|
|
|
|
{
|
|
|
|
CollisionFlag1 = 0;
|
|
|
|
CollisionFlag2 = 1;
|
|
|
|
srcRay.Direction.X = RotOrigin.X - posX;
|
|
|
|
srcRay.Direction.Y = RotOrigin.Y - posY;
|
2022-05-13 10:15:30 +02:00
|
|
|
maths::normalize_2d(srcRay.Direction);
|
2021-01-10 13:22:06 +01:00
|
|
|
|
|
|
|
srcRay.Origin.X = posX - srcRay.Direction.X * 5.0f;
|
|
|
|
srcRay.Origin.Y = posY - srcRay.Direction.Y * 5.0f;
|
|
|
|
srcRay.MaxDistance = ogRay->MaxDistance + 10.0f;
|
2022-05-16 08:28:35 +02:00
|
|
|
if (maths::distance_to_flipper(srcRay, dstRay) >= 1e+09f)
|
2021-01-10 13:22:06 +01:00
|
|
|
{
|
|
|
|
NextBallPosition.X = posX;
|
|
|
|
NextBallPosition.Y = posY;
|
|
|
|
CollisionDirection.X = -srcRay.Direction.X;
|
|
|
|
CollisionDirection.Y = -srcRay.Direction.Y;
|
2021-01-09 17:11:03 +01:00
|
|
|
return 0.0;
|
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
|
|
|
|
NextBallPosition = dstRay.Origin;
|
|
|
|
CollisionDirection = dstRay.Direction;
|
|
|
|
NextBallPosition.X -= srcRay.Direction.X * 1e-05f;
|
|
|
|
NextBallPosition.Y -= srcRay.Direction.Y * 1e-05f;
|
|
|
|
return 0.0;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2022-05-13 10:15:30 +02:00
|
|
|
linePtr = &lineB.PerpendicularC;
|
|
|
|
srcRay.Direction.Y = lineB.PerpendicularC.Y;
|
|
|
|
srcRay.Direction.X = lineB.PerpendicularC.X;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
|
|
|
|
CollisionLinePerp = *linePtr;
|
|
|
|
CollisionFlag2 = 0;
|
|
|
|
CollisionFlag1 = 1;
|
|
|
|
srcRay.Direction.X = -srcRay.Direction.X;
|
|
|
|
srcRay.Direction.Y = -srcRay.Direction.Y;
|
|
|
|
srcRay.MinDistance = 0.002f;
|
|
|
|
srcRay.Origin.X = ogRay->Origin.X - srcRay.Direction.X * 5.0f;
|
|
|
|
srcRay.Origin.Y = ogRay->Origin.Y - srcRay.Direction.Y * 5.0f;
|
|
|
|
srcRay.MaxDistance = ogRay->MaxDistance + 10.0f;
|
2022-05-16 08:28:35 +02:00
|
|
|
auto distance = maths::distance_to_flipper(srcRay, dstRay);
|
2021-01-10 13:22:06 +01:00
|
|
|
CollisionDirection = dstRay.Direction;
|
2021-02-18 10:53:25 +01:00
|
|
|
if (distance >= 1e+09f)
|
2021-01-10 13:22:06 +01:00
|
|
|
{
|
2021-01-09 17:11:03 +01:00
|
|
|
return 1e+09;
|
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
NextBallPosition = dstRay.Origin;
|
|
|
|
NextBallPosition.X -= srcRay.Direction.X * 1e-05f;
|
|
|
|
NextBallPosition.Y -= srcRay.Direction.Y * 1e-05f;
|
|
|
|
return 0.0;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
|
|
|
|
srcRay.Direction = ogRay->Direction;
|
|
|
|
srcRay.MinDistance = ogRay->MinDistance;
|
|
|
|
srcRay.Origin = ogRay->Origin;
|
|
|
|
srcRay.MaxDistance = rayMaxDistance;
|
2022-05-16 08:28:35 +02:00
|
|
|
auto distance = maths::distance_to_flipper(srcRay, dstRay);
|
2021-02-18 10:53:25 +01:00
|
|
|
if (distance < 1e+09f)
|
2021-01-10 13:22:06 +01:00
|
|
|
{
|
|
|
|
NextBallPosition = dstRay.Origin;
|
|
|
|
NextBallPosition.X -= srcRay.Direction.X * 1e-05f;
|
|
|
|
NextBallPosition.Y -= srcRay.Direction.Y * 1e-05f;
|
2022-05-11 15:47:13 +02:00
|
|
|
vector2* linePtr;
|
2021-01-10 13:22:06 +01:00
|
|
|
if (FlipperFlag == 2)
|
|
|
|
{
|
2022-05-13 10:15:30 +02:00
|
|
|
linePtr = &lineB.PerpendicularC;
|
2021-02-18 10:53:25 +01:00
|
|
|
CollisionFlag1 = AngleMax <= 0.0f;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
else
|
|
|
|
{
|
2021-02-18 10:53:25 +01:00
|
|
|
CollisionFlag1 = AngleMax > 0.0f;
|
2022-05-13 10:15:30 +02:00
|
|
|
linePtr = &lineA.PerpendicularC;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
CollisionLinePerp = *linePtr;
|
|
|
|
CollisionDirection = dstRay.Direction;
|
|
|
|
return distance;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
timeNow = timeNow + CollisionTimeAdvance;
|
|
|
|
posX = posX + posXAdvance;
|
|
|
|
posY = posY + posYAdvance;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-10 13:22:06 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
EdgeCollisionFlag = 0;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
|
|
|
return 1e+09;
|
|
|
|
}
|
|
|
|
|
2022-05-20 10:51:00 +02:00
|
|
|
void TFlipperEdge::EdgeCollision(TBall* ball, float distance)
|
2021-01-09 17:11:03 +01:00
|
|
|
{
|
2021-01-10 13:22:06 +01:00
|
|
|
EdgeCollisionFlag = 1;
|
|
|
|
if (!FlipperFlag || !CollisionFlag2 || CollisionFlag1)
|
2021-01-09 17:11:03 +01:00
|
|
|
{
|
2021-01-23 11:33:30 +01:00
|
|
|
float boost = 0.0;
|
2021-01-10 13:22:06 +01:00
|
|
|
if (CollisionFlag1)
|
2021-01-09 17:11:03 +01:00
|
|
|
{
|
|
|
|
float dx = NextBallPosition.X - RotOrigin.X;
|
|
|
|
float dy = NextBallPosition.Y - RotOrigin.Y;
|
2022-05-20 10:51:00 +02:00
|
|
|
float distanceSq = dy * dy + dx * dx;
|
|
|
|
if (circlebase.RadiusSq * 1.01f < distanceSq)
|
2021-01-09 17:11:03 +01:00
|
|
|
{
|
|
|
|
float v11;
|
2022-05-20 10:51:00 +02:00
|
|
|
float v20 = sqrt(distanceSq / DistanceDivSq) * (fabs(AngleMax) / AngleMult);
|
2022-05-13 10:15:30 +02:00
|
|
|
float dot1 = maths::DotProduct(CollisionLinePerp, CollisionDirection);
|
2021-02-18 10:53:25 +01:00
|
|
|
if (dot1 >= 0.0f)
|
2021-01-09 17:11:03 +01:00
|
|
|
v11 = dot1 * v20;
|
|
|
|
else
|
|
|
|
v11 = 0.0;
|
2021-01-23 11:33:30 +01:00
|
|
|
boost = v11 * CollisionMult;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 10:53:25 +01:00
|
|
|
float threshold = boost <= 0.0f ? 1000000000.0f : -1.0f;
|
2021-01-09 17:11:03 +01:00
|
|
|
maths::basic_collision(
|
|
|
|
ball,
|
|
|
|
&NextBallPosition,
|
|
|
|
&CollisionDirection,
|
2021-01-23 11:33:30 +01:00
|
|
|
Elasticity,
|
|
|
|
Smoothness,
|
|
|
|
threshold,
|
|
|
|
boost);
|
2021-01-09 17:11:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-23 11:33:30 +01:00
|
|
|
float elasticity;
|
2021-01-09 17:11:03 +01:00
|
|
|
float dx = NextBallPosition.X - RotOrigin.X;
|
|
|
|
float dy = NextBallPosition.Y - RotOrigin.Y;
|
2022-05-20 10:51:00 +02:00
|
|
|
float distanceSq = dy * dy + dx * dx;
|
|
|
|
if (circlebase.RadiusSq * 1.01f < distanceSq)
|
|
|
|
elasticity = (1.0f - sqrt(distanceSq / DistanceDivSq)) * Elasticity;
|
2021-01-09 17:11:03 +01:00
|
|
|
else
|
2021-01-23 11:33:30 +01:00
|
|
|
elasticity = Elasticity;
|
|
|
|
maths::basic_collision(ball, &NextBallPosition, &CollisionDirection, elasticity, Smoothness, 1000000000.0, 0.0);
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TFlipperEdge::place_in_grid()
|
|
|
|
{
|
|
|
|
float x0 = RotOrigin.X - CirclebaseRadius;
|
|
|
|
float y0 = RotOrigin.Y - CirclebaseRadius;
|
2021-01-10 13:22:06 +01:00
|
|
|
float x1 = RotOrigin.X + CirclebaseRadius;
|
|
|
|
float y1 = RotOrigin.Y + CirclebaseRadius;
|
2021-01-09 17:11:03 +01:00
|
|
|
|
|
|
|
float v2 = T1Src.X - CircleT1Radius;
|
|
|
|
if (v2 < x0)
|
|
|
|
x0 = v2;
|
|
|
|
|
|
|
|
float v3 = T1Src.Y - CircleT1Radius;
|
|
|
|
if (v3 < y0)
|
|
|
|
y0 = v3;
|
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
float v4 = T1Src.X + CircleT1Radius;
|
2021-01-09 17:11:03 +01:00
|
|
|
if (v4 > x1)
|
|
|
|
x1 = v4;
|
|
|
|
|
|
|
|
float v5 = T1Src.Y + CircleT1Radius;
|
2021-01-10 13:22:06 +01:00
|
|
|
if (v5 > y1)
|
|
|
|
y1 = v5;
|
2021-01-09 17:11:03 +01:00
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
float v6 = T2Src.X - CircleT1Radius;
|
2021-01-09 17:11:03 +01:00
|
|
|
if (v6 < x0)
|
|
|
|
x0 = v6;
|
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
float v7 = T2Src.Y - CircleT1Radius;
|
2021-01-09 17:11:03 +01:00
|
|
|
if (v7 < y0)
|
|
|
|
y0 = v7;
|
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
float v8 = T2Src.X + CircleT1Radius;
|
2021-01-09 17:11:03 +01:00
|
|
|
if (v8 > x1)
|
|
|
|
x1 = v8;
|
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
float v9 = T2Src.Y + CircleT1Radius;
|
|
|
|
if (v9 > y1)
|
|
|
|
y1 = v9;
|
2021-01-09 17:11:03 +01:00
|
|
|
|
|
|
|
TTableLayer::edges_insert_square(y0, x0, y1, x1, this, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFlipperEdge::set_control_points(float timeNow)
|
|
|
|
{
|
2022-05-16 08:28:35 +02:00
|
|
|
maths::SinCos(flipper_angle(timeNow), flipper_sin_angle, flipper_cos_angle);
|
2021-01-09 17:11:03 +01:00
|
|
|
A1 = A1Src;
|
|
|
|
A2 = A2Src;
|
|
|
|
B1 = B1Src;
|
|
|
|
B2 = B2Src;
|
|
|
|
T1 = T1Src;
|
2022-05-13 10:15:30 +02:00
|
|
|
maths::RotatePt(A1, flipper_sin_angle, flipper_cos_angle, RotOrigin);
|
|
|
|
maths::RotatePt(A2, flipper_sin_angle, flipper_cos_angle, RotOrigin);
|
|
|
|
maths::RotatePt(T1, flipper_sin_angle, flipper_cos_angle, RotOrigin);
|
|
|
|
maths::RotatePt(B1, flipper_sin_angle, flipper_cos_angle, RotOrigin);
|
|
|
|
maths::RotatePt(B2, flipper_sin_angle, flipper_cos_angle, RotOrigin);
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TFlipperEdge::build_edges_in_motion()
|
|
|
|
{
|
2022-05-16 08:28:35 +02:00
|
|
|
maths::line_init(lineA, A1.X, A1.Y, A2.X, A2.Y);
|
|
|
|
maths::line_init(lineB, B1.X, B1.Y, B2.X, B2.Y);
|
2021-01-09 17:11:03 +01:00
|
|
|
circlebase.RadiusSq = CirclebaseRadiusSq;
|
|
|
|
circlebase.Center.X = RotOrigin.X;
|
|
|
|
circlebase.Center.Y = RotOrigin.Y;
|
|
|
|
circleT1.RadiusSq = CircleT1RadiusSq;
|
|
|
|
circleT1.Center.X = T1.X;
|
|
|
|
circleT1.Center.Y = T1.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
float TFlipperEdge::flipper_angle(float timeNow)
|
|
|
|
{
|
|
|
|
if (!FlipperFlag)
|
|
|
|
return Angle1;
|
|
|
|
float angle = (Angle1 - Angle2) / AngleMax * AngleMult;
|
2021-02-18 10:53:25 +01:00
|
|
|
if (angle < 0.0f)
|
2021-01-09 17:11:03 +01:00
|
|
|
angle = -angle;
|
|
|
|
|
2021-02-18 10:53:25 +01:00
|
|
|
if (angle >= 0.0000001f)
|
2021-01-10 13:22:06 +01:00
|
|
|
angle = (timeNow - InputTime) / angle;
|
2021-01-09 17:11:03 +01:00
|
|
|
else
|
|
|
|
angle = 1.0;
|
|
|
|
|
2021-09-14 14:33:18 +02:00
|
|
|
angle = std::min(1.0f, std::max(angle, 0.0f));
|
2021-01-09 17:11:03 +01:00
|
|
|
if (FlipperFlag == 2)
|
|
|
|
angle = 1.0f - angle;
|
|
|
|
return angle * AngleMax;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TFlipperEdge::is_ball_inside(float x, float y)
|
|
|
|
{
|
2022-05-11 15:47:13 +02:00
|
|
|
vector2 testPoint{};
|
2021-01-09 17:11:03 +01:00
|
|
|
float dx = RotOrigin.X - x;
|
|
|
|
float dy = RotOrigin.Y - y;
|
2021-10-26 16:15:45 +02:00
|
|
|
if (((A2.X - A1.X) * (y - A1.Y) - (A2.Y - A1.Y) * (x - A1.X) >= 0.0f &&
|
2021-02-02 16:29:54 +01:00
|
|
|
(B1.X - A2.X) * (y - A2.Y) - (B1.Y - A2.Y) * (x - A2.X) >= 0.0f &&
|
|
|
|
(B2.X - B1.X) * (y - B1.Y) - (B2.Y - B1.Y) * (x - B1.X) >= 0.0f &&
|
2021-10-26 16:15:45 +02:00
|
|
|
(A1.X - B2.X) * (y - B2.Y) - (A1.Y - B2.Y) * (x - B2.X) >= 0.0f) ||
|
2021-01-09 17:11:03 +01:00
|
|
|
dy * dy + dx * dx <= CirclebaseRadiusSq ||
|
|
|
|
(T1.Y - y) * (T1.Y - y) + (T1.X - x) * (T1.X - x) < CircleT1RadiusSq)
|
|
|
|
{
|
2021-02-18 10:53:25 +01:00
|
|
|
float flipperLR = AngleMax < 0.0f ? -1.0f : 1.0f;
|
2021-01-09 17:11:03 +01:00
|
|
|
if (FlipperFlag == 1)
|
2021-02-18 10:53:25 +01:00
|
|
|
testPoint = AngleMax < 0.0f ? B1 : B2;
|
2021-01-09 17:11:03 +01:00
|
|
|
else if (FlipperFlag == 2)
|
2021-02-18 10:53:25 +01:00
|
|
|
testPoint = AngleMax < 0.0f ? A2 : A1;
|
2021-01-09 17:11:03 +01:00
|
|
|
else
|
2021-01-10 13:22:06 +01:00
|
|
|
testPoint = T1;
|
2021-01-09 17:11:03 +01:00
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
if (((y - testPoint.Y) * (RotOrigin.X - testPoint.X) -
|
2021-02-02 16:29:54 +01:00
|
|
|
(x - testPoint.X) * (RotOrigin.Y - testPoint.Y)) * flipperLR < 0.0f)
|
2021-01-09 17:11:03 +01:00
|
|
|
return 4;
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFlipperEdge::SetMotion(int code, float value)
|
|
|
|
{
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case 1:
|
2021-01-10 13:22:06 +01:00
|
|
|
Angle2 = flipper_angle(value);
|
|
|
|
Angle1 = AngleMax;
|
2021-10-07 07:01:34 +02:00
|
|
|
AngleMult = ExtendTime;
|
2021-01-09 17:11:03 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-01-10 13:22:06 +01:00
|
|
|
Angle2 = flipper_angle(value);
|
|
|
|
Angle1 = 0.0;
|
2021-10-07 07:01:34 +02:00
|
|
|
AngleMult = RetractTime;
|
2021-01-09 17:11:03 +01:00
|
|
|
break;
|
|
|
|
case 1024:
|
2021-01-10 13:22:06 +01:00
|
|
|
FlipperFlag = 0;
|
|
|
|
Angle1 = 0.0;
|
2021-01-09 17:11:03 +01:00
|
|
|
return;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2021-01-10 13:22:06 +01:00
|
|
|
if (!FlipperFlag)
|
|
|
|
InputTime = value;
|
|
|
|
FlipperFlag = code;
|
|
|
|
AngleStopTime = AngleMult + InputTime;
|
2021-01-09 17:11:03 +01:00
|
|
|
}
|