Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RotateTransformInteractor : TransformInteractor
- {
- public Transform trackedObject; //The rotational value to track that will be mapped onto the interactable.(Player Hand)
- private Quaternion trackedObjStartRot; //The starting rotation of the rotational target to track.
- private Quaternion targetStartRot; //The starting rotation of the interactable target to rotate.
- //Called when pointer hits a valid object.
- internal override void ValidHit(GameObject hit)
- {
- //Save the starting values for the objects.
- trackedObjStartRot = trackedObject.rotation;
- targetStartRot = transformObject.transform.rotation;
- }
- //Called every frame that pointer is over valid object.
- internal override void TransformObject(Vector3 rayPos)
- {
- if (transformObject == null || trackedObject==null) return;
- Quaternion axisQRot = new Quaternion(0,0,0,0);
- Quaternion currentTargetRot = trackedObject.rotation;
- float result = 0;
- float currentRotFromStart = 0;
- currentRotFromStart = trackedObjStartRot.z - currentTargetRot.z;//Hand z rotation from start in quat.
- //float angle = Quaternion.Angle(targetStartRot, currentTargetRot);
- switch (activeAxis)
- {
- case AxisManipulation.x:
- result = targetStartRot.x - currentRotFromStart;
- axisQRot = new Quaternion(result, transformObject.transform.rotation.y, transformObject.transform.rotation.z,
- transformObject.transform.rotation.w);
- break;
- case AxisManipulation.y:
- result = targetStartRot.y - currentRotFromStart;
- axisQRot = new Quaternion(transformObject.transform.rotation.y, result, transformObject.transform.rotation.z,
- transformObject.transform.rotation.w);
- break;
- case AxisManipulation.z:
- result = targetStartRot.z - currentRotFromStart;
- axisQRot = new Quaternion(transformObject.transform.rotation.x, transformObject.transform.rotation.y, result,
- transformObject.transform.rotation.w);
- break;
- default:
- Debug.Log("Transform tool issue: No axis chosen to manipulate.");
- break;
- }
- transformObject.transform.rotation = axisQRot;
- Debug.Log("Result: "+result.ToString("#0.0"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement