Box2D Forums

It is currently Fri May 24, 2013 5:23 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Jun 07, 2012 3:04 am 
Offline

Joined: Mon May 28, 2012 4:27 am
Posts: 10
Hey guys.

I had everything working fine with a box, which I defined as per the hello world example.

But I want to use a circle, so I create it like so:

Code:
b2BodyDef bodyDef;
      bodyDef.type = b2_dynamicBody;
      bodyDef.position.Set(pi->startPos[i].x, pi->startPos[i].y);
      b2Body* body = bw->CreateBody(&bodyDef);

      // Define another box shape for our dynamic body.

      b2CircleShape circle;
      circle.m_p.Set(pi->startPos[i].x, pi->startPos[i].y);
      circle.m_radius = 7.0f;

      //b2PolygonShape dynamicBox;
      //dynamicBox.SetAsBox(7.0f, 7.0f);

      // Define the dynamic body fixture.
      b2FixtureDef fixtureDef;
      fixtureDef.shape = &circle;

      // Set the box density to be non-zero, so it will be dynamic.
      fixtureDef.density = gPuckDensity;

      // Override the default friction.
      fixtureDef.friction = gPuckFriction;

      fixtureDef.restitution = 0.8;


When I apply force to it - exactly the same force as the box, which worked fine - it starts off going in the right direction and then moves very quickly off the bottom left of the screen! Have I left something out?? The circles also DO NOT collide with my other shapes, just roll over them.

Thanks,
Ian


Top
 Profile  
 
PostPosted: Thu Jun 07, 2012 3:08 am 
Offline

Joined: Mon May 28, 2012 4:27 am
Posts: 10
Ah, turns out I mustn't have this line:

Code:
circle.m_p.Set(pi->startPos[i].x, pi->startPos[i].y);


Weird result though!


Top
 Profile  
 
PostPosted: Thu Jun 07, 2012 3:38 am 
Offline

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
The positions of shapes are local to the body it's in. The default circle.m_p is (0,0), so yeah. Changing the m_p will offset the shape's position from the body's position.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group