source: trunk/src/ps3input.cpp @ 838

Last change on this file since 838 was 838, checked in by sam, 8 years ago

ps3: add a simple PS3 input system that currently merely emulates mouse
movements with the right stick and one mouse button with the L1 or R1 buttons.

File size: 2.1 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#if defined __CELLOS_LV2__
16#   include <padutil.h>
17#endif
18
19#include "core.h"
20#include "ps3input.h"
21
22namespace lol
23{
24
25/*
26 * PS3 Input implementation class
27 */
28
29class Ps3InputData
30{
31    friend class Ps3Input;
32
33    vec2 mousepos;
34    vec3i mousebuttons;
35};
36
37/*
38 * Public Ps3Input class
39 */
40
41Ps3Input::Ps3Input()
42  : data(new Ps3InputData())
43{
44#if defined __CELLOS_LV2__
45    cellPadUtilPadInit();
46    cellPadUtilSetSensorMode(true);
47    cellPadUtilSetPressMode(true);
48    cellPadUtilSetSensorFilter(CELL_PADFILTER_IIR_CUTOFF_2ND_LPF_BT_010);
49
50    data->mousepos = vec2(320.0f, 240.0f);
51    data->mousebuttons = vec3i(0, 0, 0);
52
53    gamegroup = GAMEGROUP_BEFORE;
54#endif
55}
56
57void Ps3Input::TickGame(float deltams)
58{
59    Entity::TickGame(deltams);
60
61#if defined __CELLOS_LV2__
62    cellPadUtilUpdate();
63
64    int pad = cellPadUtilGetFirstConnectedPad();
65    if (pad >= 0)
66    {
67        CellPadUtilAxis axis = cellPadUtilGetAxisValue(pad, CELL_UTIL_ANALOG_RIGHT);
68        vec2 delta(4e-3f * (abs(axis.x - 127) < 16 ? 0 : axis.x - 127),
69                   -4e-3f * (abs(axis.y - 127) < 16 ? 0 : axis.y - 127));
70        data->mousepos += delta * deltams;
71        Input::SetMousePos((vec2i)data->mousepos);
72
73        // L1 for mouse button
74        uint32_t paddata = cellPadUtilGetDigitalData(pad);
75        int but = cellPadUtilDigitalButtonPressed(paddata, CELL_UTIL_BUTTON_L1)
76               || cellPadUtilDigitalButtonPressed(paddata, CELL_UTIL_BUTTON_R1);
77       
78        if (but && !data->mousebuttons.x)
79            Input::SetMouseButton(0);
80        else if (!but && data->mousebuttons.x)
81            Input::UnsetMouseButton(0);
82
83        data->mousebuttons.x = but;
84    }
85#endif
86}
87
88Ps3Input::~Ps3Input()
89{
90    delete data;
91}
92
93} /* namespace lol */
94
Note: See TracBrowser for help on using the repository browser.