MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / handleInput

Method handleInput

physx/samples/samplesubmarine/SampleSubmarine.cpp:1222–1269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1220///////////////////////////////////////////////////////////////////////////////
1221
1222void 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

Callers

nothing calls this directly

Calls 8

PxAbsFunction · 0.85
getCrabBodyMethod · 0.80
getViewDirMethod · 0.80
PxVec3Class · 0.50
setAccelerationMethod · 0.45
getGlobalPoseMethod · 0.45
getNormalizedMethod · 0.45
rotateInvMethod · 0.45

Tested by

no test coverage detected