public ImageSetHelper(ImageSetType dataSetType, BandPass bandPass)
        {
            generic = true;
            name = "Generic";
            sparse = false;
            this.dataSetType = dataSetType;

            this.bandPass = bandPass;
            quadTreeTileMap = "";
            url = "";
            levels = 0;
            baseTileDegrees = 0;
            imageSetID = 0;
            extension = "";
            projection = ProjectionType.Equirectangular;
            bottomsUp = false;
            baseLevel = 0;
            mercator = (projection == ProjectionType.Mercator);
            centerX = 0;
            centerY = 0;
            rotation = 0;
            //todo add scale
            thumbnailUrl = "";

            matrix = Matrix3d.Identity;
            matrix.Multiply(Matrix3d.RotationX((((Rotation)) / 180f * Math.PI)));
            matrix.Multiply(Matrix3d.RotationZ(((CenterY) / 180f * Math.PI)));
            matrix.Multiply(Matrix3d.RotationY((((360 - CenterX) + 180) / 180f * Math.PI)));

            Earth3d.AddImageSetToTable(GetHash(), this);
        }
 private void ComputeMatrix()
 {
     matrixComputed = true;
     matrix = Matrix3d.Identity;
     matrix.Multiply(Matrix3d.RotationX((((this.rotationField)) / 180f * Math.PI)));
     matrix.Multiply(Matrix3d.RotationZ(((this.CenterY) / 180f * Math.PI)));
     matrix.Multiply(Matrix3d.RotationY((((360 - this.CenterX) + 180) / 180f * Math.PI)));
 }
Example #3
0
        private void SetupMatricesSpaceDome(bool forStars, RenderTypes renderType)
        {

            if (SolarSystemTrack != SolarSystemObjects.Custom && SolarSystemTrack != SolarSystemObjects.Undefined)
            {
                viewCamera.ViewTarget = Planets.GetPlanetTargetPoint(SolarSystemTrack, ViewLat, ViewLong, 0);
            }


            double camLocal = CameraRotate;
            if ((Settings.Active.LocalHorizonMode && !Settings.Active.GalacticMode) && CurrentImageSet.DataSetType == ImageSetType.Sky)
            {
                if (Properties.Settings.Default.ShowHorizon != false)
                {
                    Properties.Settings.Default.ShowHorizon = false;
                }
                Coordinates zenithAltAz = new Coordinates(0, 0);

                zenithAltAz.Az = 0;

                zenithAltAz.Alt = 0;

                ZoomFactor = TargetZoom = ZoomMax;
                alt = 0;
                az = 0;

                Coordinates zenith = Coordinates.HorizonToEquitorial(zenithAltAz, SpaceTimeController.Location, SpaceTimeController.Now);

                double raPart = -((zenith.RA - 6) / 24.0 * (Math.PI * 2));
                double decPart = -(((zenith.Dec)) / 360.0 * (Math.PI * 2));
                string raText = Coordinates.FormatDMS(zenith.RA);
                WorldMatrix = Matrix3d.RotationY(-raPart);
                WorldMatrix.Multiply(Matrix3d.RotationX(decPart));

                if (SpaceTimeController.Location.Lat < 0)
                {
                    WorldMatrix.Multiply(Matrix3d.RotationY(((az) / 180.0 * Math.PI)));

                    WorldMatrix.Multiply(Matrix3d.RotationX(((alt) / 180.0 * Math.PI)));
                    camLocal += Math.PI;
                }
                else
                {
                    WorldMatrix.Multiply(Matrix3d.RotationY(((-az) / 180.0 * Math.PI)));

                    WorldMatrix.Multiply(Matrix3d.RotationX(((-alt) / 180.0 * Math.PI)));
                }

                Coordinates currentRaDec = Coordinates.HorizonToEquitorial(Coordinates.FromLatLng(alt, az), SpaceTimeController.Location, SpaceTimeController.Now);

                TargetLat = ViewLat = currentRaDec.Dec;
                TargetLong = ViewLong = RAtoViewLng(currentRaDec.RA);

            }

            Vector3d center = viewCamera.ViewTarget;
            RenderContext11.LightingEnabled = false;

            double localZoom = ZoomFactor * 20;
            Vector3d lookAt = new Vector3d(0, 0, -1);
            FovAngle = ((ZoomFactor/**16*/) / FOVMULT) / Math.PI * 180;


             double distance = (Math.Min(1, (.5 * (ZoomFactor / 180)))) - 1 + 0.0001;

            RenderContext11.CameraPosition = new Vector3d(0, 0, distance);
            Vector3d lookUp = new Vector3d(Math.Sin(-CameraRotate), Math.Cos(-CameraRotate), 0.0001f);

            Matrix3d lookAtAdjust = Matrix3d.Identity;

            switch (renderType)
            {
                case RenderTypes.DomeUp:
                    lookAtAdjust.Multiply(Matrix3d.RotationX(Math.PI / 2));
                    break;
                case RenderTypes.DomeLeft:
                    lookAtAdjust.Multiply(Matrix3d.RotationY(Math.PI / 2));
                    break;
                case RenderTypes.DomeRight:
                    lookAtAdjust.Multiply(Matrix3d.RotationY(-Math.PI / 2));
                    break;
                case RenderTypes.DomeFront:
                    break;
                case RenderTypes.DomeBack:
                    lookAtAdjust.Multiply(Matrix3d.RotationY(Math.PI));
                    break;
                default:
                    break;
            }


            if ((Settings.Active.GalacticMode && !Settings.Active.LocalHorizonMode) && CurrentImageSet.DataSetType == ImageSetType.Sky)
            {
                if (!galMatInit)
                {
                    galacticMatrix = Matrix3d.Identity;
                    galacticMatrix.Multiply(Matrix3d.RotationY(-(90 - (17.7603329867975 * 15)) / 180.0 * Math.PI));
                    galacticMatrix.Multiply(Matrix3d.RotationX(-((-28.9361739586894)) / 180.0 * Math.PI));
                    galacticMatrix.Multiply(Matrix3d.RotationZ(((31.422052860102041270114993238783) - 90) / 180.0 * Math.PI));
                    galMatInit = true;
                }

                WorldMatrix = galacticMatrix;
                WorldMatrix.Multiply(Matrix3d.RotationY(((az)) / 180.0 * Math.PI));
                WorldMatrix.Multiply(Matrix3d.RotationX(-((alt)) / 180.0 * Math.PI));


                double[] gPoint = Coordinates.GalactictoJ2000(az, alt);

                this.RA = gPoint[0] / 15;
                this.Dec = gPoint[1];
                targetViewCamera.Lat = viewCamera.Lat;
                targetViewCamera.Lng = viewCamera.Lng;
            }
            else
            {
                // Show in Ecliptic

                WorldMatrix = Matrix3d.RotationY(-((this.ViewLong + 90.0) / 180.0 * Math.PI));
                WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180.0 * Math.PI)));
            }

            RenderContext11.World = WorldMatrix;
            RenderContext11.WorldBase = WorldMatrix;


            if (Settings.Active.LocalHorizonMode)
            {
                Matrix3d matNorth = Matrix3d.RotationY(Properties.Settings.Default.FaceNorth ? 0 : Math.PI);
                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * matNorth * DomeAngleMatrix * lookAtAdjust;
            }
            else
            {
                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * lookAtAdjust;
            }
            Vector3d temp = lookAt - RenderContext11.CameraPosition;
            temp.Normalize();
            ViewPoint = temp;

            // Set the near clip plane close enough that the sky dome isn't clipped
            double cameraZ = (Math.Min(1, (.5 * (ZoomFactor / 180)))) - 1 + 0.0001;
            m_nearPlane = (float)(1.0 + cameraZ) * 0.5f;

            ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 2.0), 1.0f, m_nearPlane, -1f);
            RenderContext11.PerspectiveFov = (Math.PI / 2.0);
            if (multiMonClient)
            {
                ProjMatrix.M11 *= MonitorCountX * bezelSpacing;
                ProjMatrix.M22 *= MonitorCountY * bezelSpacing;
                ProjMatrix.M31 = (MonitorCountX - 1) - (MonitorX * bezelSpacing * 2);
                ProjMatrix.M32 = -((MonitorCountY - 1) - (MonitorY * bezelSpacing * 2));
            }

            RenderContext11.Projection = ProjMatrix;

            ViewMatrix = RenderContext11.View;
            RenderContext11.ViewBase = RenderContext11.View;
            MakeFrustum();
        }
Example #4
0
        private void SetupMatricesVideoOverlayDome(bool forStars, RenderTypes renderType)
        {


            Vector3d center = viewCamera.ViewTarget;
            RenderContext11.LightingEnabled = false;

            double localZoom = ZoomFactor * 20;
            Vector3d lookAt = new Vector3d(0, 0, -1);
            FovAngle = ((360) / FOVMULT) / Math.PI * 180;

            double distance = 1;

            RenderContext11.CameraPosition = new Vector3d(0, 0, distance);
            Vector3d lookUp = new Vector3d(Math.Sin(-0), Math.Cos(-0), 0.0001f);

            Matrix3d lookAtAdjust = Matrix3d.Identity;

            switch (renderType)
            {
                case RenderTypes.DomeUp:
                    lookAtAdjust.Multiply(Matrix3d.RotationX(Math.PI / 2));
                    break;
                case RenderTypes.DomeLeft:
                    lookAtAdjust.Multiply(Matrix3d.RotationY(Math.PI / 2));
                    break;
                case RenderTypes.DomeRight:
                    lookAtAdjust.Multiply(Matrix3d.RotationY(-Math.PI / 2));
                    break;
                case RenderTypes.DomeFront:
                    break;
                case RenderTypes.DomeBack:
                    lookAtAdjust.Multiply(Matrix3d.RotationY(Math.PI));
                    break;
                default:
                    break;
            }

            WorldMatrix = Matrix3d.RotationY(-((0 + 90) / 180f * Math.PI));
            WorldMatrix.Multiply(Matrix3d.RotationX(((0) / 180f * Math.PI)));
            RenderContext11.World = WorldMatrix;
            RenderContext11.WorldBase = WorldMatrix;

            if (rift)
            {
                double amount = 0;
                Matrix3d stereoTranslate = Matrix3d.Translation(renderType == RenderTypes.LeftEye ? amount : -amount, 0, 0);
                Matrix3d matRiftView = Matrix3d.RotationY(GetHeading()) * Matrix3d.RotationX(GetPitch()) * Matrix3d.RotationZ(-GetRoll());
                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * lookAtAdjust * matRiftView * stereoTranslate;
            }
            else
            {
                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * lookAtAdjust;
            }

            Vector3d temp = lookAt - RenderContext11.CameraPosition;
            temp.Normalize();
            ViewPoint = temp;


            m_nearPlane = ((.000000001));

            if (rift)
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH(riftFov, 1.0f, m_nearPlane, -1f);
            }
            else
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 2.0), 1.0f, m_nearPlane, -1f);
            }

            if (multiMonClient)
            {
                ProjMatrix.M11 *= MonitorCountX * bezelSpacing;
                ProjMatrix.M22 *= MonitorCountY * bezelSpacing;
                ProjMatrix.M31 = (MonitorCountX - 1) - (MonitorX * bezelSpacing * 2);
                ProjMatrix.M32 = -((MonitorCountY - 1) - (MonitorY * bezelSpacing * 2));
            }

            if (rift)
            {
                if (renderType == RenderTypes.LeftEye)
                {

                    ProjMatrix.M31 += iod;
                }
                else
                {
                    ProjMatrix.M31 -= iod;
                }
            }

            RenderContext11.Projection = ProjMatrix;

            ViewMatrix = RenderContext11.View;
            RenderContext11.ViewBase = RenderContext11.View;
            MakeFrustum();
        }
Example #5
0
        private void SetupMatricesLand11(RenderTypes renderType)
        {
            WorldMatrix = Matrix3d.RotationY(((this.ViewLong + 90f) / 180f * Math.PI));
            WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180f * Math.PI)));
            RenderContext11.World = WorldMatrix;
            RenderContext11.WorldBase = WorldMatrix;


            double distance = 0;
            if (CurrentImageSet.IsMandelbrot)
            {

                distance = (4.0 * (ZoomFactor / 180)) + 0.00000000000000000000000000000000000000001;
            }
            else
            {

                distance = (4.0 * (ZoomFactor / 180)) + 0.000001;
            }

            if (Settings.Active.ShowElevationModel)
            {
                targetAltitude = GetScaledAltitudeForLatLong(ViewLat, ViewLong);
                double heightNow = 1 + targetAltitude;
                targetAltitude *= RenderContext11.NominalRadius;
                if ((double.IsNaN(heightNow)))
                {
                    heightNow = 0;
                }

                if (targetHeight < heightNow)
                {
                    targetHeight = (((targetHeight * 2) + heightNow) / 3);
                }
                else
                {
                    targetHeight = (((targetHeight * 9) + heightNow) / 10);
                }
                if (double.IsNaN(targetHeight))
                {
                    targetHeight = 0;
                }
                if (config.MultiChannelDome1 || config.MultiProjector)
                {
                    targetHeight = heightNow = NetControl.focusAltitude;
                }

            }
            else
            {
                targetAltitude = 0;
                targetHeight = 1;
            }
            double rotLocal = CameraRotate;
            if (!rift)
            {
                if (renderType == RenderTypes.RightEye)
                {
                    rotLocal -= .008;
                }
                if (renderType == RenderTypes.LeftEye)
                {
                    rotLocal += .008;
                }
            }

            RenderContext11.CameraPosition = new Vector3d(
                (Math.Sin(rotLocal) * Math.Sin(CameraAngle) * distance),
                (Math.Cos(rotLocal) * Math.Sin(CameraAngle) * distance),
                (-targetHeight - (Math.Cos(CameraAngle) * distance)));
            cameraTarget = new Vector3d(0.0f, 0.0f, -targetHeight);

            double camHeight = RenderContext11.CameraPosition.Length();
            if (Tile.GrayscaleStyle)
            {
                if (CurrentImageSet.Projection == ProjectionType.Toast && (CurrentImageSet.MeanRadius > 0 && CurrentImageSet.MeanRadius < 4000000))
                {
                    int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000)));
                    SkyColor = Color.FromArgb(213 * val / 255, 165 * val / 255, 118 * val / 255);
                }
                else if (CurrentImageSet.DataSetType == ImageSetType.Earth)
                {
                    SkyColor = Color.FromArgb(255, 184, 184, 184);
                }
                else
                {
                    SkyColor = Color.Black;
                }
            }
            else
            {
                if (CurrentImageSet.ReferenceFrame == "Mars" && Settings.Active.ShowEarthSky)
                {
                    int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000)));
                    SkyColor = Color.FromArgb(213 * val / 255, 165 * val / 255, 118 * val / 255);
                }
                else if (CurrentImageSet.DataSetType == ImageSetType.Earth && Settings.Active.ShowEarthSky)
                {
                    int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000)));
                    SkyColor = Color.FromArgb(255, val / 3, val / 3, val);
                }
                else
                {
                    SkyColor = Color.Black;
                }
            }
 
            if (config.MultiChannelGlobe)
            {
                // Move the camera to some fixed distance from the globe
                RenderContext11.CameraPosition *= 50.0 / RenderContext11.CameraPosition.Length();

                // Modify camera position in globe mode
                Matrix3d globeCameraRotation =
                    Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) *
                    Matrix3d.RotationY((config.Heading / 180 * Math.PI)) *
                    Matrix3d.RotationX(((config.Pitch) / 180 * Math.PI));
                RenderContext11.CameraPosition = globeCameraRotation.Transform(RenderContext11.CameraPosition);
                cameraTarget = globeCameraRotation.Transform(cameraTarget);
                RenderContext11.View = Matrix3d.LookAtLH(
                    RenderContext11.CameraPosition,
                    cameraTarget,
                    new Vector3d(Math.Sin(rotLocal) * Math.Cos(CameraAngle), Math.Cos(rotLocal) * Math.Cos(CameraAngle), Math.Sin(CameraAngle)));
            }
            else if (config.MultiChannelDome1)
            {
                Matrix3d matHeadingPitchRoll =
                    Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) *
                    Matrix3d.RotationY((config.Heading / 180 * Math.PI)) *
                    Matrix3d.RotationX(((config.Pitch) / 180 * Math.PI));
                RenderContext11.View = Matrix3d.LookAtLH(
                            RenderContext11.CameraPosition,
                            cameraTarget,
                            new Vector3d(Math.Sin(rotLocal) * Math.Cos(CameraAngle), Math.Cos(rotLocal) * Math.Cos(CameraAngle), Math.Sin(CameraAngle)))
                            * DomeMatrix
                            * matHeadingPitchRoll;
                RenderContext11.ViewBase = RenderContext11.View;
            }
            else
            {

                Vector3d lookUp = new Vector3d(Math.Sin(rotLocal) * Math.Cos(CameraAngle), Math.Cos(rotLocal) * Math.Cos(CameraAngle), Math.Sin(CameraAngle));

                if (DomePreviewPopup.Active)
                {
                    Matrix3d matDomePreview =
                         Matrix3d.RotationY((DomePreviewPopup.Az / 180 * Math.PI)) *
                         Matrix3d.RotationX((DomePreviewPopup.Alt / 180 * Math.PI));
                    RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, cameraTarget, lookUp) * Matrix3d.RotationX(((-config.TotalDomeTilt) / 180 * Math.PI)) * matDomePreview;
                }
                else if (rift)
                {
                    double amount = distance / 100;
                    Matrix3d stereoTranslate = Matrix3d.Translation(renderType == RenderTypes.LeftEye ? amount : -amount, 0, 0);
                    Matrix3d matRiftView = Matrix3d.RotationY(GetHeading()) * Matrix3d.RotationX(GetPitch()) * Matrix3d.RotationZ(-GetRoll());
                    RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, cameraTarget, lookUp) * Matrix3d.Translation(HeadPosition) * matRiftView * stereoTranslate;
                }
                else
                {
                    RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, cameraTarget, lookUp) * Matrix3d.Translation(HeadPosition);

                }

                if (multiMonClient)
                {
                    RenderContext11.View = RenderContext11.View * Matrix3d.RotationY((config.Heading / 180 * Math.PI));
                }


                RenderContext11.ViewBase = RenderContext11.View;


            }

            back = Math.Sqrt((distance + 1f) * (distance + 1f) - 1);
            back = Math.Max(.5, back);

            if (Properties.Settings.Default.EarthCutawayView.State)
            {
                back = 20;
            }
            m_nearPlane = distance * .05f;
            if (config.MultiChannelGlobe)
            {
                m_nearPlane = RenderContext11.CameraPosition.Length() - 2.0;
                back = m_nearPlane + 4.0;
                ProjMatrix = Matrix3d.OrthoLH(config.Aspect * 2.0, 2.0, m_nearPlane, back);
            }
            else if (config.MultiChannelDome1)
            {
                double aspect = config.Aspect;
                double top = m_nearPlane * 2 / ((1 / Math.Tan(config.UpFov / 180 * Math.PI))) / 2;
                double bottom = m_nearPlane * 2 / -(1 / Math.Tan(config.DownFov / 180 * Math.PI)) / 2;
                double right = m_nearPlane * 2 / (1 / Math.Tan((config.UpFov + config.DownFov) / 2 / 180 * Math.PI)) * aspect / 2;
                double left = -right;

                ProjMatrix = Matrix3d.PerspectiveOffCenterLH(
                    left,
                    right,
                    bottom,
                    top,
                    m_nearPlane,
                    back);


            }
            else if (config.MultiProjector)
            {
                RenderContext11.View = RenderContext11.View * config.ViewMatrix;
                ProjMatrix = Matrix3d.PerspectiveFovLH((75f / 180f) * Math.PI, 1.777778, m_nearPlane, back);
                RenderContext11.ViewBase = RenderContext11.View;

            }
            else if (multiMonClient)
            {
                double fov = (((config.UpFov + config.DownFov) / 2 / 180 * Math.PI));
                if (fov == 0)
                {
                    fov = (Math.PI / 4.0);
                }

                m_nearPlane = distance * .05f;
                ProjMatrix = Matrix3d.PerspectiveFovLH(fov, (monitorWidth * MonitorCountX) / (monitorHeight * MonitorCountY), m_nearPlane, back);
            }
            else if (rift)
            {
                m_nearPlane = distance * .05f;
                ProjMatrix = Matrix3d.PerspectiveFovLH(riftFov, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back);
                RenderContext11.PerspectiveFov = riftFov;

            }
            else
            {

                m_nearPlane = distance * .05f;
                ProjMatrix = Matrix3d.PerspectiveFovLH(fovLocal, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back);
                RenderContext11.PerspectiveFov = fovLocal;
            }


            if (multiMonClient && !config.MultiChannelDome1 && !Config.MultiProjector && !Config.MultiChannelGlobe)
            {
                ProjMatrix.M11 *= MonitorCountX * bezelSpacing;
                ProjMatrix.M22 *= MonitorCountY * bezelSpacing;
                ProjMatrix.M31 = (MonitorCountX - 1) - (MonitorX * bezelSpacing * 2);
                ProjMatrix.M32 = -((MonitorCountY - 1) - (MonitorY * bezelSpacing * 2));
            }

            if (rift)
            {
                if (renderType == RenderTypes.LeftEye)
                {

                    ProjMatrix.M31 += iod;
                }
                else
                {
                    ProjMatrix.M31 -= iod;
                }
            }


            RenderContext11.Projection = ProjMatrix;

            colorBlend = 1 / distance;

            ViewMatrix = RenderContext11.View;


            MakeFrustum();
        }
Example #6
0
        private void SetupMatricesLandDome(RenderTypes renderType)
        {
            FovAngle = 60;

            RenderContext11.LightingEnabled = false;

            double localZoom = ZoomFactor * 20;
            double distance = (4.0 * (ZoomFactor / 180)) + 0.000001;


            Vector3d lookAt = new Vector3d(0.0f, 0.0f, -targetHeight);

            if (Settings.Active.ShowElevationModel)
            {
                double heightNow = 1 + GetScaledAltitudeForLatLong(ViewLat, ViewLong);
                if (targetHeight < heightNow)
                {
                    targetHeight = (((targetHeight * 2) + heightNow) / 3);
                }
                else
                {
                    targetHeight = (((targetHeight * 9) + heightNow) / 10);
                }

            }
            else
            {
                targetHeight = 1;
            }

            double rotLocal = CameraRotate;

            if (renderType == RenderTypes.RightEye)
            {
                rotLocal -= .008;
            }
            if (renderType == RenderTypes.LeftEye)
            {
                rotLocal += .008;
            }

            RenderContext11.CameraPosition = new Vector3d(
                (Math.Sin(rotLocal) * Math.Sin(CameraAngle) * distance),
                (Math.Cos(rotLocal) * Math.Sin(CameraAngle) * distance),
                (-targetHeight - (Math.Cos(CameraAngle) * distance)));

            Matrix3d lookAtAdjust = Matrix3d.Identity;

            Vector3d lookUp = new Vector3d(Math.Sin(rotLocal) * Math.Cos(CameraAngle), Math.Cos(rotLocal) * Math.Cos(CameraAngle), Math.Sin(CameraAngle));

            Matrix3d cubeMat = Matrix3d.Identity;

            switch (renderType)
            {
                case RenderTypes.DomeUp:
                    cubeMat = Matrix3d.RotationX((Math.PI / 2));
                    break;
                case RenderTypes.DomeLeft:
                    cubeMat = Matrix3d.RotationY((Math.PI / 2));
                    break;
                case RenderTypes.DomeRight:
                    cubeMat = Matrix3d.RotationY(-(Math.PI / 2));
                    break;
                case RenderTypes.DomeFront:
                    break;
                case RenderTypes.DomeBack:
                    cubeMat = Matrix3d.RotationY((Math.PI));
                    break;
                default:
                    break;
            }
            double camHeight = RenderContext11.CameraPosition.Length();

            if (CurrentImageSet.Projection == ProjectionType.Toast && (CurrentImageSet.MeanRadius > 0 && CurrentImageSet.MeanRadius < 4000000))
            {
                int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000)));
                SkyColor = Color.FromArgb(213 * val / 255, 165 * val / 255, 118 * val / 255);
            }
            else if (CurrentImageSet.DataSetType == ImageSetType.Earth && Settings.Active.ShowEarthSky)
            {
                int val = (int)Math.Max(0, Math.Min(255, 255 - Math.Min(255, (camHeight - 1) * 5000)));
                SkyColor = Color.FromArgb(255, val / 3, val / 3, val);
            }
            else
            {
                SkyColor = Color.Black;
            }

            WorldMatrix = Matrix3d.RotationY(((this.ViewLong + 90f) / 180f * Math.PI));
            WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180f * Math.PI)));
            RenderContext11.World = WorldMatrix;
            RenderContext11.WorldBase = WorldMatrix;

            if (config.MultiChannelDome1)
            {
                Matrix3d matHeadingPitchRoll =
                    Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) *
                    Matrix3d.RotationX((config.Pitch / 180 * Math.PI)) *
                    Matrix3d.RotationY((config.Heading / 180 * Math.PI));

                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp)
                    * DomeMatrix
                    * matHeadingPitchRoll;
            }
            else
            {
                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * DomeMatrix * cubeMat;
            }

            Vector3d temp = lookAt - RenderContext11.CameraPosition;
            temp.Normalize();
            ViewPoint = temp;


            back = Math.Sqrt((distance + 1f) * (distance + 1f) - 1);
            m_nearPlane = distance * .1f;


            ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 2.0), 1.0f, m_nearPlane, back);
            if (config.MultiChannelDome1)
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH(((config.UpFov + config.DownFov) / 180 * Math.PI), (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back);
            }

            else if (multiMonClient)
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH((Math.PI / 2.0), 1.0f, m_nearPlane, back);
                RenderContext11.PerspectiveFov = (Math.PI / 2.0);
            }

            RenderContext11.Projection = ProjMatrix;


            ViewMatrix = RenderContext11.View;
            RenderContext11.ViewBase = RenderContext11.View;

            MakeFrustum();
        }
Example #7
0
        private void SetupMatricesSpaceMultiChannel(double localZoomFactor, RenderTypes renderType)
        {
            bool faceSouth = false;

            if ((Settings.Active.LocalHorizonMode && !Settings.Active.GalacticMode) && CurrentImageSet.DataSetType == ImageSetType.Sky)
            {
                faceSouth = !Properties.Settings.Default.FaceNorth;
                Coordinates currentRaDec = Coordinates.HorizonToEquitorial(Coordinates.FromLatLng(0, 0), SpaceTimeController.Location, SpaceTimeController.Now);

                alt = 0;
                az = 0;
                config.DomeTilt = 0;
                if (Properties.Settings.Default.DomeTilt != 0)
                {
                    Properties.Settings.Default.DomeTilt = 0;
                }

                TargetLat = ViewLat = currentRaDec.Dec;
                TargetLong = ViewLong = RAtoViewLng(currentRaDec.RA);

            }

            if (SolarSystemTrack != SolarSystemObjects.Custom && SolarSystemTrack != SolarSystemObjects.Undefined)
            {
                viewCamera.ViewTarget = Planets.GetPlanetTargetPoint(SolarSystemTrack, ViewLat, ViewLong, 0);
            }

            RenderContext11.LightingEnabled = false;

            double localZoom = ZoomFactor * 20;
            Vector3d lookAt = new Vector3d(0, 0, -1);
            FovAngle = ((ZoomFactor/**16*/) / FOVMULT) / Math.PI * 180;

            // for constellations
            ViewPoint = Coordinates.RADecTo3d(this.RA, -this.Dec, 1.0);


            double distance = (Math.Min(1, (.5 * (ZoomFactor / 180)))) - 1 + 0.0001;

            RenderContext11.CameraPosition = new Vector3d(0, 0, distance);
            Vector3d lookUp = new Vector3d(Math.Sin(CameraRotate), Math.Cos(CameraRotate), 0.0001f);

            Matrix3d lookAtAdjust = Matrix3d.Identity;

            if ((Settings.Active.GalacticMode && !Settings.Active.LocalHorizonMode) && CurrentImageSet.DataSetType == ImageSetType.Sky)
            {
                if (!galMatInit)
                {
                    galacticMatrix = Matrix3d.Identity;
                    galacticMatrix.Multiply(Matrix3d.RotationY(-(90 - (17.7603329867975 * 15)) / 180.0 * Math.PI));
                    galacticMatrix.Multiply(Matrix3d.RotationX(-((-28.9361739586894)) / 180.0 * Math.PI));
                    galacticMatrix.Multiply(Matrix3d.RotationZ(((31.422052860102041270114993238783) - 90) / 180.0 * Math.PI));
                    galMatInit = true;
                }

                WorldMatrix = galacticMatrix;
                WorldMatrix.Multiply(Matrix3d.RotationY(((az)) / 180.0 * Math.PI));
                WorldMatrix.Multiply(Matrix3d.RotationX(-((alt)) / 180.0 * Math.PI));


                double[] gPoint = Coordinates.GalactictoJ2000(az, alt);

                this.RA = gPoint[0] / 15;
                this.Dec = gPoint[1];
                targetViewCamera.Lat = viewCamera.Lat;
                targetViewCamera.Lng = viewCamera.Lng;
            }
            else
            {
                // Show in Ecliptic

                WorldMatrix = Matrix3d.RotationY(-((this.ViewLong + 90) / 180.0 * Math.PI));
                WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180.0 * Math.PI)));
            }


            RenderContext11.World = WorldMatrix;
            RenderContext11.WorldBase = WorldMatrix;



            lookAt.TransformCoordinate(lookAtAdjust);
            Matrix3d matHeadingPitchRoll;

            if (DomePreviewPopup.Active)
            {
                matHeadingPitchRoll =

                      Matrix3d.RotationY((DomePreviewPopup.Az / 180 * Math.PI)) *
                      Matrix3d.RotationX((DomePreviewPopup.Alt / 180 * Math.PI));
            }
            else
            {
                matHeadingPitchRoll =
                      Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) *
                      Matrix3d.RotationY((config.Heading / 180 * Math.PI)) *
                      Matrix3d.RotationX(((config.Pitch) / 180 * Math.PI));
            }

            if (rift)
            {
                Matrix3d matRiftView = Matrix3d.RotationY(GetHeading()) * Matrix3d.RotationX(GetPitch()) * Matrix3d.RotationZ(-GetRoll());
                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * matRiftView;
            }
            else
            {
                Matrix3d matNorth = Matrix3d.RotationY(faceSouth ? Math.PI : 0);

                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, lookAt, lookUp) * matNorth * DomeMatrix * matHeadingPitchRoll;
            }

            Vector3d temp = lookAt - RenderContext11.CameraPosition;
            temp.Normalize();
            ViewPoint = temp;

            // Set the near clip plane close enough that the sky dome isn't clipped
            double cameraZ = (Math.Min(1, (.5 * (ZoomFactor / 180)))) - 1 + 0.0001;
            m_nearPlane = (float)(1.0 + cameraZ) * 0.5f;

            back = 12;
            double aspect = config.Aspect;
            double top = m_nearPlane * 2 / ((1 / Math.Tan(config.UpFov / 180 * Math.PI))) / 2;
            double bottom = m_nearPlane * 2 / -(1 / Math.Tan(config.DownFov / 180 * Math.PI)) / 2;
            double right = m_nearPlane * 2 / (1 / Math.Tan((config.UpFov + config.DownFov) / 2 / 180 * Math.PI)) * aspect / 2;
            double left = -right;


            if (config.MultiChannelDome1)
            {
                ProjMatrix = Matrix3d.PerspectiveOffCenterLH(
                    left,
                    right,
                    bottom,
                    top,
                    m_nearPlane,
                    back);
            }
            else if (rift)
            {
                RenderContext11.View = RenderContext11.View * config.ViewMatrix;
                ProjMatrix = Matrix3d.PerspectiveFovLH(riftFov, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back);
                RenderContext11.PerspectiveFov = riftFov;

            }
            else
            {
                RenderContext11.View = RenderContext11.View * config.ViewMatrix;
                ProjMatrix = Matrix3d.PerspectiveFovLH((75f / 180f) * Math.PI, 1.777778, m_nearPlane, back);

            }

            if (rift)
            {
                if (renderType == RenderTypes.LeftEye)
                {

                    ProjMatrix.M31 += iod;
                }
                else
                {
                    ProjMatrix.M31 -= iod;
                }
            }


            RenderContext11.Projection = ProjMatrix;

            ViewMatrix = RenderContext11.View;
            RenderContext11.ViewBase = RenderContext11.View;
            MakeFrustum();
        }
Example #8
0
        // video
        private void SetupMatricesVideoOverlay(double localZoomFactor)
        {
            if (config.MultiChannelDome1 || config.MultiProjector || DomePreviewPopup.Active)
            {
                SetupMatricesVideoOverlayMultiChannel(localZoomFactor);
                return;
            }

            WorldMatrix = Matrix3d.RotationY(-((0 + 90) / 180.0 * Math.PI));
            WorldMatrix.Multiply(Matrix3d.RotationX(((-0) / 180.0 * Math.PI)));

            double camLocal = 0;


            RenderContext11.World = WorldMatrix;
            RenderContext11.WorldBase = WorldMatrix;
            // altaz

            ViewPoint = Coordinates.RADecTo3d(0, 0, 1.0);

            
            FovAngle = ((360) / FOVMULT) / Math.PI * 180;
            RenderContext11.CameraPosition = new Vector3d(0.0, 0.0, 0.0);
            // This is for distance Calculation. For space everything is the same distance, so camera target is key.

            RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, new Vector3d(0.0, 0.0, -1.0), new Vector3d(Math.Sin(camLocal), Math.Cos(camLocal), 0.0));
            RenderContext11.ViewBase = RenderContext11.View;

            m_nearPlane = 0f;
            if (multiMonClient)
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)(monitorWidth * MonitorCountX) / (double)(monitorHeight * MonitorCountY), 0, -2.0);

            }
            else if (rift)
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH(riftFov, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, m_nearPlane, back);
                RenderContext11.PerspectiveFov = riftFov;

            }
            else
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, 0, -2.0);

            }



            if (multiMonClient)
            {
                ProjMatrix.M11 *= MonitorCountX * bezelSpacing;
                ProjMatrix.M22 *= MonitorCountY * bezelSpacing;
                ProjMatrix.M31 = (MonitorCountX - 1) - (MonitorX * bezelSpacing * 2);
                ProjMatrix.M32 = -((MonitorCountY - 1) - (MonitorY * bezelSpacing * 2));
            }

            if (rift)
            {
                if (CurrentRenderType == RenderTypes.LeftEye)
                {

                    ProjMatrix.M31 += iod;
                }
                else
                {
                    ProjMatrix.M31 -= iod;
                }
            }

            RenderContext11.Projection = ProjMatrix;

            ViewMatrix = RenderContext11.View;

            MakeFrustum();

        }
        private void ComputeOrbital(RenderContext11 renderContext)
        {
            CAAEllipticalObjectElements ee = Elements;
            Vector3d point = CAAElliptical.CalculateRectangular(SpaceTimeController.JNow, ee, out MeanAnomoly);

            Vector3d pointInstantLater = CAAElliptical.CalculateRectangular(ee, MeanAnomoly + .001);

            Vector3d direction = point - pointInstantLater;

            direction.Normalize();
            Vector3d up = point;
            up.Normalize();
            direction.Normalize();

            double dist = point.Length();
            double scaleFactor = 1.0;
            switch (SemiMajorAxisUnits)
            {
                case AltUnits.Meters:
                    scaleFactor = 1.0;
                    break;
                case AltUnits.Feet:
                    scaleFactor = 1.0 / 3.2808399;
                    break;
                case AltUnits.Inches:
                    scaleFactor = (1.0 / 3.2808399) / 12;
                    break;
                case AltUnits.Miles:
                    scaleFactor = 1609.344;
                    break;
                case AltUnits.Kilometers:
                    scaleFactor = 1000;
                    break;
                case AltUnits.AstronomicalUnits:
                    scaleFactor = UiTools.KilometersPerAu * 1000;
                    break;
                case AltUnits.LightYears:
                    scaleFactor = UiTools.AuPerLightYear * UiTools.KilometersPerAu * 1000;
                    break;
                case AltUnits.Parsecs:
                    scaleFactor = UiTools.AuPerParsec * UiTools.KilometersPerAu * 1000;
                    break;
                case AltUnits.MegaParsecs:
                    scaleFactor = UiTools.AuPerParsec * UiTools.KilometersPerAu * 1000 * 1000000;
                    break;
                case AltUnits.Custom:
                    scaleFactor = 1;
                    break;
                default:
                    break;
            }
            scaleFactor *= 1 / renderContext.NominalRadius;

            Matrix3d look = Matrix3d.LookAtLH(new Vector3d(0, 0, 0), direction, up);
            look.Invert();

            WorldMatrix = Matrix3d.Identity;
            WorldMatrix.Translate(Translation);

            double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius;
            WorldMatrix.Scale(new Vector3d(localScale, localScale, localScale));
            WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI)));
            if (RotationalPeriod != 0)
            {
                double rotationCurrent = (((SpaceTimeController.JNow - this.ZeroRotationDate) / RotationalPeriod) * Math.PI * 2) % (Math.PI * 2);
                WorldMatrix.Multiply(Matrix3d.RotationX(-rotationCurrent));
            }

            point = Vector3d.Scale(point, scaleFactor);

            WorldMatrix.Translate(point);

            if (StationKeeping)
            {
                WorldMatrix = look * WorldMatrix;
            }
        }
Example #10
0
        private void SetupMatricesSpace11(double localZoomFactor, RenderTypes renderType)
        {
            if (config.MultiChannelDome1 || config.MultiProjector || DomePreviewPopup.Active || rift)
            {
                SetupMatricesSpaceMultiChannel(localZoomFactor, renderType);
                return;
            }

            if ((Settings.Active.GalacticMode && !Settings.Active.LocalHorizonMode) && CurrentImageSet.DataSetType == ImageSetType.Sky)
            {
                // Show in galactic coordinates
                if (!galMatInit)
                {
                    galacticMatrix = Matrix3d.Identity;
                    galacticMatrix.Multiply(Matrix3d.RotationY(-(90 - (17.7603329867975 * 15)) / 180.0 * Math.PI));
                    galacticMatrix.Multiply(Matrix3d.RotationX(-((-28.9361739586894)) / 180.0 * Math.PI));
                    galacticMatrix.Multiply(Matrix3d.RotationZ(((31.422052860102041270114993238783) - 90) / 180.0 * Math.PI));
                    galMatInit = true;
                }

                WorldMatrix = galacticMatrix;
                WorldMatrix.Multiply(Matrix3d.RotationY(((az)) / 180.0 * Math.PI));
                WorldMatrix.Multiply(Matrix3d.RotationX(-((alt)) / 180.0 * Math.PI));


                double[] gPoint = Coordinates.GalactictoJ2000(az, alt);

                this.RA = gPoint[0] / 15;
                this.Dec = gPoint[1];
                viewCamera.Lat = targetViewCamera.Lat;
                viewCamera.Lng = targetViewCamera.Lng;

            }
            else
            {
                // Show in Ecliptic

                WorldMatrix = Matrix3d.RotationY(-((this.ViewLong + 90.0) / 180.0 * Math.PI));
                WorldMatrix.Multiply(Matrix3d.RotationX(((-this.ViewLat) / 180.0 * Math.PI)));
            }
            double camLocal = CameraRotate;

            // altaz
            if ((Settings.Active.LocalHorizonMode && !Settings.Active.GalacticMode) && CurrentImageSet.DataSetType == ImageSetType.Sky)
            {
                Coordinates zenithAltAz = new Coordinates(0, 0);

                zenithAltAz.Az = 0;

                zenithAltAz.Alt = 0;



                if (!config.Master)
                {
                    alt = 0;
                    az = 0;
                    config.DomeTilt = 0;
                    if (Properties.Settings.Default.DomeTilt != 0)
                    {
                        Properties.Settings.Default.DomeTilt = 0;
                    }
                }

                Coordinates zenith = Coordinates.HorizonToEquitorial(zenithAltAz, SpaceTimeController.Location, SpaceTimeController.Now);

                double raPart = -((zenith.RA - 6) / 24.0 * (Math.PI * 2));
                double decPart = -(((zenith.Dec)) / 360.0 * (Math.PI * 2));
                string raText = Coordinates.FormatDMS(zenith.RA);
                WorldMatrix = Matrix3d.RotationY(-raPart);
                WorldMatrix.Multiply(Matrix3d.RotationX(decPart));

                if (SpaceTimeController.Location.Lat < 0)
                {
                    WorldMatrix.Multiply(Matrix3d.RotationY(((az) / 180.0 * Math.PI)));

                    WorldMatrix.Multiply(Matrix3d.RotationX(((alt) / 180.0 * Math.PI)));
                    camLocal += Math.PI;
                }
                else
                {
                    WorldMatrix.Multiply(Matrix3d.RotationY(((-az) / 180.0 * Math.PI)));

                    WorldMatrix.Multiply(Matrix3d.RotationX(((-alt) / 180.0 * Math.PI)));
                }

                Coordinates currentRaDec = Coordinates.HorizonToEquitorial(Coordinates.FromLatLng(alt, az), SpaceTimeController.Location, SpaceTimeController.Now);

                TargetLat = ViewLat = currentRaDec.Dec;
                TargetLong = ViewLong = RAtoViewLng(currentRaDec.RA);
            }

            RenderContext11.World = WorldMatrix;
            RenderContext11.WorldBase = WorldMatrix;
            // altaz

            ViewPoint = Coordinates.RADecTo3d(this.RA, -this.Dec, 1.0);



            double distance = (4.0 * (localZoomFactor / 180)) + 0.000001;

            FovAngle = ((localZoomFactor/**16*/) / FOVMULT) / Math.PI * 180;
            RenderContext11.CameraPosition = new Vector3d(0.0, 0.0, 0.0);
            // This is for distance Calculation. For space everything is the same distance, so camera target is key.

            RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, new Vector3d(0.0, 0.0, -1.0), new Vector3d(Math.Sin(camLocal), Math.Cos(camLocal), 0.0));

            if (config.MultiChannelGlobe)
            {
                Matrix3d globeCameraRotation =
                    Matrix3d.RotationZ((config.Roll / 180 * Math.PI)) *
                    Matrix3d.RotationY((config.Heading / 180 * Math.PI)) *
                    Matrix3d.RotationX(((config.Pitch) / 180 * Math.PI));
                RenderContext11.View = RenderContext11.View * globeCameraRotation;
            }



            if (multiMonClient)
            {
                RenderContext11.View = RenderContext11.View * Matrix3d.RotationY((config.Heading / 180 * Math.PI));
            }


            RenderContext11.ViewBase = RenderContext11.View;

            m_nearPlane = 0f;
            if (multiMonClient)
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH((localZoomFactor/**16*/) / FOVMULT, (double)(monitorWidth * MonitorCountX) / (double)(monitorHeight * MonitorCountY), .1, -2.0);

            }
            else
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH((localZoomFactor/**16*/) / FOVMULT, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, .1, -2.0);

            }
            RenderContext11.PerspectiveFov = (localZoomFactor) / FOVMULT;


            if (multiMonClient)
            {
                ProjMatrix.M11 *= MonitorCountX * bezelSpacing;
                ProjMatrix.M22 *= MonitorCountY * bezelSpacing;
                ProjMatrix.M31 = (MonitorCountX - 1) - (MonitorX * bezelSpacing * 2);
                ProjMatrix.M32 = -((MonitorCountY - 1) - (MonitorY * bezelSpacing * 2));
            }

            if (config.MultiChannelGlobe)
            {
                ProjMatrix = Matrix3d.OrthoLH(config.Aspect * 2.0, 2.0, 0.0, 2.0);
            }



            RenderContext11.Projection = ProjMatrix;

            ViewMatrix = RenderContext11.View;

            MakeFrustum();

        }
        private void ComputeFrameTrajectory(RenderContext11 renderContext)
        {
            Vector3d vector = new Vector3d();
            Vector3d point = GetTragectoryPoint(SpaceTimeController.JNow, out vector);

            Vector3d direction = vector;

            direction.Normalize();
            Vector3d up = point;
            up.Normalize();
            direction.Normalize();

            double dist = point.Length();
            double scaleFactor = 1.0;
            //scaleFactor = UiTools.KilometersPerAu * 1000;
            scaleFactor *= 1 / renderContext.NominalRadius;

            Matrix3d look = Matrix3d.LookAtLH(new Vector3d(0, 0, 0), direction, new Vector3d(0, 1, 0));
            look.Invert();

            WorldMatrix = Matrix3d.Identity;
            WorldMatrix.Translate(Translation);
            double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius;
            WorldMatrix.Scale(new Vector3d(localScale, localScale, localScale));
            WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI)));
            if (RotationalPeriod != 0)
            {
                double rotationCurrent = (((SpaceTimeController.JNow - this.ZeroRotationDate) / RotationalPeriod) * Math.PI * 2) % (Math.PI * 2);
                WorldMatrix.Multiply(Matrix3d.RotationX(-rotationCurrent));
            }

            point = Vector3d.Scale(point, scaleFactor);

            WorldMatrix.Translate(point);

            if (StationKeeping)
            {
                WorldMatrix = look * WorldMatrix;
            }
        }
        private void ComputeFrameSynodic(RenderContext11 renderContext)
        {
            // A synodic frame is a rotating frame of reference in which
            // the x-axis is the direction between the bodies in a two-body
            // system. The origin is at the secondary body, and +x points
            // in the direction opposite the primary. The z-axis is in the orbital
            // plane and normal to x; it points in the direction of the instantaneous
            // orbital velocity of the secondary.

            // The origin is offset by then translation. The five libration points in a
            // two-body system can be approximated by choosing different offsets. For
            // example, the Sun-Earth L2 point is approximated by using x = 1,500,000 km, y = 0 and z = 0.

            WorldMatrix = Matrix3d.Identity;
            double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius;
            WorldMatrix.Scale(new Vector3d(localScale, localScale, localScale));
            WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI)));
            WorldMatrix.Translate(Translation / 6371.000);

            // Currently we assume the Sun-Earth system
            double jd = SpaceTimeController.JNow;
            double B = CAACoordinateTransformation.DegreesToRadians(CAAEarth.EclipticLatitude(jd));
            double L = CAACoordinateTransformation.DegreesToRadians(CAAEarth.EclipticLongitude(jd));
            Vector3d eclPos = new Vector3d(Math.Cos(L) * Math.Cos(B), Math.Sin(L) * Math.Cos(B), Math.Sin(B));

            // Just approximate the orbital velocity for now
            Vector3d eclVel = Vector3d.Cross(eclPos, new Vector3d(0.0, 0.0, 1.0));
            eclVel.Normalize();

            // Convert to WWT's coordinate convention by swapping Y and Z
            eclPos = new Vector3d(eclPos.X, eclPos.Z, eclPos.Y);
            eclVel = new Vector3d(eclVel.X, eclVel.Z, eclVel.Y);

            Vector3d xaxis = eclPos;
            Vector3d yaxis = Vector3d.Cross(eclVel, eclPos);
            Vector3d zaxis = eclVel;
            Matrix3d rotation = new Matrix3d(xaxis.X, yaxis.X, zaxis.X, 0, xaxis.Y, yaxis.Y, zaxis.Y, 0, xaxis.Z, yaxis.Z, zaxis.Z, 0, 0, 0, 0, 1);

            // Convert from ecliptic to J2000 EME (equatorial) system
            double earthObliquity = CAACoordinateTransformation.DegreesToRadians(Coordinates.MeanObliquityOfEcliptic(jd));
            rotation = rotation * Matrix3d.RotationX(-earthObliquity);

            WorldMatrix.Multiply(rotation);
        }
        private void ComputeFixedSherical(RenderContext11 renderContext)
        {
            if (ObservingLocation)
            {
                Lat = SpaceTimeController.Location.Lat;
                Lng = SpaceTimeController.Location.Lng;
                Altitude = SpaceTimeController.Altitude;
            }

            WorldMatrix = Matrix3d.Identity;
            WorldMatrix.Translate(Translation);
            double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius;
            WorldMatrix.Scale(new Vector3d(localScale, localScale, localScale));
            //WorldMatrix.Scale(new Vector3d(1000, 1000, 1000));
            WorldMatrix.Rotate(Quaternion.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI)));
            WorldMatrix.Multiply(Matrix3d.RotationZ(-90.0 / 180.0 * Math.PI));
            if (RotationalPeriod != 0)
            {
                double rotationCurrent = (((SpaceTimeController.JNow - this.ZeroRotationDate) / RotationalPeriod) * Math.PI * 2) % (Math.PI * 2);
                WorldMatrix.Multiply(Matrix3d.RotationX(-rotationCurrent));
            }
            WorldMatrix.Translate(new Vector3d(1 + (Altitude / renderContext.NominalRadius), 0, 0));
            WorldMatrix.Multiply(Matrix3d.RotationZ(Lat / 180 * Math.PI));
            WorldMatrix.Multiply(Matrix3d.RotationY(-(Lng) / 180 * Math.PI));
        }
Example #14
0
        // video
        private void SetupMatricesVideoOverlay(double localZoomFactor)
        {
            if (config.MultiChannelDome1 || config.MultiProjector || DomePreviewPopup.Active)
            {
                SetupMatricesVideoOverlayMultiChannel(localZoomFactor);
                return;
            }

            WorldMatrix = Matrix3d.RotationY(-((0 + 90) / 180.0 * Math.PI));
            WorldMatrix.Multiply(Matrix3d.RotationX(((-0) / 180.0 * Math.PI)));

            double camLocal = 0;


            RenderContext11.World = WorldMatrix;
            RenderContext11.WorldBase = WorldMatrix;
            // altaz

            ViewPoint = Coordinates.RADecTo3d(0, 0, 1.0);

            
            FovAngle = ((360) / FOVMULT) / Math.PI * 180;
            RenderContext11.CameraPosition = new Vector3d(0.0, 0.0, 0.0);
            // This is for distance Calculation. For space everything is the same distance, so camera target is key.
            if (rift)
            {
                Matrix3d matRiftView = Matrix3d.Identity;
                float yaw = 0;
                float pitch = 0;
                float roll = 0;
                eyeRenderPose[0].Orientation.GetEulerAngles(out yaw, out pitch, out roll);

                matRiftView = Matrix3d.RotationY(yaw) * Matrix3d.RotationX(pitch) * Matrix3d.RotationZ(-roll);
                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, new Vector3d(0.0, 0.0, -1.0), new Vector3d(Math.Sin(camLocal), Math.Cos(camLocal), 0.0)) * matRiftView;
                RenderContext11.ViewBase = RenderContext11.View;
            }
            else
            {
                RenderContext11.View = Matrix3d.LookAtLH(RenderContext11.CameraPosition, new Vector3d(0.0, 0.0, -1.0), new Vector3d(Math.Sin(camLocal), Math.Cos(camLocal), 0.0));
                RenderContext11.ViewBase = RenderContext11.View;
            }
            m_nearPlane = 0f;
            if (multiMonClient)
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)(monitorWidth * MonitorCountX) / (double)(monitorHeight * MonitorCountY), 0, -2.0);

            }
            else if (rift)
            {
                FovPort fovPort = eyeRenderDesc[0].Fov;
                RenderContext11.PerspectiveFov = Math.Atan(fovPort.UpTan + fovPort.DownTan);
                ProjMatrix = new Matrix3d();
                var projMat = OVR.MatrixProjection(fovPort, (float)m_nearPlane, (float)back, Projection.None);
                projMat.Transpose();

                ProjMatrix.Matrix11 = projMat;
            }
            else if (megaFrameDump)
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)megaWidth / (double)megaHeight, 0, -2.0);

            }
            else
            {
                ProjMatrix = Matrix3d.PerspectiveFovLH((360/**16*/) / FOVMULT, (double)ViewWidth / (double)renderWindow.ClientRectangle.Height, 0, -2.0);

            }



            if (multiMonClient)
            {
                ProjMatrix.M11 *= MonitorCountX * bezelSpacing;
                ProjMatrix.M22 *= MonitorCountY * bezelSpacing;
                ProjMatrix.M31 = (MonitorCountX - 1) - (MonitorX * bezelSpacing * 2);
                ProjMatrix.M32 = -((MonitorCountY - 1) - (MonitorY * bezelSpacing * 2));
            }

            RenderContext11.Projection = ProjMatrix;

            ViewMatrix = RenderContext11.View;

            MakeFrustum();

        }
Example #15
0
        private static double SetupMatrixForPlanetGeometry(RenderContext11 renderContext, int planetID, Vector3d centerPoint, bool makeFrustum)
        {
            var radius = GetAdjustedPlanetRadius(planetID);

            double rotationCurrent = 0;
            if (planetID == (int)SolarSystemObjects.Earth)
            {
                rotationCurrent = Coordinates.MstFromUTC2(SpaceTimeController.Now, 0) / 180.0 * Math.PI;
            }
            else
            {
                rotationCurrent = (((jNow - 2451545.0) / planetRotationPeriod[planetID]) * Math.PI * 2) % (Math.PI * 2);
            }

            if (planetID == (int)SolarSystemObjects.Moon)
            {
                rotationCurrent -= Math.PI / 2;
            }

            var matLocal = renderContext.World;
            var matNonRotating = renderContext.World;
            var translation = planet3dLocations[planetID] - centerPoint;

            var orientationAtEpoch = GetPlanetOrientationAtEpoch(planetID);

            matLocal.Scale(new Vector3d(radius, radius, radius));
            matLocal.Multiply(Matrix3d.RotationY(-rotationCurrent));
            matLocal.Multiply(orientationAtEpoch);

            if (planetID == (int)Earth3d.MainWindow.viewCamera.Target)
            {
                EarthMatrix = Matrix3d.Identity;
                EarthMatrix.Multiply(Matrix3d.RotationY(-rotationCurrent));
                EarthMatrix.Multiply(orientationAtEpoch);

                EarthMatrixInv = EarthMatrix;
                EarthMatrixInv.Invert();
            }

            matLocal.Multiply(Matrix3d.Translation(translation));
            renderContext.World = matLocal;
            renderContext.WorldBase = renderContext.World;
            renderContext.NominalRadius = GetPlanetRadiusInMeters(planetID);

            if (makeFrustum)
            {
                Earth3d.MainWindow.MakeFrustum();
            }
            matNonRotating.Scale(new Vector3d(radius, radius, radius));
            matNonRotating.Multiply(orientationAtEpoch);
            matNonRotating.Multiply(Matrix3d.Translation(translation));
            renderContext.WorldBaseNonRotating = matNonRotating;
            return rotationCurrent;
        }