private MolRelDirection GetMolRelativeDirection()
    {
        Camera ARCam = MainController.FirstPersonCamera.GetComponent <Camera>();

        Vector3         relativeUp      = ARCam.transform.TransformDirection(Vector3.up);
        Vector3         relativeRight   = ARCam.transform.TransformDirection(Vector3.right);
        Vector3         molRelUp        = transform.InverseTransformDirection(relativeUp);
        Vector3         molRelRight     = transform.InverseTransformDirection(relativeRight);
        MolRelDirection molRelDirection = new MolRelDirection {
            molrelRight = molRelRight, molRelUp = molRelUp
        };

        return(molRelDirection);
    }
    private void OnMouseUp()
    {
        Vector2 deltaFingerPos = Input.GetTouch(0).position - mouseDownPixelPos;

        if (MainController.enableVelocity && !userRotatingMolecule && !isScaling && Math.Abs(deltaFingerPos.x) > 0.5 && Math.Abs(deltaFingerPos.y) > 0.5)
        {
            molRigidBody.constraints = RigidbodyConstraints.None;
            NewMolPos = Vector3.zero; //so velocity not updated in late update
            Vector3 throwVector   = transform.position - prevPos;
            float   throwSpeed    = throwVector.magnitude / Time.deltaTime;
            Vector3 throwVelocity = throwSpeed * throwVector.normalized;
            molRigidBody.velocity = throwVelocity;
        }

        if (userRotatingMolecule && MainController.enableVelocity && Math.Abs(deltaFingerPos.x) > 0.5 && Math.Abs(deltaFingerPos.y) > 0.5)
        {
            molRigidBody.constraints = RigidbodyConstraints.None;
            NewMolPos = Vector3.zero;
            molRigidBody.angularVelocity = Vector3.zero;

            if (pitchRotation)
            {
                float force = GenerateForce(totalZRotation, rotationTime) / 40;
                molRigidBody.AddTorque(0, 0, force);
            }

            else
            {
                float xDistance = Input.GetTouch(0).deltaPosition.x * 15 * Mathf.Deg2Rad;
                float yDistance = Input.GetTouch(0).deltaPosition.y * 15 * Mathf.Deg2Rad;

                MolRelDirection molRelDirection = GetMolRelativeDirection();

                molRigidBody.AddTorque((molRelDirection.molRelUp) * GenerateForce(xDistance, rotationTime));
                molRigidBody.AddRelativeTorque((molRelDirection.molrelRight) * GenerateForce(-yDistance, rotationTime));
            }

            pitchRotation  = false;
            totalZRotation = 0;
            recordRotTime  = false;
            rotationTime   = 0;
        }
    }
    public void RotateLeftRight(float rotateLeftRight, float rotateUpDown)
    {
        float sensitivity = 35f;

        MolRelDirection molRelDirection = GetMolRelativeDirection();

        Quaternion rotateBy = Quaternion.AngleAxis(rotateLeftRight / gameObject.transform.parent.transform.localScale.x * sensitivity, molRelDirection.molRelUp)
                              * Quaternion.AngleAxis(-rotateUpDown / gameObject.transform.parent.transform.localScale.x * sensitivity, molRelDirection.molrelRight);


        _rotateBy = rotateBy;

        try
        {
            //molRigidBody.MoveRotation(rotateBy * transform.rotation);
            transform.Rotate(rotateBy.eulerAngles);
        }

        catch (Exception e)
        {
            ChemviewHelper.ShowAndroidToastMessage(e.ToString());
        }
        //TODO: Use rotation in fixed update to potentially solve jittery issues
    }