ofBox2dEdge Scale and Rotation - How To?


I’m making a hexagon with bouncing balls inside it.

The hexagon is made of 5 ofPolylines, which are used as input to ofxBox2dEdges:

Called in setup():

void ofApp::tombolaVerts(){

    // vertex positions for tomobola
    v0.set(712, 384, 0);
    v1.set(612, 557.205, 0);
    v2.set(412, 557.205, 0);
    v3.set(312, 384, 0);
    v4.set(412, 210.795, 0);
    v5.set(612, 210.795, 0);
    // Creating polylines for use in ofxBoxEdges
    // [...]

    // Creating edges
    auto edge = std::make_shared<ofxBox2dEdge>();
    // [...]
void ofApp::update(){

    for (auto &edge : tEdges){
void ofApp::draw(){
    for (auto &circle : circles){
    for (auto &edge : tEdges){

What I would like to do is have user control of scale and rotation of the ofxBox2dEdges.
But for the life of me, nothing that I try works.
But when I try with the same process to alter the ofxBox2dCircles, everything works…

For example:

void ofApp::keyPressed(int key){
    if (key == 'a') {
        // this does not work - nothing happens
        for (auto &edge : tEdges){
            edge->scale(50, 50);

       // this works
        for (auto &circle : circles){
        cout << "key pressed: a" << endl;

The one thing I’m thinking is that the tombolaVerts() function gets called in setup() - as setting the vectors every frame was too cpu heavy.
But I’m thinking that because the process is called in setup, the values can therefore not be modified afterwards?
If this is the case, I have no good idea about how to get around it.

Any ideas?

The problem was that ofxBox2d and the polylines are two different processes / objects.
The ofxBox2dEdges were indeed being scaled, but the scaling was not being reflected in the graphical representation of the polylines.

To get around this I had to recalculate the original vector points, relative to the user slider.
These new vector points were then updated, meaning that the polylines and edges both changed - as those objects derive their coordinates from those vectors.

// if slider changes value do this (slider value = e.value)
// this calculates the new points that ofxBox2dEdges and Polylines should derive their positions from.
  v0.set(e.value * cos(glm::radians(0.0)), e.value * sin(glm::radians(0.0)), 0);
            v1.set(e.value * cos(glm::radians(60.0)), e.value * sin(glm::radians(60.0)), 0);
            v2.set(e.value * cos(glm::radians(120.0)), e.value * sin(glm::radians(120.0)), 0);
            v3.set(e.value * cos(glm::radians(180.0)), e.value * sin(glm::radians(180.0)), 0);
            v4.set(e.value * cos(glm::radians(240.0)), e.value * sin(glm::radians(240.0)), 0);
            v5.set(e.value * cos(glm::radians(300.0)), e.value * sin(glm::radians(300.0)), 0);
1 Like