forked from getdunne/Voxvu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PolyhedronRenderer.cpp
102 lines (87 loc) · 2.98 KB
/
PolyhedronRenderer.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// PolyhedronRenderer.cpp implementation of class PolyhedronRenderer
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "PolyhedronRenderer.h"
inline CPoint ConvPt(const Vector3 &v)
{
return CPoint(int(v.x+0.5),int(v.y+0.5));
}
#define BACKGROUND_COLOR RGB(40,40,40)
#define PLANE_BACK_COLOR RGB(100,100,100)
//--------------------------------------------------------------
// Fast interactive renderer
//--------------------------------------------------------------
void PolyhedronRenderer::RenderQuick ()
{
ASSERT(m_pPoly != NULL);
// set up for drawing into our DrawContext
CDC* pDC = m_pDB->GetMemoryDCPtr();
// erase background
CRect rc(CPoint(0,0),m_pDB->GetDimensions());
CBrush bgb(BACKGROUND_COLOR);
pDC->FillRect(rc,&bgb);
// set up our PolyFiller
int maxVerts = 0;
for (int side=0; side<m_pPoly->GetFaceCount(); ++side) {
if (m_pPoly->plane[side].n.z > 0.) continue;
int nv = m_pPoly->poly[side].GetVertexCount();
if (nv > maxVerts) maxVerts = nv;
}
m_PolyFiller.Setup(maxVerts);
m_PolyFiller.m_pLineProc = GetFastLineProcPtr();
m_PolyFiller.m_clipRect = rc;
m_PolyFiller.m_pbContinue = NULL;
m_PolyFiller.m_pUserData = (LPVOID)this;
if (m_toDraw == -1)
// render front faces of box
for (int side=0; side<m_pPoly->GetFaceCount(); ++side) {
if (m_pPoly->poly[side].GetVertexCount() < 3) continue;
if (m_pPoly->plane[side].n.z > 0.) continue;
m_PolyFiller.Fill(m_pPoly->poly[side], m_pPoly->plane[side]);
}
else {
ASSERT(m_toDraw >=0 && m_toDraw < m_pPoly->GetFaceCount());
m_PolyFiller.Fill(m_pPoly->poly[m_toDraw],m_pPoly->plane[m_toDraw]);
}
}
//--------------------------------------------------------------
// Slower high-quality renderer
//--------------------------------------------------------------
BOOL PolyhedronRenderer::RenderBest (BOOL* pbContinue)
{
ASSERT(m_pPoly != NULL);
// set up for drawing into our DrawContext
CDC* pDC = m_pDB->GetMemoryDCPtr();
// erase background
CRect rc(CPoint(0,0),m_pDB->GetDimensions());
CBrush bgb(BACKGROUND_COLOR);
pDC->FillRect(rc,&bgb);
// set up our PolyFiller
int maxVerts = 0;
for (int side=0; side<m_pPoly->GetFaceCount(); ++side) {
if (m_pPoly->plane[side].n.z > 0.) continue;
int nv = m_pPoly->poly[side].GetVertexCount();
if (nv > maxVerts) maxVerts = nv;
}
m_PolyFiller.Setup(maxVerts);
m_PolyFiller.m_pLineProc = GetBestLineProcPtr();
m_PolyFiller.m_clipRect = rc;
m_PolyFiller.m_pbContinue = pbContinue;
m_PolyFiller.m_pUserData = (LPVOID)this;
if (m_toDraw == -1) {
// render front faces of box
for (int side=0; side<m_pPoly->GetFaceCount(); ++side) {
if (m_pPoly->poly[side].GetVertexCount() < 3) continue;
if (m_pPoly->plane[side].n.z > 0.) continue;
if (!m_PolyFiller.Fill(m_pPoly->poly[side], m_pPoly->plane[side]))
return FALSE;
}
return TRUE;
}
else {
ASSERT(m_toDraw >=0 && m_toDraw < m_pPoly->GetFaceCount());
return m_PolyFiller.Fill(m_pPoly->poly[m_toDraw],
m_pPoly->plane[m_toDraw]);
}
}