Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 68a79bd

Browse files
spline tweak
1 parent 1f25177 commit 68a79bd

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

OFS-lib/Funscript/FunscriptSpline.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ class FunscriptSpline
2929
return glm::catmullRom(v0, v1, v2, v3, time).x;
3030
}
3131

32+
static inline float catmul_rom_spline_alt(const FunscriptArray& actions, int32_t i, float time) noexcept
33+
{
34+
OFS_PROFILE(__FUNCTION__);
35+
int i0 = glm::clamp<int>(i - 1, 0, actions.size() - 1);
36+
int i1 = glm::clamp<int>(i, 0, actions.size() - 1);
37+
int i2 = glm::clamp<int>(i + 1, 0, actions.size() - 1);
38+
int i3 = glm::clamp<int>(i + 2, 0, actions.size() - 1);
39+
40+
if(actions[i1].pos == actions[i2].pos) return actions[i1].pos / 100.f;
41+
42+
glm::vec1 v0(actions[i0].pos / 100.f);
43+
glm::vec1 v1(actions[i1].pos / 100.f);
44+
glm::vec1 v2(actions[i2].pos / 100.f);
45+
glm::vec1 v3(actions[i3].pos / 100.f);
46+
47+
time -= actions[i1].atS;
48+
time /= actions[i2].atS - actions[i1].atS;
49+
50+
return glm::catmullRom(v0, v1, v2, v3, time).x;
51+
}
52+
3253
inline float Sample(const FunscriptArray& actions, float time) noexcept
3354
{
3455
OFS_PROFILE(__FUNCTION__);
@@ -38,12 +59,12 @@ class FunscriptSpline
3859

3960
if (actions[cacheIdx].atS <= time && actions[cacheIdx + 1].atS >= time) {
4061
// cache hit!
41-
return catmull_rom_spline(actions, cacheIdx, time);
62+
return catmul_rom_spline_alt(actions, cacheIdx, time);
4263
}
4364
else if (cacheIdx + 2 < actions.size() && actions[cacheIdx+1].atS <= time && actions[cacheIdx+2].atS >= time) {
4465
// sort of a cache hit
4566
cacheIdx += 1;
46-
return catmull_rom_spline(actions, cacheIdx, time);
67+
return catmul_rom_spline_alt(actions, cacheIdx, time);
4768
}
4869
else {
4970
// cache miss
@@ -59,7 +80,7 @@ class FunscriptSpline
5980
it--;
6081
// cache index
6182
cacheIdx = std::distance(actions.begin(), it);
62-
return catmull_rom_spline(actions, cacheIdx, time);
83+
return catmul_rom_spline_alt(actions, cacheIdx, time);
6384
}
6485

6586
return 0.f;

OFS-lib/UI/ScriptPositionsOverlayMode.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ void BaseOverlay::DrawActionLines(const OverlayDrawingCtx& ctx) noexcept
181181
}
182182
};
183183

184+
auto drawLine = [](const OverlayDrawingCtx& ctx, ImVec2 p1, ImVec2 p2, uint32_t color) noexcept
185+
{
186+
ctx.draw_list->AddLine(p1, p2, IM_COL32(0, 0, 0, 255), 7.0f); // border
187+
ColoredLines.emplace_back(std::move(BaseOverlay::ColoredLine{ p1, p2, color }));
188+
};
189+
184190
if (SplineMode) {
185191
const FunscriptAction* prevAction = nullptr;
186192
for (; startIt != endIt; startIt++) {
@@ -213,8 +219,7 @@ void BaseOverlay::DrawActionLines(const OverlayDrawingCtx& ctx) noexcept
213219
// calculate speed relative to maximum speed
214220
ImColor speedColor;
215221
getActionLineColor(&speedColor, speedGradient, action, *prevAction);
216-
ctx.draw_list->AddLine(p1, p2, IM_COL32(0, 0, 0, 255), 7.0f); // border
217-
ColoredLines.emplace_back(std::move(BaseOverlay::ColoredLine{ p1, p2, ImGui::ColorConvertFloat4ToU32(speedColor) }));
222+
drawLine(ctx, p1, p2, ImGui::ColorConvertFloat4ToU32(speedColor));
218223
}
219224

220225
prevAction = &action;

0 commit comments

Comments
 (0)