所以,我正在尝试创建一个与SFML精灵相关联的Human实体,以及一个Box2D体和夹具。但是我得到了这个错误:
Assertion failed: area > 1.19209289550781250000e-7F, file ...b2PolygonShape.cpp, line 352
所以我做了一些快速的谷歌搜索,发现我的问题在于我的形状不正确的顶点。但是如果我使用Shape.SetAsBox()
函数......
这是我的代码:
#include "../../include/entity/Human.hpp"
Human::Human(unsigned int id, b2World& world, sf::Vector2f pos, sf::Texture* texture)
: AnimatedEntity(id, world, pos, sf::Vector2i(32, 32), texture)
{
b2PolygonShape shape;
shape.SetAsBox((32/2)/SCALE, (32/2)/SCALE); // Set the size; Box2D takes the half-width/height as params, and then scale.
b2FixtureDef fixtureDef;
fixtureDef.density = .8f;
fixtureDef.friction = .4f;
fixtureDef.restitution = .2f;
fixtureDef.shape = &shape;
e_body->CreateFixture(&fixtureDef); // Assuming: shape and density are set
}
FTR,SCALE
是static const int
,其值为30
(30px / 1m)。怎么了?
答案 0 :(得分:2)
我认为billz的意思是:
(32/2) = 16
16 / 30 = 0
你只需要为SCALE使用浮点而不是int ...