如何基于 b2Joint 实例化提取/创建 JointDef
我正在尝试序列化 b2World,由于 Box2D 有许多内部使用、创建和删除的私有对象,问题变得更加复杂。我决定应该使用这些内部对象 get() 函数来获取我需要的数据,并在保存时基于它创建一个“b2Definition”对象,并使用全局工厂“create”方法的定义来重新创建对象。
我遇到了一些需要帮助的问题:在下面的代码中是我需要的所有 JointDef 数据,但无法弄清楚如何从指针获取正确类型的对象。
我还想知道我是否应该尝试保存联系人数据......它是在工厂创建方法中自动创建的吗?
b2WeldJointDef JointDef; //QUESTION: how do i get this
//JointDef.referenceAngle= Joint-> ?????
b2GearJointDef JointDef; //QUESTION: how do i get these
//JointDef.joint1= Joint-> ??????
//JointDef.joint2= Joint-> ??????
b2LineJointDef JointDef; //QUESTION: how do i get these??
//JointDef.localAxisA= Joint-> ????
//JointDef.lowerTranslation= Joint-> ????
//JointDef.upperTranslation= Joint-> ????
b2MouseJointDef JointDef; //No problems
b2PrismaticJointDef JointDef; //QUESTION: how do i get these??
//JointDef.referenceAngle= Joint-> ????
//JointDef.localAxis1= Joint-> ????
//JointDef.lowerTranslation= Joint-> ???? //JointDef.upperTranslation= Joint-> ????
//JointDef.maxMotorForce= Joint-> ????
b2PulleyJointDef JointDef; //QUESTION: how do i get these?
//JointDef.maxLengthA= Joint-> ????
//JointDef.maxLengthB= Joint-> ????
b2RevoluteJointDef JointDef; //QUESTION: how do i get these?
//JointDef.maxMotorTorque= Joint-> ????
//JointDef.referenceAngle Joint-> ????
//JointDef.lowerAngle= Joint-> ????
//JointDef.upperAngle= Joint-> ????
b2JointDef JointDef;
//JointDef.collideConnected= ????
我需要上面的数据吗?有办法得到吗?
I'm trying to serialize a b2World, and due to Box2D's many private objects that are used, made, and deleted internally, the issue becomes much more complicated. I decided that i should use these internal objects get() functions to get the data i need, and create a "b2Definition" object based off it at save time, and use the definition with the global factories "create" methods to recreate the objects.
I have encountered a few problems i need help on however: In the following code is all the JointDef data i need, but can't figure out how to get from the pointer to the correct type of object.
I also am wondering if i should even attempt to save contact data.... Is it automatically made in the factory create metods?
b2WeldJointDef JointDef; //QUESTION: how do i get this
//JointDef.referenceAngle= Joint-> ?????
b2GearJointDef JointDef; //QUESTION: how do i get these
//JointDef.joint1= Joint-> ??????
//JointDef.joint2= Joint-> ??????
b2LineJointDef JointDef; //QUESTION: how do i get these??
//JointDef.localAxisA= Joint-> ????
//JointDef.lowerTranslation= Joint-> ????
//JointDef.upperTranslation= Joint-> ????
b2MouseJointDef JointDef; //No problems
b2PrismaticJointDef JointDef; //QUESTION: how do i get these??
//JointDef.referenceAngle= Joint-> ????
//JointDef.localAxis1= Joint-> ????
//JointDef.lowerTranslation= Joint-> ???? //JointDef.upperTranslation= Joint-> ????
//JointDef.maxMotorForce= Joint-> ????
b2PulleyJointDef JointDef; //QUESTION: how do i get these?
//JointDef.maxLengthA= Joint-> ????
//JointDef.maxLengthB= Joint-> ????
b2RevoluteJointDef JointDef; //QUESTION: how do i get these?
//JointDef.maxMotorTorque= Joint-> ????
//JointDef.referenceAngle Joint-> ????
//JointDef.lowerAngle= Joint-> ????
//JointDef.upperAngle= Joint-> ????
b2JointDef JointDef;
//JointDef.collideConnected= ????
Do i need the data above? Is there a way to get it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近做了很多这样的事情来制作一个导出/导入实用程序,将 Box2D 世界序列化为 JSON,然后再次加载它。您可能会发现源代码很有用 - 查看 http://www.iforce2d.net/b2djson 滚动至最下面可以看到源代码,看一下函数 b2dJson::b2j(b2Joint* joint)
并不复杂,只需要检查joint类型并转换为该类型的指针即可访问内容:
但需要注意一些事项:
I did a lot of this recently to make an export/import utility to serialize a Box2D world to JSON and then load it again. You may find the source code useful - check out http://www.iforce2d.net/b2djson Scroll towards the bottom and you can see the source code, look at the function b2dJson::b2j(b2Joint* joint)
It's not complicated, you just need to check the joint type and cast to a pointer of that type to access the contents:
A few things to note though: