//-------------------------------------------------------------- int ofxMSAInteractiveObject::getMouseX() const { return ofGetMouseX(); }
//-------------------------------------------------------------- void testApp::draw(){ if(ofGetKeyPressed('u')){ //update frame if u pressed contrastFbo.readToPixels(contrastPix); feedback.loadData(contrastPix); } sharpenFbo.begin(); ofPushStyle(); //ofSetColor(0); //ofCircle(ofGetMouseX(), ofGetMouseY(), 100); ofPopStyle(); ofPushStyle(); ofSetColor(0,0,0,5); ofRect(0,0,w,h); ofPopStyle(); glEnable(GL_BLEND); glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_DST_COLOR); glTranslatef(0.0, 0.0, ofMap(ofGetMouseX(), 0, w, 0, 250)); glRotatef(ofMap(ofGetMouseY(), 0, w, 0, 10), 1, 0, 0); feedback.draw(0,0); if(drawSquare){ ofPushStyle(); ofSetColor(0, 0, 0); ofEllipse(ofGetMouseX(),ofGetMouseY(),200, 200); ofPopStyle(); drawSquare = false; } sharpen.begin(); sharpen.setUniformTexture("src_tex_unit0", contrastFbo.getTextureReference(), 0); sharpen.setUniform1f("imgWidth", 1.0/1280.0); sharpen.setUniform1f("imgHeight", 1.0/720.0); feedback.draw(0,0); sharpen.end(); glDisable(GL_BLEND); sharpenFbo.end(); sharpenFbo.readToPixels(fbPix); feedback.loadData(fbPix); contrastFbo.begin(); contrast.begin(); contrast.setUniformTexture("src_tex_unit0", cam.getTextureReference(), 0); contrast.setUniform1f("imgWidth", 1); contrast.setUniform1f("imgHeight", 1); contrast.setUniform1f("contrast", 2); cam.draw(0,0); contrast.end(); contrastFbo.end(); /* combine.begin(); glEnable(GL_BLEND); glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_SRC_COLOR); sharpenFbo.draw(0, 0); ofScale(1,ofGetMouseY()); sharpenFbo.draw(ofGetMouseX(), 0); glDisable(GL_BLEND); combine.end(); */ //combine.draw(0, 0); sharpenFbo.draw(0,0); blurFbo.begin(); blur.begin(); blur.setUniformTexture("src_tex_unit0", sharpenFbo.getTextureReference(),0); blur.setUniform1f("time", ofGetElapsedTimef()*0.250); blur.setUniform1f("speed", 0.050); sharpenFbo.draw(0,0); blur.end(); blurFbo.end(); blurFbo.draw(0, 0); }
//-------------------------------------------------------------- void ofApp::update(){ int numVerts = mesh.getNumVertices(); for (int i=0; i<numVerts; ++i) { ofVec3f vert = mesh.getVertex(i); float time = ofGetElapsedTimef(); float timeScale = 5.0; float displacementScale = 0.75; ofVec3f timeOffsets = offsets[i]; vert.x += (ofSignedNoise(time*timeScale+timeOffsets.x)) * displacementScale; vert.y += (ofSignedNoise(time*timeScale+timeOffsets.y)) * displacementScale; vert.z += (ofSignedNoise(time*timeScale+timeOffsets.z)) * displacementScale; } if(orbiting) { int numVerts = mesh.getNumVertices(); for (int i=0; i<numVerts; ++i) { ofVec3f vert = mesh.getVertex(i); float distance = distances[i]; float angle = angles[i]; float elapsedTime = ofGetElapsedTimef() - startOrbitTime; float speed = ofMap(distance, 0, 200, 1, 0.25, true); float rotatedAngle = elapsedTime * speed + angle + meshSpeed; /* vert.x = distance * cos(rotatedAngle) + meshCentroid.x; vert.y = distance * sin(rotatedAngle) + meshCentroid.y; */ vert.x += 10 * cos(rotatedAngle); vert.y += 10 * sin(rotatedAngle); mesh.setVertex(i, vert); } } meshCopy = mesh; /***************** AttackVisualizeSphere *****************/ for (int i = 0; i < cubes.size(); i++) { float vol = ofRandom(30.0, 50.0); cubes[i]->update(vol, AttackColor, mluti_size); if (cubes[i]->LifeLimite < 0) { cubes.erase(cubes.begin() + i); } } /***************** ofxOsc *****************/ for(int i = 0; i < NUM_MSG_STRINGS; i++){ if(timers[i] < ofGetElapsedTimef()){ msg_strings[i] = ""; } } // check for waiting messages isAttack = 0; while(receiver.hasWaitingMessages()){ ofxOscMessage m; receiver.getNextMessage(&m); if(m.getAddress() == "/mouse/position"){ mouseX = m.getArgAsInt32(0); mouseY = m.getArgAsInt32(1); } else if(m.getAddress() == "/mouse/button"){ mouseButtonState = m.getArgAsString(0); } else if(m.getAddress() == "/image" ){ ofBuffer buffer = m.getArgAsBlob(0); receivedImage.loadImage(buffer); } else{ string msg_string; msg_string = m.getAddress(); msg_string += ": "; isAttack = 1; for(int i = 0; i < m.getNumArgs(); i++){ msg_string += m.getArgTypeName(i); msg_string += ":"; if(m.getArgType(i) == OFXOSC_TYPE_INT32){ msg_string += ofToString(m.getArgAsInt32(i)); } else if(m.getArgType(i) == OFXOSC_TYPE_FLOAT){ msg_string += ofToString(m.getArgAsFloat(i)); } else if(m.getArgType(i) == OFXOSC_TYPE_STRING){ msg_string += m.getArgAsString(i); } else{ msg_string += "unknown"; } } msg_strings[current_msg_string] = msg_string; timers[current_msg_string] = ofGetElapsedTimef() + 5.0f; current_msg_string = (current_msg_string + 1) % NUM_MSG_STRINGS; msg_strings[current_msg_string] = ""; } } kickVolume = scaledVol*totem_vol; /***************** AttackTimingFunction *****************/ if(isAttack) { ofVec3f mousePositon = ofVec3f(ofGetMouseX(), ofGetMouseY(), 0); cubes.push_back(new CubeSpreadInteraction(mousePositon)); } else { if(kickVolume < 0.1) { //kickVolume *= 0.85; } } /***************** Totems *****************/ for (int i = 0; i < totems.size(); i++) { totems[i]->update(totemColor, kickVolume, multi_r+scaledVol*0.8); } /***************** ofSoundStream *****************/ scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true); vol_num = ofMap(smoothedVol, 0.0, 0.1, PARTICLE_NUM, 0.0, true); volHistory.push_back(scaledVol); if ( volHistory.size() >= 400 ) { volHistory.erase(volHistory.begin(), volHistory.begin()+1); } /***************** AttackVisualizeSphere *****************/ theta += 0.01; //theta = ofRandom(10, 20); float neaPosAddRadius = ofMap(smoothedVol, 0.0, 0.17, 0, 50, true); //radianT[i] += for (int i = 0; i < PARTICLE_NUM; i++) { //radianT[i] += speed; //nearPosRadianS[i] += speed; ofVec3f vert = nearPosMesh.getVertex(i); vert.x = (nearPosRadius + neaPosAddRadius) * sin(nearPosRadianS[i]) * cos(nearPosRadianT[i]); vert.y = (nearPosRadius + neaPosAddRadius) * sin(nearPosRadianS[i]) * sin(nearPosRadianT[i]); vert.z = (nearPosRadius + neaPosAddRadius) * cos(nearPosRadianS[i]); nearPosMesh.setVertex(i, vert); float c = ofMap(smoothedVol, 0.0, 0.25, 20, 100, true); meshColors[i].a = c; nearPosMesh.setColor(i, meshColors[i]); } /***************** vboSphere *****************/ for (int i = 0; i < PARTICLE_NUM; i++) { //radianT[i] += speed; radianS[i] += speed; particle_pos[i] = ofVec3f((50+movingArea+neaPosAddRadius) * sin(radianS[i]) * cos(radianT[i]), (50+movingArea+neaPosAddRadius) * sin(radianS[i]) * sin(radianT[i]), (50+movingArea+neaPosAddRadius) * cos(radianS[i])); /* ofVec3f fromeP = particle_pos[i]; for(int j = 0; j < PARTICLE_NUM; j++){ ofVec3f toP = particle_pos[j]; float dist = (fromeP - toP).length(); if(dist < lengthLimit){ nearPosMesh.addVertex(toP); } } */ } }
//---------------------------------------- void ofEasyFingerCam::begin(ofRectangle viewport) { glEnable(GL_DEPTH_TEST); viewportRect = viewport; ofCamera::begin(viewport); ofPushMatrix(); glGetDoublev(GL_PROJECTION_MATRIX, this->matP); glGetDoublev(GL_MODELVIEW_MATRIX, this->matM); glGetIntegerv(GL_VIEWPORT, this->viewport); bool hasTweens = false; if(rTweens.size()>0) { hasTweens = true; setAnglesFromOrientation(); targetXRot = rTweens[0]->x; targetYRot = rTweens[0]->y; targetZRot = rTweens[0]->z; updateRotation(); if(targetXRot - rotationX <1 && targetXRot - rotationX >-1 && targetYRot - rotationY <1 && targetYRot - rotationY >-1 && targetZRot - rotationZ <1 && targetZRot - rotationZ >-1) { rTweens.erase(rTweens.begin()); } setAnglesFromOrientation(); } if(sTweens.size()>0) { hasTweens = true; if(abs(sTweens.at(0)->scale - getDistance()) < 10) { float newvalue = (getDistance()-sTweens.at(0)->scale)*0.05/100; setDistance(getDistance()+newvalue); } } if(pTweens.size()>0) { hasTweens = true; if(target.getPosition().distance(pTweens.at(0)->pan) > 1) { ofVec3f newTranslation; newTranslation = pTweens.at(0)->pan - target.getPosition(); translation = newTranslation/10; target.move(translation); } else { pTweens.erase(pTweens.begin()); } } if(hasTweens) { currentState = TWEENING; } else { currentState = STABLE; if(bMouseInputEnabled||bFingerInputEnabled) { if(!bDistanceSet) { setDistance(getImagePlaneDistance(viewport), true); } if (fingers.size() > 0 ) { // it's important to check whether we've already accounted for the mouse // just in case you use the camera multiple times in a single frame if (lastFrame != ofGetFrameNum()) { lastFrame = ofGetFrameNum(); currentState = STABLE; if (fingers.size() == 1) { if(selectedPlane->axis == AxisPlane::NOAXIS) { currentState = ROTATING; // if there is some smart way to use dt to scale the values drag, we should do it // you can't simply multiply drag etc because the behavior is unstable at high framerates // float dt = ofGetLastFrameTime(); ofVec2f mousePosScreen = ofVec3f(fingers[0]->getX()*ofGetWidth() - viewport.width/2 - viewport.x, viewport.height/2 - (fingers[0]->getY()*ofGetHeight() - viewport.y), 0); ofVec2f mouseVelScreen = (mousePosScreen - mousePosScreenPrev).lengthSquared(); ofVec3f targetPos = target.getGlobalPosition(); ofVec3f mousePosXYZ = ofVec3f(mousePosScreen.x, mousePosScreen.y, targetPos.z); float sphereRadius = min(viewport.width, viewport.height)/2; float diffSquared = sphereRadius * sphereRadius - (targetPos - mousePosXYZ).lengthSquared(); if(diffSquared <= 0) { mousePosXYZ.z = 0; } else { mousePosXYZ.z = sqrtf(diffSquared); } mousePosXYZ.z += targetPos.z; ofVec3f mousePosView = ofMatrix4x4::getInverseOf(target.getGlobalTransformMatrix()) * mousePosXYZ; //calc new rotation velocity ofQuaternion newRotation; if(fingerPressedPrev[0]) { newRotation.makeRotate(mousePosViewPrev, mousePosView); } fingerPressedPrev[0] = true; //apply drag towards new velocities rotation.slerp(drag, rotation, newRotation); // TODO: add dt mousePosViewPrev = ofMatrix4x4::getInverseOf(target.getGlobalTransformMatrix()) * mousePosXYZ; // apply transforms if they're big enough // TODO: these should be scaled by dt if(translation.lengthSquared() > epsilonTransform) { // TODO: this isn't quite right, it needs to move wrt the rotation target.move(translation); } if (rotation.asVec3().lengthSquared() > epsilonTransform) { target.rotate(rotation.conj()); } if (abs(distanceScaleVelocity - 1.0f) > epsilonTransform) { setDistance(getDistance() * (1.0f + distanceScaleVelocity), false); } mousePosScreenPrev = mousePosScreen; // targetFut.setPosition(target.getPosition()); } } if (fingers.size() == 2) { currentState = SCALING; if(zooming) { ofVec2f pointa = ofVec2f(fingers[0]->getX()*ofGetWidth(),fingers[0]->getY()*ofGetHeight()); ofVec2f pointb = ofVec2f(fingers[1]->getX()*ofGetWidth(),fingers[1]->getY()*ofGetHeight()); float newDistance = pointa.distance(pointb); float newDistanceScaleVelocity = 0.0f; if(prevDistance == 0) { prevDistance = newDistance; } else { newDistanceScaleVelocity = zoomSpeed * ( prevDistance - newDistance) / ofVec2f(0,0).distance(ofVec2f(ofGetHeight(),ofGetWidth())); distanceScaleVelocity = ofLerp(distanceScaleVelocity, newDistanceScaleVelocity, drag); if (abs(distanceScaleVelocity - 1.0f) > epsilonTransform) { setDistance(getDistance() * (1.0f + distanceScaleVelocity), false); } prevDistance = newDistance; } } } else { prevDistance = 0; } if (fingers.size() == 3) { currentState = POINTING; } if (fingers.size() == 5) { if(selectedPlane->axis == AxisPlane::NOAXIS) { currentState = PANNING; //DECIDE LATER } } if (fingers.size() == 10) { if(selectedPlane->axis == AxisPlane::NOAXIS) { currentState = RESET; addPanningTween(ofVec3f(0,0,0)); addRotationTween(0, 0, 0, 1); } } } } else { //MOUSE fingerPressedPrev[0] = false; // it's important to check whether we've already accounted for the mouse // just in case you use the camera multiple times in a single frame if (lastFrame != ofGetFrameNum()) { lastFrame = ofGetFrameNum(); if(selectedPlane->axis == AxisPlane::NOAXIS) { // if there is some smart way to use dt to scale the values drag, we should do it // you can't simply multiply drag etc because the behavior is unstable at high framerates // float dt = ofGetLastFrameTime(); currentState = STABLE; ofVec2f mousePosScreen = ofVec3f(ofGetMouseX() - viewport.width/2 - viewport.x, viewport.height/2 - (ofGetMouseY() - viewport.y), 0); ofVec2f mouseVelScreen = (mousePosScreen - mousePosScreenPrev).lengthSquared(); ofVec3f targetPos = target.getGlobalPosition(); ofVec3f mousePosXYZ = ofVec3f(mousePosScreen.x, mousePosScreen.y, targetPos.z); float sphereRadius = min(viewport.width, viewport.height)/2; float diffSquared = sphereRadius * sphereRadius - (targetPos - mousePosXYZ).lengthSquared(); if(diffSquared <= 0) { mousePosXYZ.z = 0; } else { mousePosXYZ.z = sqrtf(diffSquared); } mousePosXYZ.z += targetPos.z; ofVec3f mousePosView = ofMatrix4x4::getInverseOf(target.getGlobalTransformMatrix()) * mousePosXYZ; bool mousePressedCur[] = {ofGetMousePressed(0), ofGetMousePressed(2)}; //calc new rotation velocity ofQuaternion newRotation; if(mousePressedPrev[0] && mousePressedCur[0]) { newRotation.makeRotate(mousePosViewPrev, mousePosView); } //calc new scale velocity float newDistanceScaleVelocity = 0.0f; if(mousePressedPrev[1] && mousePressedCur[1]) { newDistanceScaleVelocity = zoomSpeed * (mousePosScreenPrev.y - mousePosScreen.y) / viewport.height; } mousePressedPrev[0] = mousePressedCur[0]; mousePressedPrev[1] = mousePressedCur[1]; ofVec3f newTranslation; // TODO: this doesn't work at all. why not? if(ofGetMousePressed() && ofGetKeyPressed(OF_KEY_SHIFT)) { newTranslation = mousePosScreenPrev - mousePosScreen; } //apply drag towards new velocities distanceScaleVelocity = ofLerp(distanceScaleVelocity, newDistanceScaleVelocity, drag); // TODO: add dt rotation.slerp(drag, rotation, newRotation); // TODO: add dt translation.interpolate(newTranslation, drag); mousePosViewPrev = ofMatrix4x4::getInverseOf(target.getGlobalTransformMatrix()) * mousePosXYZ; // apply transforms if they're big enough // TODO: these should be scaled by dt if(translation.lengthSquared() > epsilonTransform) { // TODO: this isn't quite right, it needs to move wrt the rotation target.move(translation); } if (rotation.asVec3().lengthSquared() > epsilonTransform) { target.rotate(rotation.conj()); } if (abs(distanceScaleVelocity - 1.0f) > epsilonTransform) { setDistance(getDistance() * (1.0f + distanceScaleVelocity), false); } mousePosScreenPrev = mousePosScreen; //targetFut.setPosition(target.getPosition()); } } } } setAnglesFromOrientation(); } ofCamera::begin(viewport); }
void QuadWarp :: draw(bool lockAxis) { if(!visible) return; if(curPointIndex>=0) { ofVec3f diff(ofGetMouseX(), ofGetMouseY()); diff-=dragStartPoint; diff*=0.1; if(lockAxis) { if(abs(diff.x)-abs(diff.y)>1) diff.y = 0; else if (abs(diff.y)-abs(diff.x)>1) diff.x = 0; } ofVec3f& curPoint = dstPoints[curPointIndex]; curPoint = dragStartPoint+diff+clickOffset; curPoint.x = round(curPoint.x*10)/10; curPoint.y = round(curPoint.y*10)/10; } ofPushStyle(); ofNoFill(); ofEnableSmoothing(); //ofScale(1024, 768); for(int i = 0; i < dstPoints.size(); i++) { ofSetColor(ofColor::black); ofSetLineWidth(3); ofVec3f& point = dstPoints[i]; ofCircle(point, 1); ofSetColor(pointColour); ofSetLineWidth(1); ofCircle(point, pointRadius); ofCircle(point, 1); if(i == curPointIndex){ ofLine(point.x, point.y - 100, point.x, point.y+100); ofLine(point.x-100, point.y, point.x+100, point.y); ofDrawBitmapStringHighlight(ofToString(point.x), point.x, point.y-30, ofColor(0,0,0,100)); ofDrawBitmapStringHighlight(ofToString(point.y), point.x-30, point.y, ofColor(0,0,0,100)); } } ofPopStyle(); }
//-------------------------------------------------------------- void ofApp::draw(){ ofBackground(0); ofNoFill(); ofCircle(ofGetMouseX(), ofGetMouseY(), 50); }
void ofxCamMapper::drawPanel(int x,int y){ ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofPushMatrix(); ofTranslate(x, y); //カメラポジションの描画 ofSetHexColor(0xFFFFFF); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofPushMatrix(); ofTranslate(camWin_pos.x,camWin_pos.y); //camera.draw(0,0, camWin_pos.width, camWin_pos.height); for (int i = 0;i < cam_pts.size();i++){ ofPoint draw_pt = ofPoint(cam_pts[i].x/CAM_WIDTH*camWin_pos.width, cam_pts[i].y/CAM_HEIGHT*camWin_pos.height); if (i >= (*out_pts).size()){ ofLine(draw_pt.x-3, draw_pt.y, draw_pt.x+3, draw_pt.y); ofLine(draw_pt.x, draw_pt.y-3, draw_pt.x, draw_pt.y+3); } } ofPopMatrix(); main_scroll.set(MAX(0,MIN(ofGetMouseX(),BUFFER_WIDTH-1024.0)), MAX(0,MIN(ofGetMouseY(),BUFFER_HEIGHT-768))); //メインアウトポジションの描画 ofSetHexColor(0xFFFFFF); ofPushMatrix(); ofTranslate(vert_child.drawArea.x,vert_child.drawArea.y); if (vert_child.enableScroll){ Buffer_out.getTextureReference().bind(); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(vert_child.sclPt.x,vert_child.sclPt.y); glVertex2f(0, 0); glTexCoord2f(vert_child.sclPt.x+vert_child.drawArea.width,vert_child.sclPt.y); glVertex2f(vert_child.drawArea.width, 0); glTexCoord2f(vert_child.sclPt.x,vert_child.sclPt.y+vert_child.drawArea.height); glVertex2f(0, vert_child.drawArea.height); glTexCoord2f(vert_child.sclPt.x+vert_child.drawArea.width,vert_child.sclPt.y+vert_child.drawArea.height); glVertex2f(vert_child.drawArea.width,vert_child.drawArea.height); glEnd(); Buffer_out.getTextureReference().unbind(); }else{ Buffer_out.draw(0, 0,vert_child.drawArea.width,vert_child.drawArea.height); } if (drawChild){ vert_child.draw(); } ofPopMatrix(); //ソースポジションの描画 ofSetHexColor(0xFFFFFF); ofPushMatrix(); ofTranslate(src_editor.drawArea.x,src_editor.drawArea.y); if (src_editor.enableScroll){ Buffer_src.getTextureReference().bind(); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(src_editor.sclPt.x,src_editor.sclPt.y); glVertex2f(0, 0); glTexCoord2f(src_editor.sclPt.x+src_editor.drawArea.width,src_editor.sclPt.y); glVertex2f(src_editor.drawArea.width, 0); glTexCoord2f(src_editor.sclPt.x,src_editor.sclPt.y+src_editor.drawArea.height); glVertex2f(0, src_editor.drawArea.height); glTexCoord2f(src_editor.sclPt.x+src_editor.drawArea.width,src_editor.sclPt.y+src_editor.drawArea.height); glVertex2f(src_editor.drawArea.width,src_editor.drawArea.height); glEnd(); Buffer_src.getTextureReference().unbind(); }else{ Buffer_src.draw(0, 0,src_editor.drawArea.width,src_editor.drawArea.height); } for (int i = 0;i < src_pts.size();i++){ ofCircle(src_pts[i].x, src_pts[i].y, 3); } ofPopMatrix(); if (drawChild){ src_editor.draw(); } ofPopMatrix(); //マスクの描画 ofSetHexColor(0xFFFFFF); ofPushMatrix(); ofTranslate(mask.drawArea.x, mask.drawArea.y); if (mask.enableScroll){ Buffer_out.getTextureReference().bind(); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(mask.sclPt.x,mask.sclPt.y); glVertex2f(0, 0); glTexCoord2f(mask.sclPt.x+mask.drawArea.width,mask.sclPt.y); glVertex2f(mask.drawArea.width, 0); glTexCoord2f(mask.sclPt.x,mask.sclPt.y+mask.drawArea.height); glVertex2f(0, mask.drawArea.height); glTexCoord2f(mask.sclPt.x+mask.drawArea.width,mask.sclPt.y+mask.drawArea.height); glVertex2f(mask.drawArea.width,mask.drawArea.height); glEnd(); Buffer_out.getTextureReference().unbind(); } if (drawChild){ mask.draw(); } ofPopMatrix(); //キャリブレーション表示 ofPushMatrix(); ofTranslate(BUFFER_WIDTH, 0); ofSetColor(sampleColor); ofRect(0, 480, 40, 40); ofSetColor(trackingColor); ofRect(40, 480, 40, 40); string info = ""; info += "Score: " + ofToString(color_score) + "/" + ofToString(Genframe) + "\n"; info += "Size:" + ofToString(size) + "\n"; info += "Elapsed:" + ofToString(ofGetElapsedTimeMillis() - calib_waiter) + "\n"; ofDrawBitmapString(info, 10,540); if ((abs(trackingColor.r - sampleColor.r) < 100)&& (abs(trackingColor.g - sampleColor.g) < 100)&& (abs(trackingColor.b - sampleColor.b) < 100)){ ofNoFill(); ofSetHexColor(0xFFFFFF); ofRect(0, 480, 80, 40); ofFill(); } ofPopMatrix(); menu.draw(); ofSetHexColor(0xFFFF00); ofLine(SelectedPt.x-5, SelectedPt.y, SelectedPt.x+5, SelectedPt.y); ofLine(SelectedPt.x, SelectedPt.y-5, SelectedPt.x, SelectedPt.y+5); vector<string> PresetBranch; PresetBranch.push_back("Msk_Preset0"); PresetBranch.push_back("Msk_Preset1"); PresetBranch.push_back("Msk_Preset2"); PresetBranch.push_back("Msk_Preset3"); PresetBranch.push_back("Msk_Preset4"); PresetBranch.push_back("Msk_Preset5"); PresetBranch.push_back("Msk_Preset6"); PresetBranch.push_back("Msk_Preset7"); PresetBranch.push_back("Msk_Preset8"); PresetBranch.push_back("Msk_Preset9"); mask.menu.UnRegisterMenu("Save"); mask.menu.RegisterBranch("Save", &PresetBranch); }
//-------------------------------------------------------------- void MonsterScene::keyPressed(int key) { if(bDebug) { //ferryBuilding.keyPressed(key); if(key == ' ') { // createBuildingContour(); } if(key == 'M') { saveMonsterSettings(); } // if(key == '1') { // ferryBuilding.setupBuilding("buildingRefrences/buidlingFiles/BuildingMonsters_0.xml"); // createBuildingContour(); // } // if(key == '2') { // ferryBuilding.setupBuilding("buildingRefrences/buidlingFiles/BuildingMonsters_1.xml"); // createBuildingContour(); // } // if(key == '3') { // ferryBuilding.setupBuilding("buildingRefrences/buidlingFiles/BuildingMonsters_2.xml"); // createBuildingContour(); // } } if(key == 'd') { bDebug = !bDebug; //panel.setValueB("DEBUG", bDebug); } // add some if(key == 't') { float bx = ofGetMouseX(); float by = ofGetMouseY(); //bx -= ((RM->getWidth() - W)/2); //by -= (RM->getHeight() - H); //shared_ptr<ofxBox2dRect>(new ofxBox2dRect) shared_ptr<MonsterBall> bub = shared_ptr<MonsterBall> (new MonsterBall()); //MonsterBall bub; bub->initTime = ofGetElapsedTimef(); bub->setPhysics(30.0, 0.93, 0.1); // mass - bounce - friction bub->setup(box2d.getWorld(), bx, by, ofRandom(10, 20)); bub->img = &dotImage; balls.push_back(bub); } // if(key == 'b') { // for(int i=0; i<box2dBuilding.size(); i++) { // box2dBuilding[i].destroyShape(); // } // box2dBuilding.clear(); // } // if(key == 'v'){ // createBuildingContour(); // } //if(key == 'p') bMonsterTimer = !bMonsterTimer; }
//-------------------------------------------------------------- void ofApp::update(){ for (int i = 0; i < NUMCIRCLE; i++) { myCircle[i].update(ofVec2f(ofGetMouseX(), ofGetMouseY())); } }
//---------------------------------------- void ofEasyCam::updateMouse(){ mouse = ofVec2f(ofGetMouseX(), ofGetMouseY()); if(viewport.inside(mouse.x, mouse.y) && !bValidClick && ofGetMousePressed()){ unsigned long curTap = ofGetElapsedTimeMillis(); if(lastTap != 0 && curTap - lastTap < doubleclickTime){ reset(); } if ((bEnableMouseMiddleButton && ofGetMousePressed(OF_MOUSE_BUTTON_MIDDLE)) || ofGetKeyPressed(doTranslationKey) || ofGetMousePressed(OF_MOUSE_BUTTON_RIGHT) || ofGetMousePressed(OF_MOUSE_BUTTON_LEFT)){ // <>< # Added left mouse button for dragging bDoTranslate = true; bDoRotate = false; bApplyInertia = false; }/*else if (ofGetMousePressed(OF_MOUSE_BUTTON_LEFT)) { bDoTranslate = false; bDoRotate = true; bApplyInertia = false; if(ofVec2f(mouse.x - viewport.x - (viewport.width/2), mouse.y - viewport.y - (viewport.height/2)).length() < min(viewport.width/2, viewport.height/2)){ bInsideArcball = true; }else { bInsideArcball = false; } }*/ lastTap = curTap; //lastMouse = ofVec2f(ofGetPreviousMouseX(),ofGetPreviousMouseY()); //this was causing the camera to have a tiny "random" rotation when clicked. lastMouse = mouse; bValidClick = true; bApplyInertia = false; } if (bValidClick) { if (!ofGetMousePressed()) { bApplyInertia = true; bValidClick = false; }else { int vFlip; if(isVFlipped()){ vFlip = -1; }else{ vFlip = 1; } mouseVel = mouse - lastMouse; if (bDoTranslate) { moveX = 0; moveY = 0; moveZ = 0; if (ofGetMousePressed(OF_MOUSE_BUTTON_RIGHT)) { moveZ = mouseVel.y * sensitivityZ * (getDistance() + FLT_EPSILON)/ viewport.height; }else { moveX = -mouseVel.x * sensitivityXY * (getDistance() + FLT_EPSILON)/viewport.width; moveY = vFlip * mouseVel.y * sensitivityXY * (getDistance() + FLT_EPSILON)/viewport.height; } }else { xRot = 0; yRot = 0; zRot = 0; if (bInsideArcball) { xRot = vFlip * -mouseVel.y * rotationFactor; yRot = -mouseVel.x * rotationFactor; }else { ofVec2f center(viewport.width/2, viewport.height/2); zRot = - vFlip * ofVec2f(mouse.x - viewport.x - center.x, mouse.y - viewport.y - center.y).angle(lastMouse - ofVec2f(viewport.x, viewport.y) - center); } } lastMouse = mouse; } } }
//-------------------------------------------------------------- void ofApp::update(){ scratch.updateValue("position/mouseX", ofGetMouseX()); scratch.updateValue("elapsedTime", ofGetElapsedTimeMillis()); scratch.updateValue("position/mouseY", ofGetMouseY()); }
//------------------------------------------------------------------ void demoParticle::update(){ //1 - APPLY THE FORCES BASED ON WHICH MODE WE ARE IN if( mode == PARTICLE_MODE_ATTRACT ){ ofPoint attractPt(ofGetMouseX(), ofGetMouseY()); frc = attractPt-pos; // we get the attraction force/vector by looking at the mouse pos relative to our pos frc.normalize(); //by normalizing we disregard how close the particle is to the attraction point vel *= drag; //apply drag vel += frc * 0.6; //apply force } else if( mode == PARTICLE_MODE_REPEL ){ ofPoint attractPt(ofGetMouseX(), ofGetMouseY()); frc = attractPt-pos; //let get the distance and only repel points close to the mouse float dist = frc.length(); frc.normalize(); vel *= drag; if( dist < 150 ){ vel += -frc * 0.6; //notice the frc is negative }else{ //if the particles are not close to us, lets add a little bit of random movement using noise. this is where uniqueVal comes in handy. frc.x = ofSignedNoise(uniqueVal, pos.y * 0.01, ofGetElapsedTimef()*0.2); frc.y = ofSignedNoise(uniqueVal, pos.x * 0.01, ofGetElapsedTimef()*0.2); vel += frc * 0.04; } } else if( mode == PARTICLE_MODE_NOISE ){ //lets simulate falling snow //the fake wind is meant to add a shift to the particles based on where in x they are //we add pos.y as an arg so to prevent obvious vertical banding around x values - try removing the pos.y * 0.006 to see the banding float fakeWindX = ofSignedNoise(pos.x * 0.003, pos.y * 0.006, ofGetElapsedTimef() * 0.6); frc.x = fakeWindX * 0.25 + ofSignedNoise(uniqueVal, pos.y * 0.04) * 0.6; frc.y = ofSignedNoise(uniqueVal, pos.x * 0.006, ofGetElapsedTimef()*0.2) * 0.09 + 0.18; vel *= drag; vel += frc * 0.4; //we do this so as to skip the bounds check for the bottom and make the particles go back to the top of the screen if( pos.y + vel.y > ofGetHeight() ){ pos.y -= ofGetHeight(); } } else if( mode == PARTICLE_MODE_NEAREST_POINTS ){ if( attractPoints ){ //1 - find closest attractPoint ofPoint closestPt; int closest = -1; float closestDist = 9999999; for(unsigned int i = 0; i < attractPoints->size(); i++){ float lenSq = ( attractPoints->at(i)-pos ).lengthSquared(); if( lenSq < closestDist ){ closestDist = lenSq; closest = i; } } //2 - if we have a closest point - lets calcuate the force towards it if( closest != -1 ){ closestPt = attractPoints->at(closest); float dist = sqrt(closestDist); //in this case we don't normalize as we want to have the force proportional to distance frc = closestPt - pos; vel *= drag; //lets also limit our attraction to a certain distance and don't apply if 'f' key is pressed if( dist < 300 && dist > 40 && !ofGetKeyPressed('f') ){ vel += frc * 0.003; }else{ //if the particles are not close to us, lets add a little bit of random movement using noise. this is where uniqueVal comes in handy. frc.x = ofSignedNoise(uniqueVal, pos.y * 0.01, ofGetElapsedTimef()*0.2); frc.y = ofSignedNoise(uniqueVal, pos.x * 0.01, ofGetElapsedTimef()*0.2); vel += frc * 0.4; } } } } //2 - UPDATE OUR POSITION pos += vel; //3 - (optional) LIMIT THE PARTICLES TO STAY ON SCREEN //we could also pass in bounds to check - or alternatively do this at the ofApp level if( pos.x > ofGetWidth() ){ pos.x = ofGetWidth(); vel.x *= -1.0; }else if( pos.x < 0 ){ pos.x = 0; vel.x *= -1.0; } if( pos.y > ofGetHeight() ){ pos.y = ofGetHeight(); vel.y *= -1.0; } else if( pos.y < 0 ){ pos.y = 0; vel.y *= -1.0; } }
void ofApp::update() { grabber.update(); if (grabber.isFrameNew()) { if (isBuffering) { // 0. Save the current frame in our buffer! pixelBuffer.push_back(grabber.getPixels()); // 1. Delete older frames if we have too many buffered. while (pixelBuffer.size() > maxBufferSize) { // This is how we delete the FIRST (oldest) frame from our buffer. pixelBuffer.erase(pixelBuffer.begin()); } } // 2. Make a "time" map. This map (which could be any grayscale pixel // mask) will determine how "deep" we go into the past (i.e. the buffer) // for each x / y position. // // In our mask, which has values from 0 - 255 for each pixel, a value of // 0 means that we choose the most recent buffer frame to get our pixel. // A value of 255 means we get our oldest frame. Thus, depending on // what the value of the `maxBufferSize`, you will be able to go further // "back" in time through the buffer. // // Here we create a mask that is simply the distance of each pixel from // the cursor. int mouseX = ofGetMouseX(); int mouseY = ofGetMouseY(); // std::min will take two numbers and give you back the smaller of the // two numbers. std::max, will take the same, but give you back the // larger of the two. int maximumDimension = std::min(grabber.getWidth(), grabber.getHeight()); for (int x = 0; x < grabber.getWidth(); x++) { for (int y = 0; y < grabber.getHeight(); y++) { if (useLinearGradient) { // The x-distance from the mouse to pixel x/y. float distance = ofDist(mouseX, y, x, y); // Map distance to grayscale. int grayscaleValue = ofMap(distance, 0, grabber.getWidth(), 0, 255, true); // Set our time map values. timeMapPixels.setColor(x, y, ofColor(grayscaleValue)); } else { // The distance from the mouse to pixel x/y. float distance = ofDist(mouseX, mouseY, x, y); // Map distance to grayscale. int grayscaleValue = ofMap(distance, 0, maximumDimension, 0, 255, true); // Set our time map values. timeMapPixels.setColor(x, y, ofColor(grayscaleValue)); } } } timeMapTexture.loadData(timeMapPixels); // 3. Now that we have the updated time map, we will dive into our // and pick out "historical" pixels based on our map. for (int x = 0; x < grabber.getWidth(); x++) { for (int y = 0; y < grabber.getHeight(); y++) { // First, we get the current value of the "time map" and we // map it to the buffer index (this goes from 0 for an empty // buffer to pixelBuffer.size() for a full buffer). // // Remember the buffer keeps adding new frames and removing the // oldest frames. // This value will range between 0 - 255. int value = timeMapPixels.getColor(x, y).getBrightness(); // Next we map it. std::size_t pixelBufferIndex = ofMap(value, 0, 255, 0, pixelBuffer.size() - 1, true); // Now we get the color of x/y pixels at the frame from the // pixel buffer that we just figured out above (pixelBufferIndex). // When we call pixelBuffer[pixelBufferIndex], we are asking for // the ofPixels inside of the pixelBuffer at the index == pixelBufferIndex. ofColor colorFromTheBuffer = pixelBuffer[pixelBufferIndex].getColor(x, y); // Now save it in our current pixels array to display! pixels.setColor(x, y, colorFromTheBuffer); } } texture.loadData(pixels); } }