0
我試圖創建一個最小的測試用例約Box2D的另一個問題,但我不能引起我的自定義抽屜的成員函數被調用:不叫b2Draw子類的成員函數
#include <iostream>
#include "Box2D/Box2D.h"
class DebugDrawer : public b2Draw
{
public:
DebugDrawer() {
AppendFlags(b2Draw::e_shapeBit);
AppendFlags(b2Draw::e_jointBit);
AppendFlags(b2Draw::e_aabbBit);
AppendFlags(b2Draw::e_pairBit);
AppendFlags(b2Draw::e_centerOfMassBit);
}
void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color&)
{
for (int vertex = 0; vertex < vertexCount; ++vertex) {
b2Vec2 vec = vertices[vertex];
std::cout << "DrawPolygon" << "vertex" << vertex << "x" << vec.x << "y" << vec.y;
}
}
void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color&)
{
for (int vertex = 0; vertex < vertexCount; ++vertex) {
b2Vec2 vec = vertices[vertex];
std::cout << "DrawSolidPolygon" << "vertex" << vertex << "x" << vec.x << "y" << vec.y;
}
}
void DrawCircle(const b2Vec2& center, float32 radius, const b2Color&)
{
std::cout << "DrawCircle" << "x" << center.x << "y" << center.y << "radius" << radius;
}
void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2&, const b2Color&) {
std::cout << "DrawSolidCircle" << "x" << center.x << "y" << center.y << "radius" << radius;
}
void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color&) {
std::cout << "DrawSegment" << "p1.x" << p1.x << "p1.y" << p1.y << "p2.x" << p2.x << "p2.y" << p2.y;
}
void DrawTransform(const b2Transform& xf) {
std::cout << "DrawTransform" << "x" << xf.p.x << "y" << xf.p.y << "angle" << xf.q.GetAngle();
}
};
int main(int argc, char** argv)
{
b2World world(b2Vec2(0.0f, 0.0f));
DebugDrawer debugDrawer;
world.SetDebugDraw(&debugDrawer);
// body
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position = b2Vec2(0, 0);
b2Body *body = world.CreateBody(&bd);
// shape
b2CircleShape shape;
shape.m_radius = 1.0f;
// fixture
b2FixtureDef fd;
fd.shape = &shape;
fd.density = 1.0f;
body->CreateFixture(&fd);
world.Step(1.0f/120.0f, 8, 3);
return 0;
}
我我曾嘗試多次致電Step()
,迫使身體保持清醒,等等。我錯過了什麼?
啊,是的,就是這樣!謝謝!是的。這個例子是從另一個設置文件確定哪些標誌被設置的,因此我需要單獨測試每個標誌。 – Mitch