/// <summary> /// Converts the native TabletDeviceStatesListNative structure into an array of TabletState structures. /// </summary> /// <param name="deviceStatesNative">The retrieved TabletDeviceStatesListNative structure.</param> /// <returns>Returns an array of TabletState structures.</returns> public static MLInput.TabletState[] DeviceStatesToArray(TabletDeviceStatesListNative deviceStatesNative) { MLInput.TabletState[] deviceStates = new MLInput.TabletState[deviceStatesNative.Count]; for (int i = 0; i < (int)deviceStatesNative.Count; i++) { deviceStates[i] = Marshal.PtrToStructure <NativeBindings.TabletDeviceStateNative>(deviceStatesNative.Data + (i * Marshal.SizeOf(typeof(NativeBindings.TabletDeviceStateNative)))).Data; } return(deviceStates); }
private void HandleOnTabletPenTouch(byte tabletId, MLInput.TabletState tabletState) { // Set the location of the pen. _pen.localPosition = new Vector3(tabletState.PenTouchPosAndForce.x / -7.75f, tabletState.PenDistance / 100, tabletState.PenTouchPosAndForce.y / 13.25f); // Set the rotation of the pen. if (tabletState.ValidityCheck.HasFlag(MLInput.TabletDeviceStateMask.HasAdditionalPenTouchData)) { _pen.localRotation = Quaternion.Euler(-90, 0, 0) * Quaternion.Euler(tabletState.AdditionalPenTouchData[1], tabletState.AdditionalPenTouchData[0] * -1, 0); } // Only draw when the pen is touching. if (tabletState.IsPenTouchActive) { // Determine the hit location on the canvas from the location of the pen. if (Physics.Raycast(new Ray(_pen.transform.position + (_pen.transform.forward * 0.0025f), _canvasRenderer.transform.up * -1), out _pixelHit)) { // Confirm the correct object is being hit. if (_pixelHit.collider.gameObject == _canvasRenderer.gameObject) { // Only draw the pixel if it doesn't match what was detected. if (_pixelPoint != _pixelHit.lightmapCoord) { _pixelPoint = _pixelHit.lightmapCoord; _pixelPoint.y *= RESOLUTION; _pixelPoint.x *= RESOLUTION; // Check if the tool type is set to erase, or if the user is pressing the erase button. bool erase = (tabletState.ToolType == MLInput.TabletDeviceToolType.Eraser || ButtonErase); DrawTexture(_canvas, _pixelPoint.x, _pixelPoint.y, tabletState.PenTouchPosAndForce.z, erase); } } } } // Update our last state, used for on-screen information. LastPositionAndForce = tabletState.PenTouchPosAndForce; LastDistance = tabletState.PenDistance; // Pen tilt information. if (tabletState.ValidityCheck.HasFlag(MLInput.TabletDeviceStateMask.HasAdditionalPenTouchData)) { LastTilt = new Vector2(tabletState.AdditionalPenTouchData[0], tabletState.AdditionalPenTouchData[1]); } LastIsTouching = tabletState.IsPenTouchActive; LastToolType = tabletState.ToolType; }