mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2025-12-23 04:10:06 +00:00
Add NPC chunk management + Generalize lerp
This commit is contained in:
@@ -255,19 +255,7 @@ void TableData::constructPath(nlohmann::json::iterator _pathData) {
|
||||
for (_point++; _point != pathPoints.end(); _point++) {
|
||||
point = _point.value();
|
||||
WarpLocation coords = { point["iX"] , point["iY"] , point["iZ"] };
|
||||
// Calculate distance between this point and the last
|
||||
int dXY = hypot(last.x - coords.x, last.y - coords.y); // XY plane distance
|
||||
int distanceBetween = hypot(dXY, last.z - coords.z); // total distance
|
||||
int lerps = distanceBetween / (int)pathData["iMonkeySpeed"]; // integer division to ensure a whole number of in-between points
|
||||
for (int i = 0; i < lerps; i++) {
|
||||
WarpLocation lerp;
|
||||
// lerp math
|
||||
float frac = (i + 1) * 1.0f / (lerps + 1);
|
||||
lerp.x = (last.x * (1.0f - frac)) + (coords.x * frac);
|
||||
lerp.y = (last.y * (1.0f - frac)) + (coords.y * frac);
|
||||
lerp.z = (last.z * (1.0f - frac)) + (coords.z * frac);
|
||||
points.push(lerp); // add lerp'd point to the queue
|
||||
}
|
||||
TransportManager::lerp(&points, last, coords, pathData["iMonkeySpeed"]);
|
||||
points.push(coords); // add keyframe to the queue
|
||||
last = coords; // update start pos
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user