Box2d - 非 POD 元素类型“b2Vec2”的可变长度数组;
我正在为我的游戏开发一个导入器,它读取 xml,然后为所有内容创建 box2d 主体。
例如,
<polygon vertexCount="3" density="0" friction="0.25" restitution="0.30000000000000004">
<vertice x="6.506500000000001" y="0.4345"/>
<vertice x="6.534970527648927" y="0.48385302734375"/>
<vertice x="6.478029472351075" y="0.48385302734375"/>
</polygon>
问题出在导出器中,我现在面对多边形部分,我需要在添加顶点并设置它们的位置之前设置一个 b2vec2 数组。
int count = [[childnode attributeForName:@"vertexCount"] intValue];
b2Vec2 points[count];
但是box2d希望points[5]是一个实际的文字数字(就像points[5]而不是变量points[number],当我有变量count时它输出的错误是:
Variable length array of non-POD element type 'b2Vec2'
我该如何解决这个问题?我尝试将其设为常量,但这也不起作用(并且对我没有帮助,因为我需要它是动态的)。
I'm working on a importer for a game of mine, it reads an xml and then creates the box2d bodies for everything.
For example
<polygon vertexCount="3" density="0" friction="0.25" restitution="0.30000000000000004">
<vertice x="6.506500000000001" y="0.4345"/>
<vertice x="6.534970527648927" y="0.48385302734375"/>
<vertice x="6.478029472351075" y="0.48385302734375"/>
</polygon>
The problem is in the exporter I'm now facing the polygon part, I need to setup a b2vec2 array before adding the vertices and setting their positions.
int count = [[childnode attributeForName:@"vertexCount"] intValue];
b2Vec2 points[count];
but box2d wants the points[5] to be an actual literal number (like points[5] instead of a variable points[number], the error it outputs when I have the variable count in there is:
Variable length array of non-POD element type 'b2Vec2'
How do I solve this? I tried making it a constant but that doesn't work either (and doesn't help me since I need it to be dynamic).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在堆上创建数组:
完成后不要忘记手动删除数组。
或者更好地使用 std::vector:
You have to create the array on a heap:
Don't forget to delete the array manually when finished.
or better use std::vector:
采用更简单的路线并访问 not Should to vars:
然后将它们设置在 forloop 中:
它工作得很好:)
Took the easier route and accessed the not suppose to vars:
and then set them in the forloop:
it's working perfectly fine :)