Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
MultiController.cpp
Go to the documentation of this file.
1
/* Project nGenEx
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: nGenEx.lib
6
FILE: MultiController.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
MultiController Input class
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
MultiController.h
"
17
18
// +--------------------------------------------------------------------+
19
20
MultiController::MultiController
()
21
: x(0), y(0), z(0), p(0), r(0), w(0), c(0), p1(0), r1(0), w1(0), t(0)
22
{
23
for
(
int
i = 0; i <
MotionController::MaxActions
; i++)
24
action
[i] = 0;
25
26
nctrl
= 0;
27
for
(
int
i = 0; i < 4; i++)
28
ctrl
[i] = 0;
29
}
30
31
MultiController::~MultiController
()
32
{
33
for
(
int
i = 0; i < 4; i++)
34
delete
ctrl
[i];
35
}
36
37
// +--------------------------------------------------------------------+
38
39
void
40
MultiController::AddController
(
MotionController
* c)
41
{
42
if
(
nctrl
< 4 && c)
43
ctrl
[
nctrl
++] =
c
;
44
}
45
46
void
47
MultiController::MapKeys
(
KeyMapEntry
* mapping,
int
nkeys)
48
{
49
for
(
int
i = 0; i <
nctrl
; i++)
50
ctrl
[i]->
MapKeys
(mapping, nkeys);
51
}
52
53
int
54
MultiController::GetSwapYawRoll
()
const
55
{
56
if
(
nctrl
)
57
return
ctrl
[0]->
GetSwapYawRoll
();
58
59
return
0;
60
}
61
62
void
63
MultiController::SwapYawRoll
(
int
swap)
64
{
65
for
(
int
i = 0; i <
nctrl
; i++)
66
ctrl
[i]->
SwapYawRoll
(swap);
67
}
68
69
// +--------------------------------------------------------------------+
70
71
inline
void
clamp
(
double
& x) {
if
(x<-1)x=-1;
else
if
(x>1)x=1; }
72
73
void
74
MultiController::Acquire
()
75
{
76
t
=
x
=
y
=
z
=
p
=
r
=
w
=
c
= 0;
77
78
for
(
int
i = 0; i <
MotionController::MaxActions
; i++)
79
action
[i] = 0;
80
81
for
(
int
i = 0; i <
nctrl
; i++) {
82
ctrl
[i]->
Acquire
();
83
84
x
+=
ctrl
[i]->
X
();
85
y
+=
ctrl
[i]->
Y
();
86
z
+=
ctrl
[i]->
Z
();
87
88
r
+=
ctrl
[i]->
Roll
();
89
p
+=
ctrl
[i]->
Pitch
();
90
w
+=
ctrl
[i]->
Yaw
();
91
c
+=
ctrl
[i]->
Center
();
92
t
+=
ctrl
[i]->
Throttle
();
93
94
for
(
int
a = 0; a <
MotionController::MaxActions
; a++)
95
action
[a] +=
ctrl
[i]->
Action
(a);
96
}
97
98
clamp
(
x
);
99
clamp
(
y
);
100
clamp
(
z
);
101
clamp
(
r
);
102
clamp
(
p
);
103
clamp
(
w
);
104
clamp
(
t
);
105
}
106
107
// +--------------------------------------------------------------------+
108
109
void
110
MultiController::SetThrottle
(
double
throttle)
111
{
112
for
(
int
i = 0; i <
nctrl
; i++)
113
ctrl
[i]->
SetThrottle
(throttle);
114
}
115
116
// +--------------------------------------------------------------------+
117
118
int
119
MultiController::ActionMap
(
int
key)
120
{
121
for
(
int
i = 0; i <
nctrl
; i++) {
122
int
result =
ctrl
[i]->
ActionMap
(key);
123
124
if
(result)
125
return
result;
126
}
127
128
return
0;
129
}
130
nGenEx
MultiController.cpp
Generated on Tue Jun 5 2012 20:46:25 for Starshatter_Open by
1.8.1