CCTouch.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013-2017 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #include "base/CCTouch.h"
  22. #include "base/CCDirector.h"
  23. NS_CC_BEGIN
  24. // returns the current touch location in screen coordinates
  25. Vec2 Touch::getLocationInView() const
  26. {
  27. return _point;
  28. }
  29. // returns the previous touch location in screen coordinates
  30. Vec2 Touch::getPreviousLocationInView() const
  31. {
  32. return _prevPoint;
  33. }
  34. // returns the start touch location in screen coordinates
  35. Vec2 Touch::getStartLocationInView() const
  36. {
  37. return _startPoint;
  38. }
  39. // returns the current touch location in OpenGL coordinates
  40. Vec2 Touch::getLocation() const
  41. {
  42. return Director::getInstance()->convertToGL(_point);
  43. }
  44. // returns the previous touch location in OpenGL coordinates
  45. Vec2 Touch::getPreviousLocation() const
  46. {
  47. return Director::getInstance()->convertToGL(_prevPoint);
  48. }
  49. // returns the start touch location in OpenGL coordinates
  50. Vec2 Touch::getStartLocation() const
  51. {
  52. return Director::getInstance()->convertToGL(_startPoint);
  53. }
  54. // returns the delta position between the current location and the previous location in OpenGL coordinates
  55. Vec2 Touch::getDelta() const
  56. {
  57. return getLocation() - getPreviousLocation();
  58. }
  59. // Returns the current touch force for 3d touch.
  60. float Touch::getCurrentForce() const
  61. {
  62. return _curForce;
  63. }
  64. // Returns the maximum touch force for 3d touch.
  65. float Touch::getMaxForce() const
  66. {
  67. return _maxForce;
  68. }
  69. NS_CC_END