[ Video ]
[ About ]
Android TabletでopenFramworksを動かしました。
openFrameworks for Android.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include "ofMain.h" #include "ofApp.h" int main(){ ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN // pass in width and height too: ofRunApp( new ofApp() ); return 0; } #ifdef TARGET_ANDROID #include <jni.h> //======================================================================== extern "C"{ void Java_cc_openframeworks_OFAndroid_init( JNIEnv* env, jobject thiz ){ main(); } } #endif |
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 |
#pragma once #include "ofMain.h" #include "ofxAndroid.h" #include "Particle.h" class ofApp : public ofxAndroidApp{ public: ~ofApp(); void setup(); void update(); void draw(); void keyPressed(int key); void keyReleased(int key); void windowResized(int w, int h); void touchDown(int x, int y, int id); void touchMoved(int x, int y, int id); void touchUp(int x, int y, int id); void touchDoubleTap(int x, int y, int id); void touchCancelled(int x, int y, int id); void swipe(ofxAndroidSwipeDir swipeDir, int id); void pause(); void stop(); void resume(); void reloadTextures(); bool backPressed(); void okPressed(); void cancelPressed(); vector<Particle*> particles; ofVec2f mouse_point; ofVec2f prev_mouse_point; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- ofApp::~ofApp(){ for (int i = this->particles.size() - 1; i > -1; i--) { delete this->particles[i]; this->particles.erase(this->particles.begin() + i); } } //-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); ofBackground(255); } //-------------------------------------------------------------- void ofApp::update(){ this->mouse_point = ofVec2f(ofGetMouseX() - ofGetWidth() / 2, ofGetMouseY() - ofGetHeight() / 2 ); ofVec2f velocity = prev_mouse_point - mouse_point; if (velocity.length() > 0) { this->particles.push_back(new Particle(mouse_point, velocity)); } for (int i = this->particles.size() - 1; i > -1; i--) { this->particles[i]->update(); if (this->particles[i]->isDead()){ delete this->particles[i]; this->particles.erase(this->particles.begin() + i); } } this->prev_mouse_point = this->mouse_point; } //-------------------------------------------------------------- void ofApp::draw(){ ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2); for (Particle* p : this->particles) { p->draw(); } } //-------------------------------------------------------------- void ofApp::keyPressed (int key){ } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::touchDown(int x, int y, int id){ } //-------------------------------------------------------------- void ofApp::touchMoved(int x, int y, int id){ } //-------------------------------------------------------------- void ofApp::touchUp(int x, int y, int id){ } //-------------------------------------------------------------- void ofApp::touchDoubleTap(int x, int y, int id){ } //-------------------------------------------------------------- void ofApp::touchCancelled(int x, int y, int id){ } //-------------------------------------------------------------- void ofApp::swipe(ofxAndroidSwipeDir swipeDir, int id){ } //-------------------------------------------------------------- void ofApp::pause(){ } //-------------------------------------------------------------- void ofApp::stop(){ } //-------------------------------------------------------------- void ofApp::resume(){ } //-------------------------------------------------------------- void ofApp::reloadTextures(){ } //-------------------------------------------------------------- bool ofApp::backPressed(){ return false; } //-------------------------------------------------------------- void ofApp::okPressed(){ } //-------------------------------------------------------------- void ofApp::cancelPressed(){ } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#pragma once #include "ofMain.h" class Particle { public: Particle(); Particle(ofVec2f location, ofVec2f velocity); ~Particle(); void update(); void draw(); bool isDead(); private: ofVec2f location; ofVec2f velocity; float body_size; ofColor body_color; int alpha; }; |
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 |
#include "Particle.h" Particle::Particle() : Particle(ofVec2f(0, 0), ofVec2f(0, 0)){ } Particle::Particle(ofVec2f location, ofVec2f velocity) { this->location = location; this->velocity = velocity; this->alpha = 255; this->body_size = velocity.length() * 5; this->body_color.setHsb(ofRandom(255), 255, 255); } Particle::~Particle(){ } void Particle::update() { this->location += this->velocity; this->alpha -= 5; } void Particle::draw() { ofSetColor(this->body_color, this->alpha); ofDrawEllipse(this->location, this->body_size, this->body_size); } bool Particle::isDead() { return this->alpha < 0; } |