-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollageImage.cpp
315 lines (233 loc) · 7.78 KB
/
CollageImage.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
///////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: CollageImage.cpp
//
// Author: David Borland
//
// Description: Includes Image behavior for Collage
//
///////////////////////////////////////////////////////////////////////////////////////////////
#include "CollageImage.h"
#include "CollageGraphics.h"
CollageImage::CollageImage(Behavior imageBehavior) : Image(imageBehavior) {
border = false;
windowHeight = 768;
stereoOffset = 0.0f;
stereoImage = NULL;
}
CollageImage::~CollageImage() {
if (stereoImage) delete stereoImage;
}
void CollageImage::SetWindowHeight(int height) {
windowHeight = height;
}
void CollageImage::SetPosition(const Vec2& pos) {
Image::SetPosition(pos);
if (stereoImage) {
stereoImage->SetPosition(pos);
}
}
void CollageImage::SetScale(float scaleValue) {
Image::SetScale(scaleValue);
if (stereoImage) {
stereoImage->SetScale(scaleValue);
}
}
bool CollageImage::Intersect(const Vec2& point) {
// Extent of the image
float left, right, bottom, top;
GetExtent(left, right, bottom, top);
// Check for intersection
if (point.X() >= left &&
point.X() <= right &&
point.Y() >= bottom &&
point.Y() <= top) {
return true;
}
// View width
float viewWidth = xMax - xMin;
// Left coyp
if (point.X() >= left - viewWidth &&
point.X() <= right - viewWidth &&
point.Y() >= bottom &&
point.Y() <= top) {
return true;
}
// Right copy
if (point.X() >= left + viewWidth &&
point.X() <= right + viewWidth &&
point.Y() >= bottom &&
point.Y() <= top) {
return true;
}
return false;
}
void CollageImage::Translate(const Vec2& translation) {
SetPosition(position + translation);
}
void CollageImage::FitToScreen() {
SetPosition(Vec2(position.X(), 0.5));
SetScale(1.0);
}
void CollageImage::NativeResolution() {
SetPosition(Vec2(position.X(), 0.5));
SetScale((float)resolution[1] / (float)windowHeight);
}
void CollageImage::GetExtent(float& left, float& right, float& bottom, float& top) {
left = position.X() - aspectRatio * scale * 0.5;
right = position.X() + aspectRatio * scale * 0.5;
bottom = position.Y() - scale * 0.5;
top = position.Y() + scale * 0.5;
}
void CollageImage::BorderOn() {
border = true;
if (stereoImage) stereoImage->BorderOn();
}
void CollageImage::BorderOff() {
border = false;
if (stereoImage) stereoImage->BorderOff();
}
void CollageImage::SetStereoImage(CollageImage* image) {
stereoImage = image;
stereoImage->SetPosition(position);
stereoImage->SetScale(scale);
if (border) stereoImage->BorderOn();
else stereoImage->BorderOff();
}
bool CollageImage::HasStereoImage() {
return stereoImage != NULL;
}
CollageImage* CollageImage::RemoveStereoImage() {
CollageImage* temp = stereoImage;
stereoImage = NULL;
return temp;
}
void CollageImage::IncreaseStereoDepth() {
stereoOffset -= 0.001f;
if (stereoImage) stereoImage->SetStereoOffset(stereoOffset);
}
void CollageImage::DecreaseStereoDepth() {
stereoOffset += 0.001f;
if (stereoImage) stereoImage->SetStereoOffset(stereoOffset);
}
void CollageImage::SetStereoOffset(float offset) {
stereoOffset = offset;
}
void CollageImage::RenderStereo() {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
float offset = stereoOffset;
float depth = 0.02f;
if (!stereoImage) {
if (border) {
// Pop out
offset -= depth;
}
else {
// Recede
offset += depth;
}
}
glTranslatef(offset, 0.0f, 0.0f);
if (stereoImage) stereoImage->Render();
else Render();
glPopMatrix();
}
// Code to display a 'legend' on each image, currently this is the file name, but will be later expanded to provide other metadata
/*
void CollageImage::ShowLegend(float translateX, float translateY) {
// if I don't have a font loaded, don't do this
FTFont * font = collageGraphics->GetFont();
if (font->Error()) return;
if (collageGraphics->IsShowTitle()) {
glPushAttrib(GL_TEXTURE_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
// draw a legend box
glColor3f(0.5, 0.5, 1.0) ;
glBegin(GL_QUADS);
glVertex2d(-0.5 * aspectRatio, -0.5);
glVertex2d(0.5 * aspectRatio , -0.5);
glVertex2d(0.5 * aspectRatio, -0.2);
glVertex2d(-0.5 * aspectRatio, -0.2);
glEnd();
// here, I'm either rendering right or left. Adding fonts is done using screen space, not the scaling that was set
// in glOrtho. There are actually two displays, and they share one context. When the second display is swapped in, I will need
// to render the text positioned at 6144-12288 as if it was 0-6143.
font->FaceSize(72 * scale);
float xBegin = translateX - (aspectRatio * scale * .5);
float xToPixel = xBegin * 768;
if (collageGraphics->IsRenderLeft() && xToPixel < 6144) {
// if i'm rendering to the 0-6143 screen, I'm rendering
FTPoint point = FTPoint(xToPixel, ((position.Y() - scale * 0.5) * 768) + (20 * scale));
font->Render(collageItemMetadata.fileName.c_str(), -1, point);
} else if (!collageGraphics->IsRenderLeft() && xToPixel >= 6144) {
// if i'm rendering right and the postion is greater than or equal to 6144, then render, but adjust the x so it's based
// on a 0-6143 range
xToPixel -= 6144;
FTPoint point = FTPoint(xToPixel, ((position.Y() - scale * 0.5) * 768) + (20 * scale));
font->Render(collageItemMetadata.fileName.c_str(), -1, point);
}
glPopAttrib();
}
}
*/
void CollageImage::DoRender() {
// Render 3 times to get a toroidal wraparound
glMatrixMode(GL_MODELVIEW);
// Center image
glPushMatrix();
glTranslatef((GLfloat)position.X(), (GLfloat)position.Y(), 0.0);
glScalef((GLfloat)scale, (GLfloat)scale, 1.0);
RenderQuad();
if (border) RenderBorder();
// ShowLegend(position.X(), position.Y());
glPopMatrix();
if (behavior == Toroidal) {
// Render two more times
float viewWidth = xMax - xMin;
// Left image
glPushMatrix();
glTranslatef((GLfloat)(position.X() - viewWidth), (GLfloat)position.Y(), 0.0);
glScalef((GLfloat)scale, (GLfloat)scale, 1.0);
RenderQuad();
if (border) RenderBorder();
// ShowLegend(position.X() - viewWidth, position.Y());
glPopMatrix();
// Right image
glPushMatrix();
glTranslatef((GLfloat)(position.X() + viewWidth), (GLfloat)position.Y(), 0.0);
glScalef((GLfloat)scale, (GLfloat)scale, 1.0);
RenderQuad();
if (border) RenderBorder();
// ShowLegend(position.X() + viewWidth, position.Y());
glPopMatrix();
}
}
void CollageImage::RenderBorder() {
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINES);
glVertex2f((GLfloat)(-0.5 * aspectRatio), -0.5);
glVertex2f((GLfloat)(0.5 * aspectRatio), -0.5);
glVertex2f((GLfloat)(0.5 * aspectRatio), -0.5);
glVertex2f((GLfloat)(0.5 * aspectRatio), 0.5);
glVertex2f((GLfloat)(0.5 * aspectRatio), 0.5);
glVertex2f((GLfloat)(-0.5 * aspectRatio), 0.5);
glVertex2f((GLfloat)(-0.5 * aspectRatio), 0.5);
glVertex2f((GLfloat)(-0.5 * aspectRatio), -0.5);
glEnd();
glPopAttrib();
}
CollageItemMetadata* CollageImage::GetCollageItemMetadata() {
return &collageItemMetadata;
}
void CollageImage::SetCollageGraphics(CollageGraphics* collageGraphics) {
this->collageGraphics = collageGraphics;
}
CollageGraphics* CollageImage::GetCollageGraphics() {
return this->collageGraphics;
}