changeset 191:5e3b0405a44b

fix Joystick Button
author gongo@gendarme.cr.ie.u-ryukyu.ac.jp
date Mon, 12 Jan 2009 10:32:25 +0900
parents 9131b3233988
children 4f5c64e713c7
files TaskManager/Test/test_render/ChangeLog TaskManager/Test/test_render/Joystick.cpp TaskManager/Test/test_render/viewer.cpp
diffstat 3 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/ChangeLog	Thu Jan 08 19:07:52 2009 +0900
+++ b/TaskManager/Test/test_render/ChangeLog	Mon Jan 12 10:32:25 2009 +0900
@@ -1,3 +1,26 @@
+2009-01-12  Wataru MIYAGUNI  <gongo@cr.ie.u-ryukyu.ac.jp>
+
+	* Joystick.cpp: TODO
+	使用している Joystick が
+
+	1. PS3 コントローラ
+	2. PS2 コントローラにUSB変換をかましたやつ
+
+	によってボタンの番号配置が違うので
+	そこを自動的に取得して割り振りたい
+
+	SDL_JoystickName() で名前取れるんだけど
+	全部共通なのかなー。「PS3って文字列があるか否か」でわけてもいいけど
+	
+	* Joystick.cpp: fix
+	コントローラボタンの番号を PS3 コントローラに合わせました。
+
+	- 参考
+	PS3 Linux SDLでプログラミング -コントローラを使う-
+	http://yun.cup.com/ps3sdl007.html
+
+	アナログスティックの方はまだです
+	
 2009-01-08  Wataru MIYAGUNI  <gongo@cr.ie.u-ryukyu.ac.jp>
 
 	* spe/DrawSpanRenew.cpp (DrawSpanRenew::run): fix
--- a/TaskManager/Test/test_render/Joystick.cpp	Thu Jan 08 19:07:52 2009 +0900
+++ b/TaskManager/Test/test_render/Joystick.cpp	Mon Jan 12 10:32:25 2009 +0900
@@ -1,6 +1,28 @@
 #include <SDL.h>
 #include "Joystick.h"
 
+/**
+ * PS3 コントローラの配置
+ */
+static const int SELECT   = 0;
+static const int L3       = 1;
+static const int R3       = 2;
+static const int START    = 3;
+static const int UP       = 4;
+static const int RIGHT    = 5;
+static const int DOWN     = 6;
+static const int LEFT     = 7;
+static const int L2       = 8;
+static const int R2       = 9;
+static const int L1       = 10;
+static const int R1       = 11;
+static const int TRIANGLE = 12;
+static const int CIRCLE   = 13;
+static const int CROSS    = 14;
+static const int SQUARE   = 15;
+static const int PS       = 16;
+
+#if 0
 static const int CROSS = 0;
 static const int CIRCLE = 1;
 static const int SQUARE = 2;
@@ -19,6 +41,7 @@
 static const int LEFT = 15;
 static const int ESCAPE = 16;
 static const int SPACE = 17;
+#endif
 
 Joystick::Joystick(SDL_Joystick *j)
 {
@@ -102,6 +125,28 @@
 	r3.release_work();
     }
 
+    if (SDL_JoystickGetButton(joy,UP)==SDL_PRESSED) {
+	up.push_work();
+    } else {
+	up.release_work();
+    }
+
+    if (SDL_JoystickGetButton(joy,DOWN)==SDL_PRESSED) {
+	down.push_work();
+    } else {
+	down.release_work();
+    }
+    if (SDL_JoystickGetButton(joy,RIGHT)==SDL_PRESSED) {
+	right.push_work();
+    } else {
+	right.release_work();
+    }
+    if (SDL_JoystickGetButton(joy,LEFT)==SDL_PRESSED) {
+	left.push_work();
+    } else {
+	left.release_work();
+    }
+
     axis = SDL_JoystickGetAxis(joy,0);
     if (axis >= 3200) {
 	left.release_work();
--- a/TaskManager/Test/test_render/viewer.cpp	Thu Jan 08 19:07:52 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.cpp	Mon Jan 12 10:32:25 2009 +0900
@@ -44,6 +44,7 @@
 	SDL_Joystick *joy = SDL_JoystickOpen(0);
 	if (!joy) {
 	    fprintf(stderr, "%s: failed to open joystick", __FUNCTION__);
+	    fprintf(stderr, "Instead use Keyboard\n");
 	    return new Keyboard;
 	} else {
 	    printf("Use Joystick\n");