Advertisement
keybode

h1z1 IsPointVisible

Jan 20th, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. physx::PxPhysics* GetPhysX() {
  2.     HMODULE hModule = GetModuleHandleA("PhysX3CHECKED_x64.dll");
  3.  
  4.     if (!hModule) {
  5.         return nullptr;
  6.     }
  7.  
  8.     typedef physx::PxPhysics* (__cdecl* GetPhysicsFn)();
  9.  
  10.     GetPhysicsFn GetPhysics = (GetPhysicsFn)GetProcAddress(hModule, "PxGetPhysics");
  11.  
  12.     if (!GetPhysics) {
  13.         return nullptr;
  14.     }
  15.  
  16.     return GetPhysics();
  17. }
  18.  
  19. physx::PxScene* g_pPxScene = nullptr;
  20.  
  21. void UpdatePhysX() {
  22.     physx::PxPhysics* pPhysX = GetPhysX();
  23.  
  24.     if (!pPhysX) {
  25.         return;
  26.     }
  27.    
  28.     pPhysX->getScenes(&g_pPxScene, 1);
  29. }
  30.  
  31. bool IsPointVisible(const Vector3& vStart, const Vector3& vEnd) {
  32.     if (!g_pPxScene) {
  33.         return false;
  34.     }
  35.  
  36.     physx::PxVec3 pStart = *(physx::PxVec3*)&vStart;
  37.     physx::PxVec3 pEnd = *(physx::PxVec3*)&vEnd;
  38.  
  39.     physx::PxVec3 pDirection = pEnd - pStart;
  40.  
  41.     physx::PxReal pLength = pDirection.magnitude();
  42.  
  43.     pDirection.normalize();
  44.  
  45.     physx::PxSceneQueryHit pHit;
  46.  
  47.     if (g_pPxScene->raycastAny(pStart, pDirection, pLength, pHit, physx::PxSceneQueryFilterData(physx::PxSceneQueryFilterFlag::eSTATIC))) {
  48.         return false;
  49.     }
  50.  
  51.     return true;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement