Advertisement
Guest User

rot

a guest
Apr 22nd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. public class RotateTransformInteractor : TransformInteractor
  2. {
  3.     public Transform trackedObject;     //The rotational value to track that will be mapped onto the interactable.(Player Hand)
  4.  
  5.     private Quaternion trackedObjStartRot;  //The starting rotation of the rotational target to track.
  6.     private Quaternion targetStartRot;      //The starting rotation of the interactable target to rotate.
  7.  
  8.  
  9.     //Called when pointer hits a valid object.
  10.     internal override void ValidHit(GameObject hit)
  11.     {
  12.         //Save the starting values for the objects.
  13.         trackedObjStartRot = trackedObject.rotation;
  14.         targetStartRot = transformObject.transform.rotation;
  15.     }
  16.  
  17.     //Called every frame that pointer is over valid object.
  18.     internal override void TransformObject(Vector3 rayPos)
  19.     {
  20.  
  21.         if (transformObject == null || trackedObject==null) return;
  22.  
  23.  
  24.  
  25.         Quaternion axisQRot = new Quaternion(0,0,0,0);
  26.         Quaternion currentTargetRot = trackedObject.rotation;
  27.         float result = 0;
  28.         float currentRotFromStart = 0;
  29.  
  30.         currentRotFromStart = trackedObjStartRot.z - currentTargetRot.z;//Hand z rotation from start in quat.
  31.  
  32.         //float angle = Quaternion.Angle(targetStartRot, currentTargetRot);
  33.  
  34.         switch (activeAxis)
  35.         {
  36.             case AxisManipulation.x:
  37.                 result = targetStartRot.x - currentRotFromStart;
  38.  
  39.                 axisQRot = new Quaternion(result, transformObject.transform.rotation.y, transformObject.transform.rotation.z,        
  40.                                           transformObject.transform.rotation.w);
  41.                 break;
  42.  
  43.             case AxisManipulation.y:
  44.                 result = targetStartRot.y - currentRotFromStart;
  45.  
  46.                 axisQRot = new Quaternion(transformObject.transform.rotation.y, result, transformObject.transform.rotation.z,
  47.                                           transformObject.transform.rotation.w);
  48.                 break;
  49.  
  50.             case AxisManipulation.z:
  51.                 result = targetStartRot.z - currentRotFromStart;
  52.  
  53.                 axisQRot = new Quaternion(transformObject.transform.rotation.x, transformObject.transform.rotation.y, result,
  54.                                           transformObject.transform.rotation.w);
  55.                 break;
  56.  
  57.             default:
  58.                 Debug.Log("Transform tool issue: No axis chosen to manipulate.");
  59.                 break;
  60.         }
  61.  
  62.  
  63.      
  64.         transformObject.transform.rotation = axisQRot;
  65.  
  66.  
  67.         Debug.Log("Result: "+result.ToString("#0.0"));
  68.  
  69.  
  70.  
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement