private OutsideSimulatorApp(string title)
            : base(title)
        {
            //
            // Dirtyables...
            //
            ProjMatrix = new Dirtyable<SlimDX.Matrix>(() =>
            {
                return SlimDX.Matrix.PerspectiveFovLH(0.25f * (float)Math.PI, AspectRatio, 0.1f, 10000.0f);
            });

            //
            // Subscribers...
            //
            KeyDownSubscribers = new List<KeyDownSubscriber>();
            KeyUpSubscribers = new List<KeyUpSubscriber>();
            MouseDownSubscribers = new List<MouseDownSubscriber>();
            MouseWheelSubscribers = new List<MouseWheelSubscriber>();
            MouseMoveSubscribers = new List<MouseMoveSubscriber>();
            MouseUpSubscribers = new List<MouseUpSubscriber>();
            TimerTickSubscribers = new List<TimerTickSubscriber>();

            CommandStack = new CommandStack();
            Subscribe(CommandStack);

            RenderEffects = new List<RenderEffect>();
        }
示例#2
0
        private OutsideSimulatorApp(string title) : base(title)
        {
            //
            // Dirtyables...
            //
            ProjMatrix = new Dirtyable <SlimDX.Matrix>(() =>
            {
                return(SlimDX.Matrix.PerspectiveFovLH(0.25f * (float)Math.PI, AspectRatio, 0.1f, 10000.0f));
            });

            //
            // Subscribers...
            //
            KeyDownSubscribers    = new List <KeyDownSubscriber>();
            KeyUpSubscribers      = new List <KeyUpSubscriber>();
            MouseDownSubscribers  = new List <MouseDownSubscriber>();
            MouseWheelSubscribers = new List <MouseWheelSubscriber>();
            MouseMoveSubscribers  = new List <MouseMoveSubscriber>();
            MouseUpSubscribers    = new List <MouseUpSubscriber>();
            TimerTickSubscribers  = new List <TimerTickSubscriber>();

            CommandStack = new CommandStack();
            Subscribe(CommandStack);

            RenderEffects = new List <RenderEffect>();
        }
示例#3
0
        /// <summary>
        /// Initialize to whatever, it really doesn't matter.
        /// </summary>
        public Camera()
        {
            ViewMatrix = new Dirtyable<Matrix>(() =>
            {
                return Matrix.LookAtLH(Position, LookAt, Up);
            });

            Position = new Vector3(0.0f, 0.0f, 0.0f);
            Up = new Vector3(0.0f, 1.0f, 0.0f);
            LookAt = new Vector3(0.0f, 0.0f, -1.0f);
        }
示例#4
0
        /// <summary>
        /// Initialize to whatever, it really doesn't matter.
        /// </summary>
        public Camera()
        {
            ViewMatrix = new Dirtyable <Matrix>(() =>
            {
                return(Matrix.LookAtLH(Position, LookAt, Up));
            });

            Position = new Vector3(0.0f, 0.0f, 0.0f);
            Up       = new Vector3(0.0f, 1.0f, 0.0f);
            LookAt   = new Vector3(0.0f, 0.0f, -1.0f);
        }
 public void BadConstruction()
 {
     try
     {
         Dirtyable<int> BadIntDirtyable = new Dirtyable<int>(null);
         Assert.Fail("Dirtyable<int> should throw exception when created with null for its computation function");
     }
     catch (Exception ex)
     {
         Assert.IsInstanceOfType(ex, typeof(ArgumentNullException), "Exception thrown on bad creation of Dirtyable<int> should be of type ArgumentNullException");
     }
 }
        public void ConcurrentThreadedValueRequest()
        {
            // Perform this test multiple times, to try and catch a bad case
            for (int i = 0; i < 10; i++)
            {
                // On dirtying, takes a full second to recompute value, which is just 2.
                int askCount = 0;
                Dirtyable<int> expensiveDirtyable = null;
                expensiveDirtyable = new Dirtyable<int>(() =>
                {
                    Thread.Sleep(1000);
                    ++askCount;
                    return 2;
                });

                // Ask for Value twice, concurrently
                Stopwatch sw = new Stopwatch();
                Thread t1 = new Thread(() => {
                    Assert.AreEqual(2, expensiveDirtyable.Value, "The expensive dirtying operation still should just return 2... (from thread 1)");
                });
                Thread t2 = new Thread(() => {
                    Assert.AreEqual(2, expensiveDirtyable.Value, "The expensive dirtying operation still should just return 2... (from thread 2)");
                    Assert.AreEqual(1, askCount, "The dirtyable should lock the ComputeValue method, and only invoke it once in case of interleave");
                    sw.Stop();
                    Assert.IsTrue(sw.ElapsedMilliseconds >= 1000, "The dirtying method for this test should take more than 1000 ms");
                });

                // This won't be precise, but since the time frame is 1000 ms, it doesn't have to be.
                sw.Start();
                t1.Start();
                Thread.Sleep(5);
                t2.Start();

                t1.Join();
                t2.Join();

                askCount = 0;
            }
        }
        public SceneGraph(Matrix transformMatrix, IRenderable renderable = null)
        {
            //
            // Setup dirtyables...
            //
            D_Transform      = new Dirtyable <Matrix>(() => { return(Matrix.Transformation(Vector3.Zero, Quaternion.Identity, Scale, Vector3.Zero, Rotation, Translation)); });
            D_WorldTransform = new Dirtyable <Matrix>(() =>
            {
                if (Parent == null)
                {
                    return(D_Transform.Value);
                }
                else
                {
                    // TODO KAM: I'm not sure if this is the proper order in which to multiply matrices to find the WorldTransform
                    return(D_Transform.Value * Parent.D_WorldTransform.Value);
                }
            });

            //
            // Setup transformation data...
            //
            Vector3    trans;
            Quaternion rot;
            Vector3    scale;

            transformMatrix.Decompose(out scale, out rot, out trans);
            Translation = trans;
            Rotation    = rot;
            Scale       = scale;

            //
            // Setup other data...
            //
            Parent     = null;
            Children   = new Dictionary <string, SceneGraph>();
            Renderable = renderable;
        }
        public SceneGraph(Matrix transformMatrix, IRenderable renderable = null)
        {
            //
            // Setup dirtyables...
            //
            D_Transform = new Dirtyable<Matrix>(() => { return Matrix.Transformation(Vector3.Zero, Quaternion.Identity, Scale, Vector3.Zero, Rotation, Translation); });
            D_WorldTransform = new Dirtyable<Matrix>(() =>
            {
                if (Parent == null)
                {
                    return D_Transform.Value;
                }
                else
                {
                    // TODO KAM: I'm not sure if this is the proper order in which to multiply matrices to find the WorldTransform
                    return D_Transform.Value * Parent.D_WorldTransform.Value;
                }
            });

            //
            // Setup transformation data...
            //
            Vector3 trans;
            Quaternion rot;
            Vector3 scale;
            transformMatrix.Decompose(out scale, out rot, out trans);
            Translation = trans;
            Rotation = rot;
            Scale = scale;

            //
            // Setup other data...
            //
            Parent = null;
            Children = new Dictionary<string, SceneGraph>();
            Renderable = renderable;
        }
        public void Dirtying()
        {
            int k = 0;
            Dirtyable<int> BoringIntDirtyable = new Dirtyable<int>(() => { return ++k; });

            Assert.IsTrue(BoringIntDirtyable.Dirty, "Dirtyable should be dirty immediately after construction");
            Assert.AreEqual(1, BoringIntDirtyable.Value, "Dirtyable should compute value upon invoking Value property");
            Assert.IsFalse(BoringIntDirtyable.Dirty, "Dirtyable should be clean immediately after invoking Value property");

            BoringIntDirtyable.MakeDirty();
            Assert.IsTrue(BoringIntDirtyable.Dirty, "Dirtyable should be dirty immediately after doing the nasty");
            Assert.AreEqual(2, BoringIntDirtyable.Value, "Dirtyable should re-compute value upon invoking Value property after being dirtied");
            Assert.IsFalse(BoringIntDirtyable.Dirty, "Dirtyable should once again be clean after invoking Value property");
        }
 public void RegularConstruction()
 {
     Dirtyable<int> BoringIntDirtyable = new Dirtyable<int>(() => { return 2; });
     Assert.IsNotNull(BoringIntDirtyable, "Dirtyable<int> constructor should return a non-null reference to a new Dirtyable<int>");
     Assert.IsInstanceOfType(BoringIntDirtyable, typeof(Dirtyable<int>), "Value assigned from Dirtyable<int> constructor should be an instance of type Dirtyable<int>");
     Assert.IsTrue(BoringIntDirtyable.Dirty, "Upon construction, Dirtyable<int> should be dirty");
     Assert.IsNotNull(BoringIntDirtyable.ComputeValue, "Method which computes the value for a Dirtyable<int> should be set");
 }
        public void EventFiring()
        {
            int k = 5;
            bool FirstDependentChanged = false;
            bool SecondDependentChanged = false;
            Dirtyable<int> FirstDependentValue = new Dirtyable<int>(() => { return k * 2; });
            Dirtyable<int> SecondDependentValue = new Dirtyable<int>(() => { return FirstDependentValue.Value * 5; });

            FirstDependentValue.OnDirtied += (o, e) => { FirstDependentChanged = true; };
            SecondDependentValue.OnDirtied += (o, e) => { SecondDependentChanged = true; };

            FirstDependentValue.OnDirtied += (o, e) => { SecondDependentValue.MakeDirty(); };

            Assert.IsFalse(FirstDependentChanged, "OnUpdate event should not be fired on construction of an independent Dirtyable");
            Assert.IsFalse(SecondDependentChanged, "OnUpdate event should not be fired on construction of a dependent Dirtyable");

            Assert.AreEqual(5, k, "Integer value should equal what we told it to equal");
            Assert.AreEqual(10, FirstDependentValue.Value, "Independent Dirtyable should be equal to value expected on first invocation");
            Assert.AreEqual(50, SecondDependentValue.Value, "Dependent Dirtyable should be equal to value expected on first invocation");

            Assert.IsFalse(FirstDependentChanged, "Computation of value should not fire DependantChanged event on independent Dirtyable");
            Assert.IsFalse(SecondDependentChanged, "Computation of value should not fire DependantChanged event on dependant Dirtyable");

            k = 10;
            FirstDependentValue.MakeDirty();

            Assert.IsTrue(FirstDependentChanged, "Dependent Dirtyable should fire event on doing the nasty");
            Assert.IsTrue(SecondDependentChanged, "Independent Dirtyable should fire event when triggered from primary Dirtyable");

            Assert.AreEqual(10, k, "Integer value should equal what we told it to equal when re-assigning");
            Assert.AreEqual(20, FirstDependentValue.Value, "Independent Dirtyable should be equal to value expected on later invocation");
            Assert.AreEqual(100, SecondDependentValue.Value, "Dependent Dirtyable should be equal to value expected on later invocation");
        }