Box2D 获取我身体的形状
Body b;
while ((b=box2d.physics.PhysicssWorld.world.getBodyList().getNext())!=null) {
Shape shape;
while ((shape=b.getShapeList().getNext())!=null) {
Log.e("name",""+b.getUserData().toString()+" "+shape+" ");
opengl.saveMatrix();
Meshes.select(b.getUserData().toString())
.translate((b.getPosition().x)*RATIO, (b.getPosition().y)*RATIO)
.rotate((int) ((int) b.getAngle()* (180 / Math.PI)), 0, 0, 1)
.draw(shape, 1,1,1);
opengl.loadMatrix();
}
}
我想得到我身体的形状,但我什么也得不到,只有空..为什么?
切勿运行此行: Log.e("name",""+b.getUserData().toString()+" "+shape+" ");
所以 shape=b.getShapeList().getNext()) 总是 null...
Body b;
while ((b=box2d.physics.PhysicssWorld.world.getBodyList().getNext())!=null) {
Shape shape;
while ((shape=b.getShapeList().getNext())!=null) {
Log.e("name",""+b.getUserData().toString()+" "+shape+" ");
opengl.saveMatrix();
Meshes.select(b.getUserData().toString())
.translate((b.getPosition().x)*RATIO, (b.getPosition().y)*RATIO)
.rotate((int) ((int) b.getAngle()* (180 / Math.PI)), 0, 0, 1)
.draw(shape, 1,1,1);
opengl.loadMatrix();
}
}
I d like to get my bodies's shape, but i cant get anything, only null.. why?
never run this line: Log.e("name",""+b.getUserData().toString()+" "+shape+" ");
so shape=b.getShapeList().getNext()) always null...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己刚刚开始使用 Box2D。据我对图书馆的了解,获取人体形状的主要方法是通过它们的固定装置。从夹具中,您可以获得一个 b2Shape 指针 - 但是,因为它的方法是虚拟的,您可能需要将其转换为 b2PolygonShape/b2CircleShape 指针才能使用。以下是一些类似的代码:
其他一些需要注意的事项: b2Body 的 .getNext() 函数返回一个指针 - 这是链表的实现。 b2Fixture::GetNext() 也是如此。您的代码中有一些(对我来说)不熟悉的东西,所以我不能肯定地说,但如果您简单地检查并确保您的变量与 Box2D 函数的返回类型匹配,它可能会工作得很好。
I'm just starting out with Box2D myself. So far as I understand the library, the primary means of getting the shapes of bodies is through their fixtures. From the fixture you get a b2Shape pointer - but, because its methods are virtual, you'll probably need to cast it as a b2PolygonShape/b2CircleShape pointer for it to be useful. Here's some code along those lines:
Some other things to note: the .getNext() function of b2Body returns a pointer - this is an implementation of a linked list. The same is true for b2Fixture::GetNext(). There's some unfamiliar stuff (to me) in your code, so I can't say for sure, but it might work fine if you simply go through and make sure your variables match up with the return types of the Box2D functions.