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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
#include "viewport.h"
//texture binding with normalised coords
void bindTexture(ofBaseHasTexture &t) {
ofTexture &tex = t.getTextureReference();
tex.bind();
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
ofTextureData texData = tex.getTextureData();
if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) {
glScalef(tex.getWidth(), tex.getHeight(), 1.0f);
} else {
glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f);
}
glMatrixMode(GL_MODELVIEW);
}
void unbindTexture(ofBaseHasTexture &t) {
t.getTextureReference().unbind();
glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
void bindTex(ofTexture &tex) {
tex.bind();
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
ofTextureData texData = tex.getTextureData();
if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) {
glScalef(tex.getWidth(), tex.getHeight(), 1.0f);
} else {
glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f);
}
glMatrixMode(GL_MODELVIEW);
}
void unbindTex(ofTexture &tex) {
tex.unbind();
glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
//--------------------------------------------------
viewport::viewport()
{
//ctor
}
viewport::viewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
setup(_w,_h,_x,_y,_r,_ox,_oy);
}
void viewport::setup(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
r=_r;
w=_w;
h=_h;
x=_x;
y=_y;
ox=_ox;
oy=_oy;
rb1.allocate(w,h,GL_RGB);
rb2.allocate(w,h,GL_RGB);
printf("%ix%i, vp offset: %f,%f\n",w,h,-(sin(ofDegToRad(r))*h/2)-(cos(ofDegToRad(r))*w/2),-(sin(ofDegToRad(r))*w/2)-(cos(ofDegToRad(r))*h/2));
xshift =0;
yshift=0;
scale=1.0;
fscale=1.0;
xrot=yrot=zrot=0.0f;
logo.loadImage("logo.png");
}
void viewport::draw(int mode,int fade,float decimate, float feat, float xr, float yr, float zr, int range, bool dologo){
/*
ofNode c=ofNode();
ofNode t=ofNode();
t.setParent(c);
t.setPosition();
//make target controls relative to rotation
c.rotate(vars["lng"].getVal(), ofVec3f(0, 1, 0));
target.setPosition(vars["targX"].getVal(),vars["targY"].getVal(),vars["targZ"].getVal());
//camera.orbit(vars[5].getVal(), vars[4].getVal(), vars[7].getVal(), target);
camera.setFov(vars["fov"].getVal());
ofVec3f p(0, 0, vars["dolly"].getVal());
//p.rotate(ofClamp(vars[2].getVal(), -89, 89), ofVec3f(1, 0, 0));
p.rotate(vars["lat"].getVal(), ofVec3f(1, 0, 0));
p.rotate(vars["lng"].getVal(), ofVec3f(0, 1, 0));
p += target.getPosition();
camera.setPosition(p);
camera.lookAt(target,ofVec3f(0,1,0).rotate(vars["roll"].getVal(),ofVec3f(0,0,1)).rotate(vars["lng"].readVal(),ofVec3f(0,1,0)));
*/
rb1.begin();
//can be done with texture offset?
int startx=((w-(w*fscale))/2)+xshift;
while (startx>0) startx-=(w*fscale);
int starty=((h-(h*fscale))/2)+yshift;
while (starty>0) starty-=(h*fscale);
for (int i=startx;i<w*2;i+=(w*fscale)) {
for (int j=starty;j<h*2;j+=(h*fscale)) {
rb2.draw(i,j,w*fscale,h*fscale);
}
}
if (fade>254) ofClear(0,0,0);
else if (fade>0) {
ofEnableAlphaBlending();
ofSetColor(0,0,0,fade);
ofRect(0,0,w,h);
ofDisableAlphaBlending();
}
camera.begin();
ofPushMatrix();
ofTranslate(0,0,-1500);
xrot+=xr;
yrot+=yr;
zrot+=zr;
ofRotateY(yrot);
ofRotateX(xrot);
ofRotateZ(zrot);
float minstep=1.0f/160.0f;
float step = decimate>minstep?1.0f/decimate:160.0f;
float scale=w/640.0f;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (mode==POINTS) {
glEnable(GL_PROGRAM_POINT_SIZE);
glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glPointSize(feat);
glBegin(GL_POINTS);
for(float y = 0.0f; y < 480.0f; y += step) {
for(float x = 0.0f; x < 640.0f; x += step) {
ofVec3f pos = kinect->getWorldCoordinateAt(x, y);
if (pos.z == 0 || pos.z>range) continue; // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd
ofColor color = kinect->getColorAt(x,y); //userID);
glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a);
glVertex3f(pos.x*scale, pos.y*scale, pos.z*scale);
}
}
glEnd();
glDisable(GL_PROGRAM_POINT_SIZE);
}
if (mode==LINES) {
glEnable(GL_LINE_SMOOTH);
glLineWidth(feat);
for(float y = 0.0f; y < 480.0f; y += step) {
glBegin(GL_LINE_STRIP);
for(float x = 0.0f; x < 640.0f; x += 1.0f+(step*0.1)) {
ofVec3f pos = kinect->getWorldCoordinateAt(x, y);
if (pos.z == 0 || pos.z>range) {
glEnd();
glBegin(GL_LINE_STRIP);
continue;
} // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd
ofColor color = kinect->getColorAt(x,y); //userID);
glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a);
glVertex3f(pos.x*scale, pos.y*scale, pos.z*scale);
}
glEnd();
}
}
ofPopMatrix();
camera.end();
glColor3f(1.0f, 1.0f, 1.0f);
rb1.end();
rb2.begin();
ofSetColor(255,255,255);
rb1.draw(0,0);
rb2.end();
ofPushMatrix();
ofTranslate(x+(w/2),y+(h/2));
ofRotate(r);
//ofTranslate(-abs(sin(ofDegToRad(r))*h/2)-abs(cos(ofDegToRad(r))*w/2),-abs(sin(ofDegToRad(r))*w/2)-abs(cos(ofDegToRad(r))*h/2));
ofTranslate(ox,oy);
rb2.draw(0,0);
if (dologo) {
ofEnableAlphaBlending();
logo.draw(0,0,ofGetWidth(),ofGetHeight());
ofDisableAlphaBlending();
}
ofPopMatrix();
}
viewport::~viewport()
{
//dtor
}
void viewport::setKinect(ofxKinect *k){
kinect=k;
}
void viewport::mousePressedEvent(int xs,int ys,float sc,float fs) {
xshift=xs;
yshift=ys;
scale=sc;
fscale=fs;
}
void viewport::setcam(map<string,float>&settings){
vars["fov"].set('w','s',settings["fov"],0.2,1.0,1.0);
vars["targX"].set('g','d',settings["targX"],100,1.0,1.0);
vars["targY"].set('r','v',settings["targY"],100,1.0,1.0);
vars["targZ"].set('t','c',settings["targZ"],100,1.0,1.0);
vars["lat"].set('u','n',settings["lat"],1,1.0,1.0);
vars["lng"].set('j','h',settings["lng"],1,1.0,1.0);
vars["roll"].set(',','m',settings["roll"],1,1.0,1.0);
vars["dolly"].set('o','l',settings["dolly"],10,1.0,1.0);
}
double viewport::getSetting(const string& setting){
return vars[setting].getVal();
}
void viewport::keyPressed(int key){
map<string,keyVar>::iterator iter;
for (iter=vars.begin();iter!=vars.end();++iter) iter->second.keyPressed(key);
if(key == 267){
xshift--;
}
if(key == 268){
xshift++;
}
if(key == 269){
yshift--;
}
if(key == 270){
yshift++;
}
if (key=='.') {
fscale*=0.99f;
}
if (key=='/') {
fscale*=1.01f;
}
};
void viewport::keyReleased(int key){
map<string,keyVar>::iterator iter;
for (iter=vars.begin();iter!=vars.end();++iter) iter->second.keyReleased(key);
};
|