hi all,
this is the first time im using box2d and i have a few questions about rendering. i set up my bodies/fixtures and now i am at the point of trying to render them.
A gravity of (0.0f, -10.0f) is shown in the examples. Is it normal to set the gravity to (0.0f, 10.0f) since +Y generally moves down?
When it comes to rendering the shapes:
When working in the testbed, a body with position (5.0f, 10.0f) is higher than one with position (5.0f, 5.0f). But when rendering, the reverse is true (since +Y is down). Why is this the case?
Is it normal to multiply the meter value by 10 to get the pixel values?
this is the first time im using box2d and i have a few questions about rendering. i set up my bodies/fixtures and now i am at the point of trying to render them.
Code:
b2Vec2 gravity(0.0f, 10.0f);
mpWorld = new b2World(gravity);
b2BodyDef bodyDef;
bodyDef.type = b2_kinematicBody;
bodyDef.position.Set(5.0f, 5.0f);
bodyDef.angle = 0;
mpBoxBody = mpWorld->CreateBody(&bodyDef);
b2PolygonShape boxShape;
boxShape.SetAsBox(1.5f, 0.5f);
b2FixtureDef fixtureDef;
fixtureDef.shape = &boxShape;
fixtureDef.density = 1.0f;
mpBoxBody->CreateFixture(&fixtureDef);
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(5.0f, 10.0f);
mpCircleBody = mpWorld->CreateBody(&bodyDef);
b2CircleShape circleShape;
circleShape.m_p.Set(0.0f, 0.0f);
circleShape.m_radius = 0.5f;
fixtureDef.shape = &circleShape;
mpCircleBody->CreateFixture(&fixtureDef);
mpWorld = new b2World(gravity);
b2BodyDef bodyDef;
bodyDef.type = b2_kinematicBody;
bodyDef.position.Set(5.0f, 5.0f);
bodyDef.angle = 0;
mpBoxBody = mpWorld->CreateBody(&bodyDef);
b2PolygonShape boxShape;
boxShape.SetAsBox(1.5f, 0.5f);
b2FixtureDef fixtureDef;
fixtureDef.shape = &boxShape;
fixtureDef.density = 1.0f;
mpBoxBody->CreateFixture(&fixtureDef);
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(5.0f, 10.0f);
mpCircleBody = mpWorld->CreateBody(&bodyDef);
b2CircleShape circleShape;
circleShape.m_p.Set(0.0f, 0.0f);
circleShape.m_radius = 0.5f;
fixtureDef.shape = &circleShape;
mpCircleBody->CreateFixture(&fixtureDef);
A gravity of (0.0f, -10.0f) is shown in the examples. Is it normal to set the gravity to (0.0f, 10.0f) since +Y generally moves down?
When it comes to rendering the shapes:
Code:
b2Vec2 boxPos = mpBoxBody->GetPosition();
b2Vec2 ballPos = mpCircleBody->GetPosition();
mpRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(ballPos.x * 10, ballPos.y * 10));
mpRenderTarget->DrawEllipse(D2D1::Ellipse(D2D1::Point2F(0.0f, 0.0f), 10.0f, 10.0f), mpBrownBrush);
mpRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(boxPos.x * 10, boxPos.y * 10));
mpRenderTarget->DrawRectangle(D2D1::RectF(0.0f, 0.0f, 30.0f, 10.0f), mpBrownBrush);
b2Vec2 ballPos = mpCircleBody->GetPosition();
mpRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(ballPos.x * 10, ballPos.y * 10));
mpRenderTarget->DrawEllipse(D2D1::Ellipse(D2D1::Point2F(0.0f, 0.0f), 10.0f, 10.0f), mpBrownBrush);
mpRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(boxPos.x * 10, boxPos.y * 10));
mpRenderTarget->DrawRectangle(D2D1::RectF(0.0f, 0.0f, 30.0f, 10.0f), mpBrownBrush);
When working in the testbed, a body with position (5.0f, 10.0f) is higher than one with position (5.0f, 5.0f). But when rendering, the reverse is true (since +Y is down). Why is this the case?
Is it normal to multiply the meter value by 10 to get the pixel values?