示例#1
0
			public void Ball()
			{
				var ball = new Ball {DefaultColor = Color.Yellow};
				Assert.False(_modelFactory.TryGetResult(ball, out _model));
				ball.Radius = 5;
				Assert.That(_modelFactory.TryGetResult(ball, out _model));
				Assert.AreEqual(1, _model.Mesh.GetMaterials().Length);
			}
示例#2
0
		public static DirectXModel CreateBall(Device device, Ball ball)
		{
			var drmodel = new DirectXModel
			              	{
			              		Mesh = Mesh.CreateSphere(device, (float)ball.Radius, Slices, Slices),
			              		ModifierMatrix = Matrix.Translation(0, 0, (float)ball.Radius)
			              	};
			drmodel.Mesh.SetMaterials(new[] {ball.DefaultColor.GetDirectXMaterial()});
			return drmodel;
		}
示例#3
0
		public void TreeMovingConstantLocation()
		{
			var world = new Body();
			var boxLocation = new Frame3D(10, 0, 0);
			var ballLocation = new Frame3D(20, 10, 0);
			var box = new Box {Location = boxLocation};
			var ball = new Ball {Location = ballLocation};
			world.Add(box);
			world.Add(ball);
			box.DetachAttachMaintaingLoction(ball);
			Assert.AreEqual(boxLocation, box.Location);
			Assert.AreEqual(ballLocation, ball.GetAbsoluteLocation());
			Assert.AreEqual(new Frame3D(10, 10, 0), ball.Location);
			world.DetachAttachMaintaingLoction(ball);
			Assert.AreEqual(ballLocation, ball.Location);
			Assert.AreEqual(ballLocation, ball.GetAbsoluteLocation());
		}
示例#4
0
		public void Equal()
		{
			var x1 = new Ball
			         	{
			         		Radius = 3,
			         		DefaultColor =  Color.Yellow,
			         		Model = new Model {FilePath = "queen"}
			         	};
			var x2 = new Ball
			         	{
			         		Radius = 3,
			         		DefaultColor = Color.FromArgb(255, 255, 255, 0),
			         		Model = new Model {FilePath = "queen"}
			         	};
			var x3 = new Ball
			         	{
			         		Radius = 3,
			         		DefaultColor = Color.Yellow,
			         		Model = new Model {FilePath = "queen"}
			         	};
			Assert.That(_comparer.Equals(x1, x2));
			Assert.That(_comparer.Equals(x2, x3));
		}
示例#5
0
 public static double IntersectBall(Ball ball, Ray ray)
 {
     //Переменные для возврата корней квадратного уравнения
     double root1, root2;
     //Расчет коэффициентов решения системы уравнений сферы и луча
     var a = ray.Direction.MultiplyScalar(ray.Direction);
     //Вспомогательный вектор
     var location = new Point3D(ball.GetAbsoluteLocation().X, ball.GetAbsoluteLocation().Y, ball.GetAbsoluteLocation().Z + ball.Radius);
     var vec = ray.Origin - location;
     var b = 2 * ray.Direction.MultiplyScalar(vec);
     var c = vec.MultiplyScalar(vec) - Math.Pow(ball.Radius, 2);
     //Обработка решения
     if ((QuadEquation.Solution(a, b, c, out root1, out root2)) && ((root1 >= 0) | (root2 >= 0)))
         if (root1 >= 0)
         {
             return ray.DistanceTo(root1);
         }
         else
         {
             return ray.DistanceTo(root2);
         }
     return Double.PositiveInfinity;
 }
示例#6
0
		public void NotEqual()
		{
			var x1 = new Ball
			         	{
			         		Radius = 3,
			         		DefaultColor = Color.Yellow,
			         		Model = new Model {FilePath = "queen"}
			         	};
			var x2 = new Ball
			         	{
			         		Radius = 3,
			         		DefaultColor = Color.Green,
			         		Model = new Model {FilePath = "queen"}
			         	};
			var x3 = new Ball
			         	{
			         		Radius = 3,
			         		DefaultColor = Color.Yellow,
			         		Model = new Model {FilePath = "king"}
			         	};
			Assert.That(!_comparer.Equals(x1, x2));
			Assert.That(!_comparer.Equals(x2, x3));
			Assert.That(!_comparer.Equals(x1, x3));
		}
示例#7
0
		public void Visit(Ball visitable)
		{
			IPhysical physical = PhysicalManager.MakeCyllinder(visitable.Radius, visitable.Radius, visitable.Radius * 2);
            physical.Body = visitable;
            AfterCreating(visitable, physical);
		}
示例#8
0
 public void RayTest(Ray ray, Ball ball, double distance)
 {
     var computedDistance = Intersector.IntersectBall(ball, ray);
     Assert.AreEqual(distance, computedDistance);
     {
         //Console.WriteLine("Distance:  {0}. Expected: {1}", computedDistance, distance);
     }
 }