Changeset 1751
- Timestamp:
- Aug 15, 2012, 10:25:00 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/input/input.cpp
r1710 r1751 32 32 */ 33 33 34 Array<ButtonSetting> Input::InputAssocationList; 35 34 36 static class InputData 35 37 { … … 114 116 } 115 117 118 //-- 119 120 //--- 121 //Internal : Updates the action status & timers 122 void Input::UpdateActionStatus(float seconds) 123 { 124 for (int i = 0; i < InputAssocationList.Count(); i++) 125 { 126 ButtonSetting &CurIT = InputAssocationList[i]; 127 128 CurIT.PrevStatus = CurIT.CurStatus; 129 CurIT.CurStatus = Input::GetButtonState(CurIT.RawButtonId); 130 131 for (int j = 0; j < CurIT.AssociatedActionList.Count(); j++) 132 { 133 ActionSetting &CurAS = CurIT.AssociatedActionList[j]; 134 135 if (CurAS.BufferedSince <= CurAS.BufferingTime) 136 CurAS.BufferedSince += seconds; 137 138 if (CurIT.CurStatus && CurAS.BufferingTime >= .0f) 139 CurAS.BufferedSince = .0f; 140 } 141 } 142 143 } 144 145 //Helps link a software input Action-Id to an hardware input Button-Id. 146 void Input::LinkActionIdToButtonId(int ActionId, int ButtonId) 147 { 148 int ITIdx = GetButtonSettingIdx(ButtonId); 149 if (ITIdx == -1) 150 { 151 ITIdx = InputAssocationList.Count(); 152 InputAssocationList << ButtonSetting(ButtonId); 153 } 154 155 ButtonSetting &CurIT = InputAssocationList[ITIdx]; 156 157 int ASIdx = CurIT.GetActionSettingIdx(ActionId); 158 if (ASIdx == -1) 159 { 160 ASIdx = CurIT.AssociatedActionList.Count(); 161 CurIT.AssociatedActionList << ActionSetting(ActionId); 162 } 163 } 164 165 //Helps unlink a software input Action-Id to an hardware input Button-Id. 166 void Input::UnlinkActionId(int ActionId) 167 { 168 for (int i = 0; i < InputAssocationList.Count(); i++) 169 { 170 ButtonSetting &CurIT = InputAssocationList[i]; 171 int ASIdx = CurIT.GetActionSettingIdx(ActionId); 172 if (ASIdx != -1) 173 CurIT.AssociatedActionList.Remove(ASIdx); 174 } 175 } 176 177 //Returns the current status of a given action 178 int Input::GetActionStatus(int ActionId) 179 { 180 for (int i = 0; i < InputAssocationList.Count(); i++) 181 { 182 ButtonSetting &CurIT = InputAssocationList[i]; 183 int ASIdx = CurIT.GetActionSettingIdx(ActionId); 184 if (ASIdx != -1) 185 { 186 ActionSetting &CurAS = CurIT.AssociatedActionList[ASIdx]; 187 188 if (CurAS.BufferingTime >= .0f && CurAS.BufferedSince <= CurAS.BufferingTime) 189 return 1; 190 return 0; 191 } 192 } 193 return 0; 194 } 195 196 //Returns TRUE if action status when from Active to Inactive this frame 197 bool Input::WasActionJustReleased(int ActionId) 198 { 199 for (int i = 0; i < InputAssocationList.Count(); i++) 200 { 201 ButtonSetting &CurIT = InputAssocationList[i]; 202 int ASIdx = CurIT.GetActionSettingIdx(ActionId); 203 if (ASIdx != -1) 204 { 205 if (!CurIT.CurStatus && CurIT.PrevStatus) 206 return TRUE; 207 return FALSE; 208 } 209 } 210 return FALSE; 211 } 212 213 //-- 116 214 void Input::TrackMouse(WorldEntity *e) 117 215 { -
trunk/src/input/input.h
r1710 r1751 25 25 class WorldEntity; 26 26 27 //Partial Key reap-off of the SDLK enum 28 #define LOLK_UNKNOWN = 0; 29 30 #define LOLK_RETURN = '\r'; 31 #define LOLK_ESCAPE = '\033'; 32 #define LOLK_BACKSPACE = '\b'; 33 #define LOLK_TAB = '\t'; 34 #define LOLK_SPACE = ' '; 35 #define LOLK_EXCLAIM = '!'; 36 #define LOLK_QUOTEDBL = '"'; 37 #define LOLK_HASH = '#'; 38 #define LOLK_PERCENT = '%'; 39 #define LOLK_DOLLAR = '$'; 40 #define LOLK_AMPERSAND = '&'; 41 #define LOLK_QUOTE = '\''; 42 #define LOLK_LEFTPAREN = '('; 43 #define LOLK_RIGHTPAREN = ')'; 44 #define LOLK_ASTERISK = '*'; 45 #define LOLK_PLUS = '+'; 46 #define LOLK_COMMA = ';'; 47 #define LOLK_MINUS = '-'; 48 #define LOLK_PERIOD = '.'; 49 #define LOLK_SLASH = '/'; 50 #define LOLK_0 = '0'; 51 #define LOLK_1 = '1'; 52 #define LOLK_2 = '2'; 53 #define LOLK_3 = '3'; 54 #define LOLK_4 = '4'; 55 #define LOLK_5 = '5'; 56 #define LOLK_6 = '6'; 57 #define LOLK_7 = '7'; 58 #define LOLK_8 = '8'; 59 #define LOLK_9 = '9'; 60 #define LOLK_COLON = ':'; 61 #define LOLK_SEMICOLON = ';'; 62 #define LOLK_LESS = '<'; 63 #define LOLK_EQUALS = '='; 64 #define LOLK_GREATER = '>'; 65 #define LOLK_QUESTION = '?'; 66 #define LOLK_AT = '@'; 67 /* 68 Skip uppercase letters 69 */ 70 #define LOLK_LEFTBRACKET = '['; 71 #define LOLK_BACKSLASH = '\\'; 72 #define LOLK_RIGHTBRACKET = ']'; 73 #define LOLK_CARET = '^'; 74 #define LOLK_UNDERSCORE = '_'; 75 #define LOLK_BACKQUOTE = '`'; 76 #define LOLK_a = 'a'; 77 #define LOLK_b = 'b'; 78 #define LOLK_c = 'c'; 79 #define LOLK_d = 'd'; 80 #define LOLK_e = 'e'; 81 #define LOLK_f = 'f'; 82 #define LOLK_g = 'g'; 83 #define LOLK_h = 'h'; 84 #define LOLK_i = 'i'; 85 #define LOLK_j = 'j'; 86 #define LOLK_k = 'k'; 87 #define LOLK_l = 'l'; 88 #define LOLK_m = 'm'; 89 #define LOLK_n = 'n'; 90 #define LOLK_o = 'o'; 91 #define LOLK_p = 'p'; 92 #define LOLK_q = 'q'; 93 #define LOLK_r = 'r'; 94 #define LOLK_s = 's'; 95 #define LOLK_t = 't'; 96 #define LOLK_u = 'u'; 97 #define LOLK_v = 'v'; 98 #define LOLK_w = 'w'; 99 #define LOLK_x = 'x'; 100 #define LOLK_y = 'y'; 101 #define LOLK_z = 'z'; 102 103 struct ActionSetting 104 { 105 int ActionId; 106 float BufferingTime; 107 float BufferedSince; 108 109 ActionSetting(int NewActionId) 110 { 111 memset(this, 0, sizeof(ActionSetting)); 112 ActionId = NewActionId; 113 } 114 }; 115 116 struct ButtonSetting 117 { 118 int RawButtonId; 119 int CurStatus; 120 int PrevStatus; 121 Array<ActionSetting> AssociatedActionList; 122 123 ButtonSetting(int NewRawButtonId) 124 { 125 memset(this, 0, sizeof(ButtonSetting)); 126 RawButtonId = NewRawButtonId; 127 } 128 int GetActionSettingIdx(int ActionId) 129 { 130 for (int i = 0; i < AssociatedActionList.Count(); i++) 131 if (AssociatedActionList[i].ActionId == ActionId) 132 return i; 133 return -1; 134 } 135 }; 136 27 137 class Input 28 138 { 139 private: 140 static Array<ButtonSetting> InputAssocationList; 141 142 static int GetButtonSettingIdx(int ButtonId) 143 { 144 for (int i = 0; i < InputAssocationList.Count(); i++) 145 if (InputAssocationList[i].RawButtonId == ButtonId) 146 return i; 147 return -1; 148 } 149 150 static void UpdateActionStatus(float seconds); 151 29 152 public: 153 30 154 /* These methods are general queries */ 31 155 static ivec2 GetMousePos(); 32 156 static ivec3 GetMouseButtons(); 33 //BH : Added this, is a v0.1 Alpha version. 157 158 //BH : Shouldn't use this 34 159 static int GetButtonState(int button); 160 161 //Action management 162 static void LinkActionIdToButtonId(int ActionId, int ButtonId); 163 static void UnlinkActionId(int ActionId); 164 static int GetActionStatus(int ActionId); 165 static bool WasActionJustReleased(int ActionId); 35 166 36 167 /* Entities can subscribe to events */ -
trunk/test/Physics/Src/EasyPhysics.cpp
r1749 r1751 157 157 m_rigid_body = new btRigidBody(NewInfos); 158 158 m_collision_object = m_rigid_body; 159 m_collision_object->setUserPointer(this); 159 160 160 161 if (m_mass == .0f) … … 185 186 m_ghost_object->setCollisionShape(m_collision_shape); 186 187 m_collision_object = m_ghost_object; 188 m_collision_object->setUserPointer(this); 187 189 188 190 SetTransform(m_local_to_world.v3.xyz, lol::quat(m_local_to_world)); … … 190 192 m_ghost_object->setCollisionFlags(m_ghost_object->getCollisionFlags()); 191 193 } 194 195 //------------- 196 //Touch logic 197 //------------- 198 // btManifoldArray manifoldArray; 199 // btBroadphasePairArray& pairArray = ghostObject->getOverlappingPairCache()->getOverlappingPairArray(); 200 // int numPairs = pairArray.size(); 201 202 // for (int i=0;i<numPairs;i++) 203 // { 204 // manifoldArray.clear(); 205 206 // const btBroadphasePair& pair = pairArray[i]; 207 // 208 // //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache: 209 // btBroadphasePair* collisionPair = dynamicsWorld->getPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1); 210 // if (!collisionPair) 211 // continue; 212 213 // if (collisionPair->m_algorithm) 214 // collisionPair->m_algorithm->getAllContactManifolds(manifoldArray); 215 216 // for (int j=0;j<manifoldArray.size();j++) 217 // { 218 // btPersistentManifold* manifold = manifoldArray[j]; 219 // btScalar directionSign = manifold->getBody0() == m_ghostObject ? btScalar(-1.0) : btScalar(1.0); 220 // for (int p=0;p<manifold->getNumContacts();p++) 221 // { 222 // const btManifoldPoint&pt = manifold->getContactPoint(p); 223 // if (pt.getDistance()<0.f) 224 //{ 225 // const btVector3& ptA = pt.getPositionWorldOnA(); 226 // const btVector3& ptB = pt.getPositionWorldOnB(); 227 // const btVector3& normalOnB = pt.m_normalWorldOnB; 228 // /// work here 229 //} 230 // } 231 // } 232 // } 233 192 234 193 235 //Add Physic object to the simulation
Note: See TracChangeset
for help on using the changeset viewer.