Skip to content

Commit 04d8b3f

Browse files
committed
- viewer frustrum culling, night mode switch and draw distance modifier keys
1 parent c27fee4 commit 04d8b3f

File tree

14 files changed

+1073
-295
lines changed

14 files changed

+1073
-295
lines changed

DriverLevelTool/model_compiler/compiler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#include "obj_loader.h"
44
#include "driver_routines/d2_types.h"
5+
56
#include <malloc.h>
7+
#include "math/TriangleUtil.inl"
68

79
#include "driver_level.h"
810
#include "core/VirtualStream.h"
@@ -399,10 +401,12 @@ void WritePolygonNormals(IVirtualStream* stream, MODEL* model, smdgroup_t* group
399401
SVECTOR* v2 = model->pVertex(poly.vindices[1]);
400402
SVECTOR* v3 = model->pVertex(poly.vindices[2]);
401403

402-
Vector3D normal = NormalOfTriangle(
403-
{ (float)v1->x, (float)v1->y, (float)v1->z },
404-
{ (float)v2->x, (float)v2->y, (float)v2->z },
405-
{ (float)v3->x, (float)v3->y, (float)v3->z });
404+
Vector3D normal;
405+
406+
ComputeTriangleNormal(normal,
407+
Vector3D((float)v1->x, (float)v1->y, (float)v1->z),
408+
Vector3D((float)v2->x, (float)v2->y, (float)v2->z),
409+
Vector3D((float)v3->x, (float)v3->y, (float)v3->z));
406410

407411
// Invert normals (REQUIRED)
408412
normal *= -1.0f;

DriverLevelTool/viewer/rendermodel.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@
77
#include "util/DkList.h"
88
#include <assert.h>
99

10+
void AddExtentVertex(Vector3D& minPoint, Vector3D& maxPoint, const Vector3D& v)
11+
{
12+
if (v.x < minPoint.x)
13+
minPoint.x = v.x;
14+
15+
if (v.x > maxPoint.x)
16+
maxPoint.x = v.x;
17+
18+
if (v.y < minPoint.y)
19+
minPoint.y = v.y;
20+
21+
if (v.y > maxPoint.y)
22+
maxPoint.y = v.y;
23+
24+
if (v.z < minPoint.z)
25+
minPoint.z = v.z;
26+
27+
if (v.z > maxPoint.z)
28+
maxPoint.z = v.z;
29+
}
30+
1031
CRenderModel::CRenderModel()
1132
{
1233
}
@@ -23,6 +44,9 @@ bool CRenderModel::Initialize(ModelRef_t* model)
2344

2445
if (!model->model)
2546
return false;
47+
48+
m_extMin = Vector3D(V_MAX_COORD);
49+
m_extMax = Vector3D(-V_MAX_COORD);
2650

2751
m_sourceModel = model;
2852
GenerateBuffers();
@@ -227,8 +251,11 @@ void CRenderModel::GenerateBuffers()
227251

228252
// get the vertex
229253
SVECTOR* vert = vertex_ref->pVertex(dec_face.vindices[VERT_IDX]);
254+
Vector3D fVert = Vector3D(vert->x * EXPORT_SCALING, vert->y * -EXPORT_SCALING, vert->z * EXPORT_SCALING);
230255

231-
(*(Vector3D*)&newVert.vx) = Vector3D(vert->x * EXPORT_SCALING, vert->y * -EXPORT_SCALING, vert->z * EXPORT_SCALING);
256+
(*(Vector3D*)&newVert.vx) = fVert;
257+
258+
AddExtentVertex(m_extMin, m_extMax, fVert);
232259

233260
if (smooth)
234261
{
@@ -342,4 +369,10 @@ void CRenderModel::Draw()
342369
GR_SetTexture(GetHWTexture(batch.tpage, 0));
343370
GR_DrawIndexed(PRIM_TRIANGLES, batch.startIndex, batch.numIndices);
344371
}
372+
}
373+
374+
void CRenderModel::GetExtents(Vector3D& outMin, Vector3D& outMax) const
375+
{
376+
outMin = m_extMin;
377+
outMax = m_extMax;
345378
}

DriverLevelTool/viewer/rendermodel.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef DRAWMODEL_H
22
#define DRAWMODEL_H
33

4+
#include "math/Vector.h"
45
#include "util/DkList.h"
56

67
struct RegionModels_t;
@@ -25,13 +26,19 @@ class CRenderModel
2526

2627
void Draw();
2728

29+
void GetExtents(Vector3D& outMin, Vector3D& outMax) const;
30+
2831
protected:
2932
void GenerateBuffers();
30-
33+
34+
Vector3D m_extMin;
35+
Vector3D m_extMax;
36+
3137
ModelRef_t* m_sourceModel { nullptr };
3238
GrVAO* m_vao { nullptr };
3339
DkList<modelBatch_t> m_batches;
3440
int m_numVerts;
41+
3542
};
3643

3744
#endif

0 commit comments

Comments
 (0)