Пример #1
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);
        }
Пример #2
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();
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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)));
        }