I am having a problem in Calculating the camera collision for my Room model which consists of sofa, tables and other models.
The users shall be moving the camera front, back, rotating so i need to make sure that the camera does not collide with any of the models with in the room.
I have treated all my models inside the room by BoundingBox[] and the camera by BoundingSphere. So, far i have implemented collision by looking into the tutorial from http://www.toymaker.info/Games/XNA/html/xna_model_collisions.html which was great. But, I guess the problem lies in the Transformation part. I debugged and found some points to be at Vector(-XXX,-XXX,-XXX) where X is digit.
Also i found my radius of some models where too large(in thousand, i just looked into its radius value before converting to BoundingBox). Do I need to scale the model for collision???
Below are my code:-
On My LoadContent():
Matrix[] transforms = new Matrix[myModel.Bones.Count];
myModel.CopyAbsoluteBoneTransformsTo(transforms);
int index = 0;
box = new List<BoundingBox>();
BoundingBox worldModel = Utility.CalculateBoundingBox(myModel);
foreach (ModelMesh mesh in myModel.Meshes)
{
Vector3[] obb = new Vector3[8];
worldModel.GetCorners(obb);
Vector3[] asdf = (Vector3[])obb.Clone();
Vector3.Transform(obb, ref transforms[mesh.ParentBone.Index], obb);
BoundingBox worldBox = BoundingBox.CreateFromPoints(obb);
box.Add(worldBox);
index++;
}
On CameraPosition Update:
BoundingSphere bs = new BoundingSphere(this.cameraPos, 5.0f);
if (RoomWalkthrough.Utility.CheckCollision(bs, bb))
{
// Do Something
}
Please Help.