-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathSector_GeoBlock.cpp
88 lines (73 loc) · 2.17 KB
/
Sector_GeoBlock.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "Sector_GeoBlock.h"
#include "ObjectManager.h"
#include "Object.h"
#include "../math/Vector4.h"
#include "../math/Math.h"
#include "../render/IDriver3D.h"
#include "../render/Camera.h"
#include "../render/RenderQue.h"
#include "WorldCell.h"
#define MAX_WORLD_UPDATE_RANGE 30
Sector_GeoBlock::~Sector_GeoBlock()
{
}
void Sector_GeoBlock::Render(IDriver3D *pDriver, Camera *pCamera)
{
if ( !m_bActive )
return;
for (const uint32_t objID : m_Objects)
{
Object *pObj = ObjectManager::GetObjectFromID(objID);
assert(pObj);
Vector3 vMin, vMax;
pObj->GetWorldBounds(vMin, vMax);
if ( pCamera->AABBInsideFrustum(vMin, vMax, pObj->GetWorldX(), pObj->GetWorldY()) != Camera::FRUSTUM_OUT )
{
int nLightCnt = 0;
const LightObject **pLightList = pObj->GetLightList(nLightCnt);
RenderQue::SetLightData( nLightCnt, pLightList );
pObj->Render(pDriver, 1.0f, Vector3::Zero);
}
}
}
void Sector_GeoBlock::Collide(CollisionPacket *packet, Vector3 *bounds, const Vector3& vOffset)
{
if ( !m_bActive )
return;
for (const uint32_t objID : m_Objects)
{
Object *pObj = ObjectManager::GetObjectFromID(objID);
assert(pObj);
Vector3 vMin = pObj->GetWorldMin() + vOffset;
Vector3 vMax = pObj->GetWorldMax() + vOffset;
if ( Math::AABB_Overlap3D(vMin, vMax, bounds[0], bounds[1]) )
{
pObj->Collide(packet, vOffset);
}
}
}
void Sector_GeoBlock::Raycast(RaycastPacket *packet, const Vector3& vOffset)
{
if ( !m_bActive )
return;
for (const uint32_t objID : m_Objects)
{
Object *pObj = ObjectManager::GetObjectFromID(objID);
assert(pObj);
Vector3 vMin = pObj->GetWorldMin() + vOffset;
Vector3 vMax = pObj->GetWorldMax() + vOffset;
if ( Math::AABB_Overlap3D(vMin, vMax, packet->bounds[0], packet->bounds[1]) )
{
pObj->Raycast(packet, this, vOffset);
}
}
}
void Sector_GeoBlock::Update(float dt)
{
if ( !m_bActive )
return;
for (LightObject *light : m_Lights)
{
light->Update( dt );
}
}