Hi, I just started with openFrameworks, and have a Processing sketch, which I would like to implement. I have mesh whose vertices I want to update, and I’m not sure how and where (update/draw) to do it. I want the amount of Perlin noise to change over time. Here’s my ofApp.cpp:
ofEasyCam easyCam;
ofMesh mesh;
float tSize = 60;
float noiseScale = 0;
float tDistance = 6;
float heightValue = 0;
float heightScale = 20;
int counter = 0;
//--------------------------------------------------------------
void ofApp::setup(){
mesh.setMode(OF_PRIMITIVE_LINES);
}
//--------------------------------------------------------------
void ofApp::update(){
counter++;
}
//--------------------------------------------------------------
void ofApp::draw(){
easyCam.begin();
glTranslatef(-tSize, 0, -tSize*0.25*tDistance);
glTranslatef(-(tSize/2)*tDistance, -(tSize/2)*tDistance, 0);
glRotatef(90, 1, 0, 0);
for (int x=0; x<tSize; x++) {
for (int y=0; y<tSize; y++) {
noiseScale = sin(counter*0.1);
heightValue = sin(ofMap(x,0,tSize,0,2*pi))*heightScale
+ sin(ofMap(y,0,tSize,0,2*pi))*heightScale*0;
heightValue += ofNoise(x*noiseScale,y*noiseScale)*20;
ofVec3f pos(tDistance*x, tDistance*y, heightValue);
mesh.addVertex(ofPoint(pos));
mesh.addColor(ofFloatColor(0,0,0));
}
}
mesh.draw();
for (int x=0; x<tSize-1; x++) {
for (int y=0; y<tSize-1; y++) {
mesh.addIndex(x+y*tSize); // 0
mesh.addIndex((x+1)+y*tSize); // 1
mesh.addIndex(x+(y+1)*tSize); // 10
mesh.addIndex((x+1)+y*tSize); // 1
mesh.addIndex((x+1)+(y+1)*tSize); // 11
mesh.addIndex(x+(y+1)*tSize); // 10
}
}
easyCam.end();
}
Thanks for your help!