| 1220 | /////////////////////////////////////////////////////////////////////////////// |
| 1221 | |
| 1222 | void SampleSubmarine::handleInput() |
| 1223 | { |
| 1224 | if(gCrab && mCameraAttachedToActor == gCrab->getCrabBody()) |
| 1225 | { |
| 1226 | PxReal accFactor = 3.0f; |
| 1227 | PxReal forward = 0, rot = 0; |
| 1228 | if(gKeyFlags & Movement::eCRAB_FWD) |
| 1229 | forward = 1.0f; |
| 1230 | if(gKeyFlags & Movement::eCRAB_BCKWD) |
| 1231 | forward = -1.0f; |
| 1232 | if(gKeyFlags & Movement::eCRAB_ROTATE_LEFT) |
| 1233 | rot = 1.0f; |
| 1234 | if(gKeyFlags & Movement::eCRAB_ROTATE_RIGHT) |
| 1235 | rot = -1.0f; |
| 1236 | PxReal left = rot + forward; |
| 1237 | PxReal right = -rot + forward; |
| 1238 | gCrab->setAcceleration(left*accFactor, right*accFactor); |
| 1239 | } |
| 1240 | else if(mSubmarineActor && mCameraAttachedToActor == mSubmarineActor) |
| 1241 | { |
| 1242 | if(gKeyFlags & Movement::eSUBMAINE_FWD) |
| 1243 | gForce.x -= gLinPower; |
| 1244 | if(gKeyFlags & Movement::eSUBMAINE_BCKWD) |
| 1245 | gForce.x += gLinPower; |
| 1246 | if(gKeyFlags & Movement::eSUBMAINE_UP) |
| 1247 | gForce.y += gLinPower; |
| 1248 | if(gKeyFlags & Movement::eSUBMAINE_DOWN) |
| 1249 | gForce.y -= gLinPower; |
| 1250 | |
| 1251 | if(gKeyFlags & (Movement::eSUBMAINE_FWD|Movement::eSUBMAINE_BCKWD)) |
| 1252 | { |
| 1253 | PxSceneReadLock scopedLock(*mScene); |
| 1254 | |
| 1255 | static const PxReal camEpsilon = 0.001f; |
| 1256 | PxTransform subPose = mSubmarineActor->getGlobalPose(); |
| 1257 | PxVec3 cameraDir = getCamera().getViewDir(); |
| 1258 | PxVec3 cameraDirInSub = subPose.rotateInv(cameraDir).getNormalized(); |
| 1259 | PxVec3 cameraUpInSub = subPose.rotateInv(PxVec3(0,1,0)).getNormalized(); |
| 1260 | |
| 1261 | if(PxAbs(cameraDirInSub.z) > camEpsilon) |
| 1262 | gTorque.y += gAngPower*cameraDirInSub.z; |
| 1263 | if(PxAbs(cameraDirInSub.y) > camEpsilon) |
| 1264 | gTorque.z -= gAngPower*cameraDirInSub.y; |
| 1265 | if(PxAbs(cameraUpInSub.z) > camEpsilon) |
| 1266 | gTorque.x += gAngPower*cameraUpInSub.z; |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | ////////////////////////////////////////////////////////////////////////// |
| 1272 |
nothing calls this directly
no test coverage detected