1

因此,我正在尝试制作一个与 SFML 精灵、Box2D 主体和夹具相关联的 Human 实体。但是,我收到此错误:

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,SCALEstatic const int一个值为30(30px/1m) 的值。怎么了?

4

1 回答 1

2

我认为 billz 的意思是:

(32/2) = 16
16 / 30 = 0

您只需要为 SCALE 使用浮点数而不是 int ...

于 2013-01-04T09:15:10.643 回答