Advertisement
Guest User

rot2

a guest
Apr 22nd, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 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.     private Vector3 trackedObjStartEuler;
  8.  
  9.  
  10.     //Called when pointer hits a valid object.
  11.     internal override void ValidHit(GameObject hit)
  12.     {
  13.         //Save the starting values for the objects.
  14.         trackedObjStartRot = trackedObject.rotation;
  15.         targetStartRot = transformObject.transform.rotation;
  16.     }
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.    
  24.     //Called every frame that pointer is over valid object.
  25.     internal override void TransformObject(Vector3 rayPos)
  26.     {
  27.  
  28.         if (transformObject == null || trackedObject==null) return;
  29.  
  30.  
  31.  
  32.         Quaternion axisQRot = new Quaternion(0,0,0,0);
  33.         Quaternion trackedObjCurrentRot = trackedObject.rotation;
  34.         Vector3 axisVector = Vector3.zero;
  35.         float currentRotFromStart = trackedObjStartRot.z - trackedObjCurrentRot.z;                  //Hand z rotation from start in quat.
  36.         float currentAngleFromStart = Quaternion.Angle(trackedObjStartRot, trackedObjCurrentRot);   //Hand rotation from start in angle.
  37.  
  38.  
  39.  
  40.         switch (activeAxis)
  41.         {
  42.             case AxisManipulation.x:
  43.                 axisVector = Vector3.right;
  44.                 break;
  45.  
  46.             case AxisManipulation.y:
  47.                 axisVector = Vector3.up;
  48.                 break;
  49.  
  50.             case AxisManipulation.z:
  51.                 axisVector = Vector3.forward;
  52.                 break;
  53.  
  54.             default:
  55.                 Debug.Log("Transform tool issue: No axis chosen to manipulate.");
  56.                 break;
  57.         }
  58.  
  59.  
  60.  
  61.         transformObject.transform.rotation *= Quaternion.AngleAxis(currentRotFromStart * 100* Time.deltaTime, axisVector);
  62.  
  63.  
  64.         //Debug.Log("Result: "+result.ToString("#0.0"));
  65.         //Debug.Log("Hand Angle   Quat: "+currentRotFromStart.ToString("#0.0")+"  Angle: "+ currentAngleFromStart);
  66.  
  67.  
  68.     }
  69.    
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement