# Binding BoundingSpheres to a world matrix in XNA

I made a program that loads the locations of items on the scene from a file like this:

using (StreamReader sr = new StreamReader(OpenFileDialog1.FileName))
{
String line;
while ((line = sr.ReadLine()) != null)
{
red = line.Split(',');
model = row[0];
x = row[1];
y = row[2];
z = row[3];
sfepheres.Add(new BoundingSphere(new Vector3(Convert.ToSingle(x), Convert.ToSingle(y), Convert.ToSingle(z)), 1f));
}


I also have a list of BoundingSpheres (called spheres) that adds a new bounding sphere for each line from the file. In this program I have one item (a simple box) that moves (it has its world matrix called matrixBox), and other items are static entire time (there is a world matrix that holds those elements called simply world). The problem i that when I move the box, bounding spheres move with it. So how can I bind all BoundingSpheres (except the one corresponding to the box) to the static world matrix so that they stay in their place when the box moves?

• How do you know the BoundingSphere objects are moving? How are you drawing them to the screen? Can you add the code for that to the question? How does the drawing differ the moving object and the static objects? – Matt Kemp Jul 11 '12 at 13:19
• I'm not drawing the BoundingSpheres, I draw the items that those BoundingSpheres should envelop. After the loading of the file, everything is placed correctly. For testing purposes, I implemented a simple picking algorithm that (when the ray intersects any of the Bounding spheres) moves the box per 0.01f down the x-axis with this code worldBox = Matrix.CreateTranslation(new Vector3(0.01f, 0f, 0f))*worldBox;. I know that the other boundingSpheres are moving because when I click the statc item, after a few moves the box stops and when I click a few pixels to the right, it starts moving again – NDraskovic Jul 11 '12 at 13:23
• In that case, how does your ray picker check against the bounding spheres? My thought is that, if worldBox is the only thing you're changing, it must co-incide somewhere with the picker algorithm. Two possible problems: 1) does the ray picker use the worldBox matrix? 2) If not, are world and worldBox created at the same time? Have you inadvertently got two references to the same matrix? – Matt Kemp Jul 11 '12 at 14:13
• You were right, I was using worldBox in calculating the ray picker. The bounding spheres are not moving now that I changed that part to simple world. Thanks a lot - can you just add that comment as an answer so I can mark it as correct – NDraskovic Jul 11 '12 at 14:24