BVB Source Codes

CRYENGINE Show FloorHeightCache.cpp Source code

Return Download CRYENGINE: download FloorHeightCache.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 "FloorHeightCache.h"
  5. #include "DebugDrawContext.h"
  6.  
  7. const float FloorHeightCache::CellSize = 0.25f;
  8. const float FloorHeightCache::InvCellSize = 1.0f / FloorHeightCache::CellSize;
  9. const float FloorHeightCache::HalfCellSize = FloorHeightCache::CellSize * 0.5f;
  10.  
  11. void FloorHeightCache::Reset()
  12. {
  13.         m_floorHeights.clear();
  14. }
  15.  
  16. void FloorHeightCache::SetHeight(const Vec3& position, float height)
  17. {
  18.         m_floorHeights.insert(CacheEntry(position, height));
  19. }
  20.  
  21. bool FloorHeightCache::GetHeight(const Vec3& position, float& height) const
  22. {
  23.         FloorHeights::const_iterator it = m_floorHeights.find(CacheEntry(position));
  24.         if (it == m_floorHeights.end())
  25.                 return false;
  26.  
  27.         height = it->height;
  28.  
  29.         return true;
  30. }
  31.  
  32. Vec3 FloorHeightCache::GetCellCenter(const Vec3& position) const
  33. {
  34.         float x = floor_tpl(position.x * InvCellSize) * CellSize + HalfCellSize;
  35.         float y = floor_tpl(position.y * InvCellSize) * CellSize + HalfCellSize;
  36.  
  37.         return Vec3(x, y, position.z);
  38. }
  39.  
  40. AABB FloorHeightCache::GetAABB(Vec3 position) const
  41. {
  42.         float x = floor_tpl(position.x * InvCellSize) * CellSize;
  43.         float y = floor_tpl(position.y * InvCellSize) * CellSize;
  44.  
  45.         return AABB(Vec3(x, y, position.z), Vec3(x + CellSize, y + CellSize, position.z));
  46. }
  47.  
  48. void FloorHeightCache::Draw(const ColorB& colorGood, const ColorB& colorBad)
  49. {
  50.         FloorHeights::iterator it = m_floorHeights.begin();
  51.         FloorHeights::iterator end = m_floorHeights.end();
  52.  
  53.         for (; it != end; ++it)
  54.         {
  55.                 const CacheEntry& entry = *it;
  56.  
  57.                 const ColorB color = entry.height < FLT_MAX ? colorGood : colorBad;
  58.                 Vec3 center = GetCellCenter(entry.x, entry.y);
  59.                 center.z = entry.height < FLT_MAX ? entry.height : (float)entry.z + 0.5f;
  60.  
  61.                 const Vec3 v0 = Vec3(center.x - HalfCellSize, center.y - HalfCellSize, center.z + 0.015f);
  62.                 const Vec3 v1 = Vec3(center.x - HalfCellSize, center.y + HalfCellSize, center.z + 0.015f);
  63.                 const Vec3 v2 = Vec3(center.x + HalfCellSize, center.y + HalfCellSize, center.z + 0.015f);
  64.                 const Vec3 v3 = Vec3(center.x + HalfCellSize, center.y - HalfCellSize, center.z + 0.015f);
  65.  
  66.                 CDebugDrawContext dc;
  67.  
  68.                 dc->SetBackFaceCulling(false);
  69.                 dc->SetDepthWrite(false);
  70.                 dc->DrawTriangle(v0, color, v1, color, v2, color);
  71.                 dc->DrawTriangle(v0, color, v2, color, v3, color);
  72.         }
  73. }
  74.  
  75. size_t FloorHeightCache::GetMemoryUsage() const
  76. {
  77.         // not sure if its only 3 pointers overhead for each node?
  78.         return m_floorHeights.size() * (sizeof(FloorHeights::value_type) + sizeof(void*) * 3);
  79. }
  80.  
downloadFloorHeightCache.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