//////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2007-2020 , Inc. All Rights Reserved. // //////////////////////////////////////////////////////////////////////////////// using UnityEngine; using GCSeries.Core.Extensions; using GCSeries.Core.Sdk; namespace GCSeries.Core.Input { public class ZStylus : ZPointer { //////////////////////////////////////////////////////////////////////// // MonoBehaviour Callbacks //////////////////////////////////////////////////////////////////////// protected override void Awake() { base.Awake(); if (ZProvider.IsInitialized) { this._target = ZProvider.StylusTarget; this._viewport = ZProvider.Viewport; } } //////////////////////////////////////////////////////////////////////// // Public Properties //////////////////////////////////////////////////////////////////////// /// /// The unique id of the stylus pointer. /// public override int Id => 0; /// /// The current visibility state of the stylus. /// public override bool IsVisible => this._target?.IsVisible ?? false; /// /// The number of buttons supported by the stylus. /// public override int ButtonCount => this._target?.ButtonCount ?? 0; /// /// The current scroll delta of the stylus. /// /// /// /// Since the stylus has not scroll support, the current implementation /// is hard-coded to the zero vector. /// public override Vector2 ScrollDelta => Vector2.zero; /// /// The pose of the stylus in tracker space. /// public Pose TrackerPose => this._target?.Pose ?? default(Pose); //////////////////////////////////////////////////////////////////////// // Public Methods //////////////////////////////////////////////////////////////////////// /// /// Gets whether the specified button is pressed. /// /// /// /// The integer id of the specified button. /// /// /// /// True if the specified button is pressed. False otherwise. /// public override bool GetButton(int id) { return this._target?.IsButtonPressed(id) ?? false; } //////////////////////////////////////////////////////////////////////// // Protected Methods //////////////////////////////////////////////////////////////////////// protected override Pose ComputeWorldPose() { if (this._target == null || this._viewport == null) { return this.transform.ToPose(); } Pose trackerPose = this._target.Pose; Matrix4x4 trackerToWorldMatrix = this.EventCamera.CameraToWorldMatrix * this._viewport.GetCoordinateSpaceTransform( ZCoordinateSpace.Tracker, ZCoordinateSpace.Camera); return trackerPose.GetTransformedBy(trackerToWorldMatrix); } //////////////////////////////////////////////////////////////////////// // Private Members //////////////////////////////////////////////////////////////////////// private ZTarget _target = null; private ZViewport _viewport = null; } }