Last active
November 10, 2019 19:48
-
-
Save prisonerjohn/82bd085256c16fc932e3eef6236a7d35 to your computer and use it in GitHub Desktop.
Sensing Machines Mobile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofMain.h" | |
#include "ofApp.h" | |
int main() | |
{ | |
ofSetupOpenGL(1024, 768, OF_WINDOW); | |
ofRunApp(new ofApp()); | |
return 0; | |
} | |
#ifdef TARGET_ANDROID | |
void ofAndroidApplicationInit() | |
{ | |
// Application scope init | |
} | |
void ofAndroidActivityInit() | |
{ | |
// Activity scope init | |
main(); | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
int main() | |
{ | |
ofiOSWindowSettings settings; | |
settings.enableRetina = true; // enables retina resolution if the device supports it. | |
settings.enableDepth = false; // enables depth buffer for 3d drawing. | |
settings.enableAntiAliasing = false; // enables anti-aliasing which smooths out graphics on the screen. | |
settings.numOfAntiAliasingSamples = 0; // number of samples used for anti-aliasing. | |
settings.enableHardwareOrientation = false; // enables native view orientation. | |
settings.enableHardwareOrientationAnimation = false; // enables native orientation changes to be animated. | |
settings.glesVersion = OFXIOS_RENDERER_ES2; // type of renderer to use, ES1, ES2, ES3 | |
settings.windowControllerType = ofxiOSWindowControllerType::GL_KIT; // Window Controller Type | |
settings.colorType = ofxiOSRendererColorFormat::RGBA8888; // color format used default RGBA8888 | |
settings.depthType = ofxiOSRendererDepthFormat::DEPTH_NONE; // depth format (16/24) if depth enabled | |
settings.stencilType = ofxiOSRendererStencilFormat::STENCIL_NONE; // stencil mode | |
settings.windowMode = OF_FULLSCREEN; | |
settings.enableMultiTouch = false; // enables multitouch support and updates touch.id etc. | |
ofCreateWindow(settings); | |
return ofRunApp(new ofApp); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
#include "ofxAccelerometer.h" | |
void ofApp::setup() | |
{ | |
ofBackground(0); | |
ofxAccelerometer.setup(); | |
} | |
void ofApp::update() | |
{ | |
glm::vec2 gravity = glm::vec2(ofxAccelerometer.getForce().x, ofxAccelerometer.getForce().y * -1); | |
for (int i = 0; i < balls.size(); i++) | |
{ | |
balls[i].update(gravity); | |
} | |
} | |
void ofApp::draw() | |
{ | |
for (int i = 0; i < balls.size(); i++) | |
{ | |
balls[i].draw(); | |
} | |
} | |
void ofApp::addBall(int x, int y) | |
{ | |
// Add a new ezBall. | |
balls.push_back(ezBall()); | |
// Setup the last added ezBall. | |
balls.back().setup(x, y); | |
} | |
void ofApp::touchDown(int x, int y, int id) | |
{ | |
addBall(x, y); | |
} | |
void ofApp::touchMoved(int x, int y, int id) | |
{ | |
addBall(x, y); | |
} | |
void ofApp::touchDoubleTap(int x, int y, int id) | |
{ | |
balls.clear(); | |
} | |
bool ofApp::backPressed() | |
{ | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
#include "ofxAndroid.h" | |
#include "ezBall.h" | |
class ofApp : public ofxAndroidApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
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(); | |
void addBall(int x, int y); | |
std::vector<ezBall> balls; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
#include "ofxAndroid.h" | |
class ofApp : public ofxAndroidApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
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(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
ofSetOrientation(OF_ORIENTATION_90_LEFT); | |
grabber.setup(1280, 720); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
} | |
void ofApp::draw() | |
{ | |
// Scale using transform matrices. | |
// Fill width. | |
float scaleRatio = ofGetWidth() / grabber.getWidth(); | |
float drawX = 0; | |
float drawHeight = grabber.getHeight() * scaleRatio; | |
float drawY = (ofGetHeight() - drawHeight) / 2.0f; | |
ofPushMatrix(); | |
{ | |
ofTranslate(drawX, drawY); | |
ofScale(scaleRatio); | |
ofSetColor(255); | |
grabber.draw(0, 0); | |
} | |
ofPopMatrix(); | |
ofSetColor(255, 0, 255); | |
ofDrawBitmapString(ofToString(ofGetFrameRate(), 2, '0') + "FPS", 100, 10); | |
} | |
bool ofApp::backPressed() | |
{ | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
#include "ofxAndroid.h" | |
#include "Ball.h" | |
class ofApp : public ofxAndroidApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
//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(); | |
ofVideoGrabber grabber; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
ofSetOrientation(OF_ORIENTATION_90_LEFT); | |
grabber.setPixelFormat(OF_PIXELS_GRAY); | |
grabber.setup(1280, 720); | |
thresholdImg.allocate(1280, 720, OF_IMAGE_GRAYSCALE); | |
thresholdVal.set("Threshold Val", 127, 0, 255); | |
drawThreshold.set("Draw Threshold", true); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
if (grabber.isFrameNew()) | |
{ | |
ofxCv::threshold(grabber, thresholdImg, thresholdVal); | |
contourFinder.findContours(thresholdImg); | |
} | |
} | |
void ofApp::draw() | |
{ | |
// Scale using transform matrices. | |
// Fill width. | |
float scaleRatio = ofGetWidth() / grabber.getWidth(); | |
float drawX = 0; | |
float drawHeight = grabber.getHeight() * scaleRatio; | |
float drawY = (ofGetHeight() - drawHeight) / 2.0f; | |
ofPushMatrix(); | |
{ | |
ofTranslate(drawX, drawY); | |
ofScale(scaleRatio); | |
ofSetColor(255); | |
if (drawThreshold) | |
{ | |
// Only update the image if we need to draw it. | |
thresholdImg.update(); | |
thresholdImg.draw(0, 0); | |
} else | |
{ | |
grabber.draw(0, 0); | |
} | |
ofSetColor(0, 255, 0); | |
contourFinder.draw(); | |
} | |
ofPopMatrix(); | |
ofSetColor(255, 0, 255); | |
ofDrawBitmapString(ofToString(ofGetFrameRate(), 2, '0') + "FPS", 100, 10); | |
} | |
void ofApp::touchMoved(int x, int y, int id) | |
{ | |
thresholdVal = ofMap(x, 0, ofGetWidth(), 0, 255); | |
} | |
void ofApp::touchDoubleTap(int x, int y, int id) | |
{ | |
drawThreshold = !drawThreshold; | |
} | |
bool ofApp::backPressed() | |
{ | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
#include "ofxAndroid.h" | |
#include "ofxCv.h" | |
class ofApp : public ofxAndroidApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
//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(); | |
ofVideoGrabber grabber; | |
ofImage thresholdImg; | |
ofxCv::ContourFinder contourFinder; | |
ofParameter<int> thresholdVal; | |
ofParameter<bool> drawThreshold; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofxiOS.h" | |
#include "ofxiOSCoreMotion.h" | |
#include "ezBall.h" | |
class ofApp : public ofxiOSApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
void touchDown(ofTouchEventArgs & touch); | |
void touchMoved(ofTouchEventArgs & touch); | |
//void touchUp(ofTouchEventArgs & touch); | |
void touchDoubleTap(ofTouchEventArgs & touch); | |
//void touchCancelled(ofTouchEventArgs & touch); | |
//void lostFocus(); | |
//void gotFocus(); | |
//void gotMemoryWarning(); | |
//void deviceOrientationChanged(int newOrientation); | |
void addBall(int x, int y); | |
ofxiOSCoreMotion coreMotion; | |
std::vector<ezBall> balls; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
ofBackground(0); | |
coreMotion.setupAccelerometer(); | |
} | |
void ofApp::update() | |
{ | |
coreMotion.update(); | |
glm::vec2 gravity = glm::vec2(coreMotion.getAccelerometerData().x, coreMotion.getAccelerometerData().y * -1); | |
for (int i = 0; i < balls.size(); i++) | |
{ | |
balls[i].update(gravity); | |
} | |
} | |
void ofApp::draw() | |
{ | |
for (int i = 0; i < balls.size(); i++) | |
{ | |
balls[i].draw(); | |
} | |
} | |
void ofApp::addBall(int x, int y) | |
{ | |
// Add a new ezBall. | |
balls.push_back(ezBall()); | |
// Setup the last added ezBall. | |
balls.back().setup(x, y); | |
} | |
void ofApp::touchDown(ofTouchEventArgs & touch) | |
{ | |
addBall(touch.x, touch.y); | |
} | |
void ofApp::touchMoved(ofTouchEventArgs & touch) | |
{ | |
addBall(touch.x, touch.y); | |
} | |
void ofApp::touchDoubleTap(ofTouchEventArgs & touch) | |
{ | |
balls.clear(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofxiOS.h" | |
class ofApp : public ofxiOSApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
void exit(); | |
void touchDown(ofTouchEventArgs & touch); | |
void touchMoved(ofTouchEventArgs & touch); | |
void touchUp(ofTouchEventArgs & touch); | |
void touchDoubleTap(ofTouchEventArgs & touch); | |
void touchCancelled(ofTouchEventArgs & touch); | |
void lostFocus(); | |
void gotFocus(); | |
void gotMemoryWarning(); | |
void deviceOrientationChanged(int newOrientation); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofxiOS.h" | |
#include "ofxCv.h" | |
class ofApp : public ofxiOSApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
//void exit(); | |
//void touchDown(ofTouchEventArgs & touch); | |
void touchMoved(ofTouchEventArgs & touch); | |
//void touchUp(ofTouchEventArgs & touch); | |
void touchDoubleTap(ofTouchEventArgs & touch); | |
//void touchCancelled(ofTouchEventArgs & touch); | |
//void lostFocus(); | |
//void gotFocus(); | |
//void gotMemoryWarning(); | |
//void deviceOrientationChanged(int newOrientation); | |
ofVideoGrabber grabber; | |
ofImage thresholdImg; | |
ofxCv::ContourFinder contourFinder; | |
ofFbo renderFbo; | |
ofParameter<int> thresholdVal; | |
ofParameter<bool> drawThreshold; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
grabber.setup(640, 480); | |
thresholdImg.allocate(640, 480, OF_IMAGE_GRAYSCALE); | |
renderFbo.allocate(640, 480); | |
thresholdVal.set("Threshold Val", 127, 0, 255); | |
drawThreshold.set("Draw Threshold", true); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
if (grabber.isFrameNew()) | |
{ | |
ofxCv::convertColor(grabber, thresholdImg, CV_RGB2GRAY); | |
ofxCv::threshold(thresholdImg, thresholdVal); | |
contourFinder.findContours(thresholdImg); | |
} | |
} | |
void ofApp::draw() | |
{ | |
renderFbo.begin(); | |
{ | |
ofSetColor(255); | |
if (drawThreshold) | |
{ | |
// Only update the image if we need to draw it. | |
thresholdImg.update(); | |
thresholdImg.draw(0, 0); | |
} else | |
{ | |
grabber.draw(0, 0); | |
} | |
ofSetColor(0, 255, 0); | |
contourFinder.draw(); | |
} | |
renderFbo.end(); | |
ofRectangle drawBounds = ofRectangle(0, 0, renderFbo.getWidth(), renderFbo.getHeight()); | |
drawBounds.scaleTo(ofGetCurrentViewport(), OF_SCALEMODE_FILL); | |
ofSetColor(255); | |
renderFbo.draw(drawBounds); | |
ofSetColor(255, 0, 255); | |
ofDrawBitmapString(ofToString(ofGetFrameRate(), 2, '0') + "FPS", 100, 10); | |
} | |
void ofApp::touchMoved(ofTouchEventArgs & touch) | |
{ | |
thresholdVal = ofMap(touch.x, 0, ofGetWidth(), 0, 255); | |
} | |
void ofApp::touchDoubleTap(ofTouchEventArgs & touch) | |
{ | |
drawThreshold = !drawThreshold; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment