public void StartSpin()
        {
            m_bSpinning = true;

            //Get IMessageDispatcher interface
            IMessageDispatcher pMessageDispatcher;

            pMessageDispatcher = new MessageDispatcherClass();

            //Set the ESC key to be seen as a cancel action
            pMessageDispatcher.CancelOnClick    = false;
            pMessageDispatcher.CancelOnEscPress = true;

            do
            {
                //Move the camera observer
                m_pSceneHookHelper.Camera.PolarUpdate(1, m_dSpinStep, 0, true);

                //Redraw the scene viewer
                m_pSceneHookHelper.ActiveViewer.Redraw(true);

                //Dispatch any waiting messages: OnMouseMove/ OnMouseDown/ OnKeyUp/ OnKeyDown events
                object b_oCancel;

                pMessageDispatcher.Dispatch(m_pSceneHookHelper.ActiveViewer.hWnd, false, out b_oCancel);

                if (bCancel == true)
                {
                    m_bSpinning = false;
                }
            }while(bCancel == false);

            bCancel = false;
        }
Example #2
0
        public void Flight()
        {
            //speed in scene units
            double motionUnit = (0.000001 + Math.Abs(observer.Norm() - 1.0) / 200.0) * motion;
            //Get IMessageDispatcher interface
            IMessageDispatcher pMessageDispatcher;

            pMessageDispatcher = new MessageDispatcherClass();

            //Set the ESC key to be seen as a cancel action
            pMessageDispatcher.CancelOnClick    = false;
            pMessageDispatcher.CancelOnEscPress = true;
            bCancel = false;
            do
            {
                //Get the elapsed time
                long   currentClock      = theClock.TickCount;
                double lastFrameDuration = (double)(currentClock - lastClock) / 1000;
                lastClock = currentClock;

                if (lastFrameDuration < 0.01)
                {
                    lastFrameDuration = 0.01;
                }

                if (lastFrameDuration > 1)
                {
                    lastFrameDuration = 0.1;
                }

                System.Diagnostics.Debug.Print(lastFrameDuration.ToString());

                //Windows API call to get windows client coordinates
                Rectangle rect = new Rectangle();
                if (GetClientRect(globeDisplay.ActiveViewer.hWnd, ref rect) == 0)
                {
                    return;
                }

                //Get normal vectors
                double dXMouseNormal, dYMouseNormal;

                dXMouseNormal = 2 * ((double)mouseX / (double)(rect.Right - rect.Left)) - 1;
                dYMouseNormal = 2 * ((double)mouseY / (double)(rect.Bottom - rect.Top)) - 1;

                PointZ dir = this.RotateNormal(lastFrameDuration, dXMouseNormal, dYMouseNormal);

                PointZ visTarget = new PointZ(observer.x + distance * dir.x, observer.y + distance * dir.y, observer.z + distance * dir.z);
                target.x = visTarget.x;
                target.y = visTarget.y;
                target.z = visTarget.z;

                if (speed != 0)
                {
                    int speedFactor = (speed > 0) ? (1 << speed) : -(1 << (-speed));

                    //Move the camera in the viewing directions
                    observer.x = observer.x + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.x);
                    observer.y = observer.y + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.y);
                    observer.z = observer.z + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.z);
                    target.x   = target.x + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.x);
                    target.y   = target.y + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.y);
                    target.z   = target.z + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.z);
                }

                ESRI.ArcGIS.GlobeCore.IGlobeViewUtil globeViewUtil = globeCamera as ESRI.ArcGIS.GlobeCore.IGlobeViewUtil;
                double obsLat;
                double obsLon;
                double obsAlt;
                double tarLat;
                double tarLon;
                double tarAlt;

                globeViewUtil.GeocentricToGeographic(observer.x, observer.y, observer.z, out obsLon, out obsLat, out obsAlt);
                globeViewUtil.GeocentricToGeographic(target.x, target.y, target.z, out tarLon, out tarLat, out tarAlt);
                globeCamera.SetObserverLatLonAlt(obsLat, obsLon, obsAlt / 1000);
                globeCamera.SetTargetLatLonAlt(tarLat, tarLon, tarAlt / 1000);

                globeCamera.SetAccurateViewDirection(target.x - observer.x, target.y - observer.y, target.z - observer.z);

                double rollAngle = 0;
                if (speed > 0)
                {
                    rollAngle = 10 * dXMouseNormal * Math.Abs(dXMouseNormal);
                }
                camera.RollAngle = rollAngle;

                //Redraw the scene viewer
                globeDisplay.RefreshViewers();

                //Dispatch any waiting messages: OnMouseMove / OnMouseUp / OnKeyUp events
                object objCancel = bCancel as object;
                pMessageDispatcher.Dispatch(globeDisplay.ActiveViewer.hWnd, false, out objCancel);

                //End flight if ESC key pressed
                if (bCancel == true)
                {
                    EndFlight();
                }
            }while (inUse == true && bCancel == false);

            bCancel = false;
        }
Example #3
0
        public void Flight()
        {
            //Get IMessageDispatcher interface
            IMessageDispatcher pMessageDispatcher;

            pMessageDispatcher = new MessageDispatcherClass();

            //Set the ESC key to be seen as a cancel action
            pMessageDispatcher.CancelOnClick    = false;
            pMessageDispatcher.CancelOnEscPress = true;

            //Get the scene graph
            ISceneGraph pSceneGraph = (ISceneGraph)m_pSceneHookHelper.SceneGraph;

            //Get the scene viewer
            ISceneViewer pSceneViewer = (ISceneViewer)m_pSceneHookHelper.ActiveViewer;

            //Get the camera
            ICamera pCamera = (ICamera)m_pSceneHookHelper.Camera;

            bCancel = false;

            do
            {
                //Get the elapsed time
                double dlastFrameDuration, dMeanFrameRate;

                pSceneGraph.GetDrawingTimeInfo(out dlastFrameDuration, out dMeanFrameRate);

                if (dlastFrameDuration < 0.01)
                {
                    dlastFrameDuration = 0.01;
                }

                if (dlastFrameDuration > 1)
                {
                    dlastFrameDuration = 1;
                }

                //Windows API call to get windows client coordinates
                Rectangle rect = new Rectangle();
                if (GetClientRect(m_pSceneHookHelper.ActiveViewer.hWnd, ref rect) == 0)
                {
                    return;
                }

                //Get normal vectors
                double dXMouseNormal, dYMouseNormal;

                dXMouseNormal = 2 * ((double)m_lMouseX / (double)rect.Right) - 1;
                dYMouseNormal = 2 * ((double)m_lMouseY / (double)rect.Bottom) - 1;

                //Set elevation and azimuth in radians for normal rotation
                m_dElevation = m_dElevation - (dlastFrameDuration * dYMouseNormal * Math.Abs(dYMouseNormal));
                m_dAzimut    = m_dAzimut - (dlastFrameDuration * dXMouseNormal * Math.Abs(dXMouseNormal));
                if (m_dElevation > 0.45 * 3.141592)
                {
                    m_dElevation = 0.45 * 3.141592;
                }

                if (m_dElevation < -0.45 * 3.141592)
                {
                    m_dElevation = -0.45 * 3.141592;
                }

                if (m_dAzimut < 0)
                {
                    m_dAzimut = m_dAzimut + (2 * 3.141592);
                }

                if (m_dAzimut > 2 * 3.141592)
                {
                    m_dAzimut = m_dAzimut - (2 * 3.141592);
                }

                double dx, dy, dz;

                dx = Math.Cos(m_dElevation) * Math.Cos(m_dAzimut);
                dy = Math.Cos(m_dElevation) * Math.Sin(m_dAzimut);
                dz = Math.Sin(m_dElevation);

                //Change the viewing directions (target)
                m_pPointTgt.X = m_pPointObs.X + (m_dDistance * dx);
                m_pPointTgt.Y = m_pPointObs.Y + (m_dDistance * dy);
                m_pPointTgt.Z = m_pPointObs.Z + (m_dDistance * dz);

                //Move the camera in the viewing directions
                m_pPointObs.X = m_pPointObs.X + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dx);
                m_pPointObs.Y = m_pPointObs.Y + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dy);
                m_pPointTgt.X = m_pPointTgt.X + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dx);
                m_pPointTgt.Y = m_pPointTgt.Y + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dy);
                m_pPointObs.Z = m_pPointObs.Z + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dz);
                m_pPointTgt.Z = m_pPointTgt.Z + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dz);

                pCamera.Observer = m_pPointObs;
                pCamera.Target   = m_pPointTgt;

                //Set the angle of the camera about the line of sight between the observer and target
                pCamera.RollAngle = 10 * dXMouseNormal * Math.Abs(dXMouseNormal);

                //Redraw the scene viewer
                pSceneViewer.Redraw(true);

                object objCancel;

                //Dispatch any waiting messages: OnMouseMove / OnMouseUp / OnKeyUp events
                //object objCancel = bCancel as object;
                pMessageDispatcher.Dispatch(m_pSceneHookHelper.ActiveViewer.hWnd, false, out objCancel);

                //End flight if ESC key pressed
                if (bCancel == true)
                {
                    EndFlight();
                }
            }while(m_bInUse == true && bCancel == false);

            bCancel = false;
        }
		public void StartSpin()
		{
			m_bSpinning = true;

			//Get IMessageDispatcher interface
			IMessageDispatcher pMessageDispatcher;
			pMessageDispatcher = new MessageDispatcherClass();

			//Set the ESC key to be seen as a cancel action
			pMessageDispatcher.CancelOnClick = false;
			pMessageDispatcher.CancelOnEscPress = true;

			do
			{
				//Move the camera observer
				m_pSceneHookHelper.Camera.PolarUpdate(1, m_dSpinStep, 0, true);

				//Redraw the scene viewer
				m_pSceneHookHelper.ActiveViewer.Redraw(true);

				//Dispatch any waiting messages: OnMouseMove/ OnMouseDown/ OnKeyUp/ OnKeyDown events
				object b_oCancel;

				pMessageDispatcher.Dispatch(m_pSceneHookHelper.ActiveViewer.hWnd, false, out b_oCancel);

				if(bCancel == true)
					m_bSpinning = false;
			}
			while(bCancel == false);

			bCancel = false;

		}
		public void Flight()
		{
			//Get IMessageDispatcher interface
			IMessageDispatcher pMessageDispatcher;
			pMessageDispatcher = new MessageDispatcherClass();

			//Set the ESC key to be seen as a cancel action
			pMessageDispatcher.CancelOnClick = false;
			pMessageDispatcher.CancelOnEscPress = true;

			//Get the scene graph
			ISceneGraph pSceneGraph = (ISceneGraph) m_pSceneHookHelper.SceneGraph;

			//Get the scene viewer
			ISceneViewer pSceneViewer = (ISceneViewer) m_pSceneHookHelper.ActiveViewer;

			//Get the camera
			ICamera pCamera = (ICamera) m_pSceneHookHelper.Camera;

			bCancel = false;

			do
			{
				//Get the elapsed time
				double dlastFrameDuration, dMeanFrameRate;

				pSceneGraph.GetDrawingTimeInfo(out dlastFrameDuration, out dMeanFrameRate);

				if(dlastFrameDuration < 0.01)
					dlastFrameDuration = 0.01;

				if(dlastFrameDuration > 1)
					dlastFrameDuration = 1;

				//Windows API call to get windows client coordinates
				Rectangle rect = new Rectangle();
				if (GetClientRect(m_pSceneHookHelper.ActiveViewer.hWnd, ref rect) == 0) return;
				
				//Get normal vectors
				double dXMouseNormal, dYMouseNormal;

				dXMouseNormal = 2 * ((double)m_lMouseX / (double)rect.Right) - 1;
				dYMouseNormal = 2 * ((double)m_lMouseY / (double)rect.Bottom) - 1;
				
				//Set elevation and azimuth in radians for normal rotation
				m_dElevation = m_dElevation - (dlastFrameDuration * dYMouseNormal * Math.Abs(dYMouseNormal));
				m_dAzimut = m_dAzimut - (dlastFrameDuration * dXMouseNormal * Math.Abs(dXMouseNormal));
				if(m_dElevation > 0.45 * 3.141592)
					m_dElevation = 0.45 * 3.141592;

				if(m_dElevation < -0.45 * 3.141592)
					m_dElevation = -0.45 * 3.141592;

				if(m_dAzimut < 0)
					m_dAzimut = m_dAzimut + (2 * 3.141592);

				if(m_dAzimut > 2 * 3.141592)
					m_dAzimut = m_dAzimut - (2 * 3.141592);
				
				double dx, dy, dz;

				dx = Math.Cos(m_dElevation) * Math.Cos(m_dAzimut);
				dy = Math.Cos(m_dElevation) * Math.Sin(m_dAzimut);
				dz = Math.Sin(m_dElevation);

				//Change the viewing directions (target)
				m_pPointTgt.X = m_pPointObs.X + (m_dDistance * dx);
				m_pPointTgt.Y = m_pPointObs.Y + (m_dDistance * dy);
				m_pPointTgt.Z = m_pPointObs.Z + (m_dDistance * dz);

				//Move the camera in the viewing directions
				m_pPointObs.X = m_pPointObs.X + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dx);
				m_pPointObs.Y = m_pPointObs.Y + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dy);
				m_pPointTgt.X = m_pPointTgt.X + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dx);
				m_pPointTgt.Y = m_pPointTgt.Y + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dy);
				m_pPointObs.Z = m_pPointObs.Z + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dz);
				m_pPointTgt.Z = m_pPointTgt.Z + (dlastFrameDuration * (2 ^ m_iSpeed) * m_dMotion * dz);

				pCamera.Observer = m_pPointObs;
				pCamera.Target = m_pPointTgt;
				
				//Set the angle of the camera about the line of sight between the observer and target
				pCamera.RollAngle = 10 * dXMouseNormal * Math.Abs(dXMouseNormal);

				//Redraw the scene viewer 
				pSceneViewer.Redraw(true);

				object objCancel;

				//Dispatch any waiting messages: OnMouseMove / OnMouseUp / OnKeyUp events
				//object objCancel = bCancel as object;
				pMessageDispatcher.Dispatch(m_pSceneHookHelper.ActiveViewer.hWnd, false, out objCancel);
				
				//End flight if ESC key pressed
				if (bCancel == true)
					EndFlight();
			}
			while(m_bInUse == true && bCancel == false);

			bCancel = false;
		}
        public void Flight()
        {
            //speed in scene units
            double motionUnit = (0.000001 + Math.Abs(observer.Norm() - 1.0) / 200.0) * motion;
            //Get IMessageDispatcher interface
            IMessageDispatcher pMessageDispatcher;
            pMessageDispatcher = new MessageDispatcherClass();

            //Set the ESC key to be seen as a cancel action
            pMessageDispatcher.CancelOnClick = false;
            pMessageDispatcher.CancelOnEscPress = true;
            bCancel = false;
            do
            {
                //Get the elapsed time
                long currentClock = theClock.TickCount;
                double lastFrameDuration = (double)(currentClock - lastClock) / 1000;
                lastClock = currentClock;

                if (lastFrameDuration < 0.01)
                    lastFrameDuration = 0.01;

                if (lastFrameDuration > 1)
                    lastFrameDuration = 0.1;

                System.Diagnostics.Debug.Print(lastFrameDuration.ToString());

                //Windows API call to get windows client coordinates
                Rectangle rect = new Rectangle();
                if (GetClientRect(globeDisplay.ActiveViewer.hWnd, ref rect) == 0) return;

                //Get normal vectors
                double dXMouseNormal, dYMouseNormal;

                dXMouseNormal = 2 * ((double)mouseX / (double)(rect.Right - rect.Left)) - 1;
                dYMouseNormal = 2 * ((double)mouseY / (double)(rect.Bottom - rect.Top)) - 1;

                PointZ dir = this.RotateNormal(lastFrameDuration, dXMouseNormal, dYMouseNormal);

                PointZ visTarget = new PointZ(observer.x + distance * dir.x, observer.y + distance * dir.y, observer.z + distance * dir.z);
                target.x = visTarget.x;
                target.y = visTarget.y;
                target.z = visTarget.z;

                if (speed != 0)
                {
                    int speedFactor = (speed > 0) ? (1 << speed) : -(1 << (-speed));

                    //Move the camera in the viewing directions
                    observer.x = observer.x + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.x);
                    observer.y = observer.y + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.y);
                    observer.z = observer.z + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.z);
                    target.x = target.x + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.x);
                    target.y = target.y + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.y);
                    target.z = target.z + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.z);
                }

                ESRI.ArcGIS.GlobeCore.IGlobeViewUtil globeViewUtil = globeCamera as ESRI.ArcGIS.GlobeCore.IGlobeViewUtil;
                double obsLat;
                double obsLon;
                double obsAlt;
                double tarLat;
                double tarLon;
                double tarAlt;

                globeViewUtil.GeocentricToGeographic(observer.x, observer.y, observer.z, out obsLon, out obsLat, out obsAlt);
                globeViewUtil.GeocentricToGeographic(target.x, target.y, target.z, out tarLon, out tarLat, out tarAlt);
                globeCamera.SetObserverLatLonAlt(obsLat, obsLon, obsAlt / 1000);
                globeCamera.SetTargetLatLonAlt(tarLat, tarLon, tarAlt / 1000);

                globeCamera.SetAccurateViewDirection(target.x - observer.x, target.y - observer.y, target.z - observer.z);

                double rollAngle = 0;
                if (speed > 0)
                {
                    rollAngle = 10 * dXMouseNormal * Math.Abs(dXMouseNormal);
                }
                camera.RollAngle = rollAngle;

                //Redraw the scene viewer 
                globeDisplay.RefreshViewers();

                //Dispatch any waiting messages: OnMouseMove / OnMouseUp / OnKeyUp events
                object objCancel = bCancel as object;
                pMessageDispatcher.Dispatch(globeDisplay.ActiveViewer.hWnd, false, out objCancel);

                //End flight if ESC key pressed
                if (bCancel == true)
                    EndFlight();

            }
            while (inUse == true && bCancel == false);

            bCancel = false;
        }