/
FloorHeightWalker.h
54 lines (42 loc) · 1.16 KB
/
FloorHeightWalker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include "inode.h"
#include "gamelib.h"
namespace camera
{
class FloorHeightWalker :
public scene::NodeVisitor
{
private:
float _current;
float& _bestUp;
float& _bestDown;
public:
FloorHeightWalker(float current, float& bestUp, float& bestDown) :
_current(current),
_bestUp(bestUp),
_bestDown(bestDown)
{
_bestUp = game::current::getValue<float>("/defaults/maxWorldCoord");
_bestDown = -game::current::getValue<float>("/defaults/maxWorldCoord");
}
bool pre(const scene::INodePtr& node)
{
if (!node->visible()) return false; // don't traverse hidden nodes
if (Node_isBrush(node)) // this node is a floor
{
const AABB& aabb = node->worldAABB();
float floorHeight = aabb.origin.z() + aabb.extents.z();
if (floorHeight > _current&& floorHeight < _bestUp)
{
_bestUp = floorHeight;
}
if (floorHeight < _current && floorHeight > _bestDown)
{
_bestDown = floorHeight;
}
return false;
}
return true;
}
};
}