应该设置球的哪些物理属性?
使用球的以下物理特性:
高尔夫球
// 创建圆形 b2CircleShape 圆; 圆.m_radius = 15.5/PTM_RATIO; // 创建球形定义并添加到主体 b2FixtureDef ballShapeDef; ballShapeDef.shape = &圆; ballShapeDef.密度 = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.2f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
板球
// 创建圆形 b2CircleShape 圆; 圆.m_radius = 17.0/PTM_RATIO; // 创建球形定义并添加到主体中 b2FixtureDef ballShapeDef; ballShapeDef.shape = &圆; ballShapeDef.密度 = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.4f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
铁球
// 创建圆形 b2CircleShape 圆; 圆.m_radius = 23.0/PTM_RATIO; // 创建球形定义并添加到主体中 b2FixtureDef ballShapeDef; ballShapeDef.shape = &圆; ballShapeDef.密度 = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.0f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
足球:
// 创建圆形 b2CircleShape 圆; 圆.m_radius = 24.0/PTM_RATIO; // 创建球形定义并添加到主体中 b2FixtureDef ballShapeDef; ballShapeDef.shape = &圆; ballShapeDef.密度 = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.8f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
篮球:
// 创建圆形 b2CircleShape 圆; 圆.m_radius = 24.0/PTM_RATIO; // 创建球形定义并添加到主体中 b2FixtureDef ballShapeDef; ballShapeDef.shape = &圆; ballShapeDef.密度 = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.6f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
作为一个新手,我所实现的一切都是基于猜测,并且我遇到了一些麻烦,例如卡住的障碍物、倾斜障碍物上该死的慢动作等等,所以如果有更好的方法解决方案,请把它们。
following physical properties of the balls is being used:
golfball
// Create circle shape b2CircleShape circle; circle.m_radius = 15.5/PTM_RATIO; // Create ball shape definition and add to body b2FixtureDef ballShapeDef; ballShapeDef.shape = &circle; ballShapeDef.density = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.2f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
cricketball
// Create circle shape b2CircleShape circle; circle.m_radius = 17.0/PTM_RATIO; // Create ball shape definition and add to body b2FixtureDef ballShapeDef; ballShapeDef.shape = &circle; ballShapeDef.density = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.4f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
ironball
// Create circle shape b2CircleShape circle; circle.m_radius = 23.0/PTM_RATIO; // Create ball shape definition and add to body b2FixtureDef ballShapeDef; ballShapeDef.shape = &circle; ballShapeDef.density = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.0f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
soccerball:
// Create circle shape b2CircleShape circle; circle.m_radius = 24.0/PTM_RATIO; // Create ball shape definition and add to body b2FixtureDef ballShapeDef; ballShapeDef.shape = &circle; ballShapeDef.density = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.8f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
basketball:
// Create circle shape b2CircleShape circle; circle.m_radius = 24.0/PTM_RATIO; // Create ball shape definition and add to body b2FixtureDef ballShapeDef; ballShapeDef.shape = &circle; ballShapeDef.density = 5000.0f; ballShapeDef.friction = 10.0f; ballShapeDef.restitution = 0.6f; ballFixture = ballBody->CreateFixture(&ballShapeDef);
Being a newbie, all I have implemented is based on guesses, and I'm having some troubles like stucked obstacle, damn slow motion on slant obstacle, and many other, so if there any better solution, please put them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我不建议您使用超过 100 的密度。它会提供糟糕的模拟效果。将密度保持在 1 - 100 范围内。就像动态物体的物体尺寸在 [0.1, 10] 范围内,静态物体的尺寸最大为 50(来自 box2d 文档)。通常摩擦力设置在 0 和 1 之间(也来自 box2d 文档)。因此,您必须在自己的单位中工作才能覆盖范围。例如,您可以将密度测量为克每 1 立方米。
要评估球的密度,您需要知道它的半径和质量。在这种情况下,您可以找到密度,单位为 m/V,其中 V 是体积。
要测量恢复原状,请在 YouTube 上找到一些视频,看看球被抛出时弹跳的高度。恢复将为 h2/h1,其中 h1 初始高度,h2 - 弹跳后的高度
First, I don't suggest you to use density more then 100. It will provide bad simulation. Keep the density in range 1 - 100. Like the sizes of the bodies in range [0.1, 10] for dynamic bodies and up to 50 for static (it's from box2d documentation). Usually friction is set between 0 and 1 (also from box2d documentation). So you have to work in your own units to feet the ranges. For example you can measure density as grams per 1 cubic santimeter.
To evaluate ball's density you need to know it's radius and mass. In this case you are able to found density as m/V, where V is the volume.
To measure restitution find some videos on youtube and see how high the ball bounces when thrown. The restitution will be h2/h1, where h1 initial height, h2 - height after bounce
我认为对此没有任何真正的答案,您可能必须选择对您来说最好的答案。不过有几点评论:密度极高,摩擦力应该在0-1之间,高尔夫球的恢复力实际上相当高。我建议从密度为 1 和摩擦力为 0.5 左右开始,然后从那里进行调整。
I don't think there is any real answer to this, you will likely have to go with what seems best to you. A few comments though: the density is extremely high, friction should be between 0-1, golf ball restitution is actually quite high. I would suggest starting with density of 1 and friction of around 0.5 and adjust from there.