27. void testApp::keyReleased(int key){
}
void testApp::mouseMoved(int x, int y){
}
void testApp::mouseDragged(int x, int y, int button){
}
void testApp::mousePressed(int x, int y, int button){
}
void testApp::mouseReleased(int x, int y, int button){
}
void testApp::windowResized(int w, int h){
}
28.
29.
30. #ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofxVectorMath.h" //ofxVectorMath
#include "ofxBox2d.h" //ofxBox2d
#include "CustomCircle.h" //CustomCircle
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
ofxBox2d box2d; //Box2D
vector <CustomCircle> circles; //CustomCircle
vector <ofxBox2dRect> rects; // ofxBox2dRect
};
31. #include "testApp.h"
void testApp::setup(){
//
ofSetVerticalSync(true);
ofEnableAlphaBlending();
ofSetCircleResolution(64);
ofBackground(0, 0, 0);
//Box2D
box2d.init(); //Box2D
box2d.setGravity(0,5); // 5
box2d.createFloor();
box2d.checkBounds(false);
box2d.setFPS(30); //30fps
//
for (int i=0; i<100; i++) { //100
ofxBox2dRect r; //ofxBox2dRect( ) r
float w = 2; // 2
float h = 2; // 2
float x = ofRandom(50, ofGetWidth()-50); // x
33. void testApp::keyPressed(int key){
// c
if (key == 'c') {
float r = ofRandom(5, 20); //
CustomCircle c; //CustomCircle
c.setPhysics(1.0, 0.8, 0.5); //
c.setup(box2d.getWorld(), mouseX, mouseY, r); //
circles.push_back(c); // circles
}
// r
if (key == 'r') {
for(int i=0; i<circles.size(); i++) {
circles[i].destroyShape();
}
circles.clear();
}
}
void testApp::keyReleased(int key){
}
void testApp::mouseMoved(int x, int y){
}
34. void testApp::mouseDragged(int x, int y, int button){
}
void testApp::mousePressed(int x, int y, int button){
}
void testApp::mouseReleased(int x, int y, int button){
}
void testApp::windowResized(int w, int h){
}
35.
36.
37.
38.
39. #ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofxOpenCv.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
ofVideoGrabber vidGrabber;
ofxCvColorImage colorImg;
};
#endif
43. #ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofxOpenCv.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
ofVideoGrabber vidGrabber;
ofxCvColorImage colorImg;
ofxCvGrayscaleImage grayImage;
};