-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofApp.cpp
189 lines (123 loc) · 3.54 KB
/
ofApp.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
#include "ofApp.h"
void ofApp::setup() {
ofSetFrameRate(60);
size = 1024;
gui.setup("Control Panel");
gui.add(numPoints.set("Num Points", 12, 4, size / 4));
gui.add(pointSize.set("Point Size", 1.0f, 0.1f, 50.0f));
gui.add(opacity.set("Opacity", 255, 0 , 255));
gui.add(blendMode.set("Blend Mode", 0, 0, 2));
gui.add(depthTest.set("Depth Test", true));
gui.add(enableSort.set("Sort", true));
gui.add(enablePoints.set("Points", false));
gui.loadFromFile("settings.xml");
numPoints.addListener(this, &ofApp::resetInt);
enableSort.addListener(this, &ofApp::resetBool);
ofSetWindowTitle("Point Texture Test");
resetMap();
ofDisableArbTex();
ofLoadImage(pointsTexture,"dot.png");
ofEnableArbTex();
bHide = false;
}
//--------------------------------------------------------------
void ofApp::update() {
}
//--------------------------------------------------------------
void ofApp::resetInt(int & value) {
resetMap();
}
//--------------------------------------------------------------
void ofApp::resetBool(bool & value) {
resetMap();
}
//--------------------------------------------------------------
void ofApp::resetMap() {
ofPlanePrimitive plane;
plane.set(size, size, numPoints, numPoints);
planeMesh = plane.getMesh();
ofColor c;
for (int i = 0; i < numPoints; i++) {
c.setHsb(ofMap(i, 0, numPoints - 1, 0, 200), 255, 255);
for (int j = 0; j < numPoints; j++) {
planeMesh.addColor(c);
}
}
}
//--------------------------------------------------------------
void ofApp::draw() {
ofBackground(0);
for (int i = 0; i < numPoints * numPoints; i++) {
ofColor c = planeMesh.getColor(i);
planeMesh.setColor(i, ofColor(c.r, c.g, c.b, opacity));
}
switch (blendMode) {
case 0:ofEnableBlendMode(OF_BLENDMODE_DISABLED); break;
case 1:ofEnableBlendMode(OF_BLENDMODE_ALPHA); break;
case 2:ofEnableBlendMode(OF_BLENDMODE_ADD); break;
}
ofPushMatrix();
ofTranslate(size / 2, size / 2, -size / 2);
ofRotateXDeg(ofMap(ofGetMouseY(), 0, ofGetHeight(), 60, 120));
ofRotateZDeg(ofMap(ofGetMouseX(), 0, ofGetWidth(), -180, 180));
glPointSize(pointSize);
if (depthTest) {
ofEnableDepthTest();
}
if (enablePoints) {
planeMesh.draw(OF_MESH_POINTS);
}
else {
if (enableSort) {
GLfloat m[16];
glGetFloatv(GL_MODELVIEW_MATRIX, m);
mat.set(m);
vector<glm::vec3> & v = planeMesh.getVertices();
vector<ofFloatColor> & c = planeMesh.getColors();
ofVec3f v0;
ofVec3f v1;
glm::vec3 temp;
ofFloatColor cTemp;
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v.size(); j++) {
v0 = v[i];
v1 = v[j];
if ((v0 * mat).lengthSquared() >= (v1 * mat).lengthSquared()) {
temp = v[i];
v[i] = v[j];
v[j] = temp;
cTemp = c[i];
c[i] = c[j];
c[j] = cTemp;
}
}
}
}
ofDisableArbTex();
ofEnablePointSprites();
pointsTexture.bind();
planeMesh.draw(OF_MESH_POINTS);
pointsTexture.unbind();
ofDisablePointSprites();
ofEnableArbTex();
}
ofPopMatrix();
if (depthTest) {
ofDisableDepthTest();
}
if (!bHide) {
gui.draw();
}
ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate()), 20, ofGetHeight() - 28);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
switch (key) {
case 's':
gui.saveToFile("settings.xml");
break;
case 'h':
bHide = !bHide;
break;
}
}