Adding Active tripod project
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#include "ofMain.h"
|
||||
#include "testApp.h"
|
||||
#include "ofAppGlutWindow.h"
|
||||
|
||||
//========================================================================
|
||||
int main( ){
|
||||
|
||||
ofAppGlutWindow window;
|
||||
ofSetupOpenGL(&window, 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 testApp());
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "testApp.h"
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::setup(){
|
||||
ofSetFrameRate(60);
|
||||
string host = Spacebrew::SPACEBREW_CLOUD; // "localhost";
|
||||
string name = "of-button-example";
|
||||
string description = "It's amazing";
|
||||
|
||||
spacebrew.addPublish("button", Spacebrew::TYPE_BOOLEAN);
|
||||
spacebrew.addSubscribe("backgroundOn", Spacebrew::TYPE_BOOLEAN); //"boolean" ); // just typing "boolean" also works
|
||||
spacebrew.connect( host, name, description );
|
||||
|
||||
// listen to spacebrew events
|
||||
Spacebrew::addListener(this, spacebrew);
|
||||
|
||||
// circle stuff
|
||||
bButtonPressed = false;
|
||||
radius = 200;
|
||||
|
||||
// background
|
||||
bBackgroundOn = false;
|
||||
|
||||
// layout stuff
|
||||
ofBackground(0);
|
||||
ofSetRectMode(OF_RECTMODE_CENTER);
|
||||
ofEnableSmoothing();
|
||||
ofSetCircleResolution(100);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::update(){}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::draw(){
|
||||
if ( !bBackgroundOn ){
|
||||
ofBackgroundGradient(ofColor(0,0,0), ofColor(50,50,50));
|
||||
} else {
|
||||
ofBackgroundGradient(ofColor(100,0,0), ofColor(150,150,0));
|
||||
}
|
||||
|
||||
string textToDraw = "PRESS ME";
|
||||
if ( bButtonPressed ){
|
||||
ofSetColor( 150, 0, 0 );
|
||||
textToDraw = "THANKS";
|
||||
} else {
|
||||
ofSetColor(150);
|
||||
}
|
||||
ofCircle(ofGetWidth() / 2.0f, ofGetHeight()/2.0f, radius);
|
||||
ofSetColor(255);
|
||||
ofDrawBitmapString(textToDraw, ofGetWidth() / 2.0f - 30, ofGetHeight()/2.0f);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::onMessage( Spacebrew::Message & m ){
|
||||
if ( m.name == "backgroundOn" ){
|
||||
bBackgroundOn = m.valueBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::mousePressed(int x, int y, int button){
|
||||
if ( checkInsideCircle( ofPoint(x,y), ofPoint(ofGetWidth() / 2.0f, ofGetHeight()/2.0f), radius) ){
|
||||
bButtonPressed = true;
|
||||
spacebrew.sendBoolean("button", true);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::mouseReleased(int x, int y, int button){
|
||||
if (bButtonPressed){
|
||||
spacebrew.sendBoolean("button", false);
|
||||
}
|
||||
bButtonPressed = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
bool testApp::checkInsideCircle( ofPoint point, ofPoint position, int radius ){
|
||||
return ( point.x < position.x + radius
|
||||
&& point.x > position.x - radius
|
||||
&& point.y < position.y + radius
|
||||
&& point.y > position.y - radius );
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "ofMain.h"
|
||||
|
||||
#include "ofxSpacebrew.h"
|
||||
|
||||
class testApp : public ofBaseApp{
|
||||
|
||||
public:
|
||||
void setup();
|
||||
void update();
|
||||
void draw();
|
||||
|
||||
void mousePressed(int x, int y, int button);
|
||||
void mouseReleased(int x, int y, int button);
|
||||
|
||||
// create your spacebrew object
|
||||
Spacebrew::Connection spacebrew;
|
||||
|
||||
// listen to spacebrew Messages
|
||||
void onMessage( Spacebrew::Message & m );
|
||||
|
||||
// button stuff
|
||||
int radius;
|
||||
bool bButtonPressed;
|
||||
bool bBackgroundOn;
|
||||
|
||||
// useful quick test
|
||||
bool checkInsideCircle( ofPoint point, ofPoint position, int radius );
|
||||
};
|
||||
Reference in New Issue
Block a user