-
Notifications
You must be signed in to change notification settings - Fork 2
/
testApp.cpp
279 lines (241 loc) · 7.11 KB
/
testApp.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
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
ofSetBackgroundAuto(false);
part2 = false;
rateSendNode = 20;
counter = 0;
part1 = false;
part3 = false;
attractToCenterBool = false;
ofEnableAlphaBlending();
//CGDisplayHideCursor(kCGDirectMainDisplay);
//glutSetCursor(
//glutSetCursor(GLUT_CURSOR_FULL_CROSSHAIR);
// open an outgoing connection to HOST:PORT
sender.setup(HOST, PORT);
ofBackgroundHex(0x000000);
ofSetFrameRate(30);
ofSetWindowPosition(500, 500);
cam.setDistance(1000);
cam.setFarClip(10000);
center = ofVec3f(0,0,0);
// this is our buffer to stroe the text data
ofBuffer buffer = ofBufferFromFile("/Users/ari/Projects/artistic/Import3dfromVRML/data/engefalos00.txt");
//ofBuffer buffer = ofBufferFromFile("engefalos00.txt");
if(buffer.size()) {
// we now keep grabbing the next line
// until we reach the end of the file
while(buffer.isLastLine() == false) {
// move on to the next line
string line = buffer.getNextLine();
// extract the vector and push it on the back of the list
ofVec3f tmpLine = findPoint(line);
points.push_back(tmpLine);
speeds.push_back(ofVec3f(ofRandomf()*2,ofRandomf()*2,ofRandomf()*2));
colors.push_back(ofFloatColor(1,1,1));
accelerations.push_back(ofVec3f(0,0,0));
initialPoints.push_back(tmpLine);
// initialPointsPos[counter] = tmpLine;
// counter++;
}
}
}
ofVec3f testApp::findPoint(string str) {
ofVec3f tempVec;
string tempString;
int tempPosition = str.find(" ");
tempString = str.substr(0,str.size());
tempVec.x = ofToFloat(tempString.substr(0,tempPosition))*300;
tempPosition = tempString.find(" ");
tempVec.y = ofToFloat(tempString.substr(tempPosition+1,tempPosition))*300;
tempString = tempString.substr(tempPosition+1,tempString.size());
tempPosition = tempString.find(" ");
tempVec.z = ofToFloat(tempString.substr(tempPosition+1,tempPosition))*300;
tempString = tempString.substr(tempPosition+1,tempString.size());
//tempString = tempString.substr(tempPosition+1,tempString.size());
//cout << tempVec << endl;
initialPointsPos[counter] = tempVec;
counter++;
return tempVec;
glPointSize(15);
}
//--------------------------------------------------------------
void testApp::update(){
if (ofGetFrameNum()%rateSendNode == true) {
randomNode = int(ofRandom(0, 40000));
if (part2 == true) {
ofxOscMessage m;
m.setAddress("node");
m.addFloatArg(initialPointsPos[randomNode].x);
m.addFloatArg(initialPointsPos[randomNode].y);
m.addFloatArg(initialPointsPos[randomNode].z);
m.addFloatArg(initialPointsPos[randomNode].distance( before ));
if (attractToCenterBool == true) {
m.addIntArg(10);
} else {
m.addIntArg(1000);
}
sender.sendMessage(m);
}
}
if (attractToCenterBool == true) {
attractToCenter();
} else {
pushThemAway();
pullToCenter();
applyPerlin();
}
ofxOscMessage m;
m.setAddress("camPos");
m.addIntArg(ofGetMouseX());
m.addIntArg(ofGetMouseY());
m.addIntArg(cam.getDistance());
sender.sendMessage(m);
}
//--------------------------------------------------------------
void testApp::draw(){
cam.begin();
if (part1) {
vbo.setColorData(&colors[0],colors.size(),GL_DYNAMIC_DRAW);
vbo.setVertexData(&points[0], points.size(), GL_DYNAMIC_DRAW);
vbo.draw(GL_POINTS, 0, (int)points.size());
}
if (part2) {
ofSetColor(255,255,0,250);
ofFill();
ofCircle(initialPointsPos[randomNode].x, initialPointsPos[randomNode].y, initialPointsPos[randomNode].z, 5);
ofLine(before.x, before.y, before.z, initialPointsPos[randomNode].x, initialPointsPos[randomNode].y, initialPointsPos[randomNode].z);
before = initialPointsPos[randomNode];
//cout << initialPointsPos[1] << endl;
}
cam.end();
if (part3) {
ofSetColor(0,0,0,30);
} else {
ofSetColor(0,0,0,0);
}
ofFill();
ofRect(-50, -50, ofGetWidth() + 100, ofGetHeight() + 100);
}
void testApp::pullToCenter() {
for (int i = 0 ; i < points.size(); i++){
ofVec3f dirToCenter = points[i] - center;
float distToCenter = dirToCenter.length();
float maxDistance = 800.0f;
if( distToCenter > maxDistance ){
dirToCenter.normalize();
float pullStrength = 0.0001f;
speeds[i] -= dirToCenter * ( ( distToCenter - maxDistance ) * pullStrength );
}
}
}
void testApp::attractToCenter() {
for (int i = 0 ; i < points.size(); i++){
ofVec3f dirToCenter = points[i] - initialPoints[i];
float distToCenter = dirToCenter.length();
float maxDistance = 0.0f;
dirToCenter.normalize();
float pullStrength = 0.001f;
speeds[i] -= dirToCenter * ( ( distToCenter - maxDistance ) * pullStrength );
points[i] += speeds[i];
colors[i] = ofFloatColor(1-speeds[i].x,1-speeds[i].y ,1-speeds[i].z + 0.2);
accelerations[i] = 0;
speeds[i] = 0.99*speeds[i];
}
}
void testApp::pushThemAway() {
for (int i = 0 ; i < points.size(); i++){
speeds[i] += accelerations[i];
points[i] += speeds[i];
colors[i] = ofFloatColor(1-speeds[i].x,0.01+speeds[i].y,0.2+speeds[i].z);
accelerations[i] = 0;
}
}
void testApp::applyPerlin() {
for (int i = 0 ; i < points.size(); i++)
{
float nX = points[i].x * 0.005f;
float nY = points[i].y * 0.005f;
float nZ = points[i].z * 0.005f;
float nW = ofGetFrameNum() * 0.0025f;
float noise = ofNoise( nX, nY, nZ );
float angle = noise * 15.0f;
ofVec3f noiseVector( cos( angle ), sin( angle ), cos(angle) );
speeds[i] += noiseVector * 0.01f;
}
}
void testApp::mouseMoved(int x, int y){
}
void testApp::mouseDragged(int x, int y, int button){}
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){
}
void testApp::keyPressed(int key){
/*
ofxOscMessage m;
m.setAddress("/test");
m.addIntArg(1);
m.addFloatArg(3.5f);
m.addStringArg("hello");
m.addFloatArg(ofGetElapsedTimef());
sender.sendMessage(m);
*/
switch(key) {
case 'M':
case 'm':
if(cam.getMouseInputEnabled()) cam.disableMouseInput();
else cam.enableMouseInput();
break;
case 'F':
case 'f':
ofToggleFullscreen();
break;
case 'i':
for (int i = 0 ; i < points.size(); i++){
points[i] = initialPoints[i];
}
break;
case 'g':
attractToCenterBool = !attractToCenterBool;
break;
case '1':
part1 = !part1;
break;
case '2':
part2 = !part2;
break;
case '3':
part3 = !part3;
break;
case 'c':
ofHideCursor();
break;
case 'C':
ofShowCursor();
break;
case '+':
rateSendNode = rateSendNode + 1;
cout << rateSendNode << endl;
break;
case '-':
if (rateSendNode> 2) {
rateSendNode = rateSendNode - 1;
cout << rateSendNode << endl;
}
break;
}
}
void testApp::keyReleased(int key){
}