Example #1
0
        private void MoveSceneUsingMouse(Vector movement)
        {
            var translation = Transformations3D.Translation(new Vector3D(movement.X * 0.001, movement.Y * 0.001, 0));

            _worldTransformation = translation * _worldTransformation;
            RefreshImage();
        }
Example #2
0
        private Matrix4X4 GetProjectionMatrix(PerspectiveType perspectiveType)
        {
            var camera = Scene?.Camera;

            if (camera == null)
            {
                return(Matrix4X4.Identity);
            }

            var aspectMatrix = Transformations3D.Scaling(new Vector3D(1.0 / _aspectRatio, 1.0, 1.0));

            Matrix4X4 projection;

            switch (perspectiveType)
            {
            case PerspectiveType.Standard:
                projection = aspectMatrix * camera.GetPerspectiveMatrix();
                break;

            case PerspectiveType.LeftEye:
                projection = aspectMatrix * camera.GetPerspectiveMatrix(-EyeDistance);
                break;

            case PerspectiveType.RightEye:
                projection = aspectMatrix * camera.GetPerspectiveMatrix(+EyeDistance);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(perspectiveType), perspectiveType, null);
            }
            return(projection);
        }
Example #3
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (!_mouseLMBDown)
            {
                return;
            }

            var position = e.GetPosition(this);
            var movement = position - _previousPosition;

            _previousPosition = position;

            if (Keyboard.IsKeyDown(Key.LeftShift))
            {
                MoveSceneUsingMouse(movement);
                return;
            }

            var rotationMatrix = Transformations3D.RotationY(0.005 * movement.X)
                                 * Transformations3D.RotationX(0.005 * movement.Y);

            _worldTransformation = rotationMatrix * _worldTransformation;

            RefreshImage();
        }
Example #4
0
        private void OnMouseWheel(object sender, MouseWheelEventArgs e)
        {
            var scalingFactor = Math.Max(0, 1.0 + e.Delta * 0.002);
            var scalingMatrix = Transformations3D.Scaling(scalingFactor);

            _worldTransformation = scalingMatrix * _worldTransformation;

            RefreshImage();
        }
Example #5
0
        public Matrix4X4 GetWorldMatrix()
        {
            var translation = Transformations3D.Translation((Vector3D)Position);
            var rotation    = Transformations3D.RotationX(Orientation.X)
                              * Transformations3D.RotationY(Orientation.Y)
                              * Transformations3D.RotationZ(Orientation.Z);
            var scaling = Transformations3D.Scaling(Scale);

            return(translation * rotation * scaling);
        }
Example #6
0
        public Matrix4X4 GetViewMatrix()
        {
            var scale       = Transformations3D.Scaling(Zoom);
            var translation = Transformations3D.Translation(-(Vector3D)Position);
            var rotation    = Transformations3D.RotationX(XRotation) *
                              Transformations3D.RotationY(YRotation);
            var d    = Transformations3D.Translation(new Vector3D(0, 0, ObserverOffset));
            var invd = Transformations3D.Translation(new Vector3D(0, 0, -ObserverOffset));

            return(scale * invd * rotation * d * translation);
        }
Example #7
0
        public Matrix4X4 GetViewMatrix()
        {
            var vec       = new Vector3D(0, 0, -1);
            var transform = Transformations3D.Scaling(Zoom)
                            * Transformations3D.RotationY(YRotation)
                            * Transformations3D.RotationX(XRotation);
            var eye = (Point3D)(vec.ExtendTo4D().Transform(transform));

            return(Transformations3D.LookAt(
                       eye,
                       new Point3D(0, 0, 0),
                       new Vector3D(0, 1, 0)));
        }
Example #8
0
        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.A:
                _worldTransformation = Transformations3D.Translation(new Vector3D(0, 0, +0.5)) * _worldTransformation;
                RefreshImage();
                break;

            case Key.Z:
                _worldTransformation = Transformations3D.Translation(new Vector3D(0, 0, -0.5)) * _worldTransformation;
                RefreshImage();
                break;
            }
        }
Example #9
0
 public Matrix4X4 GetPerspectiveMatrix(double xEyeShift = 0)
 {
     return(Transformations3D.SimplePerspectiveWithEyeShift(2.0, xEyeShift));
 }
Example #10
0
 public Matrix4X4 GetPerspectiveMatrix(double xEyeShift)
 {
     return(Transformations3D.SimplePerspectiveWithEyeShift(ObserverOffset, xEyeShift));
 }