commit c6ecc85a03388e347282a2fd3c2ad3907b4533bd
Author: Jakub Hejman <hejmanj@students.zcu.cz>
Date:   Mon May 31 13:15:37 2021 +0000

    Re #9003 - Client configuration

diff --git a/deltarobot-vr/Assets/DeltaRobotVr/Client.cs b/deltarobot-vr/Assets/DeltaRobotVr/Client.cs
index 8c7c315..ac331b3 100644
--- a/deltarobot-vr/Assets/DeltaRobotVr/Client.cs
+++ b/deltarobot-vr/Assets/DeltaRobotVr/Client.cs
@@ -18,7 +18,7 @@ namespace DeltaRobotVr
         public static readonly Client Instance = new Client();
 
         // default server
-        private const string DefaultServer = "127.0.0.1";
+        private const string DefaultHost = "127.0.0.1";
         private const int DefaultPort = 4242;
 
         // protocol constants
@@ -277,7 +277,17 @@ namespace DeltaRobotVr
             {
                 try
                 {
-                    using var client = new TcpClient(DefaultServer, DefaultPort);
+                    var host = ConfigurationProvider.Instance.Host;
+                    var port = ConfigurationProvider.Instance.Port;
+
+                    if (port < 0 || host.Length == 0)
+                    {
+                        // Obviously invalid values
+                        host = DefaultHost;
+                        port = DefaultPort;
+                    }
+
+                    using var client = new TcpClient(host, port);
                     using var stream = client.GetStream();
                     BinaryReader reader = new BinaryReader(stream);
                     BinaryWriter writer = new BinaryWriter(stream);
diff --git a/deltarobot-vr/Assets/DeltaRobotVr/Components/Actuator.cs b/deltarobot-vr/Assets/DeltaRobotVr/Components/Actuator.cs
index ff0af5e..2d480e4 100644
--- a/deltarobot-vr/Assets/DeltaRobotVr/Components/Actuator.cs
+++ b/deltarobot-vr/Assets/DeltaRobotVr/Components/Actuator.cs
@@ -19,7 +19,7 @@ namespace DeltaRobotVr.Components
             {
                 var actPosition = Client.Instance.ActuatorPosition;
                 var newPosition = Single3Utils.ToVector3(actPosition.X, actPosition.Y, actPosition.Z);
-                _transform.position = Vector3.Lerp(_transform.position, newPosition, LerpParam);
+                _transform.localPosition = Vector3.Lerp(_transform.localPosition, newPosition, LerpParam);
             }
         }
     }
diff --git a/deltarobot-vr/Assets/DeltaRobotVr/ConfigurationProvider.cs b/deltarobot-vr/Assets/DeltaRobotVr/ConfigurationProvider.cs
new file mode 100644
index 0000000..e3ba38c
--- /dev/null
+++ b/deltarobot-vr/Assets/DeltaRobotVr/ConfigurationProvider.cs
@@ -0,0 +1,75 @@
+using System.Xml.Serialization;
+using System;
+using System.IO;
+
+namespace DeltaRobotVr
+{
+    /// <summary>
+    /// Singleton class responsible for providing configuration.
+    /// </summary>
+    [Serializable]
+    public class ConfigurationProvider
+    {
+        private static readonly string Default_Config_File = "config.xml";
+        public static readonly ConfigurationProvider Instance = new ConfigurationProvider();
+
+        public float VisualizationTranslateX = 0.0f;
+        public float VisualizationTranslateY = 0.0f;
+        public float VisualizationTranslateZ = 0.0f;
+
+        public float VisualizationScaleX = 1.0f;
+        public float VisualizationScaleY = 1.0f;
+        public float VisualizationScaleZ = 1.0f;
+
+        public int Port = 4242;
+
+        public string Host = "127.0.0.1";
+
+        public string SceneName = "BasicRoomScene";
+
+
+        static ConfigurationProvider()
+        {
+            Instance = loadConfiguration(Default_Config_File);
+        }
+
+        private ConfigurationProvider()
+        {
+        }
+
+        /// <summary>
+        /// Load ConfigurationProvider instance from file.
+        /// </summary>
+        /// <param name="fileName">File to load configuration from</param>
+        /// <returns></returns>
+        private static ConfigurationProvider loadConfiguration(String fileName)
+        {
+            XmlSerializer serializer = new XmlSerializer(typeof(ConfigurationProvider));
+
+            ConfigurationProvider cp;
+
+            using (Stream reader = new FileStream(fileName, FileMode.Open))
+            {
+                cp = (ConfigurationProvider)serializer.Deserialize(reader);
+            }
+
+            return cp;
+        }
+
+        /// <summary>
+        /// Save ConfigurationProvider instance to file.
+        /// </summary>
+        /// <param name="cp">ConfigurationProvider instance to save</param>
+        /// <param name="fileName">File to save configuration to</param>
+        private static void saveConfiguration(ConfigurationProvider cp, String fileName)
+        {
+            XmlSerializer serializer = new XmlSerializer(typeof(ConfigurationProvider));
+
+            using (Stream writer = new FileStream(fileName, FileMode.Create))
+            {
+                serializer.Serialize(writer, cp);
+            }
+        }
+
+    }
+}
diff --git a/deltarobot-vr/Assets/DeltaRobotVr/ConfigurationProvider.cs.meta b/deltarobot-vr/Assets/DeltaRobotVr/ConfigurationProvider.cs.meta
new file mode 100644
index 0000000..747dcf5
--- /dev/null
+++ b/deltarobot-vr/Assets/DeltaRobotVr/ConfigurationProvider.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 99b81634dd1a93e4396ba2b51655392f
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/deltarobot-vr/Assets/DeltaRobotVr/MainScript.cs b/deltarobot-vr/Assets/DeltaRobotVr/MainScript.cs
index f55bbac..084e309 100644
--- a/deltarobot-vr/Assets/DeltaRobotVr/MainScript.cs
+++ b/deltarobot-vr/Assets/DeltaRobotVr/MainScript.cs
@@ -9,9 +9,11 @@ namespace DeltaRobotVr
     /// </summary>
     public class MainScript : MonoBehaviour
     {
+        private static readonly string DefaultScene = "BasicRoomScene";
         private void Start()
         {
-            SceneManager.LoadScene("BasicRoomScene", LoadSceneMode.Additive);
+            var sceneName = ConfigurationProvider.Instance.SceneName;
+            SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
             Client.Instance.Start();
         }
 
diff --git a/deltarobot-vr/Assets/DeltaRobotVr/SetVisualizationTransform.cs b/deltarobot-vr/Assets/DeltaRobotVr/SetVisualizationTransform.cs
new file mode 100644
index 0000000..e98a844
--- /dev/null
+++ b/deltarobot-vr/Assets/DeltaRobotVr/SetVisualizationTransform.cs
@@ -0,0 +1,25 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using DeltaRobotVr;
+
+/// <summary>
+/// Applies the transform from ConfigurationProvider.Instance
+/// to this GameObejct's transform.
+/// </summary>
+public class SetVisualizationTransform : MonoBehaviour
+{
+    void Start()
+    {
+        var x = ConfigurationProvider.Instance.VisualizationTranslateX;
+        var y = ConfigurationProvider.Instance.VisualizationTranslateY;
+        var z = ConfigurationProvider.Instance.VisualizationTranslateZ;
+
+        var sx = ConfigurationProvider.Instance.VisualizationScaleX;
+        var sy = ConfigurationProvider.Instance.VisualizationScaleY;
+        var sz = ConfigurationProvider.Instance.VisualizationScaleZ;
+
+        transform.position = new Vector3(x, y, z);
+        transform.localScale = new Vector3(sx, sy, sz);
+    }
+}
diff --git a/deltarobot-vr/Assets/DeltaRobotVr/SetVisualizationTransform.cs.meta b/deltarobot-vr/Assets/DeltaRobotVr/SetVisualizationTransform.cs.meta
new file mode 100644
index 0000000..d6a1436
--- /dev/null
+++ b/deltarobot-vr/Assets/DeltaRobotVr/SetVisualizationTransform.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 4102e3362fef6284db0f47a38afc06b3
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/deltarobot-vr/Assets/Scenes/MainScene.unity b/deltarobot-vr/Assets/Scenes/MainScene.unity
index 12c9446..7d2659a 100644
--- a/deltarobot-vr/Assets/Scenes/MainScene.unity
+++ b/deltarobot-vr/Assets/Scenes/MainScene.unity
@@ -38,7 +38,7 @@ RenderSettings:
   m_ReflectionIntensity: 1
   m_CustomReflection: {fileID: 0}
   m_Sun: {fileID: 705507994}
-  m_IndirectSpecularColor: {r: 0.59937465, g: 0.5997504, b: 0.599488, a: 1}
+  m_IndirectSpecularColor: {r: 0.59937525, g: 0.5997512, b: 0.59948856, a: 1}
   m_UseRadianceAmbientProbe: 0
 --- !u!157 &3
 LightmapSettings:
@@ -259,12 +259,12 @@ Transform:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 67930113}
-  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
   m_LocalPosition: {x: 0, y: 0, z: -4.5}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children: []
-  m_Father: {fileID: 0}
-  m_RootOrder: 5
+  m_Father: {fileID: 696353308}
+  m_RootOrder: 1
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1 &86918157
 GameObject:
@@ -703,6 +703,51 @@ Transform:
   m_Father: {fileID: 0}
   m_RootOrder: 3
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &696353306
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 696353308}
+  - component: {fileID: 696353307}
+  m_Layer: 0
+  m_Name: Visualization
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!114 &696353307
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 696353306}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 4102e3362fef6284db0f47a38afc06b3, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+--- !u!4 &696353308
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 696353306}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_Children:
+  - {fileID: 2021860140}
+  - {fileID: 67930116}
+  m_Father: {fileID: 0}
+  m_RootOrder: 6
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1 &705507993
 GameObject:
   m_ObjectHideFlags: 0
@@ -981,7 +1026,7 @@ Transform:
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children: []
   m_Father: {fileID: 0}
-  m_RootOrder: 6
+  m_RootOrder: 4
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1 &1045848415
 GameObject:
@@ -1368,7 +1413,7 @@ RectTransform:
   m_Children:
   - {fileID: 1430580983}
   m_Father: {fileID: 0}
-  m_RootOrder: 7
+  m_RootOrder: 5
   m_LocalEulerAnglesHint: {x: 0, y: 45, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
@@ -1575,15 +1620,15 @@ Transform:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 2021860136}
-  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
   m_LocalPosition: {x: 0, y: 0, z: 0}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children:
   - {fileID: 1177787072}
   - {fileID: 1535691006}
   - {fileID: 86918158}
-  m_Father: {fileID: 0}
-  m_RootOrder: 4
+  m_Father: {fileID: 696353308}
+  m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!114 &2021860141
 MonoBehaviour:
diff --git a/deltarobot-vr/config.xml b/deltarobot-vr/config.xml
new file mode 100644
index 0000000..7f7326a
--- /dev/null
+++ b/deltarobot-vr/config.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<ConfigurationProvider xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <VisualizationTranslateX>0</VisualizationTranslateX>
+  <VisualizationTranslateY>0</VisualizationTranslateY>
+  <VisualizationTranslateZ>0</VisualizationTranslateZ>
+  <VisualizationScaleX>1</VisualizationScaleX>
+  <VisualizationScaleY>1</VisualizationScaleY>
+  <VisualizationScaleZ>1</VisualizationScaleZ>
+  <Port>4242</Port>
+  <Host>127.0.0.1</Host>
+  <SceneName>BasicRoomScene</SceneName>
+</ConfigurationProvider>
\ No newline at end of file
