Example #1
0
        /// <summary>
        /// 更新camera参数
        /// </summary>
        public void UpdateCamera()
        {
            //首先计算LookAt点所在世界坐标系
            var centerLookAt = _shape.ToVector3(new Geodetic3D(_lookAtInfo.Longitude, _lookAtInfo.Latitude, _lookAtInfo.Altitude));
            //描述一个基于基本参考系的旋转平移之后的参考系
            var transform = Shape.GeographicToCartesianTransform2(new Geodetic3D(_lookAtInfo.Longitude, _lookAtInfo.Latitude, _lookAtInfo.Altitude));
            //对这个参考系再进行旋转
            //var transformLocal = Matrix4x4.CreateFromYawPitchRoll(0,(float)_lookAtInfo.Tilt, -(float)_lookAtInfo.Heading);
            //v
            var localTransformheading = Matrix4x4.CreateFromAxisAngle(Vector3.UnitZ, (float)_lookAtInfo.Heading);
            //
            var localTransformTilt = Matrix4x4.CreateFromAxisAngle(Vector3.UnitX, (float)_lookAtInfo.Tilt);

            //再创建平移矩阵
            var transTransform = Matrix4x4.CreateTranslation(0, 0, (float)_lookAtInfo.Range);
            //var localTransformheading2=  Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)_lookAtInfo.Heading);
            //var result1 = Matrix4x4.Transform(transform, localTransformheading2);
            //var result2 = transform * localTransformheading;

            //var transformAll2 = transTransform*(localTransformTilt*(localTransformheading*(localTransformheading*transform)));
            //var tttt = transform * localTransformheading * localTransformTilt;
            //* transTransform;
            var tttt = transTransform * localTransformTilt * localTransformheading * transform;

            //求其转置矩阵,
            _positon = tttt.Translation;
            var unitY = Vector3.Transform(Vector3.UnitY, Quaternion.CreateFromRotationMatrix(tttt));
            // _viewMatrix = tttt.InvertOrthonormal();
            //_positon = _viewMatrix.ExtractEyePosition();
            // _positon = new Vector3(_positon.X,-_positon.Y,_positon.Z);
            var target = Vector3.Transform(-Vector3.UnitZ, Quaternion.CreateFromRotationMatrix(tttt));

            _viewMatrix = Matrix4x4.CreateLookAt(_positon, _positon + target, unitY);
        }
Example #2
0
        /// <summary>
        /// 更新camera参数
        /// </summary>
        private void UpdateCamera()
        {
            //首先计算LookAt点,也即是相机参考系的原点
            //计算
            var centerEarth = _shape.ToVector3(new Geodetic2D(_cameraInfo.Longitude, _cameraInfo.Latitude));
            var transform   = Shape.geographicToCartesianTransform(new Geodetic3D(_cameraInfo.Longitude, _cameraInfo.Latitude, _cameraInfo.Altitude));
            //再次旋转Tile和heading,roll这里先不管
            var transformLocal = Matrix4x4.CreateFromYawPitchRoll(0, -(float)_cameraInfo.Tilt, -(float)_cameraInfo.Heading);
            //这里的transform是经过两次变换,第一次是经纬度的变化,第二次是rollpitch的变化,此时的矩阵还并不是视图矩阵,因为Camera的Z与世界坐标系是相反的,因此我们
            //世界参考系是右手参考系,相机参考系为左手参考系,此transform中的平移量即为相机坐标,相机的三个坐标系可据此进行变换,注意,只需要使用变换矩阵的旋转变量参数(一个四元组)即可
            var transoformAll = transform * transformLocal;

            var scale          = Matrix4x4.Decompose(transoformAll, out Vector3 scale1, out Quaternion rotation1, out Vector3 translation1);
            var cameraPosition = transoformAll.Translation;

            _positon = transoformAll.Translation;
            var cameraUp = Vector3.Transform(Vector3.UnitY, Quaternion.CreateFromRotationMatrix(transoformAll));
            var cameraZ  = Vector3.Transform(-Vector3.UnitZ, Quaternion.CreateFromRotationMatrix(transoformAll));
            var target   = cameraZ;

            //相机一直朝向当前相机的中心点,且此夹角不能超过90度
            _viewMatrix = Matrix4x4.CreateLookAt(cameraPosition, centerEarth, cameraUp);
            // _viewMatrix = transformAll;
        }