【发布时间】:2014-06-20 07:40:14
【问题描述】:
我正在用 c# 开发一个游戏引擎,并且正在使用 BulletSharp 进行物理。除了立方体外,它运行良好:
http://i.stack.imgur.com/EPfrw.png
(Axis-Aligned Bounding box是透明的红色,模型是白色的)
休息时,站在他们的边缘。因为我是从 Collada 模型加载的,所以我正在创建一个 ConvexHullShape() 并将数据添加为矢量云。虽然使用BoxShape() 会更有效(并且工作正常),但我不能,因为不能保证所有模型都是立方体。我无法弄清楚为什么它们停留在顶点而不是平坦的边缘。我对ConvexHullShape 的实现是错误的,还是我需要使用不同类型的形状(以使物理正常工作)?
public RigidBody AddDynamicGeometry(ColladaGeometry geometry, Matrix4 transform)
{
List<Vector3> points = new List<Vector3>();
foreach (Triangle tri in geometry.triangles)
{
points.Add(tri.vertices[0]);
points.Add(tri.vertices[1]);
points.Add(tri.vertices[2]);
}
CollisionShape shape = new ConvexHullShape(points);
shape.UserObject = geometry;
collisionShapes.Add(shape);
RigidBody body = CreateRigidBody(geometry.triangles.Count * 10, transform, shape);
return body;
}
public RigidBody CreateRigidBody(float mass, Matrix4 startTransform, CollisionShape shape)
{
bool isDynamic = (mass != 0.0f);
Vector3 localInertia = Vector3.Zero;
if (isDynamic)
shape.CalculateLocalInertia(mass, out localInertia);
DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia);
RigidBody body = new RigidBody(rbInfo);
physics_world.AddRigidBody(body);
return body;
}
【问题讨论】:
标签: c# bulletphysics