载入中...
搜索中...
未找到
ClimbingTrajectory.h
浏览该文件的文档.
1#pragma once
2
3#include "climbing/Climbing.h"
4
5#include <algorithm>
6#include <cmath>
7
8namespace eve::climbing::detail {
9
11inline float smoothStep(float value) noexcept {
12 value = std::clamp(value, 0.f, 1.f);
13 return value * value * (3.f - 2.f * value);
14}
15
17inline Vec3 interpolate(Vec3 start, Vec3 end, float amount) noexcept {
18 return {start.x + (end.x - start.x) * amount, start.y + (end.y - start.y) * amount,
19 start.z + (end.z - start.z) * amount};
20}
21
22// Join the two support planes in the horizontal plane. Each eased leg stays
23// on its own support plane; a direct chord can cut through a convex corner.
24inline Vec3 cornerPathPoint(Vec3 start, Vec3 end, Vec3 sourceNormal, Vec3 targetNormal, float normalizedTime) noexcept {
25 const float determinant = sourceNormal.x * targetNormal.z - sourceNormal.z * targetNormal.x;
26 const float t = std::clamp(normalizedTime, 0.f, 1.f);
27 if (std::abs(determinant) < 1e-4f) return interpolate(start, end, smoothStep(t));
28 const float sourcePlane = sourceNormal.x * start.x + sourceNormal.z * start.z;
29 const float targetPlane = targetNormal.x * end.x + targetNormal.z * end.z;
30 const Vec3 join{(sourcePlane * targetNormal.z - sourceNormal.z * targetPlane) / determinant,
31 (start.y + end.y) * 0.5f,
32 (sourceNormal.x * targetPlane - sourcePlane * targetNormal.x) / determinant};
33 return t < 0.5f ? interpolate(start, join, smoothStep(t * 2.f))
34 : interpolate(join, end, smoothStep((t - 0.5f) * 2.f));
35}
36
44 const ClimbingProfileDefinition& profile, float normalizedTime,
45 Vec3 sourceNormal = {}) noexcept {
46 const float t = std::clamp(normalizedTime, 0.f, 1.f);
48 return cornerPathPoint(start, candidate.landingFeet, sourceNormal, candidate.surfaceNormal, t);
49 const bool surfaceFollow = action.trajectory == ClimbingTrajectoryKind::SurfaceFollow ||
51 const bool ballistic = action.trajectory == ClimbingTrajectoryKind::BallisticArc;
52 const float frontX = start.x - candidate.frontPoint.x;
53 const float frontZ = start.z - candidate.frontPoint.z;
54 const float contactDistance = profile.capsuleRadius + 2.f * profile.skin;
55 const bool contactVault = action.kind == ClimbingActionKind::Vault &&
56 frontX * frontX + frontZ * frontZ <= contactDistance * contactDistance;
57 if (!ballistic && !surfaceFollow &&
58 (action.kind == ClimbingActionKind::Mantle || action.kind == ClimbingActionKind::ClimbUp || contactVault)) {
59 constexpr float riseEnd = 0.4f;
60 constexpr float crossEnd = 0.85f;
61 const float clearance = std::max({start.y, candidate.topPoint.y + profile.skin,
62 candidate.landingFeet.y + profile.skin});
63 const Vec3 raisedStart{start.x, clearance, start.z};
64 const Vec3 raisedLanding{candidate.landingFeet.x, clearance, candidate.landingFeet.z};
65 if (t < riseEnd) return interpolate(start, raisedStart, smoothStep(t / riseEnd));
66 if (t < crossEnd)
68 return interpolate(raisedStart, raisedLanding, smoothStep((t - riseEnd) / (crossEnd - riseEnd)));
70 return interpolate(raisedLanding, candidate.landingFeet, smoothStep((t - crossEnd) / (1.f - crossEnd)));
71 }
72
73 if (surfaceFollow || action.kind == ClimbingActionKind::Shimmy ||
80 return interpolate(start, candidate.landingFeet, smoothStep(t));
81
82 Vec3 point = interpolate(start, candidate.landingFeet, t);
83 point.y += 4.f * action.apexHeight * t * (1.f - t);
84 return point;
85}
86
87} // namespace eve::climbing::detail
Duration start
Deterministic climbing/parkour planning and capsule-constrained execution.
std::string action
Definition PlayHost.cpp:118
Object::Ptr value
float t
size_t end
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, Vec3 sourceNormal={}) noexcept
Vec3 cornerPathPoint(Vec3 start, Vec3 end, Vec3 sourceNormal, Vec3 targetNormal, float normalizedTime) noexcept
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.