From a55e738dfad92ae7e23e45c3593384b9469f1177 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 9 May 2020 20:21:13 +0300 Subject: ccarctrl big fix --- src/control/Curves.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/control/Curves.cpp') diff --git a/src/control/Curves.cpp b/src/control/Curves.cpp index 623ab040..0a01a7aa 100644 --- a/src/control/Curves.cpp +++ b/src/control/Curves.cpp @@ -19,7 +19,7 @@ void CCurves::CalcCurvePoint(CVector* pPos1, CVector* pPos2, CVector* pDir1, CVe float actualFactor = CalcSpeedScaleFactor(pPos1, pPos2, pDir1->x, pDir1->y, pDir2->x, pDir2->y); CVector2D dir1 = *pDir1 * actualFactor; CVector2D dir2 = *pDir2 * actualFactor; - float curveCoef = 0.5f - 0.5f * cos(3.1415f * between); + float curveCoef = 0.5f - 0.5f * Cos(3.1415f * between); *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, -- cgit v1.2.3 From 3de003a8e7c99d0488b16ccaf8b441af8d8a87e7 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 9 May 2020 22:11:40 +0300 Subject: new curves + boat fix --- src/control/Curves.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/control/Curves.cpp') diff --git a/src/control/Curves.cpp b/src/control/Curves.cpp index 0a01a7aa..31a2767a 100644 --- a/src/control/Curves.cpp +++ b/src/control/Curves.cpp @@ -11,7 +11,7 @@ float CCurves::CalcSpeedScaleFactor(CVector* pPoint1, CVector* pPoint2, float di 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; + return ((1.0f - dp) * 0.25f + 1.0f) * distance; } void CCurves::CalcCurvePoint(CVector* pPos1, CVector* pPos2, CVector* pDir1, CVector* pDir2, float between, int32 timeOnCurve, CVector* pOutPos, CVector* pOutDir) @@ -19,7 +19,21 @@ void CCurves::CalcCurvePoint(CVector* pPos1, CVector* pPos2, CVector* pDir1, CVe float actualFactor = CalcSpeedScaleFactor(pPos1, pPos2, pDir1->x, pDir1->y, pDir2->x, pDir2->y); CVector2D dir1 = *pDir1 * actualFactor; CVector2D dir2 = *pDir2 * actualFactor; - float curveCoef = 0.5f - 0.5f * Cos(3.1415f * between); + float t1 = Abs(DotProduct2D(*pPos1 - *pPos2, *pDir1)); + float t2 = Abs(DotProduct2D(*pPos2 - *pPos1, *pDir2)); + float curveCoef; + if (t1 > t2) { + if (between < (t1 - t2) / (t1 + t2)) + curveCoef = 0.0f; + else + curveCoef = 0.5f - 0.5f * Cos(3.1415f * (t1 + t2) / (2 * t2) * (between - (t1 - t2) / (t1 + t2))); + } + else { + if (2 * t1 / (t1 + t2) < between) + curveCoef = 1.0f; + else + curveCoef = 0.5f - 0.5f * Cos(3.1415f * between * (t1 + t2) / (2 * t1)); + } *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, -- cgit v1.2.3