Exemple #1
0
        public override void OnMouseMove(MouseEventArgs mouseEvent)
        {
            mouseOver = false;
            // find the ray for this control
            // check what face it hits
            // mark that face to draw a highlight
            base.OnMouseMove(mouseEvent);

            // rotate the view
            if (MouseDownOnWidget)
            {
                trackballTumbleWidgetExtended.DoRotateAroundOrigin(mouseEvent.Position);
            }
            else if (world != null &&
                     cubeTraceData != null)               // Make sure we don't use the trace data before it is ready
            {
                Ray           ray  = world.GetRayForLocalBounds(mouseEvent.Position);
                IntersectInfo info = cubeTraceData.GetClosestIntersection(ray);

                if (info != null)
                {
                    mouseOver = true;

                    DrawMouseHover(GetHitData(info.HitPosition));
                }
                else
                {
                    ResetTextures();
                }
            }
        }
Exemple #2
0
        public override void OnMouseMove(MouseEventArgs mouseEvent)
        {
            // find the ray for this control
            // check what face it hits
            // mark that face to draw a highlight
            base.OnMouseMove(mouseEvent);

            // rotate the view
            if (MouseDownOnWidget)
            {
                var        movePosition             = mouseEvent.Position;
                Quaternion activeRotationQuaternion = TrackBallController.GetRotationForMove(new Vector2(Width / 2, Height / 2), world, Width, lastMovePosition, movePosition, false);

                if (activeRotationQuaternion != Quaternion.Identity)
                {
                    lastMovePosition = movePosition;
                    interactionLayer.World.RotationMatrix = interactionLayer.World.RotationMatrix * Matrix4X4.CreateRotation(activeRotationQuaternion);
                    interactionLayer.Invalidate();
                }
            }
            else if (world != null &&
                     cubeTraceData != null)               // Make sure we don't use the trace data before it is ready
            {
                Ray           ray  = world.GetRayForLocalBounds(mouseEvent.Position);
                IntersectInfo info = cubeTraceData.GetClosestIntersection(ray);

                if (info != null)
                {
                    var uV = ((TriangleShapeUv)info.closestHitObject).GetUv(info);
                }
            }
        }
        public override void OnMouseMove(MouseEventArgs mouseEvent)
        {
            mouseOver = false;
            // find the ray for this control
            // check what face it hits
            // mark that face to draw a highlight
            base.OnMouseMove(mouseEvent);

            // rotate the view
            if (MouseDownOnWidget)
            {
                var        movePosition             = mouseEvent.Position;
                Quaternion activeRotationQuaternion = TrackBallController.GetRotationForMove(new Vector2(Width / 2, Height / 2), Width, lastMovePosition, movePosition, false);

                if (activeRotationQuaternion != Quaternion.Identity)
                {
                    lastMovePosition = movePosition;
                    object3DControlLayer.World.RotationMatrix = object3DControlLayer.World.RotationMatrix * Matrix4X4.CreateRotation(activeRotationQuaternion);
                    object3DControlLayer.Invalidate();
                }
            }
            else if (world != null &&
                     cubeTraceData != null)               // Make sure we don't use the trace data before it is ready
            {
                Ray           ray  = world.GetRayForLocalBounds(mouseEvent.Position);
                IntersectInfo info = cubeTraceData.GetClosestIntersection(ray);

                if (info != null)
                {
                    mouseOver = true;

                    DrawMouseHover(GetHitData(info.HitPosition));
                }
                else
                {
                    ResetTextures();
                }
            }
        }
Exemple #4
0
        public void WorldViewPerspectiveProjectionTests()
        {
            var world = new WorldView(1, 1);

            Assert.IsTrue(world.EyePosition.Equals(Vector3.UnitZ * 7, 1e-3));
            world.CalculatePerspectiveMatrixOffCenter(567, 123, -200, 5, 55);
            Assert.IsTrue(world.GetScreenPosition(new Vector3(0, 0, 0)).Equals(new Vector2((567 - 200) / 2.0, 123 / 2.0), 1e-3));
            Assert.AreEqual(5, world.NearZ, 1e-3);
            Assert.AreEqual(55, world.FarZ, 1e-3);
            Assert.AreEqual(4.14213562373095, world.NearPlaneHeightInViewspace, 1e-3);
            var ray = world.GetRayForLocalBounds(new Vector2((567 - 200) / 2.0, 123));             // top center

            Assert.AreEqual(WorldView.DefaultPerspectiveVFOVDegrees / 2, MathHelper.RadiansToDegrees(Math.Atan2(ray.directionNormal.Y, -ray.directionNormal.Z)), 1e-3);
            Assert.IsTrue((Vector3.UnitZ * 7).Equals(ray.origin, 1e-3));
            Assert.AreEqual(world.NearPlaneHeightInViewspace * 2, world.GetViewspaceHeightAtPosition(new Vector3(1, 1, -10)), 1e-3);
            world.Scale = 3;
            Assert.AreEqual(world.NearPlaneHeightInViewspace * 2 / 3, world.GetWorldUnitsPerScreenPixelAtPosition(new Vector3(1, 1, (7 - 10) / 3.0)) * 123, 1e-3);
        }
Exemple #5
0
        public void WorldViewOrthographicProjectionTests()
        {
            var world = new WorldView(1, 1);

            Assert.IsTrue(world.EyePosition.Equals(Vector3.UnitZ * 7, 1e-3));
            world.CalculateOrthogrphicMatrixOffCenterWithViewspaceHeight(680, 240, -200, 128, 5, 55);
            Assert.IsTrue(world.GetScreenPosition(new Vector3(0, 0, 0)).Equals(new Vector2((680 - 200) / 2.0, 240 / 2.0), 1e-3));
            Assert.IsTrue(world.GetScreenPosition(new Vector3(128, 64, 0)).Equals(new Vector2(680 - 200, 240), 1e-3));
            Assert.IsTrue(world.GetScreenPosition(new Vector3(-128, -64, 0)).Equals(new Vector2(0, 0), 1e-3));
            Assert.AreEqual(5, world.NearZ, 1e-3);
            Assert.AreEqual(55, world.FarZ, 1e-3);
            Assert.AreEqual(128, world.NearPlaneHeightInViewspace, 1e-3);
            var ray = world.GetRayForLocalBounds(new Vector2((680 - 200) / 2.0, 240));             // top center

            Assert.IsTrue(Vector3.UnitZ.Equals(-ray.directionNormal.GetNormal(), 1e-3));
            Assert.IsTrue(new Vector3(0, 64, 2).Equals(ray.origin, 1e-3));
            Assert.AreEqual(world.NearPlaneHeightInViewspace, world.GetViewspaceHeightAtPosition(new Vector3(1, 1, -10)), 1e-3);
            world.Scale = 3;
            Assert.AreEqual(world.NearPlaneHeightInViewspace / 3, world.GetWorldUnitsPerScreenPixelAtPosition(new Vector3(1, 1, (7 - 10) / 3.0)) * 240, 1e-3);
        }
Exemple #6
0
 public Ray GetRay(double screenX, double screenY)
 {
     return(world.GetRayForLocalBounds(new Vector2(screenX, screenY)));
 }