Esempio n. 1
0
            public void TestSaveVisibility()
            {
                var root = new Body
                {
                    Location = new Frame3D(10, 0, 0)
                };
                Body box = new Box
                {
                    Location = new Frame3D(10, 20, 30)
                };

                root.Add(box);
                var lo = new LoggingObject(box, root);

                lo.SaveVisibilityState(_totalTime);
                Assert.AreEqual(1, lo.VisibilityStates.Count);
                Assert.AreEqual(_totalTime, lo.VisibilityStates[0].StartTime);
                _totalTime++;
                lo.SaveVisibilityState(_totalTime);
                Assert.AreEqual(1, lo.VisibilityStates.Count);
                Assert.AreEqual(true, lo.VisibilityStates[0].IsVisible);
                root.Remove(box);
                _totalTime++;
                lo.SaveVisibilityState(_totalTime);
                Assert.AreEqual(_totalTime, lo.VisibilityStates.Last().StartTime);
                Assert.AreEqual(2, lo.VisibilityStates.Count);
                Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
            }
Esempio n. 2
0
            public void TestSavingVisibility2()
            {
                var root = new Body
                {
                    Location = new Frame3D(10, 0, 0)
                };
                Body box = new Box
                {
                    Location = new Frame3D(10, 20, 30)
                };
                var lo = new LoggingObject(box, root);

                for (int i = 0; i < 100; i++)
                {
                    lo.SaveVisibilityState(i);
                    Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
                    Assert.AreEqual(0, lo.VisibilityStates.Last().StartTime);
                }
                //body suddenly appears.
                const int updateTime = 100;

                root.Add(box);
                lo.SaveVisibilityState(updateTime);
                Assert.AreEqual(2, lo.VisibilityStates.Count);
                Assert.AreEqual(true, lo.VisibilityStates.Last().IsVisible);
                Assert.AreEqual(updateTime, lo.VisibilityStates.Last().StartTime);
            }
Esempio n. 3
0
			public void TestSaveVisibility()
			{
				var root = new Body
				           	{
				           		Location = new Frame3D(10, 0, 0)
				           	};
				Body box = new Box
				           	{
				           		Location = new Frame3D(10, 20, 30)
				           	};
				root.Add(box);
				var lo = new LoggingObject(box, root);
				lo.SaveVisibilityState(_totalTime);
				Assert.AreEqual(1, lo.VisibilityStates.Count);
				Assert.AreEqual(_totalTime, lo.VisibilityStates[0].StartTime);
				_totalTime ++;
				lo.SaveVisibilityState(_totalTime);
				Assert.AreEqual(1, lo.VisibilityStates.Count);
				Assert.AreEqual(true, lo.VisibilityStates[0].IsVisible);
				root.Remove(box);
				_totalTime++;
				lo.SaveVisibilityState(_totalTime);
				Assert.AreEqual(_totalTime, lo.VisibilityStates.Last().StartTime);
				Assert.AreEqual(2, lo.VisibilityStates.Count);
				Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
			}
Esempio n. 4
0
            public void TestLocation()
            {
                var root = new Body();
                var box  = new Box();

                root.Add(box);
                var      lo        = new LoggingObject(box, root);
                Movement movement1 = GetMovement(0, new Frame3D(1, 0, 0));

                lo.Movements.Add(movement1);
                Movement movement2 = GetMovement(300, new Frame3D(0, 1, 0));

                lo.Movements.Add(movement2);
                var     ol          = new ObjectLoader(lo, new Body());
                Frame3D expectedLoc = Frame3D.Identity;

                for (int i = 0; i <= _expectedLocations.Keys.Max(); i++)
                {
                    if (_expectedLocations.ContainsKey(i))
                    {
                        expectedLoc = _expectedLocations[i];
                    }
                    ol.LoadLocation(i);
                    Assert.AreEqual(expectedLoc, ol._loadedBody.Location);
                }
            }
Esempio n. 5
0
		public ObjectLoader(LoggingObject lo, Body world)
		{
			_world = world;
			_loadedBody = lo.Body;
			_loadedBody.Location = lo.InitialLocation;
			Movements = lo.Movements;
			VisibilityStates = lo.VisibilityStates;
		}
Esempio n. 6
0
			public void ZeroTime()
			{
				var root = new Body();
				var lo = new LoggingObject(root, root);
				lo.SaveBody(Frame3D.Identity, 0);
				Assert.AreEqual(1,lo.Movements.Count);
				Assert.AreEqual(1,lo.VisibilityStates.Count);
			}
Esempio n. 7
0
 public ObjectLoader(LoggingObject lo, Body world)
 {
     _world               = world;
     _loadedBody          = lo.Body;
     _loadedBody.Location = lo.InitialLocation;
     Movements            = lo.Movements;
     VisibilityStates     = lo.VisibilityStates;
 }
Esempio n. 8
0
            public void ZeroTime()
            {
                var root = new Body();
                var lo   = new LoggingObject(root, root);

                lo.SaveBody(Frame3D.Identity, 0);
                Assert.AreEqual(1, lo.Movements.Count);
                Assert.AreEqual(1, lo.VisibilityStates.Count);
            }
Esempio n. 9
0
 private static void MoveAndCheck(LoggingObject lo, Body box)
 {
     for (int i = 0; i < 5; i++)
     {
         box.Location = box.Location.Apply(new Frame3D(1, 1, 0));
         lo.SaveLocation(box.GetAbsoluteLocation(), _totalTime);
         Frame3D loc = lo.Movements.Last().NextLocation();
         Assert.AreEqual(box.GetAbsoluteLocation(), loc);
     }
     Assert.AreEqual(_totalTime, lo.Movements[_movementCount].StartTime);
     _totalTime += 0.1;
     _movementCount++;
     Assert.AreEqual(_movementCount, lo.Movements.Count);
 }
Esempio n. 10
0
        private void LogObjectsRecursively(Body body, Frame3D offset)
        {
            LoggingObject logged;

            if (!_loggingObjects.TryGetValue(body, out logged))
            {
                logged = new LoggingObject(body, _root);
                _loggingObjects.Add(body, logged);
            }
            logged.SaveBody(offset, _totalTime);
            _currentlyExistingBodies.Add(body);
            foreach (Body child in body.Nested)
            {
                LogObjectsRecursively(child, offset.Apply(child.Location));
            }
        }
Esempio n. 11
0
			public void TestSaveLocation1()
			{
				var root = new Body
				           	{
				           		Location = new Frame3D(10, 0, 0)
				           	};	
				Body box = new Box
				           	{
				           		Location = new Frame3D(10, 20, 30)
				           	};
				var lo = new LoggingObject(box, root);
				Assert.AreEqual(box, lo.Body);
				MoveAndCheck(lo, box);
				//now stop
				for(int i = 0; i < 3; i++)
					lo.SaveLocation(box.GetAbsoluteLocation(), 0.1);
				Assert.AreEqual(1, lo.Movements.Count);
				//move
				MoveAndCheck(lo, box);
			}
Esempio n. 12
0
            public void TestSaveLocation1()
            {
                var root = new Body
                {
                    Location = new Frame3D(10, 0, 0)
                };
                Body box = new Box
                {
                    Location = new Frame3D(10, 20, 30)
                };
                var lo = new LoggingObject(box, root);

                Assert.AreEqual(box, lo.Body);
                MoveAndCheck(lo, box);
                //now stop
                for (int i = 0; i < 3; i++)
                {
                    lo.SaveLocation(box.GetAbsoluteLocation(), 0.1);
                }
                Assert.AreEqual(1, lo.Movements.Count);
                //move
                MoveAndCheck(lo, box);
            }
Esempio n. 13
0
            public void TestVisibility(bool startVisible)
            {
                var root = new Body {
                    Type = "oldRoot"
                };
                var box = new Body {
                    Type = "oldBox"
                };

                if (startVisible)
                {
                    root.Add(box);
                }
                LoggingObject lo = SerializeAndDeserialize(new LoggingObject(box, root));

                lo.VisibilityStates.Add(new Visibility(startVisible, 0));
                const int visibilityChangedTime = 13;

                lo.VisibilityStates.Add(new Visibility(!startVisible, visibilityChangedTime));
                var ol = new ObjectLoader(lo, new Body());

                for (int i = 0; i < visibilityChangedTime * 2; i++)
                {
                    ol.LoadVisibility(i);
                    bool isAttached;
                    if (startVisible)
                    {
                        isAttached = i < visibilityChangedTime;
                    }
                    else
                    {
                        isAttached = i >= visibilityChangedTime;
                    }
                    Assert.AreEqual(isAttached, !lo.Body.TreeRoot.Equals(lo.Body));
                }
            }
Esempio n. 14
0
			public void TestSavingVisibility2()
			{
				var root = new Body
				           	{
				           		Location = new Frame3D(10, 0, 0)
				           	};
				Body box = new Box
				           	{
				           		Location = new Frame3D(10, 20, 30)
				           	};
				var lo = new LoggingObject(box, root);
				for (int i = 0; i < 100; i++)
				{
					lo.SaveVisibilityState(i);
					Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
					Assert.AreEqual(0, lo.VisibilityStates.Last().StartTime);
				}
				//body suddenly appears.
				const int updateTime = 100;
				root.Add(box);
				lo.SaveVisibilityState(updateTime);
				Assert.AreEqual(2, lo.VisibilityStates.Count);
				Assert.AreEqual(true, lo.VisibilityStates.Last().IsVisible);
				Assert.AreEqual(updateTime, lo.VisibilityStates.Last().StartTime);
			}
Esempio n. 15
0
			private static void MoveAndCheck(LoggingObject lo, Body box)
			{
				for(int i = 0; i < 5; i++)
				{
					box.Location = box.Location.Apply(new Frame3D(1, 1, 0));
					lo.SaveLocation(box.GetAbsoluteLocation(), _totalTime);
					Frame3D loc = lo.Movements.Last().NextLocation();
					Assert.AreEqual(box.GetAbsoluteLocation(), loc);
				}
				Assert.AreEqual(_totalTime, lo.Movements[_movementCount].StartTime);
				_totalTime += 0.1;
				_movementCount++;
				Assert.AreEqual(_movementCount, lo.Movements.Count);
			}
Esempio n. 16
0
		private void LogObjectsRecursively(Body body, Frame3D offset)
		{
			LoggingObject logged;
			if(!_loggingObjects.TryGetValue(body, out logged))
			{
				logged = new LoggingObject(body, _root);
				_loggingObjects.Add(body, logged);
			}
			logged.SaveBody(offset, _totalTime);
			_currentlyExistingBodies.Add(body);
			foreach(Body child in body.Nested)
				LogObjectsRecursively(child, offset.Apply(child.Location));
		}