Creating an update method in a different class
        Posted  
        
            by 
                Sweta Dwivedi
            
        on Game Development
        
        See other posts from Game Development
        
            or by Sweta Dwivedi
        
        
        
        Published on 2012-10-02T12:08:42Z
        Indexed on 
            2012/10/02
            15:54 UTC
        
        
        Read the original article
        Hit count: 333
        
xna-4.0
I have created a class called 3D model which will animate my 3D model by changing the model position according to the values based in a .txt file through a list... Since i'm using a foreach loop to read the point values when it reaches the end of the file.. XNA throws an out of bounds exception .. (which is obvious) but if i add the same code in my Game.cs update(gameTime) method.. then i dont have this problem..Any idea how to make my 3D model update work same as the update in game.cs ..
Here is the code for some idea:
public void patterns(GameTime gameTime)
{
    motion_z = new List<Point3D>();
    if (pattern == 1)
    {
        f = "E:/Motion_Track-output/Output1.txt";
    }
    if (pattern == 2)
    {
        f = "E:/Motion_Track-output/cruse.txt";
    }
    //   TODO: Add your update logic here
    using (StreamReader r = new StreamReader(f))
    {
        string line;
        //Viewport view = graphics.GraphicsDevice.Viewport;
        int maxWidth = view.Width;
        int maxHeight = view.Height;
        while ((line = r.ReadLine()) != null)
        {
            string[] temp = line.Split(',');
            int x = (int)Math.Floor(((float.Parse(temp[0]) * 0.5f) + 0.5f) * maxWidth);
            int y = (int)Math.Floor(((float.Parse(temp[1]) * -0.5f) + 0.5f) * maxHeight);
            int z = (int)Math.Floor(((float.Parse(temp[2]) / 4 * 20000)));
            motion_z.Add(new Point3D(x, y, z));
        }
        modelPosition.X = (float)(motion_z[i].X);
        modelPosition.Y = (float)(motion_z[i].Y);
        modelPosition.Z = (float)(motion_z[i].Z);
        i++;
    }
    //Console.WriteLine("modelposX:" + modelPosition.X + "," + "motionzX:" + motion_z[i].X);
}
© Game Development or respective owner