gpt4 book ai didi

c++ - b2Draw子类成员函数未调用

转载 作者:行者123 更新时间:2023-11-28 06:16:20 25 4
gpt4 key购买 nike

我正在尝试为另一个关于 Box2d 的问题创建一个最小测试用例,但我无法调用我的自定义抽屉的成员函数:

#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(),强制 body 保持清醒等。我错过了什么?

最佳答案

我认为您明确需要调用 world.DrawDebugData()

此外,您知道您可以调用 SetFlags(a | b | c); 而不是 AppendFlags(a);附加标志(b); AppendFlags(c);?

关于c++ - b2Draw子类成员函数未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30232127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com