[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3069 - in trunk/pingus: data/controller src/input
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3069 - in trunk/pingus: data/controller src/input |
Date: |
Mon, 3 Sep 2007 05:44:10 +0200 |
Author: grumbel
Date: 2007-09-03 05:44:09 +0200 (Mon, 03 Sep 2007)
New Revision: 3069
Added:
trunk/pingus/data/controller/xbox360.scm
Modified:
trunk/pingus/src/input/control.hpp
trunk/pingus/src/input/core_driver.cpp
trunk/pingus/src/input/wiimote.cpp
Log:
- deadzones for axis
- AxisScroller implemented
- added example file for XBox360 controller
Added: trunk/pingus/data/controller/xbox360.scm
===================================================================
--- trunk/pingus/data/controller/xbox360.scm 2007-09-02 19:56:03 UTC (rev
3068)
+++ trunk/pingus/data/controller/xbox360.scm 2007-09-03 03:44:09 UTC (rev
3069)
@@ -0,0 +1,42 @@
+(pingus-controller
+ (standard-pointer
+ (core:axis-pointer
+ (x-axis (sdl:joystick-axis (device 1) (axis 0)))
+ (y-axis (sdl:joystick-axis (device 1) (axis 1)))))
+
+ (standard-scroller
+ (core:axis-scroller
+ (x-axis (sdl:joystick-axis (device 1) (axis 4)))
+ (y-axis (sdl:joystick-axis (device 1) (axis 3)))))
+
+ (primary-button
+ (sdl:joystick-button (device 1) (button 0)))
+
+ (secondary-button
+ (sdl:joystick-button (device 1) (button 1)))
+
+ (pause-button
+ (sdl:joystick-button (device 1) (button 6))
+ (sdl:joystick-button (device 1) (button 5)))
+
+ (fast-forward-button
+ (sdl:joystick-button (device 1) (button 10))
+ (sdl:joystick-button (device 1) (button 4)))
+
+ (armageddon-button
+ (sdl:joystick-button (device 1) (button 7)))
+
+ (escape-button
+ (sdl:keyboard-button (key "escape")))
+
+ (action-axis
+ (sdl:joystick-axis (device 1) (axis 7)))
+
+ (action-up-button
+ (sdl:joystick-button (device 1) (button 2)))
+
+ (action-down-button
+ (sdl:joystick-button (device 1) (button 3)))
+ )
+
+;; EOF ;;
Modified: trunk/pingus/src/input/control.hpp
===================================================================
--- trunk/pingus/src/input/control.hpp 2007-09-02 19:56:03 UTC (rev 3068)
+++ trunk/pingus/src/input/control.hpp 2007-09-03 03:44:09 UTC (rev 3069)
@@ -24,6 +24,7 @@
#include <iostream>
#include <vector>
+#include <math.h>
#include "math.hpp"
#include "math/vector2f.hpp"
@@ -147,16 +148,26 @@
{
protected:
float pos;
+ float dead_zone;
+ bool invert;
public:
Axis(Control* parent)
: Control(parent),
- pos(0.0f)
+ pos(0.0f),
+ dead_zone(0.2f),
+ invert(false)
{}
float get_pos() const { return pos; }
virtual void set_state(float new_pos) {
+ if (invert)
+ new_pos = -new_pos;
+
+ if (fabsf(new_pos) < dead_zone)
+ new_pos = 0.0f;
+
if (new_pos != pos)
{
pos = new_pos;
@@ -236,12 +247,8 @@
}
new_pos = Math::clamp(-1.0f, new_pos, 1.0f);
-
- if (pos != new_pos)
- {
- pos = new_pos;
- notify_parent();
- }
+
+ set_state(new_pos);
}
};
Modified: trunk/pingus/src/input/core_driver.cpp
===================================================================
--- trunk/pingus/src/input/core_driver.cpp 2007-09-02 19:56:03 UTC (rev
3068)
+++ trunk/pingus/src/input/core_driver.cpp 2007-09-03 03:44:09 UTC (rev
3069)
@@ -90,7 +90,60 @@
}
}
};
+
+class AxisScroller : public Scroller
+{
+private:
+ Axis* x_axis;
+ Axis* y_axis;
+ Button* speed_button;
+ float speed;
+public:
+ AxisScroller(Control* parent)
+ : Scroller(parent),
+ x_axis(0), y_axis(0), speed_button(0),
+ speed(800.0f)
+ {
+ }
+
+ ~AxisScroller()
+ {
+ }
+
+ void setup(Axis* x, Axis* y, Button* s = 0)
+ {
+ x_axis = x;
+ y_axis = y;
+ speed_button = s;
+ }
+
+ void update(Control* )
+ {
+ //std::cout << "event" << std::endl;
+ }
+
+ void update(float delta)
+ {
+ x_axis->update(delta);
+ y_axis->update(delta);
+
+ if (speed_button) speed_button->update(delta);
+
+ float c_speed = speed;
+
+ if (speed_button && speed_button->get_state() == BUTTON_PRESSED)
+ {
+ c_speed *= 5.0f;
+ }
+
+ this->delta.x = -x_axis->get_pos() * c_speed * delta;
+ this->delta.y = y_axis->get_pos() * c_speed * delta;
+
+ notify_parent();
+ }
+};
+
Button*
CoreDriver::create_button(const FileReader& reader, Control* parent)
{
@@ -106,7 +159,50 @@
Scroller*
CoreDriver::create_scroller(const FileReader& reader, Control* parent)
{
- return 0;
+ if (reader.get_name() == "core:axis-scroller")
+ {
+ AxisScroller* axis = new AxisScroller(parent);
+
+ FileReader x_reader;
+ if (!reader.read_section("x-axis", x_reader))
+ {
+ std::cout << "CoreDriver: Couldn't find x-axis" << std::endl;
+ delete axis;
+ return 0;
+ }
+
+ FileReader y_reader;
+ if (!reader.read_section("y-axis", y_reader))
+ {
+ std::cout << "CoreDriver: Couldn't find y-axis" << std::endl;
+ delete axis;
+ return 0;
+ }
+
+ Axis* x_axis = manager->create_axis(x_reader.get_sections().front(),
axis);
+ Axis* y_axis = manager->create_axis(y_reader.get_sections().front(),
axis);
+
+ Button* button = 0;
+ FileReader button_reader;
+ if (reader.read_section("button", button_reader))
+ {
+ button =
manager->create_button(button_reader.get_sections().front(), axis);
+ }
+
+ if (x_axis && y_axis)
+ {
+ axis->setup(x_axis, y_axis, button);
+ return axis;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ else
+ {
+ return 0;
+ }
}
Pointer*
Modified: trunk/pingus/src/input/wiimote.cpp
===================================================================
--- trunk/pingus/src/input/wiimote.cpp 2007-09-02 19:56:03 UTC (rev 3068)
+++ trunk/pingus/src/input/wiimote.cpp 2007-09-03 03:44:09 UTC (rev 3069)
@@ -174,7 +174,7 @@
CWIID_RPT_STATUS |
CWIID_RPT_NUNCHUK |
CWIID_RPT_ACC |
- //CWIID_RPT_IR |
+ CWIID_RPT_IR |
CWIID_RPT_BTN))
{
std::cerr << "Wiimote: Error setting report mode" << std::endl;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3069 - in trunk/pingus: data/controller src/input,
grumbel at BerliOS <=