/
cworldpatch.cpp
140 lines (123 loc) · 4.25 KB
/
cworldpatch.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "cworldpatch.h"
#include <GL/glu.h>
#define WORLD_PATCHS_RADIUS WORLD_SPHERE_RADIUS*1.005
cWorldPatch::cWorldPatch()
: m_PatchBegin(WorldCoord()),
m_PatchEnd(WorldCoord()),
m_AlphaValue(0.0f)
//m_AlphaReduction(ALPHA_REDUCTION)
{
}
cWorldPatch::cWorldPatch(WorldCoord begin, WorldCoord end)
: m_PatchBegin(begin),
m_PatchEnd(end),
m_AlphaValue(0.0f)
//m_AlphaReduction(ALPHA_REDUCTION)
{
}
cWorldPatch::cWorldPatch(WorldCoord begin, WorldCoord end, int stacks, int slices)
: m_PatchBegin(begin),
m_PatchEnd(end),
m_AlphaValue(0.0f)
//m_AlphaReduction(ALPHA_REDUCTION)
{
createPatch(stacks, slices);
}
cWorldPatch::~cWorldPatch()
{
m_PatchPoints.clear();
}
void cWorldPatch::setAlphaValue(float val){
m_AlphaValue = val;
}
void cWorldPatch::setHistory(unsigned int count){
m_HistoryCount = count;
}
void cWorldPatch::createPatch(int stacks, int slices){
float longDist = m_PatchEnd.longitude-m_PatchBegin.longitude;
float latiDist = m_PatchEnd.latitude-m_PatchBegin.latitude;
float perLong = longDist/stacks;
float perLati = latiDist/slices;
for (int i=0; i < stacks; ++i){
float longi = m_PatchBegin.longitude+i*perLong;
for (int j=0; j < slices; ++j){
float lati = m_PatchBegin.latitude+j*perLati;
Point p(WORLD_PATCHS_RADIUS*sin(THETA(lati))*sin(PHI(longi)),
WORLD_PATCHS_RADIUS*cos(THETA(lati)),
WORLD_PATCHS_RADIUS*sin(THETA(lati))*cos(PHI(longi)));
m_PatchPoints.push_back(p);
}
Point p(WORLD_PATCHS_RADIUS*sin(THETA(m_PatchEnd.latitude))*sin(PHI(longi)),
WORLD_PATCHS_RADIUS*cos(THETA(m_PatchEnd.latitude)),
WORLD_PATCHS_RADIUS*sin(THETA(m_PatchEnd.latitude))*cos(PHI(longi)));
m_PatchPoints.push_back(p);
}
for (int j=0; j < slices; ++j){
float lati = m_PatchBegin.latitude+j*perLati;
Point p(WORLD_PATCHS_RADIUS*sin(THETA(lati))*sin(PHI(m_PatchEnd.longitude)),
WORLD_PATCHS_RADIUS*cos(THETA(lati)),
WORLD_PATCHS_RADIUS*sin(THETA(lati))*cos(PHI(m_PatchEnd.longitude)));
m_PatchPoints.push_back(p);
}
Point p(WORLD_PATCHS_RADIUS*sin(THETA(m_PatchEnd.latitude))*sin(PHI(m_PatchEnd.longitude)),
WORLD_PATCHS_RADIUS*cos(THETA(m_PatchEnd.latitude)),
WORLD_PATCHS_RADIUS*sin(THETA(m_PatchEnd.latitude))*cos(PHI(m_PatchEnd.longitude)));
m_PatchPoints.push_back(p);
for (int i=0; i < stacks; ++i){
for (int j=0; j < slices; ++j){
Quad q(&m_PatchPoints.at(i+j*(stacks+1)),
&m_PatchPoints.at(i+(j+1)*(stacks+1)),
&m_PatchPoints.at(i+1+(j+1)*(stacks+1)),
&m_PatchPoints.at(i+1+j*(stacks+1)));
m_PatchQuads.push_back(q);
}
}
}
bool cWorldPatch::isInPatch(WorldCoord coord){
if (m_PatchBegin.longitude > coord.longitude)
return false;
if (m_PatchEnd.longitude < coord.longitude)
return false;
if (m_PatchBegin.latitude > coord.latitude)
return false;
if(m_PatchEnd.latitude < coord.latitude)
return false;
return true;
}
void cWorldPatch::updateAlpha(unsigned char detection){
int f_neu = detection == 4 ? 1 : 0;
// m_AlphaValue = (m_AlphaValue * m_AlphaReduction + f_neu)/
// (m_AlphaReduction + 1);
if (f_neu){
m_AlphaValue = MAX_ALPHA;
}
else{
// if (m_AlphaValue > MIN_ALPHA){
// m_AlphaValue -= (MAX_ALPHA-MIN_ALPHA)/m_HistoryCount;
// }
m_AlphaValue *= 0.9995;
}
}
void cWorldPatch::drawPatch(){
glColor4f(1.0f, 0.3f, 0.3f, m_AlphaValue);
glBegin(GL_QUADS);
for (Quad q : m_PatchQuads){
glVertex3fv(q.a()->data());
glVertex3fv(q.b()->data());
glVertex3fv(q.c()->data());
glVertex3fv(q.d()->data());
}
glEnd();
// // the test the Patch size
// glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
// glLineWidth(1.5);
// for (Quad q : m_PatchQuads){
// glBegin(GL_LINE_LOOP);
// glVertex3fv(q.a()->data());
// glVertex3fv(q.b()->data());
// glVertex3fv(q.c()->data());
// glVertex3fv(q.d()->data());
// glEnd();
// }
// glLineWidth(1);
}