BVB Source Codes

CRYENGINE Show CoverScorer.cpp Source code

Return Download CRYENGINE: download CoverScorer.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "CoverScorer.h"
  5.  
  6. float DefaultCoverScorer::ScoreByDistance(const ICoverLocationScorer::Params& params) const
  7. {
  8.         float distance = (params.location - params.userLocation).len();
  9.         float maxDistance = params.totalLength;
  10.         if (maxDistance < distance)
  11.                 maxDistance = distance;
  12.  
  13.         assert(distance <= maxDistance);
  14.  
  15.         float score = 1.0f;
  16.         if (maxDistance >= 0.1f)
  17.                 score = 1.0f - min(1.0f, distance / maxDistance);
  18.  
  19.         return score;
  20. }
  21.  
  22. float DefaultCoverScorer::ScoreByDistanceToTarget(const ICoverLocationScorer::Params& params) const
  23. {
  24.         float locationToTarget = (params.location - params.target).len();
  25.  
  26.         const float ConsiderClose = 10.0f;
  27.         const float ConsiderFar = 25.0f;
  28.  
  29.         bool isClose = (locationToTarget < ConsiderClose);
  30.         bool isFar = (locationToTarget > ConsiderFar);
  31.  
  32.         float score = 1.0f;
  33.         if (isClose)
  34.                 score = (locationToTarget / ConsiderClose);
  35.         else if (isFar)
  36.                 score = 1.0f - max(1.0f, (locationToTarget - ConsiderFar) / ConsiderFar);
  37.  
  38.         return score;
  39. }
  40.  
  41. float DefaultCoverScorer::ScoreByAngle(const ICoverLocationScorer::Params& params) const
  42. {
  43.         Vec3 locationToTargetDir = (params.target - params.location).GetNormalized();
  44.         float angleCos = locationToTargetDir.Dot(params.direction);
  45.         if (angleCos <= 0.1f)
  46.                 return 0.0f;
  47.  
  48.         return angleCos;
  49. }
  50.  
  51. float DefaultCoverScorer::Score(const ICoverLocationScorer::Params& params) const
  52. {
  53.         float score = 0.0f;
  54.  
  55.         switch (params.usage)
  56.         {
  57.         case eCU_Hide:
  58.                 {
  59.                         score += 0.2f * ScoreByDistance(params);
  60.                         score += 0.3f * ScoreByAngle(params);
  61.                         score += 0.5f * ScoreByDistanceToTarget(params);
  62.                 }
  63.                 break;
  64.         case eCU_UnHide:
  65.                 {
  66.                         score += 0.5f * ScoreByDistance(params);
  67.                         score += 0.0f * ScoreByAngle(params);
  68.                         score += 0.5f * ScoreByDistanceToTarget(params);
  69.                 }
  70.         default:
  71.                 assert(0);
  72.                 break;
  73.         }
  74.  
  75.         return score;
  76. }
  77.  
downloadCoverScorer.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