MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / checkInFoV

Method checkInFoV

Engine/source/T3D/aiPlayer.cpp:1344–1382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1342}
1343
1344bool AIPlayer::checkInFoV(GameBase* target, F32 camFov, bool _checkEnabled)
1345{
1346 if (!isServerObject()) return false;
1347 if (!target)
1348 {
1349 target = mAimObject.getPointer();
1350 if (!target)
1351 return false;
1352 }
1353 if (_checkEnabled)
1354 {
1355 if (target->getTypeMask() & ShapeBaseObjectType)
1356 {
1357 ShapeBase *shapeBaseCheck = static_cast<ShapeBase *>(target);
1358 if (shapeBaseCheck)
1359 if (shapeBaseCheck->getDamageState() != Enabled) return false;
1360 }
1361 else
1362 return false;
1363 }
1364
1365 MatrixF cam = getTransform();
1366 Point3F camPos;
1367 VectorF camDir;
1368
1369 cam.getColumn(3, &camPos);
1370 cam.getColumn(1, &camDir);
1371
1372 camFov = mDegToRad(camFov) / 2;
1373
1374 Point3F shapePos = target->getBoxCenter();
1375 VectorF shapeDir = shapePos - camPos;
1376 // Test to see if it's within our viewcone, this test doesn't
1377 // actually match the viewport very well, should consider
1378 // projection and box test.
1379 shapeDir.normalize();
1380 F32 dot = mDot(shapeDir, camDir);
1381 return (dot > mCos(camFov));
1382}
1383
1384DefineEngineMethod(AIPlayer, checkInFoV, bool, (ShapeBase* obj, F32 fov, bool checkEnabled), (nullAsType<ShapeBase*>(), 45.0f, false),
1385 "@brief Check whether an object is within a specified veiw cone.\n"

Callers 1

aiPlayer.cppFile · 0.80

Calls 9

mDegToRadFunction · 0.85
mCosFunction · 0.85
getTypeMaskMethod · 0.80
getColumnMethod · 0.80
getBoxCenterMethod · 0.80
mDotFunction · 0.50
getPointerMethod · 0.45
getDamageStateMethod · 0.45
normalizeMethod · 0.45

Tested by

no test coverage detected