Exemplo n.º 1
0
        public void SetupMatricesSolarSystem(bool forStars)
        {
            Lighting = Settings.Active.SolarSystemLighting;

            Space = false;
            if (SolarSystemTrack != SolarSystemObjects.Custom && SolarSystemTrack != SolarSystemObjects.Undefined)
            {
                ViewCamera.ViewTarget = Planets.GetPlanetTargetPoint(SolarSystemTrack, ViewCamera.Lat, ViewCamera.Lng, 0);
            }
            RenderTriangle.CullInside = false;


            double cameraDistance = SolarSystemCameraDistance;

            Matrix3d trackingMatrix = Matrix3d.Identity;

            cameraDistance -= 0.000001;

            bool activeTrackingFrame = false;
            //if (SolarSystemTrack == SolarSystemObjects.Custom && !string.IsNullOrEmpty(TrackingFrame))
            //{
            //    activeTrackingFrame = true;
            //    viewCamera.ViewTarget = LayerManager.GetFrameTarget(RenderContext, TrackingFrame, out trackingMatrix);
            //}
            //else if (!string.IsNullOrEmpty(TrackingFrame))
            {
                TrackingFrame = "";
            }


            Vector3d center = ViewCamera.ViewTarget;
            //Vector3d lightPosition = -center;

            double   localZoom = ViewCamera.Zoom * 20;
            Vector3d lookAt    = new Vector3d();

            Matrix3d viewAdjust = Matrix3d.Identity;

            viewAdjust.Multiply(Matrix3d.RotationX(((-ViewCamera.Lat) / 180f * Math.PI)));
            viewAdjust.Multiply(Matrix3d.RotationY(((-ViewCamera.Lng) / 180f * Math.PI)));

            Matrix3d lookAtAdjust = Matrix3d.Identity;


            bool dome = false;

            Vector3d lookUp;


            if (useSolarSystemTilt && !SandboxMode)
            {
                double angle = ViewCamera.Angle;
                if (cameraDistance > 0.0008)
                {
                    angle = 0;
                }
                else if (cameraDistance > 0.00001)
                {
                    double val = Math.Min(1.903089987, Util.Log10(cameraDistance) + 5) / 1.903089987;

                    angle = angle * Math.Max(0, 1 - val);
                }



                CameraPosition = Vector3d.Create(
                    (Math.Sin(-ViewCamera.Rotation) * Math.Sin(angle) * cameraDistance),
                    (Math.Cos(-ViewCamera.Rotation) * Math.Sin(angle) * cameraDistance),
                    ((Math.Cos(angle) * cameraDistance)));
                lookUp = Vector3d.Create(Math.Sin(-ViewCamera.Rotation), Math.Cos(-ViewCamera.Rotation), 0.00001f);
            }
            else
            {
                CameraPosition = Vector3d.Create(0, 0, ((cameraDistance)));

                lookUp = Vector3d.Create(Math.Sin(-ViewCamera.Rotation), Math.Cos(-ViewCamera.Rotation), 0.0001f);
            }


            CameraPosition = viewAdjust.Transform(CameraPosition);

            cameraOffset = CameraPosition.Copy();

            Matrix3d tmp = trackingMatrix.Clone();

            tmp.Invert();
            cameraOffset = Vector3d.TransformCoordinate(cameraOffset, tmp);



            lookUp = viewAdjust.Transform(lookUp);


            // WorldMatrix = Matrix3d.Identity;
            World     = Matrix3d.Identity;
            WorldBase = World.Clone();


            View = Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(trackingMatrix, Matrix3d.LookAtLH(CameraPosition, lookAt, lookUp)), lookAtAdjust);


            ViewBase = View.Clone();


            Vector3d temp = Vector3d.SubtractVectors(lookAt, CameraPosition);

            temp.Normalize();
            temp = Vector3d.TransformCoordinate(temp, trackingMatrix);
            temp.Normalize();
            viewPoint = temp;



            //if (activeTrackingFrame)
            //{
            //    Vector3d atfCamPos = RenderContext11.CameraPosition;
            //    Vector3d atfLookAt = lookAt;
            //    Vector3d atfLookUp = lookUp;
            //    Matrix3d mat = trackingMatrix;
            //    mat.Invert();

            //    atfCamPos.TransformCoordinate(mat);
            //    atfLookAt.TransformCoordinate(mat);
            //    atfLookUp.TransformCoordinate(mat);
            //    atfLookAt.Normalize();
            //    atfLookUp.Normalize();

            //    CustomTrackingParams.Angle = 0;
            //    CustomTrackingParams.Rotation = 0;
            //    CustomTrackingParams.DomeAlt = viewCamera.DomeAlt;
            //    CustomTrackingParams.DomeAz = viewCamera.DomeAz;
            //    CustomTrackingParams.TargetReferenceFrame = "";
            //    CustomTrackingParams.ViewTarget = viewCamera.ViewTarget;
            //    CustomTrackingParams.Zoom = viewCamera.Zoom;
            //    CustomTrackingParams.Target = SolarSystemObjects.Custom;


            //    Vector3d atfLook = atfCamPos - atfLookAt;
            //    atfLook.Normalize();



            //    Coordinates latlng = Coordinates.CartesianToSpherical2(atfLook);
            //    CustomTrackingParams.Lat = latlng.Lat;
            //    CustomTrackingParams.Lng = latlng.Lng - 90;

            //    Vector3d up = Coordinates.GeoTo3dDouble(latlng.Lat + 90, latlng.Lng - 90);
            //    Vector3d left = Vector3d.Cross(atfLook, up);

            //    double dotU = Math.Acos(Vector3d.Dot(atfLookUp, up));
            //    double dotL = Math.Acos(Vector3d.Dot(atfLookUp, left));

            //    CustomTrackingParams.Rotation = dotU;// -Math.PI / 2;
            //}


            double radius = Planets.GetAdjustedPlanetRadius((int)SolarSystemTrack);


            if (cameraDistance < radius * 2.0 && !forStars)
            {
                nearPlane = cameraDistance * 0.03;

                //m_nearPlane = Math.Max(m_nearPlane, .000000000030);
                nearPlane = Math.Max(nearPlane, .00000000001);
                back      = 1900;
            }
            else
            {
                if (forStars)
                {
                    back      = 900056;
                    back      = cameraDistance > 900056 ? cameraDistance * 3 : 900056;
                    nearPlane = .00003f;

                    // m_nearPlane = cameraDistance * 0.03;

                    // back = 9937812653;
                    //  back = 21421655730;
                }
                else
                {
                    back = cameraDistance > 1900 ? cameraDistance + 200 : 1900;

                    // m_nearPlane = .0001f;
                    if (Settings.Active.SolarSystemScale < 13)
                    {
                        nearPlane = (float)Math.Min(cameraDistance * 0.03, 0.01);
                    }
                    else
                    {
                        nearPlane = .001f;
                    }
                }
            }


            Projection     = Matrix3d.PerspectiveFovLH((fovLocal), (double)Width / (double)Height, nearPlane, back);
            PerspectiveFov = fovLocal;
            fovAngle       = ((this.ViewCamera.Zoom) / FOVMULT) / Math.PI * 180;
            fovScale       = (fovAngle / Height) * 3600;

            SetMatrixes();
            MakeFrustum();
        }