-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcustom_bounce_model.cpp
More file actions
54 lines (44 loc) · 1.7 KB
/
custom_bounce_model.cpp
File metadata and controls
54 lines (44 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Minimal custom BounceModel: fixed COR, no spin coupling.
// Decompose velocity along surface normal, reflect normal component, scale
// tangential by a fixed friction factor. Spin passes through unchanged.
#include "BounceModel.hpp"
#include "FlightSimulator.hpp"
#include "ground_surface.hpp"
#include "math_utils.hpp"
#include <cstdio>
#include <memory>
class FixedCorBounceModel : public BounceModel
{
public:
FixedCorBounceModel(float cor, float tangentialRetention)
: cor_(cor), tang_(tangentialRetention) {}
BounceResult resolveBounce(const BounceState &s,
const GroundSurface & /*surface*/) const override
{
const Vector3D vn = math_utils::project(s.velocity, s.surfaceNormal);
const Vector3D vt{s.velocity[0] - vn[0],
s.velocity[1] - vn[1],
s.velocity[2] - vn[2]};
const Vector3D vnPost{-cor_ * vn[0], -cor_ * vn[1], -cor_ * vn[2]};
const Vector3D vtPost{tang_ * vt[0], tang_ * vt[1], tang_ * vt[2]};
return {{vnPost[0] + vtPost[0],
vnPost[1] + vtPost[1],
vnPost[2] + vtPost[2]},
s.spinVector};
}
private:
float cor_;
float tang_;
};
int main()
{
const LaunchData launch{160.0F, 11.0F, 0.0F, 3000.0F, 0.0F};
const AtmosphericData atmos{70.0F, 0.0F, 0.0F, 0.0F, 0.0F, 50.0F, 29.92F};
GroundSurface ground;
auto bounce = std::make_shared<FixedCorBounceModel>(0.35F, 0.6F);
FlightSimulator sim(launch, atmos, ground, /*aero*/ nullptr, bounce);
sim.run();
const LandingResult r = sim.getLandingResult();
std::printf("Landing: %.1f %.1f %.1f yards\n", r.xF, r.yF, r.zF);
return 0;
}