Hey, i'm trying to create a ropeJoint but nothing prints out on the screen. What have I done wrong? using VS-10. Tested circle, polygon, solidpolygon before this, and it have worked perfectly.
In the update I printed out the position of my body, it says (190,100), so should be visable on the screen
.h-file
.cpp
In the update I printed out the position of my body, it says (190,100), so should be visable on the screen
.h-file
Code:
private:
std::string _nextState;
b2World* _world;
b2BodyDef bd;
b2Body* ground;
b2Body* prevBody;
b2Body* body;
b2EdgeShape shape;
b2PolygonShape shapes;
b2FixtureDef fd;
b2RevoluteJointDef jd;
b2RopeJointDef m_ropeDef;
b2Joint* m_rope;
GLTexture* _glTexture;
GLTexture* _bg;
Entity* _entity;
float32 timeStep;
int32 velocityIterations;
int32 positionIterations;
DebugDraw _debugDraw;
std::string _nextState;
b2World* _world;
b2BodyDef bd;
b2Body* ground;
b2Body* prevBody;
b2Body* body;
b2EdgeShape shape;
b2PolygonShape shapes;
b2FixtureDef fd;
b2RevoluteJointDef jd;
b2RopeJointDef m_ropeDef;
b2Joint* m_rope;
GLTexture* _glTexture;
GLTexture* _bg;
Entity* _entity;
float32 timeStep;
int32 velocityIterations;
int32 positionIterations;
DebugDraw _debugDraw;
.cpp
Code:
b2Vec2 gravity = b2Vec2(0.0f, 9.8f);
_world = new b2World(gravity);
ground = NULL;
{
ground = _world->CreateBody(&bd);
shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
ground->CreateFixture(&shape, 0.0f);
}
{
shapes.SetAsBox(10.5f, 10.125f);
fd.shape = &shape;
fd.density = 20.0f;
fd.friction = 0.2f;
fd.filter.categoryBits = 0x0001;
fd.filter.maskBits = 0xFFFF & ~0x0002;
jd.collideConnected = false;
const int32 N = 10;
const float32 y = 100.0f;
m_ropeDef.localAnchorA.Set(0.0f, y);
prevBody = ground;
for (int32 i = 0; i < N; ++i)
{
bd.type = b2_dynamicBody;
bd.position.Set(100.0f + 10.0f * i, y);
if (i == N - 1)
{
shapes.SetAsBox(10.5f, 10.5f);
fd.density = 100.0f;
fd.filter.categoryBits = 0x0002;
bd.position.Set(100.0f + 10.0f * i, y);
bd.angularDamping = 0.4f;
}
body = _world->CreateBody(&bd);
body->CreateFixture(&fd);
b2Vec2 anchor(float32(i), y);
jd.Initialize(prevBody, body, anchor);
_world->CreateJoint(&jd);
prevBody = body;
}
m_ropeDef.localAnchorB.SetZero();
float32 extraLength = 0.01f;
m_ropeDef.maxLength = N - 1.0f + extraLength;
m_ropeDef.bodyB = prevBody;
}
{
m_ropeDef.bodyA = ground;
m_rope = _world->CreateJoint(&m_ropeDef);
}
_world->Step(timeStep, velocityIterations, positionIterations);
_world->SetDebugDraw(&_debugDraw);
_debugDraw.SetFlags(b2Draw::e_shapeBit);
bool IntroState::update(float deltaTime)
{
_world->Step(timeStep, velocityIterations, positionIterations);
_world->DrawDebugData();
std::cout << body->GetPosition().x << " " << body->GetPosition().y << std::endl;
_world = new b2World(gravity);
ground = NULL;
{
ground = _world->CreateBody(&bd);
shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
ground->CreateFixture(&shape, 0.0f);
}
{
shapes.SetAsBox(10.5f, 10.125f);
fd.shape = &shape;
fd.density = 20.0f;
fd.friction = 0.2f;
fd.filter.categoryBits = 0x0001;
fd.filter.maskBits = 0xFFFF & ~0x0002;
jd.collideConnected = false;
const int32 N = 10;
const float32 y = 100.0f;
m_ropeDef.localAnchorA.Set(0.0f, y);
prevBody = ground;
for (int32 i = 0; i < N; ++i)
{
bd.type = b2_dynamicBody;
bd.position.Set(100.0f + 10.0f * i, y);
if (i == N - 1)
{
shapes.SetAsBox(10.5f, 10.5f);
fd.density = 100.0f;
fd.filter.categoryBits = 0x0002;
bd.position.Set(100.0f + 10.0f * i, y);
bd.angularDamping = 0.4f;
}
body = _world->CreateBody(&bd);
body->CreateFixture(&fd);
b2Vec2 anchor(float32(i), y);
jd.Initialize(prevBody, body, anchor);
_world->CreateJoint(&jd);
prevBody = body;
}
m_ropeDef.localAnchorB.SetZero();
float32 extraLength = 0.01f;
m_ropeDef.maxLength = N - 1.0f + extraLength;
m_ropeDef.bodyB = prevBody;
}
{
m_ropeDef.bodyA = ground;
m_rope = _world->CreateJoint(&m_ropeDef);
}
_world->Step(timeStep, velocityIterations, positionIterations);
_world->SetDebugDraw(&_debugDraw);
_debugDraw.SetFlags(b2Draw::e_shapeBit);
bool IntroState::update(float deltaTime)
{
_world->Step(timeStep, velocityIterations, positionIterations);
_world->DrawDebugData();
std::cout << body->GetPosition().x << " " << body->GetPosition().y << std::endl;