void ofApp::setup(){
ofEnableDepthTest();
ofEnableLighting();
ofEnableNormalizedTexCoords();
light.setPointLight();
light.setDiffuseColor(ofFloatColor(0.7, 0.7, 0.7));
light.setAmbientColor(ofFloatColor(0.9, 0.9, 0.9));
light.setPosition(ofGetWidth()*.5, ofGetHeight()*.7, 300);
boxMaterial.setDiffuseColor(ofFloatColor(1.0, 0.0, 0.0));
boxRotateX = 0;
boxX = ofGetWidth()/2;
boxY = ofGetHeight()/2;
boxZ = 0;
dBox.setTexture(ofImage("s1.jpg"));
dBox2.setTexture(ofImage("s2.jpg"));
dBox3.setTexture(ofImage("s4.jpg"));
dBox.setWidth(25);
dBox.setHeight(500);
dBox.setDepth(500);
dBox.moveTo(0, ofGetHeight()/2, 0);
dBox2.setWidth(25);
dBox2.setHeight(500);
dBox2.setDepth(500);
dBox2.moveTo(ofGetWidth(), ofGetHeight()/2, 0);
dBox3.setWidth(ofGetWidth());
dBox3.setHeight(500);
dBox3.setDepth(50); //(25)
dBox3.moveTo(ofGetWidth()/2, ofGetHeight()/2, -540);
//sound
space.loadSound("Space.wav");
space.setVolume(1.0);
space.setLoop(true);
//tosen
anime = false;
fftSmooth = new float [8192];
for (int i = 0; i < 8192; i++){
fftSmooth [i] = 0;
}
bands = 64;
}
//--------------------------------------------------------------
void ofApp::update(){
boxRotateX += 0.25;
dBox.rotateXDeg(1.0);
dBox2.rotateXDeg(1.0);
dBox3.rotateXDeg(1.0);
ofSoundUpdate();
float * value = ofSoundGetSpectrum(bands);
for (int i = 0; i < bands; i++){
fftSmooth[i] *= 0.5f;
if(fftSmooth[i] < value[i]){
fftSmooth[i] = value[i];
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255,255,255,220);
light.enable();
ofSetColor(220,220,220,226);
ofPushMatrix();
ofTranslate(ofGetWidth()/2.0, ofGetHeight()/2.0,-742.0);
ofRotate(180);
textureImg.bind();
boxback.draw();
boxback.setWidth(ofGetWidth()*2.0);
boxback.setHeight(ofGetHeight()*2.0);
textureImg.unbind();
ofPopMatrix();
dBox.draw();
dBox2.draw();
dBox3.draw();
if(anime){
for(double i = 0.0; i < 3.0; i++){
ofRotateXDeg(boxRotateX * -i);
}
ofSetColor(220,220,220,226);
for(int i = 0; i < bands; i++){
ofTranslate(ofGetWidth()/2.0, ofGetHeight()/2.0,-(fftSmooth[i]*150));
ofRotate(180);
tosenImg.bind();
tosen.draw();
dBox.draw();
dBox2.draw();
tosen.setWidth(ofGetWidth()/2.0);
tosen.setHeight(ofGetHeight()/20.0);
tosen.setDepth(-500.0);
tosenImg.unbind();
}
}
light.disable();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
switch (key) {
case ‘1’ :
space.play();
anime = true;
dBox3.draw();
break;
case ‘2’ :
space.stop();
anime = false;
break;
}
}