与测试平台应用程序相比,调试绘制Box2D非常大
debug draw Box2D very large compared to Testbed app
我正在尝试在自己的游戏中设置Box2D。我目前有一些代码在工作,我在我的游戏中添加了一个 DebugDraw 类,该类绘制了 Box2D 创建的多边形。
现在,如果我将其与 Testbed 应用程序中的代码进行比较(我复制了一些代码以重新创建 OneSidedPlatform 测试),它在我的游戏中显示的比在原始应用程序中要大得多。
我想这与OpenGL/SDL本身有关,所以这里有一些代码:
这在我的游戏中设置了OpenGL:
// START SDL
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
logSDLError(std::cout, "SDL_Init");
return 1;
}
// SETUP OPENGL SETTINGS (THEY CAN BE SET WITHOUT ACTUALLY BEING USED)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
// CREATE A WINDOW
m_pWindow = SDL_CreateWindow("SDL/OpenGL Game Client - With Networking Library", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL);
if (m_pWindow == nullptr)
{
logSDLError(std::cout, "CreateWindow");
return 2;
}
m_GlContext = SDL_GL_CreateContext(m_pWindow);
if( m_GlContext == NULL )
{
printf( "OpenGL context could not be created! SDL Error: %sn", SDL_GetError() );
}
else
{
//INITIALIZE GLEW
glewExperimental = GL_TRUE;
GLenum glewError = glewInit();
if( glewError != GLEW_OK )
{
printf( "Error initializing GLEW! %sn", glewGetErrorString( glewError ) );
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
// CREATE A RENDERER TO DRAW THE WINDOW TO
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (m_pRenderer == nullptr)
{
logSDLError(std::cout, "CreateRenderer");
return 3;
}
这是 Box2D 对象的创建(从原始测试应用程序复制):
// Ground
{
b2BodyDef bd;
b2Body* ground = Engine::GetInstance()->GetPhysicsWorld()->CreateBody(&bd);
b2EdgeShape shape;
shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f));
ground->CreateFixture(&shape, 0.0f);
}
// Platform
{
b2BodyDef bd;
bd.position.Set(0.0f, 10.0f);
b2Body* body = Engine::GetInstance()->GetPhysicsWorld()->CreateBody(&bd);
b2PolygonShape shape;
shape.SetAsBox(3.0f, 0.5f);
m_platform = body->CreateFixture(&shape, 0.0f);
m_bottom = 10.0f - 0.5f;
m_top = 10.0f + 0.5f;
}
// Actor
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(0.0f, 12.0f);
b2Body* body = Engine::GetInstance()->GetPhysicsWorld()->CreateBody(&bd);
m_radius = 0.5f;
b2CircleShape shape;
shape.m_radius = m_radius;
m_character = body->CreateFixture(&shape, 20.0f);
body->SetLinearVelocity(b2Vec2(0.0f, -50.0f));
m_state = e_unknown;
}
// Set debug
Engine::GetInstance()->GetPhysicsWorld()->SetDebugDraw(&m_debugDraw);
m_debugDraw.SetFlags(b2Draw::e_shapeBit);
我不知道我必须去哪里改变我的游戏视图或Box2D的规模。我还将我的OpenGL代码与Testbed应用程序中的代码进行了比较,但我找不到任何真正的区别。
在 TestBed app 的 Main.cpp 中查看此方法:
static void Resize(int32 w, int32 h)
{
...
// those are the lines you may consider incorporating into your code:
b2Vec2 lower = settings.viewCenter - extents;
b2Vec2 upper = settings.viewCenter + extents;
// L/R/B/T
gluOrtho2D(lower.x, upper.x, lower.y, upper.y);
}
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 在linux上调试巨大的C++项目
- 为什么使用__LINE_的代码在发布模式下在MSVC下编译,而不是在调试模式下
- 如何针对特定情况调试和修复此双自由内存损坏问题
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- 正在VS调试器中监视映射条目
- 使用调试/崩溃报告将应用程序部署到客户端
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- VC++本机单元测试,找不到调试符号
- 如何在C++生成器中禁用"使用调试.dcus"
- 如何在QT中的自定义视频小工具t上绘制矩形
- 使用vscode调试时,GDB意外退出
- 即使使用调试编译标志,表达式也是"optimized out"
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 无法使用VAO和EBO(openGL)绘制多个对象
- 在UE4中绘制而不是调试线
- 我的窗口未在调试器中运行时无法正确绘制
- 与测试平台应用程序相比,调试绘制Box2D非常大
- Box2D调试绘制在特定层