BoundingSpheres move when they should not

Posted by NDraskovic on Game Development See other posts from Game Development or by NDraskovic
Published on 2012-07-09T11:41:39Z Indexed on 2012/07/09 15:25 UTC
Read the original article Hit count: 236

I have a XNA 4.0 project in which I load a file that contains type and coordinates of items I need to draw to the screen. Also I need to check if one particular type (the only movable one) is passing in front or trough other items. This is the code I use to load the configuration:

    if (ks.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.L))
    {
        this.GraphicsDevice.Clear(Color.CornflowerBlue);
        Otvaranje.ShowDialog();
        try
        {
            using (StreamReader sr = new StreamReader(Otvaranje.FileName))
            {
                String linija;
                while ((linija = sr.ReadLine()) != null)
                {
                    red = linija.Split(',');                          
                    model = red[0];
                    x = red[1];
                    y = red[2];
                    z = red[3];
                    elementi.Add(Convert.ToInt32(model));
                    podatci.Add(new Vector3(Convert.ToSingle(x), Convert.ToSingle(y), Convert.ToSingle(z)));

                    sfere.Add(new BoundingSphere(new Vector3(Convert.ToSingle(x), Convert.ToSingle(y), Convert.ToSingle(z)), 1f));

                }
            }                   
        }
        catch (Exception ex)
        {
            Window.Title = ex.ToString();
        }
    }

The "Otvaranje" is an OpenFileDialog object, "elementi" is a List (determines the type of item that would be drawn), podatci is a List (determines the location where the items will be drawn) and sfere is a List. Now I solved the picking algorithm (checking for ray and bounding sphere intersection) and it works fine, but the collision detection does not. I noticed, while using picking, that BoundingSphere's move even though the objects that they correspond to do not. The movable object is drawn to the world1 Matrix, and the static objects are drawn into the world2 Matrix (world1 and world2 have the same values, I just separated them so that the static elements would not move when the movable one does). The problem is that when I move the item I want, all boundingSpheres move accordingly. How can I move only the boundingSphere that corresponds to that particular item, and leave the rest where they are?

© Game Development or respective owner

Related posts about collision-detection

Related posts about xna-4.0