Created
November 11, 2013 20:29
-
-
Save jedahan/7419803 to your computer and use it in GitHub Desktop.
polyline weirdness
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 "testApp.h" | |
//-------------------------------------------------------------- | |
void testApp::setup(){ | |
ofSetCircleResolution(6); | |
_x = ofGetWidth()/2; | |
_y = ofGetHeight()/2; | |
_r = ofGetWidth()/5; | |
ofSetVerticalSync(true); | |
ofBackgroundHex(0xfdefc2); | |
ofSetLogLevel(OF_LOG_NOTICE); | |
box2d.init(); | |
box2d.setGravity(10, 0); | |
box2d.setFPS(30.0); | |
box2d.registerGrabbing(); | |
int buffer=200; | |
p.addVertex(buffer,buffer); | |
p.addVertex(ofGetWidth()-buffer,buffer); | |
p.addVertex(ofGetWidth()-buffer,ofGetHeight()-buffer); | |
p.addVertex(buffer,ofGetHeight()-buffer); | |
//p.addVertex(buffer,buffer); | |
p.close(); | |
ofxBox2dCircle c; | |
for(ofPoint v : p.getResampledBySpacing(20).getVertices()){ | |
cout << v.x << ":" << v.y << endl; | |
c.setup(box2d.getWorld(),v.x,v.y,20); | |
anchors.push_back(c); | |
} | |
mouse.setup(box2d.getWorld(),ofGetWidth()/2,ofGetHeight()/2,20); | |
// now connect each anchor with a joint | |
for (int i=0; i<anchors.size(); i++) { | |
ofxBox2dJoint joint; | |
joint.setup(box2d.getWorld(), anchors[i].body, anchors[(i+1)%4].body); | |
joint.setLength(20); | |
joints.push_back(joint); | |
} | |
} | |
//-------------------------------------------------------------- | |
void testApp::update(){ | |
box2d.update(); | |
} | |
//-------------------------------------------------------------- | |
void testApp::draw(){ | |
ofSetHexColor(0xf2ab01); | |
mouse.draw(); | |
p.draw(); | |
for(ofxBox2dCircle b : anchors) { | |
ofFill(); | |
ofSetHexColor(0x01b1f2); | |
b.draw(); | |
} | |
for(int i=0; i<joints.size(); i++) { | |
ofSetHexColor(0x444342); | |
joints[i].draw(); | |
} | |
string info = ""; | |
// info += "FPS: "+ofToString(ofGetFrameRate(), 1)+"\n"; | |
ofSetHexColor(0x444342); | |
ofDrawBitmapString(info, 30, 30); | |
} | |
//-------------------------------------------------------------- | |
void testApp::keyPressed(int key){ | |
if(key == 't') ofToggleFullscreen(); | |
} | |
//-------------------------------------------------------------- | |
void testApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseMoved(int x, int y ){ | |
mouse.setPosition(x, 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){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::dragEvent(ofDragInfo dragInfo){ | |
} |
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 "ofxBox2d.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); | |
void dragEvent(ofDragInfo dragInfo); | |
void gotMessage(ofMessage msg); | |
int _x, _y, _r; | |
ofxBox2d box2d; | |
ofxBox2dCircle mouse; | |
vector <ofxBox2dCircle> circles; | |
vector <ofxBox2dCircle> anchors; | |
vector <ofxBox2dJoint> joints; | |
ofPolyline p; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment