@Nexonbird wrote:
Hi!! im developing my first OF app, im Using Kinect and Box2d add ons. i have already make work the integration successfully, but now im trying to make a textured polygon using the example of the ofxBox2d addon, but with my own drawings, i have make a list of the vertices points of the texture but i can't make it work. the polygon have the desired form but the texture is a mess..i can't understand how texture coordenates work, im really beginner with this kind of development, here are my questions:
Someone can explain how addTexCoord work if i have a custom imagen and a custom form or polygon?(exactly i want to make a box2d polygon with a turtle form and drawing).
What its the best method for do the texturing for box2d texturing thinking in performance?
someone know links or examples for do that?
here it my actual code
static ofPoint points[6] = {ofPoint(6.000,33.000),ofPoint(213.000,17.000),ofPoint(470.000,61.000),ofPoint(798.000,304.000),ofPoint(740.000,470.000),ofPoint(262.000,412.000)};
.......
void setup(ofxBox2d &world, float cx, float cy, float r) { color.setHex(hexColors[(int)ofRandom(4)]); mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); int nPts = 6; float scale = r / (float)texturePtr->getWidth(); for (int i=0; i<nPts; i++) { float n = ofMap(i, 0, nPts-1, 0.0, TWO_PI); float x =points[i].x; float y = points[i].y; float d = ofRandom(-r/2, r/2); polyShape.addVertex(ofPoint(cx + (x * r + d), cy + (y * r + d))); mesh.addTexCoord(ofPoint(0, 0)); mesh.addTexCoord(ofPoint(x * scale, y * scale)); } polyShape.setPhysics(0.3, 0.5, 0.1); polyShape.create(world.getWorld()); }
void draw() {
mesh.clearVertices(); vector<ofPoint> &pts = polyShape.getPoints(); ofPoint center = polyShape.getCentroid2D(); for (int i=0; i<pts.size(); i++) { mesh.addVertex(center); mesh.addVertex(pts[i]); } mesh.addVertex(center); mesh.addVertex(pts.front()); ofSetColor(color); texturePtr->bind(); mesh.draw(); texturePtr->unbind(); }
thanks in advance
Posts: 6
Participants: 2