Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
FreeTrackInput.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <cmath>
4
#include <cstdint>
5
6
// The shared-memory ABI is the same for 32-bit and 64-bit trackers/clients.
7
struct
FreeTrackData
8
{
9
std::uint32_t
dataID
;
10
std::int32_t
camWidth
,
camHeight
;
11
float
yaw
,
pitch
,
roll
,
x
,
y
,
z
;
12
float
rawyaw
,
rawpitch
,
rawroll
,
rawx
,
rawy
,
rawz
;
13
float
x1
,
y1
,
x2
,
y2
,
x3
,
y3
,
x4
,
y4
;
14
};
15
static_assert
(
sizeof
(
FreeTrackData
) == 92,
"FreeTrack shared memory is architecture independent"
);
16
17
// Device-independent stream state, shared by the DLL adapter and regression tests.
18
class
FreeTrackInput
19
{
20
unsigned
selection
= 0;
21
bool
haveCounter
=
false
;
22
bool
havePose
=
false
;
23
std::uint32_t
lastCounter
= 0;
24
std::uint64_t
lastFrameTime
= 0,
rateStart
= 0;
25
unsigned
frames
= 0;
26
27
public
:
28
float
yaw
= 0,
pitch
= 0,
roll
= 0,
x
= 0,
y
= 0,
z
= 0;
29
float
rate
= 0;
30
31
// A UI liveness timeout, not a tracker/physics timing constant.
32
bool
Tracking
(std::uint64_t now)
const
{
return
havePose
&& now -
lastFrameTime
< 1000; }
33
void
Reset
() { *
this
=
FreeTrackInput
{}; }
34
35
template
<
class
Reader>
36
bool
Poll
(
bool
lateral,
bool
vertical, std::uint64_t now, Reader read)
37
{
38
const
unsigned
requested = (lateral ? 1u : 0u) | (vertical ? 2u : 0u);
39
if
(requested !=
selection
)
40
{
41
Reset
();
42
selection
= requested;
43
}
44
if
(!requested)
45
return
false
;
// In particular, do not call into the DLL.
46
47
if
(!
Tracking
(now))
48
{
49
havePose
=
false
;
50
roll
=
x
=
y
=
z
=
rate
= 0;
51
frames
= 0;
52
}
53
54
FreeTrackData
sample{};
55
if
(!read(&sample))
56
return
false
;
57
if
(!
haveCounter
)
58
{
59
// Establish a baseline on enable/rebind. A retained pose from a
60
// stopped producer must not jump the camera or replay on re-enable.
61
haveCounter
=
true
;
62
lastCounter
= sample.
dataID
;
63
return
false
;
64
}
65
if
(sample.
dataID
==
lastCounter
)
66
return
false
;
67
lastCounter
= sample.
dataID
;
// Equality remains valid across wraparound.
68
if
(!std::isfinite(sample.
yaw
) || !std::isfinite(sample.
pitch
) ||
69
!std::isfinite(sample.
roll
) || !std::isfinite(sample.
x
) ||
70
!std::isfinite(sample.
y
) || !std::isfinite(sample.
z
))
71
return
false
;
72
73
if
(!
havePose
)
74
rateStart
= now;
75
else
76
++
frames
;
77
havePose
=
true
;
78
lastFrameTime
= now;
79
if
(now -
rateStart
>= 1000)
80
{
81
rate
=
static_cast<
float
>
(
frames
) * 1000.0f /
static_cast<
float
>
(now -
rateStart
);
82
rateStart
= now;
83
frames
= 0;
84
}
85
yaw
= -sample.
yaw
;
86
pitch
= -sample.
pitch
;
87
if
(lateral && vertical)
88
{
89
roll
= sample.
roll
;
90
// Preserve Rise's existing tracker translation scale (to km).
91
x
= -sample.
x
* 0.0000004f;
92
y
= -sample.
z
* 0.0000004f;
93
z
= sample.
y
* 0.0000004f;
94
}
95
return
true
;
96
}
97
98
void
Apply
(
bool
lateral,
bool
vertical,
bool
invertLateral,
bool
invertVertical,
99
float
& targetLateral,
float
& targetVertical)
const
100
{
101
if
(lateral) targetLateral = invertLateral ? -
yaw
:
yaw
;
102
if
(vertical) targetVertical = invertVertical ? -
pitch
:
pitch
;
103
}
104
};
FreeTrackInput
Definition
FreeTrackInput.h:19
FreeTrackInput::z
float z
Definition
FreeTrackInput.h:28
FreeTrackInput::Apply
void Apply(bool lateral, bool vertical, bool invertLateral, bool invertVertical, float &targetLateral, float &targetVertical) const
Definition
FreeTrackInput.h:98
FreeTrackInput::rate
float rate
Definition
FreeTrackInput.h:29
FreeTrackInput::havePose
bool havePose
Definition
FreeTrackInput.h:22
FreeTrackInput::lastCounter
std::uint32_t lastCounter
Definition
FreeTrackInput.h:23
FreeTrackInput::haveCounter
bool haveCounter
Definition
FreeTrackInput.h:21
FreeTrackInput::x
float x
Definition
FreeTrackInput.h:28
FreeTrackInput::roll
float roll
Definition
FreeTrackInput.h:28
FreeTrackInput::Poll
bool Poll(bool lateral, bool vertical, std::uint64_t now, Reader read)
Definition
FreeTrackInput.h:36
FreeTrackInput::Tracking
bool Tracking(std::uint64_t now) const
Definition
FreeTrackInput.h:32
FreeTrackInput::yaw
float yaw
Definition
FreeTrackInput.h:28
FreeTrackInput::pitch
float pitch
Definition
FreeTrackInput.h:28
FreeTrackInput::y
float y
Definition
FreeTrackInput.h:28
FreeTrackInput::Reset
void Reset()
Definition
FreeTrackInput.h:33
FreeTrackInput::lastFrameTime
std::uint64_t lastFrameTime
Definition
FreeTrackInput.h:24
FreeTrackInput::rateStart
std::uint64_t rateStart
Definition
FreeTrackInput.h:24
FreeTrackInput::selection
unsigned selection
Definition
FreeTrackInput.h:20
FreeTrackInput::frames
unsigned frames
Definition
FreeTrackInput.h:25
FreeTrackData
Definition
FreeTrackInput.h:8
FreeTrackData::camWidth
std::int32_t camWidth
Definition
FreeTrackInput.h:10
FreeTrackData::rawroll
float rawroll
Definition
FreeTrackInput.h:12
FreeTrackData::dataID
std::uint32_t dataID
Definition
FreeTrackInput.h:9
FreeTrackData::y4
float y4
Definition
FreeTrackInput.h:13
FreeTrackData::x2
float x2
Definition
FreeTrackInput.h:13
FreeTrackData::rawy
float rawy
Definition
FreeTrackInput.h:12
FreeTrackData::rawz
float rawz
Definition
FreeTrackInput.h:12
FreeTrackData::x
float x
Definition
FreeTrackInput.h:11
FreeTrackData::y
float y
Definition
FreeTrackInput.h:11
FreeTrackData::z
float z
Definition
FreeTrackInput.h:11
FreeTrackData::x1
float x1
Definition
FreeTrackInput.h:13
FreeTrackData::roll
float roll
Definition
FreeTrackInput.h:11
FreeTrackData::x3
float x3
Definition
FreeTrackInput.h:13
FreeTrackData::rawx
float rawx
Definition
FreeTrackInput.h:12
FreeTrackData::camHeight
std::int32_t camHeight
Definition
FreeTrackInput.h:10
FreeTrackData::rawpitch
float rawpitch
Definition
FreeTrackInput.h:12
FreeTrackData::y1
float y1
Definition
FreeTrackInput.h:13
FreeTrackData::pitch
float pitch
Definition
FreeTrackInput.h:11
FreeTrackData::rawyaw
float rawyaw
Definition
FreeTrackInput.h:12
FreeTrackData::y3
float y3
Definition
FreeTrackInput.h:13
FreeTrackData::x4
float x4
Definition
FreeTrackInput.h:13
FreeTrackData::yaw
float yaw
Definition
FreeTrackInput.h:11
FreeTrackData::y2
float y2
Definition
FreeTrackInput.h:13
Viewscreen
FreeTrackInput.h
Generated on
for Rise by
1.18.0