检查XNA 4.0 3D中的一个立方体,球体或任何模型的碰撞? [英] Check collision one cube, sphere or any models in XNA 4.0 3D?

查看:106
本文介绍了检查XNA 4.0 3D中的一个立方体,球体或任何模型的碰撞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查一个模型与另一个模型的碰撞.我使用碰撞检查功能,如下所示:

I want to check the collision of one model with another model.I use collision check function as follows:

//Built Bouding Sphere
 private void builtBoudingSphere()
        {
            BoundingSphere sphere = new BoundingSphere(Vector3.Zero, 0);
            foreach (ModelMesh mesh in Model.Meshes)
            {              
                BoundingSphere tranformed = mesh.BoundingSphere.Transform(modelTranforms[mesh.ParentBone.Index]);
                sphere = BoundingSphere.CreateMerged(sphere, tranformed);
            }
            this.boudingSphere = sphere;
        }
//Check Collision
 public bool CheckColision(CModel otherModel)
        {              
            return (this.BoudingSphere.Contains(otherModel.BoudingSphere)==ContainmentType.Intersects);
        }
//BoundingSphere Property
 public BoundingSphere BoudingSphere
        {
            get 
            {
                Matrix worldTranform = Matrix.CreateScale(Scale) * Matrix.CreateTranslation(Positon);
                BoundingSphere transformed = boudingSphere;
                transformed = transformed.Transform(worldTranform);
                return transformed;
            }
        }


CheckCollion函数适用于球形模型,但不适用于多维数据集或任何模型,因为我使用的是check BoudingSphere.可以帮助我检查准确的Collison吗? 特别检查多维数据集之间的碰撞.


The function CheckCollion is great with sphere model but not good with cube or any models because I''m use check BoudingSphere. Can help me check accurate collison? Especially check collision between cubes.

推荐答案

计划将其拆分成较小的块以查看碰撞.这是可以接受的解决方案.使用 BoudingSphere 检查碎片.
例如:飞机,分裂:头架飞机,尾翼飞机,机翼飞机.并检查每个零件是否碰撞.
Plan to split into smaller pieces to review collision.It can be a solution acceptable. Use BoudingSphere to check that pieces.
Example: the airplane, split: head airplane, tail airplane, wing airplane. And check each part for collision.


这篇关于检查XNA 4.0 3D中的一个立方体,球体或任何模型的碰撞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆