Sbaw090630

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Sbaw090630 - Presentation Transcript

    1. #pragma once #include "ofMain.h" #include "ofxAccelerometer.h" #include "ofxMultiTouch.h" #define NUM 10 class testApp : public ofSimpleApp, public ofxMultiTouchListener { public: void setup(); void update(); void draw(); void exit(); ...( )... ofPoint pos[NUM]; };
    2. #include "testApp.h" void testApp::setup(){ ofSetColor(0, 0, 255); ofBackground(0, 0, 0); ofSetBackgroundAuto(true); ofSetFrameRate(60); // ofxMultiTouch.addListener(this); // for(int i=0; i<NUM; i++){ pos[i].x = -100; pos[i].y = -100; } } void testApp::update(){ } void testApp::draw(){ for(int i=0; i<NUM; i++){ ofCircle(pos[i].x, pos[i].y, 40); } }
    3. void testApp::exit() { } // void testApp::mouseMoved(int x, int y){ } void testApp::mouseDragged(int x, int y, int button){ printf("mouseDragged: %i, %i %in", x, y, button); pos[0].x = x; pos[0].y = y; } void testApp::mousePressed(int x, int y, int button){ printf("mousePressed: %i, %i %in", x, y, button); pos[0].x = x; pos[0].y = y; } void testApp::mouseReleased(){ } void testApp::mouseReleased(int x, int y, int button){ printf("mouseReleased: %i, %i %in", x, y, button); pos[0].x = -100;
    4. pos[0].y = -100; } // void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData *data){ printf("touchDown: %i, %i %in", x, y, touchId); pos[touchId].x = x; pos[touchId].y = y; } void testApp::touchMoved(float x, float y, int touchId, ofxMultiTouchCustomData *data){ printf("touchMoved: %i, %i %in", x, y, touchId); pos[touchId].x = x; pos[touchId].y = y; } void testApp::touchUp(float x, float y, int touchId, ofxMultiTouchCustomData *data){ printf("touchUp: %i, %i %in", x, y, touchId); pos[touchId].x = -100; pos[touchId].y = -100; } void testApp::touchDoubleTap(float x, float y, int touchId, ofxMultiTouchCustomData *data){ }
    5. #pragma once #include "ofMain.h" #include "ofxAccelerometer.h" #include "ofxMultiTouch.h" class testApp : public ofSimpleApp, public ofxMultiTouchListener { public: void setup(); void update(); void draw(); void exit(); ...( )... ofPoint accel; };
    6. #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); ofSetBackgroundAuto(true); ofSetFrameRate(60); // ofxAccelerometer.setup(); } void testApp::update(){ //x,y,z accel.x = ofxAccelerometer.getForce().x; accel.y = ofxAccelerometer.getForce().y; accel.z = ofxAccelerometer.getForce().z; // printf("get force: %f, %f, %f n", accel.x, accel.y, accel.z); }
    7. void testApp::draw(){ // float rectScale = 200.0; ofSetColor(255, 0, 0); ofRect(0, ofGetHeight()/2, ofGetWidth()/3, accel.x * rectScale); ofSetColor(0, 255, 0); ofRect(ofGetWidth()/3, ofGetHeight()/2, ofGetWidth()/3, accel.y * rectScale); ofSetColor(0, 0, 255); ofRect(ofGetWidth()/3*2, ofGetHeight()/2, ofGetWidth()/3, accel.z * rectScale); } ...( )...
    8. #pragma once #include "ofMain.h" #include "ofxAccelerometer.h" #include "ofxMultiTouch.h" #include "Spot.h" class testApp : public ofSimpleApp, public ofxMultiTouchListener { public: void setup(); void update(); void draw(); void exit(); ...( )... private: Spot** sp; //Spot sp (**) int numSpot; // Spot };
    9. #include "testApp.h" #include "Spot.h" #define NUM_POINT 5 void testApp::setup(){ ofBackground(0, 0, 0); ofSetBackgroundAuto(true); ofSetFrameRate(60); // // ofEnableAlphaBlending(); // ofSetBackgroundAuto(false); // ofxAccelerometer.setup(); // ofxMultiTouch.addListener(this); // numSpot = 400; // sp = new Spot*[numSpot]; for(int i = 0; i < numSpot; i++){ ofPoint _pos, _velocity; _pos.x = ofRandom(0, ofGetWidth()); _pos.y = ofRandom(0, ofGetHeight());
    10. _velocity.x = 0; _velocity.y = 0; float _diameter = ofRandom(1, 10); // sp[i] = new Spot(_pos, _velocity, _diameter); // sp[i]->gravity = 0.05; // sp[i]->friction = 0.99; } } void testApp::update(){ ofSetColor(0, 0, 0, 31); ofRect(0, 0, ofGetWidth(), ofGetHeight()); for(int i = 0; i < numSpot; i++){ sp[i]->update(); } } void testApp::draw(){ for(int i = 0; i < numSpot; i++){ sp[i]->display(); } }
    11. void testApp::exit() { } void testApp::mouseMoved(int x, int y){ } void testApp::mouseDragged(int x, int y, int button){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == 0){ sp[i]->touched = true; sp[i]->moveTo(x, y); } } } void testApp::mousePressed(int x, int y, int button){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == 0){ sp[i]->touched = true; sp[i]->moveTo(x, y); } } } void testApp::mouseReleased(){ }
    12. void testApp::mouseReleased(int x, int y, int button){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == 0){ sp[i]->touched = false; } } } void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData *data){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == touchId){ sp[i]->touched = true; sp[i]->moveTo(x, y); } } } void testApp::touchMoved(float x, float y, int touchId, ofxMultiTouchCustomData *data) { for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == touchId){ sp[i]->touched = true; sp[i]->moveTo(x, y); } } }
    13. void testApp::touchUp(float x, float y, int touchId, ofxMultiTouchCustomData *data){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == touchId){ sp[i]->touched = false; } } }
    14. #ifndef _OF_SPOT #define _OF_SPOT #include "ofMain.h" #include "ofxMultiTouch.h" #include "ofxAccelerometer.h" class Spot { public: Spot(ofPoint pos, ofPoint velocity, float diameter); void update(); void display(); void moveTo(float x, float y); ofPoint pos; ofPoint velocity; float diameter; float gravity; float friction; bool touched; }; #endif
    15. #include "Spot.h" Spot::Spot(ofPoint _pos, ofPoint _velocity, float _diameter) { pos = _pos; velocity = _velocity; diameter = _diameter; touched = false; } void Spot::update() { if(!touched){ velocity *= friction; velocity.x += gravity * ofxAccelerometer.getForce().x; velocity.y -= gravity * ofxAccelerometer.getForce().y; pos.x += velocity.x * diameter; pos.y += velocity.y * diameter; if(pos.x < diameter){ velocity.x *= -1; pos.x = diameter; } if(pos.x > ofGetWidth() - diameter){ velocity.x *= -1; pos.x = ofGetWidth() - diameter; }
    16. if(pos.y < diameter){ velocity.y *= -1; pos.y = diameter; } if(pos.y > ofGetHeight()-diameter){ velocity.y *= -1; pos.y = ofGetHeight()-diameter; } } } void Spot::display() { ofSetColor(0, 127, 255, 200); ofCircle(pos.x, pos.y, diameter); } void Spot::moveTo(float x, float y) { pos.x = x; pos.y = y; velocity.x = ofRandom(-1, 1); velocity.y = ofRandom(-1, 1); }

    + Atsushi TadokroAtsushi Tadokro, 6 months ago

    custom

    324 views, 0 favs, 2 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 324
      • 157 on SlideShare
      • 167 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 1
    Most viewed embeds
    • 166 views on http://yoppa.org
    • 1 views on http://74.125.153.132

    more

    All embeds
    • 166 views on http://yoppa.org
    • 1 views on http://74.125.153.132

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?