2019-08-06 23:32:19 +02:00
|
|
|
#include "common.h"
|
2020-04-17 15:31:11 +02:00
|
|
|
|
2019-08-06 23:32:19 +02:00
|
|
|
#include "Curves.h"
|
|
|
|
|
2019-09-15 12:29:38 +02:00
|
|
|
float CCurves::CalcSpeedScaleFactor(CVector* pPoint1, CVector* pPoint2, float dir1X, float dir1Y, float dir2X, float dir2Y)
|
|
|
|
{
|
|
|
|
CVector2D dir1(dir1X, dir1Y);
|
|
|
|
CVector2D dir2(dir2X, dir2Y);
|
|
|
|
float distance = (*pPoint1 - *pPoint2).Magnitude2D();
|
|
|
|
float dp = DotProduct2D(dir1, dir2);
|
|
|
|
if (dp > 0.9f)
|
|
|
|
return distance + Abs((pPoint1->x * dir1Y - pPoint1->y * dir1X) - (pPoint2->x * dir1Y - pPoint2->y * dir1X));
|
|
|
|
else
|
|
|
|
return ((1.0f - dp) * 0.2f + 1.0f) * distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCurves::CalcCurvePoint(CVector* pPos1, CVector* pPos2, CVector* pDir1, CVector* pDir2, float between, int32 timeOnCurve, CVector* pOutPos, CVector* pOutDir)
|
|
|
|
{
|
|
|
|
float actualFactor = CalcSpeedScaleFactor(pPos1, pPos2, pDir1->x, pDir1->y, pDir2->x, pDir2->y);
|
|
|
|
CVector2D dir1 = *pDir1 * actualFactor;
|
|
|
|
CVector2D dir2 = *pDir2 * actualFactor;
|
2020-05-09 19:21:13 +02:00
|
|
|
float curveCoef = 0.5f - 0.5f * Cos(3.1415f * between);
|
2019-09-15 12:29:38 +02:00
|
|
|
*pOutPos = CVector(
|
|
|
|
(pPos1->x + between * dir1.x) * (1.0f - curveCoef) + (pPos2->x - (1 - between) * dir2.x) * curveCoef,
|
|
|
|
(pPos1->y + between * dir1.y) * (1.0f - curveCoef) + (pPos2->y - (1 - between) * dir2.y) * curveCoef,
|
|
|
|
0.0f);
|
|
|
|
*pOutDir = CVector(
|
|
|
|
(dir1.x * (1.0f - curveCoef) + dir2.x * curveCoef) / (timeOnCurve * 0.001f),
|
|
|
|
(dir1.y * (1.0f - curveCoef) + dir2.y * curveCoef) / (timeOnCurve * 0.001f),
|
|
|
|
0.0f);
|
2020-03-29 07:54:34 +02:00
|
|
|
}
|