00001 #include "event.h"
00002 #include <math.h>
00003
00004 namespace wit {
00005
00022 Event::Event(int type) : m_type(type)
00023 {
00024
00025 }
00026
00030 int Event::type() const
00031 {
00032 return m_type;
00033 }
00034
00066 InputEvent::InputEvent(int type, Controller ctype, unsigned short id) : Event(type), controllerType(ctype), controllerNumber(id)
00067 {
00068
00069 }
00070
00096 ButtonEvent::ButtonEvent(Event::Type type, Controller ctype, unsigned short id, int button) : InputEvent(type, ctype, id), button((Button)button)
00097 {
00098
00099 }
00100
00154 JoystickEvent::JoystickEvent(Controller ctype, unsigned short id, bool isRightStick) : InputEvent(Event::Joystick, ctype, id), isRightStick(isRightStick)
00155 {
00156
00157 }
00158
00162 void JoystickEvent::setByPosition(signed char px, signed char py)
00163 {
00164 setByPosition(px / 127.0f, py / 127.0f);
00165 }
00166
00170 void JoystickEvent::setByPosition(float px, float py)
00171 {
00172 if(px < -1.0)
00173 px = -1.0;
00174 else if(px > 1.0)
00175 px = 1.0;
00176 if(py < -1.0)
00177 py = -1.0;
00178 else if(py > 1.0)
00179 py = 1.0;
00180
00181 x = px;
00182 y = py;
00183 angle = ::atan2f(y, x);
00184 magnitude = ::sqrt((x * x) + (y * y));
00185 if(magnitude > 1.0)
00186 magnitude = 1.0;
00187 }
00188
00193 void JoystickEvent::setByAngle(float pangle, float pmag)
00194 {
00195 if(pmag > -0.001 && pmag < 0.001) {
00196 angle = pangle;
00197 magnitude = pmag;
00198 x = 0.0;
00199 y = 0.0;
00200 return;
00201 } else if(pmag > 1.0) {
00202 pmag = 1.0;
00203 } else if(pmag < -1.0) {
00204 pmag = -1.0;
00205 }
00206
00207 angle = pangle;
00208 magnitude = pmag;
00209 x = pmag * ::sin(M_PI * pangle / 180.0);
00210 y = pmag * ::cos(M_PI * pangle / 180.0);
00211 }
00212
00244 AnalogEvent::AnalogEvent(Controller ctype, unsigned short id, AnalogButton trigger, float pressure) : InputEvent(InputEvent::Analog, ctype, id), trigger(trigger), pressure(pressure)
00245 {
00246
00247 }
00248
00298 MotionEvent::MotionEvent(Controller ctype, unsigned short id, float x, float y, float z, float pitch, float roll)
00299 : InputEvent(Event::Motion, ctype, id), x(x), y(y), z(z), pitch(pitch), roll(roll)
00300 {
00301
00302 }
00303
00334 PointerEvent::PointerEvent(unsigned short id, float x, float y, float z) : InputEvent(Event::Pointer, WiiRemote, id), x(x), y(y), z(z)
00335 {
00336
00337 }
00338
00342 bool PointerEvent::isValid() const
00343 {
00344 return x != -1.0f || y != -1.0f || z != -1.0f;
00345 }
00346
00360 PointerLeaveEvent::PointerLeaveEvent(unsigned short id, Hotspot* hotspot) : InputEvent(Event::PointerLeave, WiiRemote, id), hotspot(hotspot)
00361 {
00362
00363 }
00364
00365 }