BVB Source Codes

CRYENGINE Show AngleAlert.cpp Source code

Return Download CRYENGINE: download AngleAlert.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /********************************************************************
  4.    ---------------------------------------------------------------------
  5.    File name:   AngleAlert.h
  6.    $Id$
  7.    $DateTime$
  8.    Description: Single angle slice
  9.    ---------------------------------------------------------------------
  10.    History:
  11.    - 11:09:2007 : Created by Ricardo Pillosu
  12.  
  13.  *********************************************************************/
  14. #include "StdAfx.h"
  15. #include "AngleAlert.h"
  16. #include "PersonalRangeSignaling.h"
  17. #include <CryAISystem/IAIObject.h>
  18. // Description:
  19. //   Constructor
  20. // Arguments:
  21. //
  22. // Return:
  23. //
  24. CAngleAlert::CAngleAlert(CPersonalRangeSignaling* pPersonal) : m_pPersonal(pPersonal), m_fAngle(-1.0f), m_fBoundary(-1.0f), m_pSignalData(NULL)
  25. {
  26.         CRY_ASSERT(pPersonal != NULL);
  27. }
  28.  
  29. // Description:
  30. //   Destructor
  31. // Arguments:
  32. //
  33. // Return:
  34. //
  35. CAngleAlert::~CAngleAlert()
  36. {
  37.         if (gEnv->pAISystem)
  38.                 gEnv->pAISystem->FreeSignalExtraData(m_pSignalData);
  39. }
  40.  
  41. // Description:
  42. //   Init
  43. // Arguments:
  44. //
  45. // Return:
  46. //
  47. void CAngleAlert::Init(float fAngle, float fBoundary, const char* sSignal, IAISignalExtraData* pData /*= NULL*/)
  48. {
  49.         CRY_ASSERT(fAngle >= 1.0f);
  50.         CRY_ASSERT(fBoundary >= 0.0f);
  51.         CRY_ASSERT(sSignal != NULL);
  52.  
  53.         m_sSignal = sSignal;
  54.         m_fAngle = DEG2RAD(fAngle);
  55.         m_fBoundary = DEG2RAD(fBoundary) + m_fAngle;
  56.  
  57.         // Clone extra data
  58.         if (pData && gEnv->pAISystem)
  59.         {
  60.                 gEnv->pAISystem->FreeSignalExtraData(m_pSignalData);
  61.                 m_pSignalData = gEnv->pAISystem->CreateSignalExtraData();
  62.                 CRY_ASSERT(m_pSignalData);
  63.                 *m_pSignalData = *pData;
  64.         }
  65. }
  66.  
  67. // Description:
  68. //
  69. // Arguments:
  70. //
  71. // Return:
  72. //
  73. bool CAngleAlert::Check(const Vec3& vPos) const
  74. {
  75.         return(GetAngleTo(vPos) < m_fAngle);
  76. }
  77.  
  78. // Description:
  79. //
  80. // Arguments:
  81. //
  82. // Return:
  83. //
  84. bool CAngleAlert::CheckPlusBoundary(const Vec3& vPos) const
  85. {
  86.         return(GetAngleTo(vPos) < m_fBoundary);
  87. }
  88.  
  89. // Description:
  90. //
  91. // Arguments:
  92. //
  93. // Return:
  94. //
  95. float CAngleAlert::GetAngleTo(const Vec3& vPos) const
  96. {
  97.         float fResult = 0.0f;
  98.         IEntity* pEntity = m_pPersonal->GetEntity();
  99.         CRY_ASSERT(pEntity);
  100.         if (pEntity)
  101.         {
  102.                 const Vec3& vEntityPos = pEntity->GetPos();
  103.                 const Vec3& vEntityDir = pEntity->GetAI()->GetViewDir();
  104.                 Vec3 vDiff = vPos - vEntityPos;
  105.                 vDiff.NormalizeSafe();
  106.                 fResult = acosf(vEntityDir.Dot(vDiff));
  107.         }
  108.         return fResult;
  109. }
  110.  
downloadAngleAlert.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top