// 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++; }
// Update is called once per frame void Update() { if (!previousButtonState && PluginImport.GetButton2State()) { light.enabled = true; previousButtonState = true; } else if (previousButtonState && !PluginImport.GetButton2State()) { light.enabled = false; previousButtonState = false; } }
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); /***************************************************************/ //Update cube workspace /***************************************************************/ myGenericFunctionsClassScript.UpdateGraphicalWorkspace(); /***************************************************************/ //Haptic Rendering Loop /***************************************************************/ PluginImport.RenderHaptic(); myGenericFunctionsClassScript.GetProxyValues(); myGenericFunctionsClassScript.GetTouchedObject(); //Debug.Log ("Button 1: " + PluginImport.GetButton1State()); //Debug.Log ("Button 2: " + PluginImport.GetButton2State()); if (PluginImport.GetButton2State()) { makeJengaBlocks(); } const float rotSpeed = 1.0f; if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { myHapticCamera.transform.RotateAround(Vector3.zero, new Vector3(0.0f, 1.0f, 0.0f), rotSpeed); } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { myHapticCamera.transform.RotateAround(Vector3.zero, new Vector3(0.0f, 1.0f, 0.0f), -rotSpeed); } }
// Update is called once per frame void Update() { double[] pos = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetDevicePosition()); Vector3 position = new Vector3((float)pos [0], (float)pos [1], (float)pos [2]); button1 = PluginImport.GetButton1State(); // getting state of button 1 on phantom Debug.Log(button1 + " " + button2); // printing button 1 and button 2 state on console if (button1 && !previousbutton1state) // routine for writing coordinate values to text file { ////////////////////////////////////////////////////////////////// using (StreamWriter writer = new StreamWriter("G:\\log.txt", true)) // Loop through ten numbers. for (int i = 0; i < 3; i++) { //Write format string to file. //writer.Write ("{0:0.0} ", position [i]); writer.WriteLine(position); } // for loop using (StreamWriter writer = new StreamWriter("G:\\log.txt", true)) { writer.WriteLine("\r\n"); // //writer.WriteLine("First target coordinates"); } // stream // } previousbutton1state = button1; ///////////////////////////////////////////////////////////////////// button2 = PluginImport.GetButton2State(); if (button2 && !previousbutton2state) // Controlling invisibility of the pointer object { visibility.GetComponent <MeshRenderer> ().enabled = false; // making object invisible } // update previousbutton2state = button2; if (Input.GetKeyDown(KeyCode.A)) { visibility.GetComponent <MeshRenderer> ().enabled = true; // Making object visible again on pressing button 2 } }
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(); 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)); }
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)); // if (PluginImport.GetButtonState(1, 2)) //{ // makeJengaBlocks(); //} if (PluginImport.GetButtonState(1, 1)) { Debug.Log("Device 1 : Button Up Pressed"); } else if (PluginImport.GetButtonState(1, 2)) { Debug.Log("Device 1 : Button Down Pressed"); } if (PluginImport.GetButtonState(2, 1)) { Debug.Log("Device 2 : Button Up Pressed"); } else if (PluginImport.GetButtonState(2, 2)) { Debug.Log("Device 2 : Button Down Pressed"); } const float rotSpeed = 1.0f; if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { myHapticCamera.transform.RotateAround(Vector3.zero, new Vector3(0.0f, 1.0f, 0.0f), rotSpeed); } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { myHapticCamera.transform.RotateAround(Vector3.zero, new Vector3(0.0f, 1.0f, 0.0f), -rotSpeed); } }
void Update() { if (PluginImport.GetButton2State()) { puncture = !puncture; } if (puncture) { PluginImport.SetMode(3); Debug.Log("Puncture"); } else { Debug.Log("Manipulation"); PluginImport.SetMode(1); } /***************************************************************/ //Update Workspace as function of camera /***************************************************************/ PluginImport.UpdateWorkspace(myHapticCamera.transform.rotation.eulerAngles.y); /***************************************************************/ //Update cube workspace /***************************************************************/ myGenericFunctionsClassScript.UpdateGraphicalWorkspace(); /***************************************************************/ //Haptic Rendering Loop /***************************************************************/ PluginImport.RenderHaptic(); myGenericFunctionsClassScript.GetProxyValues(); myGenericFunctionsClassScript.GetTouchedObject(); //For the Puncture Mode effect if (PluginImport.GetMode() == 3) { //Debug.Log ("Contact state is set to " + PluginImport.GetContact()); //Debug.Log ("Penetration State " + PluginImport.GetPenetrationRatio()); double[] myScp = new double[3]; myScp = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetFirstScpPt()); //Debug.Log (" SCP " + myScp[0] + " " + myScp[1] + " " + myScp[2]); /*double[] myProx = new double[3]; * myProx = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetProxyPosition()); * * Vector3 posProx; * posProx = ConverterClass.ConvertDouble3ToVector3(myProx); * GameObject.Find ("ProxyTipMarker").transform.position = posProx;*/ /*double[] myDev = new double[3]; * myDev = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetDevicePosition()); * * Vector3 posDevice; * posDevice = ConverterClass.ConvertDouble3ToVector3(myDev); * GameObject.Find ("DeviceTipMarker").transform.position = posDevice;*/ double[] myPinch = new double[3]; myPinch = ConverterClass.ConvertIntPtrToDouble3(PluginImport.GetPunctureDirection()); Vector3 start = new Vector3(); start = ConverterClass.ConvertDouble3ToVector3(myScp); Vector3 end = new Vector3(); end = ConverterClass.ConvertDouble3ToVector3(myPinch); end.Normalize(); Debug.DrawLine(start, start + end * maxPenetration, Color.green); //Ray Cast so we can determine the limitation of the puncture RaycastHit[] hits; hits = Physics.RaycastAll(start, end, maxPenetration); if (hits.Length != 0) { //Declare a float array to store the tissue layer float[] tissueLayers = new float[hits.Length]; //Declare a string array to store the name of the tissue layer string[] punctObjects = new string[hits.Length]; int nbLayer = 0; for (int i = 0; i < hits.Length; i++) { RaycastHit hit = hits[i]; //Only if the object is declared as touchable if (hit.collider.gameObject.tag == "Touchable") { tissueLayers[nbLayer] = hit.distance; punctObjects[nbLayer] = hit.collider.name; nbLayer++; } } /*Declaration of the Puncture Stack * Additionally, on the basis of the puncture stack components, the plugin setup a penetration restriction * - due to the fact that Proxy Method along such constraint line is not accurate - most probably due to the fact * that device position and proxy position differ because the constraint applies forces onto the device. * So, the plugin impedes the proxy to penetrate in underlying layer when their popthrough values is null */ SetPunctureStack(nbLayer, punctObjects, tissueLayers); } } }