载入中...
搜索中...
未找到
ClimbingTrajectory.h
浏览该文件的文档.
1#pragma once
2
3#include "climbing/Climbing.h"
4
5#include <algorithm>
6
7namespace eve::climbing::detail {
8
10inline float smoothStep(float value) noexcept {
11 value = std::clamp(value, 0.f, 1.f);
12 return value * value * (3.f - 2.f * value);
13}
14
16inline Vec3 interpolate(Vec3 start, Vec3 end, float amount) noexcept {
17 return {start.x + (end.x - start.x) * amount, start.y + (end.y - start.y) * amount,
18 start.z + (end.z - start.z) * amount};
19}
20
29 const ClimbingActionDefinition& action, const ClimbingProfileDefinition& profile,
30 float normalizedTime) noexcept {
31 const float t = std::clamp(normalizedTime, 0.f, 1.f);
32 const bool surfaceFollow = action.trajectory == ClimbingTrajectoryKind::SurfaceFollow ||
34 const bool ballistic = action.trajectory == ClimbingTrajectoryKind::BallisticArc;
35 const float frontX = start.x - candidate.frontPoint.x;
36 const float frontZ = start.z - candidate.frontPoint.z;
37 const float contactDistance = profile.capsuleRadius + 2.f * profile.skin;
38 const bool contactVault = action.kind == ClimbingActionKind::Vault &&
39 frontX * frontX + frontZ * frontZ <= contactDistance * contactDistance;
40 if (!ballistic && !surfaceFollow &&
41 (action.kind == ClimbingActionKind::Mantle || action.kind == ClimbingActionKind::ClimbUp || contactVault)) {
42 constexpr float riseEnd = 0.4f;
43 constexpr float crossEnd = 0.85f;
44 const float clearance = std::max({start.y, candidate.topPoint.y + profile.skin,
45 candidate.landingFeet.y + profile.skin});
46 const Vec3 raisedStart{start.x, clearance, start.z};
47 const Vec3 raisedLanding{candidate.landingFeet.x, clearance, candidate.landingFeet.z};
48 if (t < riseEnd) return interpolate(start, raisedStart, smoothStep(t / riseEnd));
49 if (t < crossEnd)
51 return interpolate(raisedStart, raisedLanding, smoothStep((t - riseEnd) / (crossEnd - riseEnd)));
53 return interpolate(raisedLanding, candidate.landingFeet, smoothStep((t - crossEnd) / (1.f - crossEnd)));
54 }
55
56 if (surfaceFollow || action.kind == ClimbingActionKind::Shimmy ||
63 return interpolate(start, candidate.landingFeet, smoothStep(t));
64
65 Vec3 point = interpolate(start, candidate.landingFeet, t);
66 point.y += 4.f * action.apexHeight * t * (1.f - t);
67 return point;
68}
69
70} // namespace eve::climbing::detail
double value
Duration start
Deterministic climbing/parkour planning and capsule-constrained execution.
std::string action
Definition PlayHost.cpp:117
float t
glm::vec3 point
float smoothStep(float value) noexcept
Smooth step.
Vec3 interpolate(Vec3 start, Vec3 end, float amount) noexcept
Interpolate.
Vec3 trajectoryPoint(Vec3 start, const ClimbingCandidate &candidate, const ClimbingActionDefinition &action, const ClimbingProfileDefinition &profile, float normalizedTime) noexcept
Trajectory point.
Definition of one geometry-compatible climbing action.
Definition Climbing.h:160
Owning, replayable climbing candidate; contains no borrowed query pointers.
Definition Climbing.h:290
Runtime profile controlling capsule geometry and probe limits.
Definition Climbing.h:218
Small owning world-space vector used at climbing module boundaries.