-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPickingManager.cpp
More file actions
164 lines (133 loc) · 3.7 KB
/
Copy pathPickingManager.cpp
File metadata and controls
164 lines (133 loc) · 3.7 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "commons.h"
#include "PickingManager.h"
#include "utils.h"
#include <cml/cml.h>
#include "OGLUtils.h"
#define _SECURE_SCL 0
using namespace std;
using namespace utils;
using namespace game_objects;
using namespace cml;
namespace game_utils
{
namespace managers
{
CPickingManager::CPickingManager(): CManager()
{
lastPickedBlock = NULL;
}
CPickingManager::~CPickingManager()
{
}
bool CPickingManager::init()
{
return true;
}
bool CPickingManager::update()
{
// 1. block picking
// 1.1 draw pickable blocks
std::vector<CBlock*> *rBlocks = CV_GAME_MANAGER->getRenderManager()->getRenderedBlocks();
if (rBlocks->size()==0)
{
return true;
}
//using a map is very slow
std::vector< pair<vector3ub, CBlock*> > colorBlockRef;
sColor sCol(50,50,50);
// transform view
CV_GAME_MANAGER->getControlManager()->getCamera()->transformView();
for (std::vector<CBlock*>::iterator bIter = rBlocks->begin(); bIter != rBlocks->end(); bIter++)
{
CBlock *block = *bIter;
sBoundingBox *bbox = block->getBoundingBox();
vector3f a(bbox->A);
vector3f b(bbox->B);
vector3f c(bbox->C);
vector3f d(bbox->D);
vector3f e(bbox->E);
vector3f f(bbox->F);
vector3f g(bbox->G);
vector3f h(bbox->H);
a[1]=b[1]=c[1]=d[1]=CV_BLOCK_HEIGHT+CV_BLOCK_HEIGHT/4.0f;
e[1]=f[1]=g[1]=h[1]=CV_BLOCK_HEIGHT/4.0f;
vector3ub col = sCol.getNextColorUB();
colorBlockRef.push_back(pair<vector3ub, CBlock*>(col, block));
glColor3ubv(&col[0]);
glBegin(GL_QUADS);
{
if (block->isFaceVisible(CBlock::BFS_TOP))
{
glVertex3fv(&a[0]);
glVertex3fv(&b[0]);
glVertex3fv(&c[0]);
glVertex3fv(&d[0]);
if (block->isFaceVisible(CBlock::BFS_RIGHT))
{
glVertex3fv(&c[0]);
glVertex3fv(&b[0]);
glVertex3fv(&f[0]);
glVertex3fv(&g[0]);
}
if (block->isFaceVisible(CBlock::BFS_LEFT))
{
glVertex3fv(&h[0]);
glVertex3fv(&e[0]);
glVertex3fv(&a[0]);
glVertex3fv(&d[0]);
}
if (block->isFaceVisible(CBlock::BFS_FRONT))
{
glVertex3fv(&e[0]);
glVertex3fv(&f[0]);
glVertex3fv(&b[0]);
glVertex3fv(&a[0]);
}
if (block->isFaceVisible(CBlock::BFS_BACK))
{
glVertex3fv(&g[0]);
glVertex3fv(&h[0]);
glVertex3fv(&d[0]);
glVertex3fv(&c[0]);
}
}else{
glVertex3fv(&e[0]);
glVertex3fv(&f[0]);
glVertex3fv(&g[0]);
glVertex3fv(&h[0]);
}
}
glEnd();
}
// 1.2 pick from backbuffer
vector2i mousePos = CV_GAME_MANAGER->getControlManager()->getInput()->getMousePos();
//convert mouse pos to relative to this window
#if WIN32
RECT cl,wnd;
GetClientRect(CV_WINDOW_HANDLE,&cl);
GetWindowRect(CV_WINDOW_HANDLE,&wnd);
int border=(wnd.right-wnd.left-cl.right)/2;
int titlebar=wnd.bottom-wnd.top-cl.bottom-border;
mousePos[0] -= border+wnd.left;
mousePos[1] -= titlebar+wnd.top;
#else
// TODO Tequila: Can we just take it as is with SDL Support ?
#endif
vector3ub pickedColor = COGLUtils::getColor(mousePos);
for(std::vector< pair<vector3ub, CBlock*> >::iterator i = colorBlockRef.begin(); i != colorBlockRef.end(); i++)
if(i->first == pickedColor)
lastPickedBlock = i->second;
// 1.3 clear the backbuffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return true;
}
bool CPickingManager::shutdown()
{
return true;
}
CBlock *CPickingManager::getLastPickedBlock()
{
return lastPickedBlock;
}
};
};