Using void * with float (ofxBox2d)

hello,
i’m working with ofxBox2d and I’d like to send out an OSC message with each collision. This message will contain the velocity of the body as well as the radius of the body (i’m using a modified ofxBox2dCircle).

To do this, I’m attaching the circle’s float radius to the box2d body using ofxBox2d’s setData(void* data) function. My problem is that i don’t know how to retrieve the float radius using Box2D’s GetUserData() function (which returns a void*).

Here’s my code:

void testApp::setup(){
    float circRadA = 100.0;
    staticCircA.setPhysics(0.0, 0.53, 0.1);                 
    staticCircA.setup(box2d.getWorld(), ofGetWidth()/2+100, ofGetHeight()/2+50, 100);
    staticCircA.setData(&circRadA);

void testApp::contactStart(ofxBox2dContactArgs &e){`ofxOscMessage m;                                    
        m.setAddress("bodyA");                              
        m.addFloatArg(*(float*)e.a->GetBody()->GetUserData());    
        m.addFloatArg(velocityA);                          
        sender.sendMessage(m);                              

I passed in a reference to the float for setData(void ) and that didn’t raise any issues.
I’m stuck on getting the float value back from e.a->GetBody()->GetUserData(). The code i have now (**(float
)… returns a long negative float of some sort.

Thanks in advance. This is my first post, so please let me know what other information you need.

I’ve got my solution… reference/pointer confusion on my part. I made radius a public member variable in the “newCircle” class. Below is how i’m attaching the UserData to both a single instance of a body and a vector of bodies.

adding UserData to a single instance of ofxBox2dCircle:

void testApp::setup(){
    staticCircA.setPhysics(0.0, 0.53, 0.1);                  
    staticCircA.setup(box2d.getWorld(), ofGetWidth()/2+100, ofGetHeight()/2+50, 10.0);
    staticCircA.setData(&staticCircA.radius);

adding UserData to an instance in a vector of circles:

void testApp::mousePressed(int x, int y, int button){
    float r = ofRandom(4, 20);                                
    newCircle circle;                                          
    circle.setPhysics(3.0, 0.53, 0.1);                          
    circle.setup(box2d.getWorld(), mouseX, mouseY, r);         
    circles.push_back(circle);                                 
    circle.setData(&circles.at(circles.size()-1).radius);      

getting the UserData back:

void testApp::contactStart(ofxBox2dContactArgs &e){
    ofLog() << "userdataA: " << *((float*)(e.a->GetBody()->GetUserData()));