您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

95 行
2.1 KiB

  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. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #if defined __CELLOS_LV2__
  14. # include <padutil.h>
  15. #endif
  16. #include "core.h"
  17. #include "ps3input.h"
  18. namespace lol
  19. {
  20. /*
  21. * PS3 Input implementation class
  22. */
  23. class Ps3InputData
  24. {
  25. friend class Ps3Input;
  26. vec2 mousepos;
  27. vec3i mousebuttons;
  28. };
  29. /*
  30. * Public Ps3Input class
  31. */
  32. Ps3Input::Ps3Input()
  33. : data(new Ps3InputData())
  34. {
  35. #if defined __CELLOS_LV2__
  36. cellPadUtilPadInit();
  37. cellPadUtilSetSensorMode(true);
  38. cellPadUtilSetPressMode(true);
  39. cellPadUtilSetSensorFilter(CELL_PADFILTER_IIR_CUTOFF_2ND_LPF_BT_010);
  40. data->mousepos = vec2(320.0f, 240.0f);
  41. data->mousebuttons = vec3i(0, 0, 0);
  42. gamegroup = GAMEGROUP_BEFORE;
  43. #endif
  44. }
  45. void Ps3Input::TickGame(float deltams)
  46. {
  47. Entity::TickGame(deltams);
  48. #if defined __CELLOS_LV2__
  49. cellPadUtilUpdate();
  50. int pad = cellPadUtilGetFirstConnectedPad();
  51. if (pad >= 0)
  52. {
  53. CellPadUtilAxis axis = cellPadUtilGetAxisValue(pad, CELL_UTIL_ANALOG_RIGHT);
  54. vec2 delta(4e-3f * (abs(axis.x - 127) < 16 ? 0 : axis.x - 127),
  55. -4e-3f * (abs(axis.y - 127) < 16 ? 0 : axis.y - 127));
  56. data->mousepos += delta * deltams;
  57. Input::SetMousePos((vec2i)data->mousepos);
  58. // L1 for mouse button
  59. uint32_t paddata = cellPadUtilGetDigitalData(pad);
  60. int but = cellPadUtilDigitalButtonPressed(paddata, CELL_UTIL_BUTTON_L1)
  61. || cellPadUtilDigitalButtonPressed(paddata, CELL_UTIL_BUTTON_R1);
  62. if (but && !data->mousebuttons.x)
  63. Input::SetMouseButton(0);
  64. else if (!but && data->mousebuttons.x)
  65. Input::UnsetMouseButton(0);
  66. data->mousebuttons.x = but;
  67. }
  68. #endif
  69. }
  70. Ps3Input::~Ps3Input()
  71. {
  72. delete data;
  73. }
  74. } /* namespace lol */