Guest User

Untitled

a guest
Dec 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. private List<Vector3> positions = new List<Vector3>();
  2. private bool recordPosition = false; //Records position when true
  3. private int valuesRecorded = 0; //Count of recorded values
  4. private bool firstValue = true; //true if it's the first recorded value
  5. private bool deleteLastRecorded = false;
  6. private float cleaningDiffTolerance = 0.2f; //Default 0.2f = 20cm
  7. private float cleaningAngleMaxDiff = 5.0f; //Default 5.0f = 5°
  8.  
  9. void Update(){
  10. if (recordPosition) {
  11. if (deleteLastRecorded) { //Check if the last recorded has been cleaned and delete the List element
  12. positions.RemoveAt (valuesRecorded - 1);
  13. if (showDebug) {
  14. Destroy (debugPoint);
  15. debugPoints.RemoveAt (valuesRecorded);
  16. }
  17. }
  18. deleteLastRecorded = false;
  19.  
  20. Vector3 tempVect = trackableObject.position; //Record position
  21.  
  22. positions.Add (tempVect); //Add value to list
  23.  
  24. if (showDebug) { //DEBUG
  25. if (!showOnlyCleaned) { //show original values
  26. debugPointOriginal = Instantiate (originalCube, tempVect, Quaternion.Euler (0, 0, 0), originalParentPoints.transform) as GameObject;
  27. debugPointsOriginal.Add (debugPointOriginal.transform);
  28. }
  29. originalCount++;
  30. //show cleaned values
  31. debugPoint = Instantiate (cleanedCube, tempVect, Quaternion.Euler (0, 0, 0), cleanedParentPoints.transform) as GameObject;
  32. debugPoints.Add (debugPoint.transform);
  33. }
  34. if (firstValue) { //Remove first recorded value
  35. if (valuesRecorded == 0) {
  36. positions.RemoveAt (valuesRecorded);
  37. if (showDebug) {
  38. Destroy (debugPoint);
  39. debugPoints.RemoveAt (valuesRecorded);
  40. }
  41. valuesRecorded--;
  42. firstValue = false;
  43. }
  44. }
  45. if (valuesRecorded > 1) { //CLEANING
  46. Vector3 valueLast = positions [valuesRecorded - 2];
  47. Vector3 valueCurrent = positions [valuesRecorded - 1];
  48. Vector3 valueNext = positions [valuesRecorded];
  49.  
  50. float diffCurrLast = Vector3.Distance (valueCurrent, valueLast); //Distance between CURRENT and LAST value
  51. float diffCurrNext = Vector3.Distance (valueCurrent, valueNext); //Distance between CURRENT and NEXT value
  52. Vector3 lastDirection = valueLast - valueCurrent; //Direction from LAST to CURRENT position
  53. Vector3 nextDirection = valueCurrent - valueNext; //Direction from CURRENT to NEXT position
  54. float diffAngle = 0;
  55.  
  56. if (diffCurrLast < cleaningDiffTolerance) { //Check Distance between CURRENT and LAST value
  57. diffAngle = Vector3.Angle (lastDirection, nextDirection); //Get Diff Angle
  58. if (diffAngle < cleaningAngleMaxDiff) {
  59. deleteLastRecorded = true;
  60. valuesRecorded--; //Reset i for next item
  61. }
  62. } else {
  63. if (diffCurrNext < cleaningDiffTolerance) { //Check Distance between CURRENT and NEXT value
  64. diffAngle = Vector3.Angle (lastDirection, nextDirection); //Get Diff Angle
  65. if (diffAngle < cleaningAngleMaxDiff) {
  66. deleteLastRecorded = true;
  67. valuesRecorded--; //Reset i for next item
  68. }
  69. }
  70. }
  71. }
  72. valuesRecorded++;
  73. }
  74. }
Add Comment
Please, Sign In to add comment