Hi, sorry for intrusion on this topic.
I have some problem with Box2D and SMFL, especialy circle shapes, i made a minimalistic code that shows problem:
VS2010
Box2D 2.21
SMFL 2.0
#include <iostream>
// SMFL
#include <SFML/Graphics.hpp>
#pragma comment(lib, "sfml-graphics-d.lib")
#pragma comment(lib, "sfml-window-d.lib")
#pragma comment(lib, "sfml-system-d.lib")
// Box2D
#include <Box2D/Box2D.h>
#pragma comment(lib, "Box2D.lib")
#define B2_PIXEL_RATIO 30.0f
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Vector2f winSize = window.GetDefaultView().GetSize();
sf::Vector2f shapePosition(winSize.x * 0.5f, winSize.y * 0.5f);
// Rect body
float radius = 20.0f;
sf::CircleShape rcShape(radius);
rcShape.SetPosition(shapePosition);
rcShape.SetFillColor(sf::Color(255,255,0,255));
b2World phWorld(b2Vec2(0, 0));
b2BodyDef shapeBodyDef;
shapeBodyDef.type = b2_dynamicBody;
shapeBodyDef.position = b2Vec2(shapePosition.x / B2_PIXEL_RATIO, shapePosition.y / B2_PIXEL_RATIO);
b2Body* shapeBody = phWorld.CreateBody(&shapeBodyDef);
b2CircleShape circleShape;
circleShape.m_radius = radius / B2_PIXEL_RATIO;
b2FixtureDef rcShapeFixDef;
rcShapeFixDef.shape = &circleShape;
rcShapeFixDef.density = 10.0f;
rcShapeFixDef.friction = 0.4f;
rcShapeFixDef.restitution = 1.0f;
shapeBody->CreateFixture(&rcShapeFixDef);
// Surround screen with static edges
b2FixtureDef groundBoxDef;
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0,0);
b2Body* groundBody = phWorld.CreateBody(&groundBodyDef);
b2Vec2 vs[5];
vs[0].Set(winSize.x / B2_PIXEL_RATIO, 0.0f);
vs[1].Set(winSize.x / B2_PIXEL_RATIO, winSize.y / B2_PIXEL_RATIO);
vs[2].Set(0.0f, winSize.y / B2_PIXEL_RATIO);
vs[3].Set(0.0f, 0.0f);
vs[4].Set(winSize.x / B2_PIXEL_RATIO, 0.0f);
b2ChainShape wallShape;
wallShape.CreateChain(vs, 5);
groundBoxDef.shape = &wallShape;
groundBody->CreateFixture(&groundBoxDef);
float scale = 5.0f;
shapeBody->SetLinearVelocity(b2Vec2(scale, scale));
while(window.IsOpen())
{
sf::Event event;
while (window.PollEvent(event))
{
if (event.Type == sf::Event::Closed)
window.Close();
}
float timeStep = 1.0f / 6000.0f;
phWorld.Step(timeStep, 10, 10);
float x = shapeBody->GetPosition().x * B2_PIXEL_RATIO;
float y = shapeBody->GetPosition().y * B2_PIXEL_RATIO;
rcShape.SetPosition(x, y);
window.Clear();
window.Draw(rcShape);
window.Display();
}
return EXIT_SUCCESS;
}
When i run this circle has some offset and penetrates bottom & right part of the screen and also for left & top can't reach all the way.
Sorry for my english, can't explain any better, and i am really frustrated as i can't find out whats wrong.
If you find time, please help.