Example #1
0
 public static void AddObject(NObject obj)
 {
     if (objectIndex < objects.Length)
     {
         objects[objectIndex++] = obj;
     }
 }
Example #2
0
 public static void Initialize(int objectNumber, int h, int w)
 {
     objects = new NObject[objectNumber];
     for (int i = 0; i < objectNumber; i++)
     {
         AddObject(NObject.GenerateRandomObject(h, w));
     }
 }
Example #3
0
        protected override void GMLoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            for (int i = 0; i < Physics.objectIndex; i++)
            {
                NObject obj = Physics.objects[i];
                obj.LoadTexture(Content.Load <Texture2D>("circle"));
            }
        }
Example #4
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Gray);

            // TODO: Add your drawing code here
            _spriteBatch.Begin();

            for (int i = 0; i < Physics.objectIndex; i++)
            {
                NObject obj = Physics.objects[i];
                System.Numerics.Vector2 objPos = obj.getDrawVector();
                _spriteBatch.Draw(obj.Texture, new Vector2(objPos.X, objPos.Y) + window_Offset, null, obj.Color, 0, Vector2.Zero, obj.Size, SpriteEffects.None, 0);
            }

            _spriteBatch.End();
        }
Example #5
0
        public void CalculateVelocities()
        {
            while (Physics.globalRunning)
            {
                for (int i = offset; i < Physics.objectIndex; i += steps)
                {
                    for (int j = 0; j < Physics.objectIndex; j++)
                    {
                        NObject obj1 = Physics.objects[i];
                        NObject obj2 = Physics.objects[j];
                        if (obj1 == obj2)
                        {
                            continue;
                        }

                        double dirx      = obj2.posx - obj1.posx;
                        double diry      = obj2.posy - obj1.posy;
                        double dirLength = Math.Sqrt(dirx * dirx + diry * diry);
                        dirx /= dirLength;
                        diry /= dirLength;

                        double forceTwo = (Physics.gravity * obj1.Mass * obj2.Mass) / (dirLength * dirLength);

                        double forx = dirx * forceTwo;
                        double fory = diry * forceTwo;
                        if (Double.IsNaN(forx))
                        {
                            forx = 0;
                        }
                        if (Double.IsNaN(fory))
                        {
                            fory = 0;
                        }
                        lock (obj1)
                        {
                            obj1.velx      += (deltaTime * forx) / obj1.Mass;
                            obj1.vely      += (deltaTime * fory) / obj1.Mass;
                            obj1.temp_posx += deltaTime * obj1.velx;
                            obj1.temp_posy += deltaTime * obj1.vely;
                        }
                    }
                }
                WaitHandle.SignalAndWait(wStatus, nStatus);
            }
        }