error The Funciton getScreenPos(Body) does not exist

186 views
Skip to first unread message

Ties

unread,
Mar 30, 2011, 4:55:49 AM3/30/11
to OSCeleton
Hi there,

I have followed Tohm Judson's tutorial (http://tohmjudson.com/?p=30)
which was great!
Everything is working in MaxMSP but I also want to use the Kinect in
combination with Processing.

In Tohm's tutorial pbox2d should be downloaded via http://code.google.com/p/pbox2d/,
but this link is not working.
I searched for an other link and found https://github.com/shiffman/PBox2D.

I used these files to run the Stickmanetic example, but this gives the
following error:

"The Funciton getScreenPos(Body) does not exist"

Can you help me with this problem?

Thanks!


nitespeed

unread,
Mar 30, 2011, 2:46:23 PM3/30/11
to OSCeleton
I actually fixed this myself a few days ago, same problem.

I think you need to use the 'box2d.coordPixelsToWorld()' function:

For example:

worldVertex = box2d.coordPixelsToWorld(screenVertex);

Good luck.

If you can tell me in which tab and line the getScreenPos is actually
found, I could compare it with my sketch.


On Mar 30, 10:55 am, Ties <thijseer...@gmail.com> wrote:
> Hi there,
>
> I have followed Tohm Judson's tutorial (http://tohmjudson.com/?p=30)
> which was great!
> Everything is working in MaxMSP but I also want to use the Kinect in
> combination with Processing.
>
> In Tohm's tutorial pbox2d should be downloaded viahttp://code.google.com/p/pbox2d/,
> but this link is not working.
> I searched for an other link and foundhttps://github.com/shiffman/PBox2D.

Ties

unread,
Mar 31, 2011, 2:33:56 AM3/31/11
to OSCeleton
Thank you for your reply.

It's in the "particle" tab.

and it's in this piece of code:

// Is the particle ready for deletion?
boolean done() {
// Let's find the screen position of the particle
Vec2 pos = box2d.getScreenPos(body);
// Is it off the bottom of the screen?
if (pos.y > height+r*2) {
killBody();
return true;
}
return false;
}

And in "void display" below this piece of code:


//
void display() {
// We look at each body and get its screen position
Vec2 pos = box2d.getScreenPos(body);
// Get its angle of rotation
float a = body.getAngle();
pushMatrix();
translate(pos.x,pos.y);
rotate(-a);
fill(175);
stroke(0);
strokeWeight(1);
ellipse(0,0,r*2,r*2);
// Let's add a line so we can see the rotation
line(0,0,r,0);
popMatrix();
}


Thanks for looking into it!

nitespeed

unread,
Mar 31, 2011, 5:41:56 AM3/31/11
to OSCeleton
I'll have to come back on this later, don't have access to my sketches
until this evening.
But, try this for now. Maybe it works :)


// Is the particle ready for deletion?
boolean done() {
// Let's find the screen position of the particle
Vec2 pos = box2d.getBodyPixelCoord(body);
// Is it off the bottom of the screen?
if (pos.y > height+r*2) {
killBody();
return true;
}
return false;
}
And in "void display" below this piece of code:
//
void display() {
// We look at each body and get its screen position
Vec2 pos = box2d.getBodyPixelCoord(body);

Ties

unread,
Mar 31, 2011, 6:45:14 AM3/31/11
to OSCeleton
It solves the error but another error pops up in the same tab, but in
the function "makeBody".

"The function screenToWorld(float, float) does not exist"

Hopefully your sketches have the answer!


// Here's our function that adds the particle to the Box2D world
void makeBody(float x, float y, float r) {
// Define a body
BodyDef bd = new BodyDef();
// Set its position
bd.position = box2d.screenToWorld(x,y);
body = box2d.world.createBody(bd);

// Make the body's shape a circle
CircleDef cd = new CircleDef();
cd.radius = box2d.scaleScreenToWorld(r);
cd.density = 1.0f;
cd.friction = 0.01f;
cd.restitution = 0.3f; // Restitution is bounciness
body.createShape(cd);

// Always do this at the end
body.setMassFromShapes();

// Give it a random initial velocity (and angular velocity)
body.setLinearVelocity(new Vec2(random(-10f,10f),random(5f,10f)));
body.setAngularVelocity(random(-10,10));
}


Aristopunk

unread,
Mar 31, 2011, 12:48:27 PM3/31/11
to OSCeleton
Hi
i had the same problem...
It is because this is a new version of Pbox2D with not the same
functions...
I ask in the forum of cycling74 to send me the old version and now
it's work perfectly on my mac (not yet in my Pcs pbl with osc....)
here you could download the good version
http://cycling74.com/forums/topic.php?id=29469&page=2#post-156513

Enjoy

Arthur

Aristopunk

unread,
Mar 31, 2011, 12:55:08 PM3/31/11
to OSCeleton
Hi
i don't know if my precedent message worked
your problem come from that your pbox2d version is a new one without
the same functions
I ask in cycling74 the old one and it's work perfectly on my mac
you could find it here http://cycling74.com/forums/topic.php?id=29469&page=2#post-156513

Enjoy

Arthur

nitespeed

unread,
Mar 31, 2011, 1:09:34 PM3/31/11
to OSCeleton
bd.position = box2d.coordPixelsToWorld(x,y);

fixes it?

johnh

unread,
Apr 1, 2011, 1:59:05 AM4/1/11
to OSCeleton
You have to change a few function names:

Change
Vec2 pos = box2d.getScreenPos(body); to Vec2 pos =
box2d.getBodyPixelCoord(body); in 2 places.
and
bd.position = box2d.screenToWorld(x,y); to bd.position =
box2d.coordPixelsToWorld(x,y); in 1 place.
and
cd.radius = box2d.scaleScreenToWorld(r); to cd.radius =
box2d.scalarPixelsToWorld(r); in 1 place.
and
worldVertex = box2d.screenToWorld(screenVertex); to
worldVertex = box2d.coordPixelsToWorld(screenVertex); in 1 place.

This worked for me.
I just figured it out by looking at pbox2d source as I couldn't find
any documentation on the function name changes.
jh

On Mar 30, 7:55 pm, Ties <thijseer...@gmail.com> wrote:
> Hi there,
>
> I have followed Tohm Judson's tutorial (http://tohmjudson.com/?p=30)
> which was great!
> Everything is working in MaxMSP but I also want to use the Kinect in
> combination with Processing.
>
> In Tohm's tutorial pbox2d should be downloaded viahttp://code.google.com/p/pbox2d/,
> but this link is not working.
> I searched for an other link and foundhttps://github.com/shiffman/PBox2D.

Ties

unread,
Apr 4, 2011, 8:39:51 AM4/4/11
to OSCeleton
Thank you guys for your replies!

Arthur, I've downloaded de the older version of pbox2d but it didn't
solve it.
After that I changed the functions as mentioned above and my example
works!
Reply all
Reply to author
Forward
0 new messages