Example #1
0
        public ParagliderSimulator()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            this.IsFixedTimeStep  = true;

            if (orEnabled)
            {
                oculusClient     = new OculusClient();
                scaleImageFactor = 0.71f;

                graphics.PreferredBackBufferWidth  = (int)Math.Ceiling(resolutionX / scaleImageFactor);
                graphics.PreferredBackBufferHeight = (int)Math.Ceiling(resolutionY / scaleImageFactor);
                graphics.IsFullScreen = true;
            }
            else
            {
                graphics.PreferredBackBufferWidth  = (int)resolutionX;
                graphics.PreferredBackBufferHeight = (int)resolutionY;
                graphics.IsFullScreen = false;
            }

            graphics.ApplyChanges();
            Window.Title = "ParagliderSim";
        }
Example #2
0
 private void DroneTakeOff()
 {
     droneClient.FlatTrim();//before take off send this command
     headPositionStart = OculusClient.GetOrientation();
     if (lastCommandSent != CommandType.TakeOff)
     {
         droneClient.Takeoff();
         lastCommandSent = CommandType.TakeOff;
     }
 }
Example #3
0
        private void SetProjectionOffset()
        {
            viewCenter             = OculusClient.GetScreenSize().X * 0.212f; // 0.25f 0.212f
            eyeProjectionShift     = viewCenter - OculusClient.GetLensSeparationDistance() * 0.5f;
            projectionCenterOffset = 4.0f * eyeProjectionShift / OculusClient.GetScreenSize().X;

            projCenter = originalProjectionMatrix;
            projLeft   = Matrix.CreateTranslation(projectionCenterOffset, 0, 0) * projCenter;
            projRight  = Matrix.CreateTranslation(-projectionCenterOffset, 0, 0) * projCenter;

            halfIPD = OculusClient.GetInterpupillaryDistance() * 0.5f;

            viewLeft  = viewMatrix * Matrix.CreateTranslation(halfIPD, 0, 0);
            viewRight = viewMatrix * Matrix.CreateTranslation(-halfIPD, 0, 0);
        }
Example #4
0
        private void InitOculus()
        {
            // Load the Oculus Rift Distortion Shader
            // https://mega.co.nz/#!E4YkjJ6K!MuIDuB78NwgHsGgeONikDAT_OLJQ0ZeLXbfGF1OAhzw
            oculusRiftDistortionShader = Content.Load <Effect>(@"Shader/OculusRift");

            aspectRatio = (float)(OculusClient.GetScreenResolution().X * 0.5f / (float)(OculusClient.GetScreenResolution().Y));
            fov_d       = OculusClient.GetEyeToScreenDistance();
            fov_x       = OculusClient.GetScreenSize().Y *scaleImageFactor;
            yfov        = 2.0f * (float)Math.Atan(fov_x / fov_d);

            // Set ProjectionMatrix
            originalProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(yfov, aspectRatio, 0.05f, 10000.0f);

            // Init left and right RenderTarget
            renderTargetLeft  = new RenderTarget2D(device, graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight, true, SurfaceFormat.Bgr565, DepthFormat.Depth24Stencil8);
            renderTargetRight = new RenderTarget2D(device, graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight, true, SurfaceFormat.Bgr565, DepthFormat.Depth24Stencil8);

            OculusClient.SetSensorPredictionTime(0, 0.03f);
            UpdateResolutionAndRenderTargets();
        }
Example #5
0
        protected override void LoadContent()
        {
            renderTarget = new RenderTarget2D(GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            spriteBatch  = new SpriteBatch(GraphicsDevice);
            hudFontSmall = Content.Load <SpriteFont>(@"Fonts\FontSmall");
            if (drawTestImage)
            {
                videoTexture = Content.Load <Texture2D>(@"test");
            }
            else
            {
                videoTexture = new Texture2D(GraphicsDevice, 640, 360, false, SurfaceFormat.Color);
            }

            colorData = new Microsoft.Xna.Framework.Color[640 * 360];
            videoPacketDecoderWorker = new VideoPacketDecoderWorker(PixelFormat.BGR24, true, OnVideoPacketDecoded);
            videoPacketDecoderWorker.Start();
            droneClient = new DroneClient();
            droneClient.VideoPacketAcquired  += OnVideoPacketAcquired;
            droneClient.ConfigurationUpdated += OnConfigurationUpdated;
            droneClient.Active = true;
            try
            {
                kinect = new KinectClient("it-IT");
                kinect.VoiceCommandRecognized   += OnVoiceCommandRecognized;
                kinect.VoiceCommandRejected     += OnVoiceCommandRejected;
                kinect.GestureCommandRecognized += OnGestureRecognized;
                kinectMessage = "Kinect trovato. Riconoscimento vocale e comandi attivi...";
            }
            catch (Exception e)
            {
                kinectMessage = e.Message;
            }
            oculusRiftDistortionShader = Content.Load <Effect>("Shaders/OculusRift");
            oculusClient = new OculusClient();
            UpdateResolutionAndRenderTargets();
            screenType = ScreenType.Splash; //The splash show commands
        }
Example #6
0
        private void UpdateViewMatrix()
        {
            Vector3 cameraPosition;

            playerBodyRotation = Matrix.CreateRotationZ(rotZ) * Matrix.CreateRotationX(updownRot) * Matrix.CreateRotationY(lefrightRot);

            if (game.OREnabled)
            {
                cameraRotation = Matrix.CreateFromQuaternion(OculusClient.GetPredictedOrientation()) * playerBodyRotation;

                //Neck movement
                Vector3 neck  = new Vector3(0, 0.3f, 0);
                Vector3 neck2 = Vector3.Transform(neck, playerBodyRotation);
                cameraPosition  = playerPosition - neck2;
                neck            = Vector3.Transform(neck, Matrix.CreateFromQuaternion((OculusClient.GetPredictedOrientation()) * 0.65f) * playerBodyRotation);
                cameraPosition += neck;
            }
            else
            {
                cameraRotation = playerBodyRotation;
                cameraPosition = playerPosition;
            }

            cameraOriginalTarget = new Vector3(0, 0, -1);
            cameraRotatedTarget  = Vector3.Transform(cameraOriginalTarget, cameraRotation);
            cameraFinalTarget    = cameraPosition + cameraRotatedTarget;

            cameraOriginalUpVector = new Vector3(0, 1, 0);
            cameraRotatedUpVector  = Vector3.Transform(cameraOriginalUpVector, cameraRotation);

            game.ViewMatrix = Matrix.CreateLookAt(cameraPosition, cameraFinalTarget, cameraRotatedUpVector);

            //player
            playerWorld  = Matrix.Identity * Matrix.CreateScale(0.01f) * Matrix.CreateRotationY((float)Math.PI) * playerBodyRotation * Matrix.CreateTranslation(playerPosition);
            playerSphere = originalPlayerSphere.Transform(playerWorld);
        }
Example #7
0
        private void processInput(float amount)
        {
            KeyboardState keyState = Keyboard.GetState();
            GamePadState  padState = GamePad.GetState(PlayerIndex.One);

            //arms
            leftArmRotX  = 0f;
            rightArmRotX = 0f;

            if (padState.IsConnected && padState.ThumbSticks.Left != Vector2.Zero && padState.ThumbSticks.Left.Y > 0)
            {
                updownRot = padState.ThumbSticks.Left.Y * 0.153f * -1f;
            }

            //downforce
            float downforce = ((float)Math.Sin(updownRot) * (-1f)) + 0.05f;

            moveSpeed = currentWing.Speed;

            //acceleration
            float leftAcceleration  = ((float)Math.Sin(updownRot) * -9.8f) + 0.25f;
            float rightAcceleration = ((float)Math.Sin(updownRot) * -9.8f) + 0.25f;
            float dragX             = 3f / 8f;

            //Keyboard
            if (keyState.IsKeyDown(Keys.Left) || keyState.IsKeyDown(Keys.A))
            {
                leftArmRotX      = -maxArmRot;
                leftAcceleration = 0;
            }
            if (keyState.IsKeyDown(Keys.Right) || keyState.IsKeyDown(Keys.D))
            {
                rightArmRotX      = -maxArmRot;
                rightAcceleration = 0;
            }
            if (keyState.IsKeyDown(Keys.R))
            {
                OculusClient.ResetSensorOrientation(0);
            }

            //gamepad
            if (padState.IsConnected && padState.Triggers.Left != 0)
            {
                leftArmRotX       = -maxArmRot * padState.Triggers.Left;
                leftAcceleration -= leftAcceleration * padState.Triggers.Left;
            }

            if (padState.IsConnected && padState.Triggers.Right != 0)
            {
                rightArmRotX       = -maxArmRot * padState.Triggers.Right;
                rightAcceleration -= rightAcceleration * padState.Triggers.Right;
            }

            if (padState.IsConnected && padState.Buttons.A == ButtonState.Pressed)
            {
                OculusClient.ResetSensorOrientation(0);
            }

            //Beveger glideren og henter ut rotasjon
            currentWing.move(wind, game.Terrain.getUpdraft(playerPosition), downforce, leftAcceleration, rightAcceleration, amount, dragX);
            lefrightRot += currentWing.getRotationY();
            rotZ         = currentWing.getRotationZ();

            Vector3 upDraft = new Vector3(0, 1, 0) * game.Terrain.getUpdraft(playerPosition);

            if (game.currentGameState == gameState.Playing)
            {
                AddToPlayerPosition(currentWing.getMovementVector() + (upDraft * amount));
            }

            UpdateViewMatrix();
        }
Example #8
0
        public CaptureSelection()
        {
            InitializeComponent();

            //Oculus code
            if (OculusClient.isHMDPresent() == true)
            {
                detectedLabel.Text = "Rift Detected; Data should be valid.";
                //Scan oculus angles. I store them in a Vector3 with 3 values for each axis.
                //It's a quaternion, so I convert it to Euler angles (X, Y, Z)
                Vector3 oculusAngles = Helpers.ToEulerAngles(OculusClient.GetPredictedOrientation());

                //Format the float angles and send them to the labels
                XLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.X);
                YLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Y);
                ZLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Z);

                //Scan Oculus's resolution and format it
                Vector2 oculusResolution = OculusClient.GetScreenResolution();
                resolutionLabel.Text = String.Format(oculusResolution.X + "x" + oculusResolution.Y);
            }
            else
            {
                detectedLabel.Text = "No Rift Detected; Data is invalid.";
            }

            //Scott's code
            var screens = System.Windows.Forms.Screen.AllScreens;

            var mapInstanceToUserFriendly = new Dictionary <string, string>();

            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM WmiMonitorID");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    string instanceName     = (string)queryObj["InstanceName"];
                    string userFriendlyName = "";

                    if ((instanceName != null) && (queryObj["UserFriendlyName"] != null))
                    {
                        UInt16[] arrUserFriendlyName = (UInt16[])(queryObj["UserFriendlyName"]);
                        foreach (UInt16 arrValue in arrUserFriendlyName)
                        {
                            if (arrValue == 0)
                            {
                                break;
                            }
                            userFriendlyName += Convert.ToChar(arrValue);
                        }

                        instanceName = instanceName.Replace('\\', '#');
                        string[] splitInstance = instanceName.Split('_');
                        if ((splitInstance != null) && (splitInstance.Length >= 1))
                        {
                            instanceName = splitInstance[0];

                            mapInstanceToUserFriendly[instanceName] = userFriendlyName;
                        }
                    }
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message + ".  Exiting.", "Ocucam - Error");
                Environment.Exit(-1);
            }


            var            mapIdsToDisplay = new Dictionary <int, Display>();
            DISPLAY_DEVICE d = new DISPLAY_DEVICE();

            d.cb = Marshal.SizeOf(d);
            try
            {
                for (int id = 0; EnumDisplayDevices(null, (uint)id, ref d, 0); id++)
                {
                    string name = d.DeviceName;
                    d.cb = Marshal.SizeOf(d);
                    EnumDisplayDevices(name, 0, ref d, EDD_GET_DEVICE_INTERFACE_NAME);

                    foreach (string instanceName in mapInstanceToUserFriendly.Keys)
                    {
                        if (d.DeviceID.Contains(instanceName))
                        {
                            mapIdsToDisplay[id] = new Display(id, mapInstanceToUserFriendly[instanceName], instanceName);
                            break;
                        }
                    }

                    d.cb = Marshal.SizeOf(d);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error enumerating display devices.  Exiting.", "Ocucam - Error");
                Environment.Exit(-1);
            }

            DSVideoCaptureCategory captureCategory = new DSVideoCaptureCategory();

            if (captureCategory.Objects.Count < 2)
            {
                if (captureCategory.Objects.Count == 0)
                {
                    MessageBox.Show("System must have at least two distinct video capture devices.  None were found.  Exiting.", "Ocucam - Error");
                }
                else
                {
                    MessageBox.Show("System must have at least two distinct video capture devices.  Only one was found.  Exiting.", "Ocucam - Error");
                }
                Environment.Exit(-1);
            }

            RegistryKey softwareKey              = Registry.CurrentUser.OpenSubKey("Software", true);
            RegistryKey scottCutlerKey           = softwareKey.CreateSubKey("Scott Cutler");
            RegistryKey ocucamKey                = scottCutlerKey.CreateSubKey("Ocucam");
            string      leftEyeDevicePathReg     = (string)ocucamKey.GetValue("leftEyeDevicePath", "");
            string      rightEyeDevicePathReg    = (string)ocucamKey.GetValue("rightEyeDevicePath", "");
            string      displayDeviceInstanceReg = (string)ocucamKey.GetValue("displayDeviceInstance", "");

            checkBoxFullScreen.Checked = ((string)ocucamKey.GetValue("fullScreen", "True") == "True") ? true : false;
            ocucamKey.Close();
            scottCutlerKey.Close();
            softwareKey.Close();

            captureCategory.Objects.Sort((a, b) => { return(a.DevicePath.CompareTo(b.DevicePath)); });

            var objectCount = new Dictionary <string, int>();

            foreach (var captureDevice in captureCategory.Objects)
            {
                if (objectCount.ContainsKey(captureDevice.DevicePath))
                {
                    objectCount[captureDevice.DevicePath]++;
                }
                else
                {
                    objectCount.Add(captureDevice.DevicePath, 1);
                }

                DSDeviceWrap dw = new DSDeviceWrap(captureDevice, objectCount[captureDevice.DevicePath]);

                leftEyeDevice.Items.Add(dw);
                if (leftEyeDevicePathReg == captureDevice.DevicePath)
                {
                    leftEyeDevice.SelectedIndex = leftEyeDevice.Items.Count - 1;
                }

                rightEyeDevice.Items.Add(dw);
                if (rightEyeDevicePathReg == captureDevice.DevicePath)
                {
                    rightEyeDevice.SelectedIndex = rightEyeDevice.Items.Count - 1;
                }
            }

            foreach (var displayId in mapIdsToDisplay.Keys)
            {
                comboBoxDisplay.Items.Add(mapIdsToDisplay[displayId]);

                if (displayDeviceInstanceReg == mapIdsToDisplay[displayId].instance)
                {
                    comboBoxDisplay.SelectedIndex = comboBoxDisplay.Items.Count - 1;
                }
            }
        }
Example #9
0
        //head dx, sx, up, down
        private void OculusHandle()
        {
            oculusXText = "On Hold";
            oculusYText = "On Hold";
            var cameraPositionNew = OculusClient.GetOrientation();
            var delta             = headPositionStart.X - cameraPositionNew.X;
            var compare           = delta;

            if (delta < 0)
            {
                delta *= -1;
            }
            if (delta >= xThreshold)
            {
                if (compare > 0)
                {
                    oculusXText = "Right";
                    if (lastCommandSent != CommandType.TurnRight)
                    {
                        lastCommandSent = CommandType.TurnRight;
                        droneClient.Progress(Drone.Commands.FlightMode.Progressive, yaw: 0.4f);
                    }
                }
                else
                {
                    oculusXText = "Left";
                    if (lastCommandSent != CommandType.TurnLeft)
                    {
                        lastCommandSent = CommandType.TurnLeft;
                        droneClient.Progress(Drone.Commands.FlightMode.Progressive, yaw: -0.4f);
                    }
                }
                return;
            }
            delta   = headPositionStart.Y - cameraPositionNew.Y;
            compare = delta;
            if (delta < 0)
            {
                delta *= -1;
            }
            if (delta >= yThreshold)
            {
                if (compare > 0)
                {
                    oculusYText = "Up";
                    if (lastCommandSent != CommandType.GoUp)
                    {
                        lastCommandSent = CommandType.GoUp;
                        droneClient.Progress(Drone.Commands.FlightMode.Progressive, gaz: 0.4f);
                    }
                }
                else
                {
                    oculusYText = "Down";
                    if (lastCommandSent != CommandType.GoDown)
                    {
                        lastCommandSent = CommandType.GoDown;
                        droneClient.Progress(Drone.Commands.FlightMode.Progressive, gaz: -0.4f);
                    }
                }
            }
        }