public void checkCollsion(ball other) { if (new BoundingSphere(this.pos, this.radius).Intersects(new BoundingSphere(other.pos, other.radius))) { Vector3 axis = other.pos - this.pos; float dist = other.radius + this.radius; float move = (dist - axis.Length()) / 2f; axis.Normalize(); Vector3 U1x = axis * (Vector3.Dot(axis, this.vel)); Vector3 U1y = this.vel - U1x; Vector3 U2x = -axis *Vector3.Dot(-axis, other.vel); Vector3 U2y = other.vel - U2x; Vector3 V1x = U2x; Vector3 V2x = U1x; this.vel = V1x + U1y; other.vel = V2x + U2y; this.vel *= 0.99f; other.vel *= .99f; other.pos += axis * move; this.pos -= axis * move; } }
protected override void LoadContent()//load in mesh { _spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here ball = Content.Load <Model>("sphere"); plane = Content.Load <Model>("plane"); dish = Content.Load <Model>("dish"); rand = new Random(); b = new ball(new Vector3(30, 25, 30), ball.Meshes[0].BoundingSphere.Radius); ballList = new List <ball>(); for (int i = 0; i < 50; i++) { ballList.Add(b = new ball(new Vector3((float)rand.NextDouble() * 30, 25, (float)rand.NextDouble() * 30), ball.Meshes[0].BoundingSphere.Radius)); } }