//Haptic Properties generic function private void ReadHapticProperties(int ObjId, GameObject obj) { myHapticPropertiesScript = obj.transform.GetComponent <HapticProperties>(); if (myHapticPropertiesScript == null) //Set default Values { PluginImport.SetStiffness(ObjId, 1.0f); PluginImport.SetDamping(ObjId, 0.0f); PluginImport.SetStaticFriction(ObjId, 0.0f); PluginImport.SetDynamicFriction(ObjId, 0.0f); PluginImport.SetTangentialStiffness(ObjId, 0.0f); PluginImport.SetTangentialDamping(ObjId, 0.0f); PluginImport.SetPopThrough(ObjId, 0.0f); PluginImport.SetPuncturedStaticFriction(ObjId, 0.0f); PluginImport.SetPuncturedDynamicFriction(ObjId, 0.0f); PluginImport.SetMass(ObjId, 0.0f); PluginImport.SetFixed(ObjId, true); Debug.Log("Haptic Characteristics not set for " + obj.name); } else { PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("stiffness"), myHapticPropertiesScript.stiffness); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("damping"), myHapticPropertiesScript.damping); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("staticFriction"), myHapticPropertiesScript.staticFriction); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("dynamicFriction"), myHapticPropertiesScript.dynamicFriction); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("tangentialStiffness"), myHapticPropertiesScript.tangentialStiffness); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("tangentialDamping"), myHapticPropertiesScript.tangentialDamping); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("popThrough"), myHapticPropertiesScript.popThrough); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("puncturedStaticFriction"), myHapticPropertiesScript.puncturedStaticFriction); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("puncturedDynamicFriction"), myHapticPropertiesScript.puncturedDynamicFriction); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("mass"), myHapticPropertiesScript.mass); PluginImport.SetHapticProperty(ObjId, ConverterClass.ConvertStringToByteToIntPtr("fixed"), System.Convert.ToInt32(myHapticPropertiesScript.fixedObj)); } }
//Updating user interface private void UpdateUI() { string myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName()); if (!myObjStringName.Equals("null")) { //Get Touched Object initial position Vector3 initialPosition; try{ initialPosition = dict[myObjStringName]; } catch (KeyNotFoundException e) { return; } //Get current cursor position Vector3 cursorPosition = GameObject.Find("Cursor").transform.position; //Get position and angle differences float posDiff = Vector3.Distance(initialPosition, cursorPosition); float angleDiff = Vector3.Angle(initialPosition, cursorPosition); //Update UI text panel GUIText panel = GameObject.Find("Panel").GetComponent <GUIText>(); panel.text = "Diferencia posicion: " + posDiff + "\nDiferencia angular: " + angleDiff; } }
public void UpdateHapticObjectMatrixTransform() { //Get array of all object with tag "Touchable" GameObject[] myObjects = GameObject.FindGameObjectsWithTag("Touchable") as GameObject[]; for (int ObjId = 0; ObjId < myObjects.Length; ObjId++) { /***************************************************************/ //Set the Transformation Matric of the Object /***************************************************************/ //Get the Transformation matrix from object Matrix4x4 m = new Matrix4x4(); //Build a transform Matrix from the translation/rotation and Scale parameters fo the object m.SetTRS(myObjects[ObjId].transform.position, myObjects[ObjId].transform.rotation, myObjects[ObjId].transform.localScale); //Convert Matrix4x4 to double16 double[] matrix = ConverterClass.ConvertMatrix4x4ToDouble16(m); //Convert Double16 To IntPtr IntPtr dstDoublePtr = ConverterClass.ConvertDouble16ToIntPtr(matrix); //Convert String to Byte[] (char* in C++) and Byte[] to IntPtr IntPtr dstCharPtr = ConverterClass.ConvertStringToByteToIntPtr(myObjects[ObjId].name); //Send the transformation Matrix of the object PluginImport.SetObjectTransform(ObjId, dstCharPtr, dstDoublePtr); /***************************************************************/ } }
public Object Convert(Object item, TypeConversionDirection direction) { var conversionMethodName = String.Empty; switch (direction) { case TypeConversionDirection.DatabaseToProperty: { conversionMethodName = ConversionToPropertyMethodName; } break; case TypeConversionDirection.PropertyToDatabase: { conversionMethodName = ConversionToDatabaseMethodName; } break; default: throw new NotImplementedException("Not a valid TypeConversionDirection."); } return(ConverterClass.InvokeMember( conversionMethodName, BindingFlags.InvokeMethod, null, null, new[] { item } )); }
void Update() { /***************************************************************/ //Update Workspace as function of camera /***************************************************************/ //PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y); //To be deprecated //Update the Workspace as function of camera for (int i = 0; i < workspaceUpdateValue.Length; i++) { workspaceUpdateValue[i] = myHapticCamera.transform.rotation.eulerAngles.y; } PluginImport.UpdateHapticWorkspace(ConverterClass.ConvertFloatArrayToIntPtr(workspaceUpdateValue)); /***************************************************************/ //Update cube workspace /***************************************************************/ myGenericFunctionsClassScript.UpdateGraphicalWorkspace(); /***************************************************************/ //Haptic Rendering Loop /***************************************************************/ PluginImport.RenderHaptic(); //Associate the cursor object with the haptic proxy value myGenericFunctionsClassScript.GetProxyValues(); }
public void ConvertFromString(int i, float f, double d, bool isTrue, string text, double2 d2, double3 d3, double4 d4, double4x4 d4x4, float2 f2, float3 f3, float4 f4, float4x4 f4x4) { ConverterClass source = new ConverterClass(); ConverterClass expected = new ConverterClass(); Node root = new Node(source); Node node = new Node(expected); Circuit circuit = new Circuit(); circuit.AddNode(root); circuit.AddNode(node); circuit.AddRoot(root); source.text = text; root.Attach("text", node, "i"); root.Attach("text", node, "f"); root.Attach("text", node, "d"); root.Attach("text", node, "text"); circuit.Execute(); Assert.True(expected.i == i, "Error when parsing to int: Should be " + i + " but is " + expected.i + "."); Assert.True(expected.f == f, "Error when parsing to float: Should be " + f + " but is " + expected.f + "."); Assert.True(expected.d == d, "Error when parsing to double: Should be " + d + " but is " + expected.d + "."); Assert.True(expected.text == text, "Error when parsing to string: Should be " + text + " but is " + expected.text + "."); }
public void UpdateTwoGraphicalWorkspaces() { //Device 1 //Position Vector3 pos1; pos1 = ConverterClass.ConvertFloat3ToVector3(myHapticClassScript.myWorkSpacePosition); myHapticClassScript.workSpaceObj.transform.position = pos1; //Orientation myHapticClassScript.workSpaceObj.transform.rotation = Quaternion.Euler(0.0f, myHapticClassScript.myHapticCamera.transform.eulerAngles.y, 0.0f); //Scale Vector3 size1; size1 = ConverterClass.ConvertFloat3ToVector3(myHapticClassScript.myWorkSpaceSize); myHapticClassScript.workSpaceObj.transform.localScale = size1; //Device 2 //Position Vector3 pos2; pos2 = ConverterClass.ConvertFloat3ToVector3(myHapticClassScript.mySecondWorkSpacePosition); myHapticClassScript.secondWorkSpaceObj.transform.position = pos2; //Orientation myHapticClassScript.secondWorkSpaceObj.transform.rotation = Quaternion.Euler(0.0f, myHapticClassScript.mySecondHapticCamera.transform.eulerAngles.y, 0.0f); //Scale Vector3 size2; size2 = ConverterClass.ConvertFloat3ToVector3(myHapticClassScript.mySecondWorkSpaceSize); myHapticClassScript.secondWorkSpaceObj.transform.localScale = size2; }
void Start() { if (PluginImport.InitHapticDevice()) { Debug.Log("OpenGL Context Launched"); Debug.Log("Haptic Device Launched"); getInitialParameters(); myGenericFunctionsClassScript.SetHapticWorkSpace(); myGenericFunctionsClassScript.GetHapticWorkSpace(); //Update Workspace as function of camera PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y); //Set Mode of Interaction /* * Mode = 0 Contact * Mode = 1 Manipulation - So objects will have a mass when handling them * Mode = 2 Custom Effect - So the haptic device simulate vibration and tangential forces as power tools * Mode = 3 Puncture - So the haptic device is a needle that puncture inside a geometry */ PluginImport.SetMode(1); //Show a text descrition of the mode myGenericFunctionsClassScript.IndicateMode(); //Set the touchable face(s) PluginImport.SetTouchableFace(ConverterClass.ConvertStringToByteToIntPtr(TouchableFace)); } else { Debug.Log("Haptic Device cannot be launched"); } /***************************************************************/ //Set Environmental Haptic Effect /***************************************************************/ // Constant Force Example - We use this environmental force effect to simulate the weight of the cursor //myGenericFunctionsClassScript.SetEnvironmentConstantForce(); /***************************************************************/ //Setup the Haptic Geometry in the OpenGL context /***************************************************************/ myGenericFunctionsClassScript.SetHapticGeometry(); //Get the Number of Haptic Object //Debug.Log ("Total Number of Haptic Objects: " + PluginImport.GetHapticObjectCount()); /***************************************************************/ //Launch the Haptic Event for all different haptic objects /***************************************************************/ PluginImport.LaunchHapticEvent(); }
void Start() { if (PluginImport.InitHapticDevice()) { Debug.Log("OpenGL Context Launched"); Debug.Log("Haptic Device Launched"); myGenericFunctionsClassScript.SetHapticWorkSpace(); myGenericFunctionsClassScript.GetHapticWorkSpace(); //Update Workspace as function of camera //PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y);//To be deprecated //Update the Workspace as function of camera for (int i = 0; i < workspaceUpdateValue.Length; i++) { workspaceUpdateValue[i] = myHapticCamera.transform.rotation.eulerAngles.y; } PluginImport.UpdateHapticWorkspace(ConverterClass.ConvertFloatArrayToIntPtr(workspaceUpdateValue)); //Set Mode of Interaction /* * Mode = 0 Contact * Mode = 1 Manipulation - So objects will have a mass when handling them * Mode = 2 Custom Effect - So the haptic device simulate vibration and tangential forces as power tools * Mode = 3 Puncture - So the haptic device is a needle that puncture inside a geometry */ PluginImport.SetMode(ModeIndex); //Show a text descrition of the mode myGenericFunctionsClassScript.IndicateMode(); } else { Debug.Log("Haptic Device cannot be launched"); } /***************************************************************/ //Set Environmental Haptic Effect /***************************************************************/ // Constant Force Example - We use this environmental force effect to simulate the weight of the cursor myGenericFunctionsClassScript.SetEnvironmentConstantForce(); /***************************************************************/ //Setup the Haptic Geometry in the OpenGL context //And read haptic characteristics /***************************************************************/ myGenericFunctionsClassScript.SetHapticGeometry(); //Get the Number of Haptic Object //Debug.Log ("Total Number of Haptic Objects: " + PluginImport.GetHapticObjectCount()); /***************************************************************/ //Launch the Haptic Event for all different haptic objects /***************************************************************/ PluginImport.LaunchHapticEvent(); }
// Update is called once per frame void Update() { bool button1State = PluginImport.GetButton1State(); if (button1State && !previousButton1State) { penColorNum = (penColorNum + 1) % penColors.Length; } previousButton1State = button1State; //if (PluginImport.GetButton2State()) cleanBoard(); bool eraseState = PluginImport.GetButton2State(); if (eraseState) { changePenColor(new Color(0.25f, 0.25f, 0.25f)); } else { changePenColor(penColorNum); } bool shouldDraw = PluginImport.GetContact() && (myCounter > 0); if (shouldDraw) { double[] pos = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyPosition()); double[] dir = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyDirection()); Vector3 position = new Vector3((float)pos[0], (float)pos[1], (float)pos[2]); Vector3 direction = new Vector3((float)dir[0], (float)dir[1], (float)dir[2]); double[] realPos = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetDevicePosition()); Vector3 realPosition = new Vector3((float)realPos[0], (float)realPos[1], (float)realPos[2]); float force = (realPosition - position).magnitude; if (force > 1.0f) { force = 1.0f; } RaycastHit hitInfo = new RaycastHit(); bool hasHit = Physics.Raycast(position, direction, out hitInfo); if (previousShouldDraw) { drawBlobLine(previousCoord, hitInfo.textureCoord, blobRadius, penColors[penColorNum], force, blobSteps, eraseState); } else { drawBlob(hitInfo.textureCoord, blobRadius, penColors[penColorNum], force, eraseState); } previousCoord = hitInfo.textureCoord; boardTexture.SetPixels(boardPixels); boardTexture.Apply(); } previousShouldDraw = shouldDraw; myCounter++; }
void setIntPtr() { //convert String to IntPtr _type = ConverterClass.ConvertStringToByteToIntPtr(Type); //Convert float[3] to intptr _position = ConverterClass.ConvertFloat3ToIntPtr(positionEffect); //Convert float[3] to intptr _direction = ConverterClass.ConvertFloat3ToIntPtr(directionEffect); }
/******************************************************************************************************************************************************************/ //Get Proxy Position and Orientation generic function public void GetProxyValues() { /*Proxy Position*/ //Convert IntPtr to Double3Array myProxyPosition = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyPosition()); Debug.Log(myProxyPosition); //Attach the Cursor Node Vector3 positionCursor = new Vector3(); positionCursor = ConverterClass.ConvertDouble3ToVector3(myProxyPosition); //Assign Haptic Values to Cursor myHapticClassScript.hapticCursor.transform.position = positionCursor; //Proxy Right - Not use in that case //Convert IntPtr to Double3Array myProxyRight = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyRight()); //Attach the Cursor Node Vector3 rightCursor = new Vector3(); rightCursor = ConverterClass.ConvertDouble3ToVector3(myProxyRight); //Proxy Direction //Convert IntPtr to Double3Array myProxyDirection = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyDirection()); //Attach the Cursor Node Vector3 directionCursor = new Vector3(); directionCursor = ConverterClass.ConvertDouble3ToVector3(myProxyDirection); //Proxy Torque myProxyTorque = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyTorque()); //Attach the Cursor Node Vector3 torqueCursor = new Vector3(); torqueCursor = ConverterClass.ConvertDouble3ToVector3(myProxyTorque); //Set Orientation myHapticClassScript.hapticCursor.transform.rotation = Quaternion.LookRotation(directionCursor, torqueCursor); //Proxy Orientation //Convert IntPtr to Double4Array /*myProxyOrientation = ConverterClass.ConvertIntPtrToDouble4(PluginImport.GetProxyOrientation()); * * //Attach the Cursor Node * Vector4 OrientationCursor = new Vector4(); * OrientationCursor = ConverterClass.ConvertDouble4ToVector4(myProxyOrientation); * * //Assign Haptic Values to Cursor * myHapticClassScript.hapticCursor.transform.rotation = new Quaternion(OrientationCursor.x,OrientationCursor.y,OrientationCursor.z,OrientationCursor.w); * Debug.Log(OrientationCursor.x + " " + OrientationCursor.y + " " + OrientationCursor.z + " " + OrientationCursor.w);*/ }
public void ConverterTest() { var expected = new ConverterClass { Field = "FieldValue" }; var actual = Roundtrip(expected); Assert.AreEqual((double)expected.Field.Length / 2, actual.HalfFieldLength); Assert.AreEqual(expected.Field, actual.Field); }
void SetPunctureStack(int nbLayer, string[] name, float[] array) { IntPtr[] objname = new IntPtr[nbLayer]; //Assign object encounter along puncture vector to the Object array for (int i = 0; i < nbLayer; i++) { objname[i] = ConverterClass.ConvertStringToByteToIntPtr(name[i]); } PluginImport.SetPunctureLayers(nbLayer, objname, ConverterClass.ConvertFloatArrayToIntPtr(array)); }
public void GetTouchedObject() { //Convert Convert IntPtr To byte[] to String //string myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName());//PluginImport.GetTouchedObjectName() - To be deprecated string myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(1)); Debug.Log("The touched object is " + myObjStringName.ToString()); //If in Manipulation Mode enable the manipulation of the selected object if (PluginImport.GetMode() == 1) { if (PluginImport.GetButton1State()) { if (clickCount == 0) { //Set the manipulated object at first click manipObj = GameObject.Find(myObjStringName); //Setup Manipulated object Hierarchy as a child of haptic cursor - Only if object is declared as Manipulable object if (manipObj != null && !PluginImport.IsFixed(PluginImport.GetManipulatedObjectId())) { //Store the Previous parent object prevParent = manipObj.transform.parent; //Asign New Parent - the tip of the manipulation object device manipObj.transform.parent = myHapticClassScript.hapticCursor.transform; } } clickCount++; } else { //Reset Click counter clickCount = 0; //Reset Manipulated Object Hierarchy if (manipObj != null) { manipObj.transform.parent = prevParent; } //Reset Manipulated Object manipObj = null; //Reset prevParent prevParent = null; } //Only in Manipulation otherwise object are not moving so there is no need to proceed UpdateHapticObjectMatrixTransform(); } }
private Stream GetFile(string xml) { MessageList mes_list = new MessageList(); MessageLog logs = new MessageLog(MessageLog.INFO, "GetFile", "Создание потока"); mes_list.Add_Message(logs); XDocument doc = XDocument.Parse(xml); FRDataForm form = new FRDataForm(); ConverterClass convert_class = new ConverterClass(); List <DataTable> list = convert_class.Converter(doc, out form); using (Report report = new Report()) { //conf.GetValue("FolderFR") "\\Report\\" String name_file = conf.GetValue("PathService") + "\\" + conf.GetValue("FolderFR") + "\\" + form.product + "\\" + form.form + ".frx"; MemoryStream mem = new MemoryStream(); logs = new MessageLog(MessageLog.INFO, "GetFile", "Отчет " + name_file); mes_list.Add_Message(logs); ExportBase export = Format(form); report.Load(name_file); EnvironmentSettings s = new EnvironmentSettings(); s.ReportSettings.ShowProgress = false; foreach (DataTable st in list) { report.RegisterData(st, st.TableName); } //report.Show(); //report.Design(); report.Prepare(); //FileStream fl = new FileStream("555.pdf", FileMode.Create); //report.Export(export, fl); //fl.Close(); //report.SavePrepared(fl); report.Export(export, mem); // } // nt.Flush(); mem.Position = 0; //byte[] file = mem.ToArray(); logs = new MessageLog(MessageLog.INFO, "GetFile", "Отчет сформирован и отправлен"); mes_list.Add_Message(logs); Logger.getInstance().Write(mes_list); return(mem); } }
public static void SetEnvironmentForce(string nType, int index, float[] positionEffect, float[] directionEffect, float gain, float magnitude, float duration, float frequency) { //convert String to IntPtr IntPtr type = ConverterClass.ConvertStringToByteToIntPtr(nType); //Convert float[3] to intptr IntPtr position = ConverterClass.ConvertFloat3ToIntPtr(positionEffect); //Convert float[3] to intptr IntPtr direction = ConverterClass.ConvertFloat3ToIntPtr(directionEffect); //Set the effect PluginImport.SetEffect(type, index, gain, magnitude, duration, frequency, position, direction); PluginImport.StartEffect(index); }
/******************************************************************************************************************************************************************/ public void GetHapticWorkSpace() { //Convert IntPtr to float3Array myWSPosition = ConverterClass.ConvertIntPtrToFloat3(PluginImport.GetWorkspacePosition()); //Convert IntPtr to float3Array myWSSize = ConverterClass.ConvertIntPtrToFloat3(PluginImport.GetWorkspaceSize()); //Refine my workspaceSize in the Unity Editor in case it has been changed myHapticClassScript.myWorkSpacePosition = ConverterClass.AssignFloat3ToFloat3(myWSPosition); //Refine my workspaceSize in the Unity Editor in case it has been changed myHapticClassScript.myWorkSpaceSize = ConverterClass.AssignFloat3ToFloat3(myWSSize); }
void Update() { if (cochlea == null) { cochlea = StatsManager.instance.GetActiveCochlea(); } if (PluginImport.GetButtonState(1, 2)) { if (!hasStarted) // user hasn't pressed start { DetachCochlea(); hasStarted = true; } } if (PluginImport.GetButtonState(1, 1) & !hasEnded) { hasEnded = true; StatsManager.instance.SetFullReset(false); simMonitor.IncrementReset(); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } /***************************************************************/ //Update Workspace as function of camera /***************************************************************/ //PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y);//To be deprecated //Update the Workspace as function of camera for (int i = 0; i < workspaceUpdateValue.Length; i++) { workspaceUpdateValue[i] = myHapticCamera.transform.rotation.eulerAngles.y; } PluginImport.UpdateHapticWorkspace(ConverterClass.ConvertFloatArrayToIntPtr(workspaceUpdateValue)); /***************************************************************/ //Update cube workspace /***************************************************************/ myGenericFunctionsClassScript.UpdateGraphicalWorkspace(); /***************************************************************/ //Haptic Rendering Loop /***************************************************************/ PluginImport.RenderHaptic(); //Associate the cursor object with the haptic proxy value myGenericFunctionsClassScript.GetProxyValues(isKinematic); }
/******************************************************************************************************************************************************************/ //Haptic workspace generic functions public void SetHapticWorkSpace() { //Convert float3Array to IntPtr IntPtr dstPosPtr = ConverterClass.ConvertFloat3ToIntPtr(myHapticClassScript.myWorkSpacePosition); //Convert float3Array to IntPtr IntPtr dstSizePtr = ConverterClass.ConvertFloat3ToIntPtr(myHapticClassScript.myWorkSpaceSize); //Set Haptic Workspace for separate update //PluginImport.SetWorkspacePosition(dstPosPtr); //PluginImport.SetWorkspaceSize(dstSizePtr); //Set Haptic Workspace PluginImport.SetWorkspace(dstPosPtr, dstSizePtr); }
public void ConvertFromFloat4x4(int i, float f, double d, bool isTrue, string text, double2 d2, double3 d3, double4 d4, double4x4 d4x4, float2 f2, float3 f3, float4 f4, float4x4 f4x4) { text = f4x4.ToString(); d4 = d4x4.Row0; f4 = f4x4.Row0; ConverterClass source = new ConverterClass(); ConverterClass expected = new ConverterClass(); Node root = new Node(source); Node node = new Node(expected); Circuit circuit = new Circuit(); circuit.AddNode(root); circuit.AddNode(node); circuit.AddRoot(root); source.f4x4 = f4x4; root.Attach("f4x4", node, "i"); root.Attach("f4x4", node, "f"); root.Attach("f4x4", node, "d"); root.Attach("f4x4", node, "isTrue"); root.Attach("f4x4", node, "text"); root.Attach("f4x4", node, "d2"); root.Attach("f4x4", node, "d3"); root.Attach("f4x4", node, "d4"); root.Attach("f4x4", node, "d4x4"); root.Attach("f4x4", node, "f2"); root.Attach("f4x4", node, "f3"); root.Attach("f4x4", node, "f4"); root.Attach("f4x4", node, "f4x4"); circuit.Execute(); Assert.True(expected.i == i, "Error when parsing to int: Should be " + i + " but is " + expected.i + "."); Assert.True(expected.f == f, "Error when parsing to float: Should be " + f + " but is " + expected.f + "."); Assert.True(expected.d == d, "Error when parsing to double: Should be " + d + " but is " + expected.d + "."); Assert.True(expected.isTrue == isTrue, "Error when parsing to bool: Should be " + isTrue + " but is " + expected.isTrue + "."); Assert.True(expected.text == text, "Error when parsing to string: Should be " + text + " but is " + expected.text + "."); Assert.True(expected.d2 == d2, "Error when parsing to double2: Should be " + d2 + " but is " + expected.d2 + "."); Assert.True(expected.d3 == d3, "Error when parsing to double3: Should be " + d3 + " but is " + expected.d3 + "."); Assert.True(expected.d4 == d4, "Error when parsing to double4: Should be " + d4 + " but is " + expected.d4 + "."); Assert.True(expected.d4x4 == d4x4, "Error when parsing to double4x4: Should be " + d4x4 + " but is " + expected.d4x4 + "."); Assert.True(expected.f2 == f2, "Error when parsing to float2: Should be " + f2 + " but is " + expected.f2 + "."); Assert.True(expected.f3 == f3, "Error when parsing to float3: Should be " + f3 + " but is " + expected.f3 + "."); Assert.True(expected.f4 == f4, "Error when parsing to float4: Should be " + f4 + " but is " + expected.f4 + "."); Assert.True(expected.f4x4 == f4x4, "Error when parsing to float4x4: Should be " + f4x4 + " but is " + expected.f4x4 + "."); }
//Get two haptic workspaces for two haptic device public void GetTwoHapticWorkSpaces() { //Convert IntPtr to float6Array myTwoWsPosition = ConverterClass.ConvertIntPtrToFloat6(PluginImport.GetWorkspacePosition()); //Convert IntPtr to float6Array myTwoWsSize = ConverterClass.ConvertIntPtrToFloat6(PluginImport.GetWorkspaceSize()); //Refine my workspaceSize in the Unity Editor in case it has been changed myHapticClassScript.myWorkSpacePosition = ConverterClass.SelectHalfFloat6toFloat3(myTwoWsPosition, 1); //Workspace position for device1 myHapticClassScript.mySecondWorkSpacePosition = ConverterClass.SelectHalfFloat6toFloat3(myTwoWsPosition, 2); //Workspace position for device2 //Refine my workspaceSize in the Unity Editor in case it has been changed myHapticClassScript.myWorkSpaceSize = ConverterClass.SelectHalfFloat6toFloat3(myTwoWsSize, 1); //Workspace size for device1 myHapticClassScript.mySecondWorkSpaceSize = ConverterClass.SelectHalfFloat6toFloat3(myTwoWsSize, 2); //Workspace size for device2 }
/******************************************************************************************************************************************************************/ /******************************************************************************************************************************************************************/ public void UpdateGraphicalWorkspace() { //Position Vector3 pos; pos = ConverterClass.ConvertFloat3ToVector3(myWSPosition); myHapticClassScript.workSpaceObj.transform.position = pos; //Orientation myHapticClassScript.workSpaceObj.transform.rotation = Quaternion.Euler(0.0f, myHapticClassScript.myHapticCamera.transform.eulerAngles.y, 0.0f); //Scale Vector3 size; size = ConverterClass.ConvertFloat3ToVector3(myWSSize); myHapticClassScript.workSpaceObj.transform.localScale = size; }
void Update() { /***************************************************************/ //Update two Workspaces as function of camera for each /***************************************************************/ //PluginImport.UpdateTwoWorkspace(myHapticCamera.transform.rotation.eulerAngles.y, myHapticCamera.transform.rotation.eulerAngles.y); //Update the Workspace as function of camera - Note that two different reference can be used to update each workspace for (int i = 0; i < workspaceUpdateValue.Length; i++) { workspaceUpdateValue[i] = myHapticCamera.transform.rotation.eulerAngles.y; } PluginImport.UpdateHapticWorkspace(ConverterClass.ConvertFloatArrayToIntPtr(workspaceUpdateValue)); /***************************************************************/ //Update 2 cubes workspaces /***************************************************************/ myGenericFunctionsClassScript.UpdateTwoGraphicalWorkspaces(); /***************************************************************/ //Haptic Rendering Loop /***************************************************************/ PluginImport.RenderHaptic(); /***************************************************************/ //Update Haptic Object Transform /***************************************************************/ myGenericFunctionsClassScript.UpdateHapticObjectMatrixTransform(); //myGenericFunctionsClassScript.GetProxyValues(); myGenericFunctionsClassScript.GetTwoProxyValues(); //myGenericFunctionsClassScript.GetTouchedObject(); /*Debug.Log("Device 1: Button 1: " + PluginImport.GetButtonState(1, 1)); * Debug.Log("Device 1: Button 2: " + PluginImport.GetButtonState(1, 2)); * Debug.Log("Device 2: Button 1: " + PluginImport.GetButtonState(2, 1)); * Debug.Log("Device 2: Button 2: " + PluginImport.GetButtonState(2, 2));*/ /*if(PluginImport.GetHapticContact(1)) * Debug.Log("Device 1 touches: " + PluginImport.GetTouchedObjId(1) + " " + ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(1))); * if (PluginImport.GetHapticContact(2)) * Debug.Log("Device 2 touches: " + PluginImport.GetTouchedObjId(2) + " " + ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(2)));*/ }
void Update() { /***************************************************************/ //Act on the rigid body of the Manipulated object // if Mode = Manipulation Mode /***************************************************************/ if (PluginImport.GetMode() == 1) { ActivatingGrabbedObjectPropperties(); } /***************************************************************/ //Update Workspace as function of camera /***************************************************************/ //PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y); //To be deprecated //Update the Workspace as function of camera for (int i = 0; i < workspaceUpdateValue.Length; i++) { workspaceUpdateValue[i] = myHapticCamera.transform.rotation.eulerAngles.y; } PluginImport.UpdateHapticWorkspace(ConverterClass.ConvertFloatArrayToIntPtr(workspaceUpdateValue)); /***************************************************************/ //Update cube workspace /***************************************************************/ myGenericFunctionsClassScript.UpdateGraphicalWorkspace(); /***************************************************************/ //Haptic Rendering Loop /***************************************************************/ PluginImport.RenderHaptic(); //Associate the cursor object with the haptic proxy value myGenericFunctionsClassScript.GetProxyValues(); myGenericFunctionsClassScript.GetTouchedObject(); //Debug.Log ("Button 1: " + PluginImport.GetButton1State()); // To be deprecated //Debug.Log ("Button 2: " + PluginImport.GetButton2State()); // To be deprecated //Debug.Log("Device 1: Button 1: " + PluginImport.GetButtonState(1, 1)); //Debug.Log("Device 1: Button 2: " + PluginImport.GetButtonState(1, 2)); }
public void ConvertFromStringToDouble2() { ConverterClass source = new ConverterClass(); ConverterClass expected = new ConverterClass(); Node root = new Node(source); Node node = new Node(expected); Circuit circuit = new Circuit(); circuit.AddNode(root); circuit.AddNode(node); circuit.AddRoot(root); source.text = "(1, 1)"; root.Attach("text", node, "d2"); circuit.Execute(); Assert.True(expected.d2 == new double2(1, 1), "Error when parsing to double2: Should be " + source.text + " but is " + expected.d2 + "."); }
public void ConvertFromStringToFloat4x4() { ConverterClass source = new ConverterClass(); ConverterClass expected = new ConverterClass(); Node root = new Node(source); Node node = new Node(expected); Circuit circuit = new Circuit(); circuit.AddNode(root); circuit.AddNode(node); circuit.AddRoot(root); source.text = "(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)"; root.Attach("text", node, "f4x4"); circuit.Execute(); Assert.True(expected.f4x4 == new float4x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), "Error when parsing to float4x4: Should be " + source.text + " but is " + expected.f4x4 + "."); }
public void SetTangentialForce() { myTangentialForceScript = transform.GetComponent <TangentialForce>(); /***************************** * Tangential Force Example *****************************/ //convert String to IntPtr IntPtr type = ConverterClass.ConvertStringToByteToIntPtr(myTangentialForceScript.Type); //Convert float[3] to intptr IntPtr position = ConverterClass.ConvertFloat3ToIntPtr(myTangentialForceScript.positionEffect); //Convert float[3] to intptr IntPtr direction = ConverterClass.ConvertFloat3ToIntPtr(myTangentialForceScript.directionEffect); //Set the effect PluginImport.SetEffect(type, myTangentialForceScript.effect_index, myTangentialForceScript.gain, myTangentialForceScript.magnitude, myTangentialForceScript.duration, myTangentialForceScript.frequency, position, direction); PluginImport.StartEffect(myTangentialForceScript.effect_index); }
void ActivatingGrabbedObjectPropperties() { GameObject grabbedObject; string myObjStringName; if (!previousButtonState && PluginImport.GetButtonState(1, 1)) { //If the object is grabbed, the gravity is deactivated and kinematic is enabled //myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjectName());//GetTouchedObjectName() - To be deprecated myObjStringName = ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(1)); if (!myObjStringName.Equals("null")) { grabbedObject = GameObject.Find(myObjStringName); //If there is a rigid body if (grabbedObject.GetComponent <Rigidbody>() != null) { grabbedObject.GetComponent <Rigidbody>().isKinematic = true; grabbedObject.GetComponent <Rigidbody>().useGravity = false; } grabbedObjectName = myObjStringName; } previousButtonState = true; } else if (previousButtonState && !PluginImport.GetButtonState(1, 1)) { //If the object is dropped, the grabity is enabled again and kinematic is deactivated if (!grabbedObjectName.Equals("")) { grabbedObject = GameObject.Find(grabbedObjectName); //If there is a rigid body if (grabbedObject.GetComponent <Rigidbody>() != null) { grabbedObject.GetComponent <Rigidbody>().isKinematic = false; grabbedObject.GetComponent <Rigidbody>().useGravity = true; } grabbedObjectName = ""; } previousButtonState = false; } }
void Update() { /***************************************************************/ //Update Workspace as function of camera /***************************************************************/ //PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y);//To be deprecated //Update the Workspace as function of camera for (int i = 0; i < workspaceUpdateValue.Length; i++) { workspaceUpdateValue[i] = myHapticCamera.transform.rotation.eulerAngles.y; } PluginImport.UpdateHapticWorkspace(ConverterClass.ConvertFloatArrayToIntPtr(workspaceUpdateValue)); /***************************************************************/ //Update cube workspace /***************************************************************/ myGenericFunctionsClassScript.UpdateGraphicalWorkspace(); /***************************************************************/ //Haptic Rendering Loop /***************************************************************/ PluginImport.RenderHaptic(); //Associate the cursor object with the haptic proxy value myGenericFunctionsClassScript.GetProxyValues(); //myGenericFunctionsClassScript.GetTouchedObject(); //Reset the writing on the board //if(ConverterClass.ConvertIntPtrToByteToString( PluginImport.GetTouchedObjectName()) == "reset") // GetTouchedObjectName - To be deprecated if (ConverterClass.ConvertIntPtrToByteToString(PluginImport.GetTouchedObjName(1)) == "reset") { myWritingScript.cleanBoard(); //Change the Color of the button material myResetButton.GetComponent <Renderer>().material.color = buttonResetColors[1]; } else { myResetButton.GetComponent <Renderer>().material.color = buttonResetColors[0]; } }