comparison Renderer/Engine/Joystick.cc @ 507:735f76483bb2

Reorganization..
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 12 Oct 2009 09:39:35 +0900
parents
children
comparison
equal deleted inserted replaced
506:1d4a8a86f26b 507:735f76483bb2
1 #include <SDL.h>
2 #include "Joystick.h"
3
4 /**
5 * PS3 コントローラの配置
6 */
7 static const int SELECT = 0;
8 static const int L3 = 1;
9 static const int R3 = 2;
10 static const int START = 3;
11 static const int UP = 4;
12 static const int RIGHT = 5;
13 static const int DOWN = 6;
14 static const int LEFT = 7;
15 static const int L2 = 8;
16 static const int R2 = 9;
17 static const int L1 = 10;
18 static const int R1 = 11;
19 static const int TRIANGLE = 12;
20 static const int CIRCLE = 13;
21 static const int CROSS = 14;
22 static const int SQUARE = 15;
23 static const int PS = 16;
24
25 #if 0 // PS2 コントローラ
26 static const int CROSS = 0;
27 static const int CIRCLE = 1;
28 static const int SQUARE = 2;
29 static const int TRIANGLE = 3;
30 static const int L1 = 4;
31 static const int R1 = 5;
32 static const int L2 = 6;
33 static const int R2 = 7;
34 static const int START = 8;
35 static const int SELECT = 9;
36 static const int L3 = 10;
37 static const int R3 = 11;
38 static const int UP = 12;
39 static const int DOWN = 13;
40 static const int RIGHT = 14;
41 static const int LEFT = 15;
42 static const int ESCAPE = 16;
43 static const int SPACE = 17;
44 #endif
45
46 Joystick::Joystick(SDL_Joystick *j)
47 {
48 joy = j;
49 }
50
51 Joystick::~Joystick(void)
52 {
53 SDL_JoystickClose(joy);
54 }
55
56 void
57 Joystick::check(void)
58 {
59 SDL_JoystickUpdate();
60
61 if (SDL_JoystickGetButton(joy,CROSS)==SDL_PRESSED) {
62 cross.push_work();
63 } else {
64 cross.release_work();
65 }
66
67 if (SDL_JoystickGetButton(joy,CIRCLE)==SDL_PRESSED) {
68 circle.push_work();
69 } else {
70 circle.release_work();
71 }
72
73 if (SDL_JoystickGetButton(joy,SQUARE)==SDL_PRESSED) {
74 square.push_work();
75 } else {
76 square.release_work();
77 }
78
79 if (SDL_JoystickGetButton(joy,TRIANGLE)==SDL_PRESSED) {
80 triangle.push_work();
81 } else {
82 triangle.release_work();
83 }
84
85 if (SDL_JoystickGetButton(joy,L1)==SDL_PRESSED) {
86 l1.push_work();
87 } else {
88 l1.release_work();
89 }
90
91 if (SDL_JoystickGetButton(joy,R1)==SDL_PRESSED) {
92 r1.push_work();
93 } else {
94 r1.release_work();
95 }
96
97 if (SDL_JoystickGetButton(joy,L2)==SDL_PRESSED) {
98 l2.push_work();
99 } else {
100 l2.release_work();
101 }
102
103 if (SDL_JoystickGetButton(joy,R2)==SDL_PRESSED) {
104 r2.push_work();
105 } else {
106 r2.release_work();
107 }
108
109 if (SDL_JoystickGetButton(joy,START)==SDL_PRESSED) {
110 start.push_work();
111 } else {
112 start.release_work();
113 }
114
115 if (SDL_JoystickGetButton(joy,SELECT)==SDL_PRESSED) {
116 select.push_work();
117 } else {
118 select.release_work();
119 }
120
121 if (SDL_JoystickGetButton(joy,L3)==SDL_PRESSED) {
122 l3.push_work();
123 } else {
124 l3.release_work();
125 }
126
127 if (SDL_JoystickGetButton(joy,R3)==SDL_PRESSED) {
128 r3.push_work();
129 } else {
130 r3.release_work();
131 }
132
133 if (SDL_JoystickGetButton(joy,UP)==SDL_PRESSED) {
134 up.push_work();
135 } else {
136 up.release_work();
137 }
138
139 if (SDL_JoystickGetButton(joy,DOWN)==SDL_PRESSED) {
140 down.push_work();
141 } else {
142 down.release_work();
143 }
144 if (SDL_JoystickGetButton(joy,RIGHT)==SDL_PRESSED) {
145 right.push_work();
146 } else {
147 right.release_work();
148 }
149 if (SDL_JoystickGetButton(joy,LEFT)==SDL_PRESSED) {
150 left.push_work();
151 } else {
152 left.release_work();
153 }
154
155 axis = SDL_JoystickGetAxis(joy,0);
156 if (axis >= 3200) {
157 left.release_work();
158 right.push_work();
159 } else if (axis <= -3200) {
160 right.release_work();
161 left.push_work();
162 } else {
163 left.release_work();
164 right.release_work();
165 }
166
167 axis = SDL_JoystickGetAxis(joy,1);
168 if (axis>=3200) {
169 up.release_work();
170 down.push_work();
171 } else if (axis<=-3200) {
172 down.release_work();
173 up.push_work();
174 } else {
175 up.release_work();
176 down.release_work();
177 }
178 }