Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I want to check the collision of one model with another model.I use collision check function as follows:
C#
//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;
            }
        }

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.
Posted
Updated 25-Oct-12 7:38am
v3
Comments
Sergey Alexandrovich Kryukov 22-Sep-12 22:50pm    
It depends on what accuracy do you want to achieve in your engine. What bounding shape do you want to have? If you want more or less realistic shape, the analysis of collisions can become quite difficult.
--SA
Sandeep Mewara 23-Sep-12 3:15am    
Reply from OP:
Yes, it's very difficult! I plan to split into smaller pieces to review collision.It can be a solution acceptable.
Sergey Alexandrovich Kryukov 2-Oct-12 17:52pm    
I just sent you a message: you should not re-post; and it cannot help you.
It's extremely unlikely that you could get an answer, especially in this forum. It means a lot of work, really.
--SA

1 solution

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900