kick
|
00001 // 00002 // Created by morten on 07/08/14. 00003 // 00004 00005 #include "touch_input.h" 00006 00007 #include <vector> 00008 #include <iostream> 00009 #include "glm/gtx/string_cast.hpp" 00010 00011 using namespace std; 00012 using namespace glm; 00013 00014 namespace kick{ 00015 std::map<int64_t,Touch> TouchInput::touches; 00016 00017 void TouchInput::setTouchStarted(int64_t fingerid, glm::ivec2 pos, float pressure) { 00018 Touch touch; 00019 touch.down = true; 00020 touch.up = false; 00021 touch.fingerId = fingerid; 00022 touch.pos = pos; 00023 touch.delta = {0,0}; 00024 touch.pressure = pressure; 00025 touches[fingerid] = touch; 00026 } 00027 00028 void TouchInput::setTouchMoved(int64_t fingerid, glm::ivec2 pos, float pressure) { 00029 auto & touch = touches[fingerid]; 00030 00031 touch.delta = pos - touch.pos; 00032 touch.pos = pos; 00033 touch.pressure = pressure; 00034 } 00035 00036 void TouchInput::setTouchEnded(int64_t fingerid, glm::ivec2 pos) { 00037 auto & touch = touches[fingerid]; 00038 touch.delta = pos - touch.pos; 00039 touch.pos = pos; 00040 touch.pressure = 0; 00041 touch.up = true; 00042 } 00043 00044 void TouchInput::reset() { 00045 vector<long> deleteKeys; 00046 for (auto keyVal : touches){ 00047 keyVal.second.down = false; 00048 keyVal.second.delta = ivec2{0}; 00049 if (keyVal.second.up){ 00050 deleteKeys.push_back(keyVal.first); 00051 } 00052 } 00053 00054 for (long del : deleteKeys){ 00055 touches.erase(del); 00056 } 00057 } 00058 00059 std::map<int64_t, Touch>::const_iterator TouchInput::begin() { 00060 return touches.begin(); 00061 } 00062 00063 map<int64_t, Touch>::const_iterator TouchInput::end() { 00064 return touches.end(); 00065 } 00066 }