-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCameraControl.h
More file actions
103 lines (85 loc) · 2.61 KB
/
CameraControl.h
File metadata and controls
103 lines (85 loc) · 2.61 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once
#include "XPLMDataAccess.h"
#include "XPLMCamera.h"
#include <array>
#include <cmath>
namespace vr_image_client
{
struct CameraTarget
{
std::array<float, 3> position{};
std::array<float, 3> orientation{};
};
struct CameraPose
{
float x{0.0f};
float y{0.0f};
float z{0.0f};
float pitch{0.0f};
float heading{0.0f};
float roll{0.0f};
};
inline float NormalizeHeading(float value)
{
float normalized = std::fmod(value, 360.0f);
if (normalized < 0.0f)
{
normalized += 360.0f;
}
return normalized;
}
inline float AbsoluteAngleDelta(float a, float b)
{
float diff = a - b;
diff = std::fmod(diff + 540.0f, 360.0f) - 180.0f;
return std::fabs(diff);
}
class CameraControl
{
public:
explicit CameraControl(bool use_pilot_orientation);
bool InitializeDataRefs();
void ResetSession();
void PrimeBasePose();
void ClearPilotHeadPose();
void SetPilotHeadBaselineOffset(const std::array<float, 3> &offset);
bool ApplyPilotHeadTarget(const CameraTarget &target);
bool ApplyTarget(const CameraTarget &target, XPLMCameraPosition_t &out_camera);
bool SampleBasePose(CameraPose &out_pose) const;
bool ReadRawData(
CameraPose &aircraft_pose,
std::array<float, 3> &pilot_position,
bool &pilot_position_valid,
std::array<float, 3> &pilot_orientation,
bool &pilot_orientation_valid) const;
bool RotateAircraftHeading(float delta_heading_deg, float &out_new_heading);
bool HasLastAppliedTarget() const;
bool IsOperational() const;
bool HasFatalError() const;
private:
bool UpdateBaseCameraPose(CameraPose &out_pose) const;
bool ShouldUsePilotPosition() const;
bool ShouldUsePilotOrientation() const;
bool use_pilot_orientation_{false};
bool datarefs_ready_{false};
bool fatal_error_{false};
CameraPose base_pose_{};
bool base_pose_valid_{false};
CameraTarget last_applied_target_{};
bool has_last_applied_target_{false};
XPLMDataRef local_x_ref_{nullptr};
XPLMDataRef local_y_ref_{nullptr};
XPLMDataRef local_z_ref_{nullptr};
XPLMDataRef pitch_ref_{nullptr};
XPLMDataRef heading_ref_{nullptr};
XPLMDataRef roll_ref_{nullptr};
XPLMDataRef groundspeed_ref_{nullptr};
XPLMDataRef pilot_head_x_ref_{nullptr};
XPLMDataRef pilot_head_y_ref_{nullptr};
XPLMDataRef pilot_head_z_ref_{nullptr};
XPLMDataRef pilot_head_psi_ref_{nullptr};
XPLMDataRef pilot_head_the_ref_{nullptr};
XPLMDataRef pilot_head_phi_ref_{nullptr};
std::array<float, 3> pilot_head_offset_{0.0f, 0.0f, 0.0f};
};
} // namespace vr_image_client