示例#1
0
    public static bool ImportDisplay(RUISDisplay display, string filename, TextAsset displaySchema, bool loadFromFileInEditor)
    {
        XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, displaySchema);

        if (xmlDoc == null)
        {
            return(false);
        }

        if (Application.isEditor && loadFromFileInEditor)
        {
            display.displayCenterPosition = XMLUtil.GetVector3FromXmlNode(xmlDoc.GetElementsByTagName("displayCenterPosition").Item(0));
            display.displayUpInternal     = XMLUtil.GetVector3FromXmlNode(xmlDoc.GetElementsByTagName("displayUp").Item(0));
            display.displayNormalInternal = XMLUtil.GetVector3FromXmlNode(xmlDoc.GetElementsByTagName("displayNormal").Item(0));
            display.width       = float.Parse(xmlDoc.GetElementsByTagName("displaySize").Item(0).Attributes["width"].Value);
            display.height      = float.Parse(xmlDoc.GetElementsByTagName("displaySize").Item(0).Attributes["height"].Value);
            display.resolutionX = int.Parse(xmlDoc.GetElementsByTagName("displayResolution").Item(0).Attributes["width"].Value);
            display.resolutionY = int.Parse(xmlDoc.GetElementsByTagName("displayResolution").Item(0).Attributes["height"].Value);
        }

        if (display.linkedCamera)
        {
            display.linkedCamera.LoadKeystoningFromXML(xmlDoc);
        }

        return(true);
    }
示例#2
0
    //Load the transformation data from an xml file created by the calibration part
    public bool LoadXML(string filename)
    {
        XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, coordinateSchema);

        if (xmlDoc == null)
        {
            return(false);
        }


        Matrix4x4 moveToKinectTransform = new Matrix4x4();
        XmlNode   translationElement    = xmlDoc.GetElementsByTagName("translate").Item(0);
        float     x = float.Parse(translationElement.Attributes["x"].Value);
        float     y = float.Parse(translationElement.Attributes["y"].Value);
        float     z = float.Parse(translationElement.Attributes["z"].Value);

        moveToKinectTransform.SetColumn(3, new Vector4(x, y, z, 1.0f));

        XmlNode rotationElement = xmlDoc.GetElementsByTagName("rotate").Item(0);

        moveToKinectTransform.m00 = float.Parse(rotationElement.Attributes["r00"].Value);
        moveToKinectTransform.m01 = float.Parse(rotationElement.Attributes["r01"].Value);
        moveToKinectTransform.m02 = float.Parse(rotationElement.Attributes["r02"].Value);
        moveToKinectTransform.m10 = float.Parse(rotationElement.Attributes["r10"].Value);
        moveToKinectTransform.m11 = float.Parse(rotationElement.Attributes["r11"].Value);
        moveToKinectTransform.m12 = float.Parse(rotationElement.Attributes["r12"].Value);
        moveToKinectTransform.m20 = float.Parse(rotationElement.Attributes["r20"].Value);
        moveToKinectTransform.m21 = float.Parse(rotationElement.Attributes["r21"].Value);
        moveToKinectTransform.m22 = float.Parse(rotationElement.Attributes["r22"].Value);

        moveToRUISTransform = moveToKinectTransform;

        List <Vector3> rotationVectors = MathUtil.Orthonormalize(MathUtil.ExtractRotationVectors(moveToKinectTransform));
        Matrix4x4      rotationMatrix  = new Matrix4x4();

        rotationMatrix.SetColumn(0, rotationVectors[0]);
        rotationMatrix.SetColumn(1, rotationVectors[1]);
        rotationMatrix.SetColumn(2, rotationVectors[2]);

        moveToKinectRotation = MathUtil.QuaternionFromMatrix(rotationMatrix);

        XmlNode kinectFloorNormalElement = xmlDoc.GetElementsByTagName("kinectFloorNormal").Item(0);

        if (kinectFloorNormalElement != null)
        {
            SetKinectFloorNormal(new Vector3(float.Parse(kinectFloorNormalElement.Attributes["x"].Value),
                                             float.Parse(kinectFloorNormalElement.Attributes["y"].Value),
                                             float.Parse(kinectFloorNormalElement.Attributes["z"].Value)));
        }

        XmlNode kinectDistanceFromFloorElement = xmlDoc.GetElementsByTagName("kinectDistanceFromFloor").Item(0);

        if (kinectDistanceFromFloorElement != null)
        {
            kinectDistanceFromFloor = float.Parse(kinectDistanceFromFloorElement.Attributes["value"].Value);
        }

        return(true);
    }
示例#3
0
    public static bool ImportInputManager(RUISInputManager inputManager, string filename, TextAsset xmlSchema)
    {
        XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, xmlSchema);

        if (xmlDoc == null)
        {
            return(false);
        }

        XmlNode psMoveNode = xmlDoc.GetElementsByTagName("PSMoveSettings").Item(0);

        inputManager.enablePSMove                    = bool.Parse(psMoveNode.SelectSingleNode("enabled").Attributes["value"].Value);
        inputManager.PSMoveIP                        = psMoveNode.SelectSingleNode("ip").Attributes["value"].Value;
        inputManager.PSMovePort                      = int.Parse(psMoveNode.SelectSingleNode("port").Attributes["value"].Value);
        inputManager.connectToPSMoveOnStartup        = bool.Parse(psMoveNode.SelectSingleNode("autoConnect").Attributes["value"].Value);
        inputManager.enableMoveCalibrationDuringPlay = bool.Parse(psMoveNode.SelectSingleNode("enableInGameCalibration").Attributes["value"].Value);
        inputManager.amountOfPSMoveControllers       = int.Parse(psMoveNode.SelectSingleNode("maxControllers").Attributes["value"].Value);

        XmlNode kinectNode = xmlDoc.GetElementsByTagName("KinectSettings").Item(0);

        inputManager.enableKinect             = bool.Parse(kinectNode.SelectSingleNode("enabled").Attributes["value"].Value);
        inputManager.maxNumberOfKinectPlayers = int.Parse(kinectNode.SelectSingleNode("maxPlayers").Attributes["value"].Value);
        inputManager.kinectFloorDetection     = bool.Parse(kinectNode.SelectSingleNode("floorDetection").Attributes["value"].Value);
        inputManager.jumpGestureEnabled       = bool.Parse(kinectNode.SelectSingleNode("jumpGestureEnabled").Attributes["value"].Value);

        XmlNode kinect2Node = xmlDoc.GetElementsByTagName("Kinect2Settings").Item(0);

        inputManager.enableKinect2 = bool.Parse(kinect2Node.SelectSingleNode("enabled").Attributes["value"].Value);

        XmlNode razerNode = xmlDoc.GetElementsByTagName("RazerSettings").Item(0);

        inputManager.enableRazerHydra = bool.Parse(razerNode.SelectSingleNode("enabled").Attributes["value"].Value);

        XmlNode riftDriftNode = xmlDoc.GetElementsByTagName("OculusDriftSettings").Item(0);

//		string magnetometerMode = riftDriftNode.SelectSingleNode("magnetometerDriftCorrection").Attributes["value"].Value;
        //inputManager.riftMagnetometerMode = (RUISInputManager.RiftMagnetometer)System.Enum.Parse(typeof(RUISInputManager.RiftMagnetometer), magnetometerMode);
        inputManager.kinectDriftCorrectionPreferred = bool.Parse(riftDriftNode.SelectSingleNode("kinectDriftCorrectionIfAvailable").Attributes["value"].Value);

        return(true);
    }
示例#4
0
    public void SaveFloorData(string filename, RUISDevice device, Vector3 normal, float distance)
    {
        string wrapperElementName = device.ToString();

        XmlNode calibrationMatrixElement;

        XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, coordinateSchema);
        XmlNode     groupElement;

        if (xmlDoc != null)
        {
            calibrationMatrixElement = xmlDoc.DocumentElement;
            groupElement             = calibrationMatrixElement.SelectSingleNode("FloorData");
            if (groupElement == null)
            {
                groupElement = xmlDoc.CreateElement("FloorData");
            }
        }
        else
        {
            xmlDoc = new XmlDocument();
            xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
            calibrationMatrixElement = xmlDoc.CreateElement("ns2", "RUISClibrationMatrix", "http://ruisystem.net/m2k");
            xmlDoc.AppendChild(calibrationMatrixElement);
            groupElement = xmlDoc.CreateElement("FloorData");
        }
        calibrationMatrixElement.AppendChild(groupElement);

        XmlElement wrapperElement = xmlDoc.CreateElement(wrapperElementName);

        groupElement.AppendChild(wrapperElement);

        XmlElement kinectFloorNormalElement = xmlDoc.CreateElement("floorNormal");

        kinectFloorNormalElement.SetAttribute("x", normal.x.ToString());
        kinectFloorNormalElement.SetAttribute("y", normal.y.ToString());
        kinectFloorNormalElement.SetAttribute("z", normal.z.ToString());
        wrapperElement.AppendChild(kinectFloorNormalElement);

        XmlElement kinectDistanceFromFloorElement = xmlDoc.CreateElement("distanceFromFloor");

        kinectDistanceFromFloorElement.SetAttribute("value", distance.ToString());

        wrapperElement.AppendChild(kinectDistanceFromFloorElement);

        XmlNode groupNode = xmlDoc.DocumentElement.SelectSingleNode("FloorData");
        XmlNode testNode  = groupNode.SelectSingleNode(wrapperElementName);

        // Element not found
        if (testNode == null)
        {
            groupNode.AppendChild(wrapperElement);
        }
        else
        {
            // Element already exists
            var oldElem = testNode;
            groupNode.ReplaceChild(wrapperElement, oldElem);
        }

        FileStream   xmlFileStream = File.Open(filename, FileMode.Create);
        StreamWriter streamWriter  = new StreamWriter(xmlFileStream);

        xmlDoc.Save(streamWriter);
        streamWriter.Flush();
        streamWriter.Close();
        xmlFileStream.Close();
    }
示例#5
0
    public void SaveTransformDataToXML(string filename, RUISDevice device1, RUISDevice device2)
    {
        string wrapperElementName = device1.ToString() + "-" + device2.ToString();

        XmlNode calibrationMatrixElement;

        XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, coordinateSchema);
        XmlNode     groupElement;

        if (xmlDoc != null)
        {
            calibrationMatrixElement = xmlDoc.DocumentElement;
            groupElement             = calibrationMatrixElement.SelectSingleNode("Transforms");
            if (groupElement == null)
            {
                groupElement = xmlDoc.CreateElement("Transforms");
            }
        }
        else
        {
            xmlDoc = new XmlDocument();
            xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
            calibrationMatrixElement = xmlDoc.CreateElement("ns2", "RUISClibrationMatrix", "http://ruisystem.net/m2k");
            xmlDoc.AppendChild(calibrationMatrixElement);
            groupElement = xmlDoc.CreateElement("Transforms");
        }
        calibrationMatrixElement.AppendChild(groupElement);

        XmlElement wrapperElement = xmlDoc.CreateElement(wrapperElementName);

        groupElement.AppendChild(wrapperElement);

        XmlElement translateElement = xmlDoc.CreateElement("translate");

        translateElement.SetAttribute("x", deviceToRootTransform[0, 3].ToString());
        translateElement.SetAttribute("y", deviceToRootTransform[1, 3].ToString());
        translateElement.SetAttribute("z", deviceToRootTransform[2, 3].ToString());

        wrapperElement.AppendChild(translateElement);

        XmlElement rotateElement = xmlDoc.CreateElement("rotate");

        rotateElement.SetAttribute("r00", deviceToRootTransform[0, 0].ToString());
        rotateElement.SetAttribute("r01", deviceToRootTransform[0, 1].ToString());
        rotateElement.SetAttribute("r02", deviceToRootTransform[0, 2].ToString());
        rotateElement.SetAttribute("r10", deviceToRootTransform[1, 0].ToString());
        rotateElement.SetAttribute("r11", deviceToRootTransform[1, 1].ToString());
        rotateElement.SetAttribute("r12", deviceToRootTransform[1, 2].ToString());
        rotateElement.SetAttribute("r20", deviceToRootTransform[2, 0].ToString());
        rotateElement.SetAttribute("r21", deviceToRootTransform[2, 1].ToString());
        rotateElement.SetAttribute("r22", deviceToRootTransform[2, 2].ToString());

        wrapperElement.AppendChild(rotateElement);

        XmlNode groupNode = xmlDoc.DocumentElement.SelectSingleNode("Transforms");
        XmlNode testNode  = groupNode.SelectSingleNode(wrapperElementName);

        // Element not found
        if (testNode == null)
        {
            groupNode.AppendChild(wrapperElement);
        }
        else
        {
            // Element already exists
            var oldElem = testNode;
            groupNode.ReplaceChild(wrapperElement, oldElem);
        }

        FileStream   xmlFileStream = File.Open(filename, FileMode.Create);
        StreamWriter streamWriter  = new StreamWriter(xmlFileStream);

        xmlDoc.Save(streamWriter);
        streamWriter.Flush();
        streamWriter.Close();
        xmlFileStream.Close();
    }
示例#6
0
    public bool LoadMultiXML(string filename)
    {
        XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, coordinateSchema);

        if (xmlDoc != null)
        {
            foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
            {
                Vector3    vector3 = new Vector3(0, 0, 0);
                Matrix4x4  device1ToDevice2Transform = new Matrix4x4();
                Quaternion quaternion = new Quaternion();

                if (node.Name == "Transforms")
                {
                    foreach (XmlNode groupElement in node.ChildNodes)
                    {
                        XmlNode translationElement = groupElement.SelectSingleNode("translate");
                        float   x = float.Parse(translationElement.Attributes["x"].Value);
                        float   y = float.Parse(translationElement.Attributes["y"].Value);
                        float   z = float.Parse(translationElement.Attributes["z"].Value);
                        vector3 = new Vector3(x, y, z);
                        device1ToDevice2Transform.SetColumn(3, new Vector4(x, y, z, 1.0f));

                        XmlNode rotationElement = groupElement.SelectSingleNode("rotate");

                        device1ToDevice2Transform.m00 = float.Parse(rotationElement.Attributes["r00"].Value);
                        device1ToDevice2Transform.m01 = float.Parse(rotationElement.Attributes["r01"].Value);
                        device1ToDevice2Transform.m02 = float.Parse(rotationElement.Attributes["r02"].Value);
                        device1ToDevice2Transform.m10 = float.Parse(rotationElement.Attributes["r10"].Value);
                        device1ToDevice2Transform.m11 = float.Parse(rotationElement.Attributes["r11"].Value);
                        device1ToDevice2Transform.m12 = float.Parse(rotationElement.Attributes["r12"].Value);
                        device1ToDevice2Transform.m20 = float.Parse(rotationElement.Attributes["r20"].Value);
                        device1ToDevice2Transform.m21 = float.Parse(rotationElement.Attributes["r21"].Value);
                        device1ToDevice2Transform.m22 = float.Parse(rotationElement.Attributes["r22"].Value);

                        List <Vector3> rotationVectors = MathUtil.Orthonormalize(MathUtil.ExtractRotationVectors(device1ToDevice2Transform));
                        Matrix4x4      rotationMatrix  = new Matrix4x4();
                        rotationMatrix.SetColumn(0, rotationVectors[0]);
                        rotationMatrix.SetColumn(1, rotationVectors[1]);
                        rotationMatrix.SetColumn(2, rotationVectors[2]);

                        quaternion = MathUtil.QuaternionFromMatrix(rotationMatrix);

                        RUISCalibrationResultsInVector3[groupElement.Name]    = vector3;
                        RUISCalibrationResultsIn4x4Matrix[groupElement.Name]  = device1ToDevice2Transform;
                        RUISCalibrationResultsInQuaternion[groupElement.Name] = quaternion;

                        // Inverses
                        string[] parts       = groupElement.Name.Split('-');
                        string   inverseName = parts[1] + "-" + parts[0];
                        RUISCalibrationResultsInVector3[inverseName]    = -vector3;
                        RUISCalibrationResultsIn4x4Matrix[inverseName]  = device1ToDevice2Transform.inverse;
                        RUISCalibrationResultsInQuaternion[inverseName] = Quaternion.Inverse(quaternion);
                    }
                }

                if (node.Name == "FloorData")
                {
                    foreach (XmlNode groupElement in node.ChildNodes)
                    {
                        Quaternion floorPitchRotation = Quaternion.identity;
                        float      distanceFromFloor  = 0;
                        foreach (XmlNode element in groupElement.ChildNodes)
                        {
                            switch (element.Name)
                            {
                            case "floorNormal":
                                float xValue = float.Parse(element.Attributes["x"].Value);
                                float yValue = float.Parse(element.Attributes["y"].Value);
                                float zValue = float.Parse(element.Attributes["z"].Value);
                                floorPitchRotation = Quaternion.Inverse(Quaternion.FromToRotation(new Vector3(xValue, yValue, zValue), Vector3.up));
                                break;

                            case "distanceFromFloor":
                                distanceFromFloor = float.Parse(element.Attributes["value"].Value);
                                break;
                            }
                        }

                        RUISCalibrationResultsFloorPitchRotation[(RUISDevice)System.Enum.Parse(typeof(RUISDevice), groupElement.Name, true)] = floorPitchRotation;
                        RUISCalibrationResultsDistanceFromFloor[(RUISDevice)System.Enum.Parse(typeof(RUISDevice), groupElement.Name, true)]  = distanceFromFloor;
                    }
                }
            }
        }
        else
        {
            return(false);
        }

        /*
         * // For debug
         * foreach (string key in RUISCalibrationResultsInVector3.Keys)
         * {
         *      print("Key: " + key + ": Value: " + RUISCalibrationResultsInVector3[key].ToString());
         * }
         * foreach (string key in RUISCalibrationResultsIn4x4Matrix.Keys)
         * {
         *      print("Key: " + key + ": Value: " + RUISCalibrationResultsIn4x4Matrix[key].ToString());
         * }
         * foreach (string key in RUISCalibrationResultsInVector3.Keys)
         * {
         *      print("Key: " + key + ": Value: " + RUISCalibrationResultsInQuaternion[key].ToString());
         * }
         * foreach (RUISDevice key in RUISCalibrationResultsFloorNormal.Keys)
         * {
         *      print("Key: " + key.ToString() + ": Value: " + RUISCalibrationResultsFloorNormal[key].ToString());
         * }
         * foreach (RUISDevice key in RUISCalibrationResultsDistanceFromFloor.Keys)
         * {
         *      print("Key: " + key.ToString() + ": Value: " + RUISCalibrationResultsDistanceFromFloor[key].ToString());
         * }
         */
        return(true);
    }
示例#7
0
    public static bool ImportInputManager(RUISInputManager inputManager, RUISCoordinateSystem coordinateSystem, string filename, TextAsset xmlSchema)
    {
        XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, xmlSchema);

        if (xmlDoc == null)
        {
            return(false);
        }

        XmlNode psMoveNode = xmlDoc.GetElementsByTagName("PSMoveSettings").Item(0);

        inputManager.enablePSMove                    = bool.Parse(psMoveNode.SelectSingleNode("enabled").Attributes["value"].Value);
        inputManager.PSMoveIP                        = psMoveNode.SelectSingleNode("ip").Attributes["value"].Value;
        inputManager.PSMovePort                      = int.Parse(psMoveNode.SelectSingleNode("port").Attributes["value"].Value);
        inputManager.connectToPSMoveOnStartup        = bool.Parse(psMoveNode.SelectSingleNode("autoConnect").Attributes["value"].Value);
        inputManager.enableMoveCalibrationDuringPlay = bool.Parse(psMoveNode.SelectSingleNode("enableInGameCalibration").Attributes["value"].Value);
        inputManager.amountOfPSMoveControllers       = int.Parse(psMoveNode.SelectSingleNode("maxControllers").Attributes["value"].Value);

        XmlNode kinectNode = xmlDoc.GetElementsByTagName("KinectSettings").Item(0);

        inputManager.enableKinect             = bool.Parse(kinectNode.SelectSingleNode("enabled").Attributes["value"].Value);
        inputManager.maxNumberOfKinectPlayers = int.Parse(kinectNode.SelectSingleNode("maxPlayers").Attributes["value"].Value);
        inputManager.kinectFloorDetection     = bool.Parse(kinectNode.SelectSingleNode("floorDetection").Attributes["value"].Value);
        inputManager.jumpGestureEnabled       = bool.Parse(kinectNode.SelectSingleNode("jumpGestureEnabled").Attributes["value"].Value);

        XmlNode kinect2Node = xmlDoc.GetElementsByTagName("Kinect2Settings").Item(0);

        inputManager.enableKinect2 = bool.Parse(kinect2Node.SelectSingleNode("enabled").Attributes["value"].Value);

        XmlNode razerNode = xmlDoc.GetElementsByTagName("RazerSettings").Item(0);

        inputManager.enableRazerHydra = bool.Parse(razerNode.SelectSingleNode("enabled").Attributes["value"].Value);

//		XmlNode riftDriftNode = xmlDoc.GetElementsByTagName("OculusDriftSettings").Item(0);
//		string magnetometerMode = riftDriftNode.SelectSingleNode("magnetometerDriftCorrection").Attributes["value"].Value;
//		inputManager.riftMagnetometerMode = (RUISInputManager.RiftMagnetometer)System.Enum.Parse(typeof(RUISInputManager.RiftMagnetometer), magnetometerMode);
//		inputManager.kinectDriftCorrectionPreferred = bool.Parse(riftDriftNode.SelectSingleNode("kinectDriftCorrectionIfAvailable").Attributes["value"].Value);

        XmlNode coordinateSystemNode = xmlDoc.GetElementsByTagName("CoordinateSystemSettings").Item(0);

        if (coordinateSystemNode != null)
        {
            if (coordinateSystemNode.SelectSingleNode("useMasterCoordinateSystem") != null)
            {
                coordinateSystem.applyToRootCoordinates = bool.Parse(coordinateSystemNode.SelectSingleNode("useMasterCoordinateSystem").Attributes["value"].Value);
            }
            if (coordinateSystemNode.SelectSingleNode("masterCoordinateSystemSensor") != null)
            {
                string masterDevice = coordinateSystemNode.SelectSingleNode("masterCoordinateSystemSensor").Attributes["value"].Value;
                coordinateSystem.rootDevice = (RUISDevice)System.Enum.Parse(typeof(RUISDevice), masterDevice);
            }
            if (coordinateSystemNode.SelectSingleNode("switchMasterToAvailableSensor") != null)
            {
                coordinateSystem.switchToAvailableDevice = bool.Parse(coordinateSystemNode.SelectSingleNode("switchMasterToAvailableSensor").Attributes["value"].Value);
            }
            if (coordinateSystemNode.SelectSingleNode("setKinectOriginToFloor") != null)
            {
                coordinateSystem.setKinectOriginToFloor = bool.Parse(coordinateSystemNode.SelectSingleNode("setKinectOriginToFloor").Attributes["value"].Value);
            }
            if (coordinateSystemNode.SelectSingleNode("coordinateSystemYRotationOffset") != null)
            {
                coordinateSystem.yawOffset = float.Parse(coordinateSystemNode.SelectSingleNode("coordinateSystemYRotationOffset").Attributes["value"].Value);
            }

            if (coordinateSystemNode.SelectSingleNode("coordinateSystemLocationOffset") != null)
            {
                XmlNode translationElement = coordinateSystemNode.SelectSingleNode("coordinateSystemLocationOffset");
                float   x = float.Parse(translationElement.Attributes["x"].Value);
                float   y = float.Parse(translationElement.Attributes["y"].Value);
                float   z = float.Parse(translationElement.Attributes["z"].Value);
                coordinateSystem.positionOffset = new Vector3(x, y, z);
            }
        }

        return(true);
    }