//////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2007-2020 , Inc. All Rights Reserved. // //////////////////////////////////////////////////////////////////////////////// using System; using System.Runtime.InteropServices; using System.Text; using UnityEngine; using GCSeries.Core.Sdk; namespace GCSeries.Core.Interop { public static class ZPlugin { //////////////////////////////////////////////////////////////////////// // Public Methods //////////////////////////////////////////////////////////////////////// public static void ThrowOnError(ZPluginError pluginError) { if (pluginError != ZPluginError.Ok) { throw new Exception(); } } public static void LogOnError(ZPluginError pluginError, string functionName) { #if ZCORE_LOGGING_ENABLED if (pluginError != ZPluginError.Ok) { #if UNITY_EDITOR Debug.LogErrorFormat("ZPlugin.{0} returned ZPluginError: {1}", functionName, pluginError); #else Debug.LogErrorFormat("ZPlugin.{0} returned ZPluginError: {1}\n\n{2}", functionName, pluginError, new System.Diagnostics.StackTrace()); #endif } #endif } public static void IssueEvent(ZPluginEvent pluginEvent) { IntPtr renderEventFunc = GetRenderEventFunc(); if (renderEventFunc != IntPtr.Zero) { GL.IssuePluginEvent(renderEventFunc, (int)pluginEvent); } else { Debug.LogError( "Invalid render event function pointer. " + $"Failed to issue plugin event: {pluginEvent}"); } } public static void InitializeLogging() { SetLogger(Marshal.GetFunctionPointerForDelegate(s_loggerCallback)); } public static void ShutDownLogging() { #if UNITY_EDITOR_OSX SetLogger(IntPtr.Zero); #endif } //////////////////////////////////////////////////////////////////////// // DLL Import Declarations //////////////////////////////////////////////////////////////////////// [DllImport( DllName, EntryPoint = "GetRenderEventFunc", CallingConvention = CallingConvention.StdCall)] internal static extern IntPtr GetRenderEventFunc(); [DllImport( DllName, EntryPoint = "zcuSetLogger", CallingConvention = CallingConvention.StdCall)] internal static extern void SetLogger( IntPtr logger); [DllImport( DllName, EntryPoint = "zcuGetPluginVersion", CallingConvention = CallingConvention.StdCall)] internal static extern void GetPluginVersion( out int major, out int minor, out int patch); [DllImport( DllName, EntryPoint = "zcuGetWindowPosition", CallingConvention = CallingConvention.StdCall)] internal static extern void GetWindowPosition( out int x, out int y); /// /// Loads the SDK runtime library and detects connected /// peripherals. For the detected peripherals, /// creates instances of all underlying Displays, TrackerDevices, /// and TrackerTargets. /// /// /// /// A handle to the internal state of the SDK. /// [DllImport( DllName, EntryPoint = "zcuInitialize", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError Initialize(out IntPtr context); /// /// Updates the underlying state of the SDK. This includes /// polling and caching tracker target pose information. /// Additionally, any stereo frustums will receive the latest /// pose information from the default head target. Call this /// once per frame. /// /// /// /// A handle to the internal state of the SDK. /// [DllImport( DllName, EntryPoint = "zcuUpdate", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError Update(IntPtr context); /// /// Frees allocated memory and unloads plugins. Call this /// on application shutdown. /// /// /// /// A handle to the internal state of the SDK. /// [DllImport( DllName, EntryPoint = "zcuShutDown", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError ShutDown(IntPtr context); /// /// Gets the version of the runtime that has been loaded by /// . The version is in the following /// format: major.minor.patch /// /// /// /// A handle to the internal state of the SDK. /// /// /// The major component of the revision number. /// /// /// The minor component of the revision number. /// /// /// The patch component of the revision number. /// [DllImport( DllName, EntryPoint = "zcuGetRuntimeVersion", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetRuntimeVersion( IntPtr context, out int major, out int minor, out int patch); /// /// Sets whether or not tracking for all devices is enabled. /// /// /// /// A handle to the internal state of the SDK. /// /// /// True to enable tracking, false to disable it. /// [DllImport( DllName, EntryPoint = "zcuSetTrackingEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetTrackingEnabled( IntPtr context, [param: MarshalAs(UnmanagedType.Bool)] bool isEnabled); /// /// Checks whether tracking for all devices is enabled. /// /// /// /// A handle to the internal state of the SDK. /// /// /// True if enabled, false otherwise. /// [DllImport( DllName, EntryPoint = "zcuIsTrackingEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsTrackingEnabled( IntPtr context, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isEnabled); /// /// Refreshes all of the underlying display information. /// /// /// /// A handle to the internal state of the SDK. /// /// /// /// This invalidates any cached display data that has been returned /// in prior queries. You must query for these display handles again. /// [DllImport( DllName, EntryPoint = "zcuRefreshDisplays", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError RefreshDisplays(IntPtr context); /// /// Gets the number of connected displays. /// /// /// /// A handle to the internal state of the SDK. /// /// /// The number of connected displays. /// [DllImport( DllName, EntryPoint = "zcuGetNumDisplays", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetNumDisplays( IntPtr context, out int numDisplays); /// /// Gets the number of connected displays based on a specified type. /// /// /// /// A handle to the internal state of the SDK. /// /// /// The type of display to query. /// /// /// The number of displays of the specified type. /// [DllImport( DllName, EntryPoint = "zcuGetNumDisplaysByType", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetNumDisplaysByType( IntPtr context, ZDisplayType displayType, out int numDisplays); /// /// Gets the display handle based on the specified /// (, ) pixel /// coordinates on the virtual desktop. /// /// /// /// A handle to the internal state of the SDK. /// /// /// The x pixel coordinate on the virtual desktop. /// /// /// The y pixel coordinate on the virtual desktop. /// /// /// The handle for the display at the specified pixel location. /// [DllImport( DllName, EntryPoint = "zcuGetDisplay", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplay( IntPtr context, int x, int y, out IntPtr displayHandle); /// /// Gets the display handle at a specified index. /// /// /// /// A handle to the internal state of the SDK. /// /// /// The index of the display to query. /// /// /// The handle for the display at the specified index. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayByIndex", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayByIndex( IntPtr context, int index, out IntPtr displayHandle); /// /// Gets the display handle for a specified type. Note /// that in this case, the index is per type. Thus if /// you have only one device of a given type, the index is 0. /// /// /// /// A handle to the internal state of the SDK. /// /// /// The display type to query. /// /// /// The index for the specified device of this type. /// /// /// The handle for the display of the specified type. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayByType", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayByType( IntPtr context, ZDisplayType displayType, int index, out IntPtr displayHandle); /// /// Gets the display's type. /// /// /// /// A handle to the display. /// /// /// The display's type. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayType", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayType( IntPtr displayHandle, out ZDisplayType displayType); /// /// Gets the display's number. The display number refers /// to the number shown for the display when you set screen /// resolution in the Windows Control Panel. /// /// /// /// A handle to the display. /// /// /// The display's number. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayNumber", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayNumber( IntPtr displayHandle, out int displayNumber); /// /// Gets the index of the GPU that is connected to the /// specified display. /// /// /// /// A handle to the display. /// /// /// The index of the display's GPU. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayAdapterIndex", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayAdapterIndex( IntPtr displayHandle, out int adapterIndex); /// /// Gets the index of the monitor attached to the display's GPU. /// /// /// /// A handle to the display. /// /// /// The index for the attached monitor. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayMonitorIndex", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayMonitorIndex( IntPtr displayHandle, out int monitorIndex); /// /// Gets the string value of the specified attribute for /// the display. See for a /// list of the available attributes. /// /// /// /// A handle to the display. /// /// /// The attribute to query. /// /// /// The user allocated character buffer to hold the attribute's /// string value. /// /// /// The size of the user allocated buffer. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayAttributeStr", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] internal static extern ZPluginError GetDisplayAttributeStr( IntPtr displayHandle, ZDisplayAttribute attribute, [param: MarshalAs(UnmanagedType.LPStr), Out()] StringBuilder buffer, int bufferSize); /// /// Gets the size of the specified attribute's value in bytes. /// /// /// /// A handle to the display. /// /// /// The attribute to query. /// /// /// The size of the attribute's value. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayAttributeStrSize", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayAttributeStrSize( IntPtr displayHandle, ZDisplayAttribute attribute, out int size); /// /// Gets the display's size in meters. /// /// /// /// A handle to the display. /// /// /// The display's width in meters. /// /// /// The display's height in meters. /// [DllImport( DllName, EntryPoint = "zcuGetDisplaySize", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplaySize( IntPtr displayHandle, out float width, out float height); /// /// Gets the (x, y) pixel location of the specified /// display on the virtual desktop (top-left corner). /// /// /// /// A handle to the display. /// /// /// The x pixel location. /// /// /// The y pixel location. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayPosition", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayPosition( IntPtr displayHandle, out int x, out int y); /// /// Gets the display's preferred native resolution in pixels. /// /// /// /// A handle to the display. /// /// /// The width in pixels. /// /// /// The height in pixels. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayNativeResolution", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayNativeResolution( IntPtr displayHandle, out int x, out int y); /// /// Gets the display's angles about each axis in degrees. /// /// /// /// A handle to the display. /// /// /// The angle of the display about the x axis. /// /// /// The angle of the display about the y axis. /// /// /// The angle of the display about the z axis. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayAngle", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayAngle( IntPtr displayHandle, out float x, out float y, out float z); /// /// Gets the display's vertical refresh rate. /// /// /// /// A handle to the display. /// /// /// The vertical refresh rate. /// [DllImport( DllName, EntryPoint = "zcuGetDisplayVerticalRefreshRate", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetDisplayVerticalRefreshRate( IntPtr displayHandle, out float refreshRate); /// /// Checks if the specified display is connected via /// the USB port. Currently this only applies to /// displays. /// /// /// /// A handle to the display. /// /// /// True if connected, false otherwise. /// [DllImport( DllName, EntryPoint = "zcuIsDisplayHardwarePresent", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsDisplayHardwarePresent( IntPtr displayHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isHardwarePresent); /// /// Performs a raycast against the display. The incoming /// pose is assumed to transform the direction of the /// negative Z vector, which is then used for the /// intersection test. /// /// /// /// A handle to the display. /// /// /// A in tracker space. /// /// /// Struct containing information about the intersection /// (i.e. hit, screen position, etc.) /// [DllImport( DllName, EntryPoint = "zcuIntersectDisplay", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IntersectDisplay( IntPtr displayHandle, [param: MarshalAs(UnmanagedType.LPStruct)] ZPose pose, out ZDisplayIntersectionInfo intersectionInfo); /// /// Creates a stereo buffer for left/right frame detection. /// /// /// /// A handle to the internal state of the SDK. /// /// /// The application's graphics API. /// /// /// A reserved argument depending on the . /// /// /// A handle for the buffer. /// [DllImport( DllName, EntryPoint = "zcuCreateStereoBuffer", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError CreateStereoBuffer( IntPtr context, int renderer, IntPtr reserved, out IntPtr bufferHandle); /// /// Destroys the stereo buffer. /// /// /// /// A handle to the buffer. /// /// /// /// Calling will free any stereo /// buffers that have not been explicitly destroyed by calling /// zcDestroyStereoBuffer(). /// [DllImport( DllName, EntryPoint = "zcuDestroyStereoBuffer", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError DestroyStereoBuffer( IntPtr bufferHandle); [DllImport( DllName, EntryPoint = "zcuBeginStereoBufferPatternDetection", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError BeginStereoBufferPatternDetection( IntPtr bufferHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isPatternDetectionEnabled); [DllImport( DllName, EntryPoint = "zcuEndStereoBufferPatternDetection", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError EndStereoBufferPatternDetection( IntPtr bufferHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isPatternDetected); [DllImport( DllName, EntryPoint = "zcuIsStereoBufferPatternDetected", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsStereoBufferPatternDetected( IntPtr bufferHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isPatternDetected); [DllImport( DllName, EntryPoint = "zcuIsStereoBufferSyncRequested", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsStereoBufferSyncRequested( IntPtr bufferHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isSyncRequested); /// /// Creates a stereo viewport. /// /// /// /// A handle to the internal state of the SDK. /// /// /// A handle to the viewport. /// /// /// /// The stereo viewport is abstract and not an actual window /// that is created and registered through the OS. It manages a /// stereo frustum, which is responsible for various stereoscopic /// 3D calculations such as calculating the view and projection /// matrices for each eye. /// [DllImport( DllName, EntryPoint = "zcuCreateViewport", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError CreateViewport( IntPtr context, out IntPtr viewportHandle); /// /// Destroys a stereo viewport. /// /// /// /// A handle to the viewport. /// /// /// /// Calling will free any /// viewports that have not been explicitly destroyed by /// calling zcDestroyViewport(). /// [DllImport( DllName, EntryPoint = "zcuDestroyViewport", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError DestroyViewport( IntPtr viewportHandle); /// /// Sets the viewport's absolute virtual desktop coordinates /// (top-left corner). /// /// /// /// A handle to the viewport. /// /// /// The x coordinate for the upper left corner of the viewport. /// /// /// The y coordinate for the upper left corner of the viewport. /// [DllImport( DllName, EntryPoint = "zcuSetViewportPosition", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetViewportPosition( IntPtr viewportHandle, int x, int y); /// /// Gets the viewport's absolute virtual desktop coordinates /// (top-left corner). /// /// /// /// A handle to the viewport. /// /// /// The x coordinate for the upper left corner of the viewport. /// /// /// The y coordinate for the upper left corner of the viewport. /// [DllImport( DllName, EntryPoint = "zcuGetViewportPosition", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetViewportPosition( IntPtr viewportHandle, out int x, out int y); /// /// Sets the viewport's size in pixels. /// /// /// /// A handle to the viewport. /// /// /// The width of the viewport in pixels. /// /// /// The height of the viewport in pixels. /// [DllImport( DllName, EntryPoint = "zcuSetViewportSize", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetViewportSize( IntPtr viewportHandle, int width, int height); /// /// Gets the viewport's size in pixels. /// /// /// /// A handle to the viewport. /// /// /// The width of the viewport in pixels. /// /// /// The height of the viewport in pixels. /// [DllImport( DllName, EntryPoint = "zcuGetViewportSize", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetViewportSize( IntPtr viewportHandle, out int width, out int height); /// /// Gets the coordinate space transformation from /// space to . /// /// /// /// A handle to the viewport. /// /// /// The source coordinate space. /// /// /// The destination coordinate space. /// /// /// The transformation matrix in order to transform from space a to b. /// [DllImport( DllName, EntryPoint = "zcuGetCoordinateSpaceTransform", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetCoordinateSpaceTransform( IntPtr viewportHandle, ZCoordinateSpace a, ZCoordinateSpace b, out ZMatrix4 transform); /// /// Transforms a 4x4 transformation matrix from /// space to . /// /// /// /// A handle to the viewport. /// /// /// The source coordinate space. /// /// /// The destination coordinate space. /// /// /// The input matrix to be transformed. /// [DllImport( DllName, EntryPoint = "zcuTransformMatrix", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError TransformMatrix( IntPtr viewportHandle, ZCoordinateSpace a, ZCoordinateSpace b, ref ZMatrix4 matrix); /// /// Gets the frustum owned by a specified viewport. /// /// /// /// A handle to the viewport. /// /// /// A handle to the frustum. /// [DllImport( DllName, EntryPoint = "zcuGetFrustum", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustum( IntPtr viewportHandle, out IntPtr frustumHandle); /// /// Sets the specified frustum attribute's value. /// /// /// /// A handle to the frustum. /// /// /// The attribute to be modified. /// /// /// The desired value to be applied to the attribute. /// [DllImport( DllName, EntryPoint = "zcuSetFrustumAttributeF32", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetFrustumAttributeF32( IntPtr frustumHandle, ZFrustumAttribute attribute, float value); /// /// Gets the specified frustum attribute's value. /// /// /// /// A handle to the frustum. /// /// /// The attribute to be queried. /// /// /// The specified attribute's current value. /// [DllImport( DllName, EntryPoint = "zcuGetFrustumAttributeF32", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustumAttributeF32( IntPtr frustumHandle, ZFrustumAttribute attribute, out float value); /// /// Sets the specified frustum attribute's value. /// /// /// /// A handle to the frustum. /// /// /// The attribute to be modified. /// /// /// The desired value to be applied to the attribute. /// [DllImport( DllName, EntryPoint = "zcuSetFrustumAttributeB", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetFrustumAttributeB( IntPtr frustumHandle, ZFrustumAttribute attribute, [param: MarshalAs(UnmanagedType.Bool)] bool value); /// /// Gets the specified frustum attribute's value. /// /// /// /// A handle to the frustum. /// /// /// The attribute to be queried. /// /// /// The specified attribute's current value. /// [DllImport( DllName, EntryPoint = "zcuGetFrustumAttributeB", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustumAttributeB( IntPtr frustumHandle, ZFrustumAttribute attribute, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool value); /// /// Sets the frustum's portal mode. In portal mode, /// the scene is fixed relative to the physical world, /// not the viewport. Refer to /// for details on portal modes. /// /// /// /// A handle to the frustum. /// /// /// A bitmask for the portal mode flags. /// [DllImport( DllName, EntryPoint = "zcuSetFrustumPortalMode", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetFrustumPortalMode( IntPtr frustumHandle, ZPortalMode portalModeFlags); /// /// Gets the frustum's setting for portal mode. In portal mode, /// the scene is fixed relative to the physical world, not the /// viewport. /// /// /// /// A handle to the frustum. /// /// /// A bitmask representing the current portal mode settings. /// [DllImport( DllName, EntryPoint = "zcuGetFrustumPortalMode", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustumPortalMode( IntPtr frustumHandle, out ZPortalMode portalModeFlags); /// /// Sets the frustum's camera offset. /// /// /// /// A handle to the frustum /// /// /// The desired camera offset in meters /// [DllImport( DllName, EntryPoint = "zcuSetFrustumCameraOffset", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetFrustumCameraOffset( IntPtr frustumHandle, [param: MarshalAs(UnmanagedType.LPStruct)] ZVector3 cameraOffset); /// /// Gets the frustum's camera offset. /// /// /// /// A handle to the frustum. /// /// /// The current camera offset in meters. /// [DllImport( DllName, EntryPoint = "zcuGetFrustumCameraOffset", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustumCameraOffset( IntPtr frustumHandle, out ZVector3 cameraOffset); /// /// Sets the frustum's head pose in tracker space. /// /// /// /// A handle to the frustum. /// /// /// The desired head pose. /// [DllImport( DllName, EntryPoint = "zcuSetFrustumHeadPose", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetFrustumHeadPose( IntPtr frustumHandle, [param: MarshalAs(UnmanagedType.LPStruct)] ZPose headPose); /// /// Gets the frustum's current head pose in tracker space. /// /// /// /// A handle to the frustum. /// /// /// The current head pose. /// [DllImport( DllName, EntryPoint = "zcuGetFrustumHeadPose", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustumHeadPose(IntPtr frustumHandle, out ZPose headPose); /// /// Gets the frustum's view matrix for a specified eye. /// The view matrix is calculated from the head pose + eye offset. /// /// /// /// A handle to the frustum. /// /// /// The eye to query. /// /// /// The view matrix for the specified eye. /// [DllImport( DllName, EntryPoint = "zcuGetFrustumViewMatrix", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustumViewMatrix( IntPtr frustumHandle, ZEye eye, out ZMatrix4 viewMatrix); /// /// Gets the frustum's projection matrix for a specified eye. /// /// /// /// A handle to the frustum. /// /// /// The eye to query. /// /// /// The projection matrix for the specified eye. /// [DllImport( DllName, EntryPoint = "zcuGetFrustumProjectionMatrix", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustumProjectionMatrix( IntPtr frustumHandle, ZEye eye, out ZMatrix4 projectionMatrix); /// /// Gets the frustum's boundaries for the specified eye. /// /// /// /// A handle to the frustum. /// /// /// The eye to query. /// /// /// The boundaries for the specified eye. /// [DllImport( DllName, EntryPoint = "zcuGetFrustumBounds", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustumBounds( IntPtr frustumHandle, ZEye eye, out ZFrustumBounds bounds); /// /// Gets the specified eye's position in the specified /// coordinate space. /// /// /// /// A handle to the frustum. /// /// /// The eye to query. /// /// /// The coordinate space in which to return the eye position. /// /// /// The eye's position. /// [DllImport( DllName, EntryPoint = "zcuGetFrustumEyePosition", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetFrustumEyePosition( IntPtr frustumHandle, ZEye eye, ZCoordinateSpace coordinateSpace, out ZVector3 eyePosition); [DllImport( DllName, EntryPoint = "zcuGetNumTrackerDevices", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetNumTrackerDevices( IntPtr context, out int numDevices); [DllImport( DllName, EntryPoint = "zcuGetTrackerDevice", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetTrackerDevice( IntPtr context, int index, out IntPtr deviceHandle); [DllImport( DllName, EntryPoint = "zcuGetTrackerDeviceByName", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] internal static extern ZPluginError GetTrackerDeviceByName( IntPtr context, [param: MarshalAs(UnmanagedType.LPStr)] string deviceName, out IntPtr deviceHandle); [DllImport( DllName, EntryPoint = "zcuSetTrackerDeviceEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetTrackerDeviceEnabled( IntPtr deviceHandle, [param: MarshalAs(UnmanagedType.Bool)] bool isEnabled); [DllImport( DllName, EntryPoint = "zcuIsTrackerDeviceEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsTrackerDeviceEnabled( IntPtr deviceHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isEnabled); [DllImport( DllName, EntryPoint = "zcuGetTrackerDeviceName", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] internal static extern ZPluginError GetTrackerDeviceName( IntPtr deviceHandle, [param: MarshalAs(UnmanagedType.LPStr), Out()] StringBuilder buffer, int bufferSize); [DllImport( DllName, EntryPoint = "zcuGetTrackerDeviceNameSize", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetTrackerDeviceNameSize( IntPtr deviceHandle, out int size); [DllImport( DllName, EntryPoint = "zcuGetNumTargets", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetNumTargets( IntPtr deviceHandle, out int numTargets); [DllImport( DllName, EntryPoint = "zcuGetNumTargetsByType", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetNumTargetsByType( IntPtr context, ZTargetType targetType, out int numTargets); [DllImport( DllName, EntryPoint = "zcuGetTarget", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetTarget( IntPtr deviceHandle, int index, out IntPtr targetHandle); [DllImport( DllName, EntryPoint = "zcuGetTargetByName", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] internal static extern ZPluginError GetTargetByName( IntPtr deviceHandle, [param: MarshalAs(UnmanagedType.LPStr)] string targetName, out IntPtr targetHandle); [DllImport( DllName, EntryPoint = "zcuGetTargetByType", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetTargetByType( IntPtr context, ZTargetType targetType, int index, out IntPtr targetHandle); [DllImport( DllName, EntryPoint = "zcuGetTargetName", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] internal static extern ZPluginError GetTargetName( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.LPStr), Out()] StringBuilder buffer, int bufferSize); [DllImport( DllName, EntryPoint = "zcuGetTargetNameSize", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetTargetNameSize( IntPtr targetHandle, out int size); [DllImport( DllName, EntryPoint = "zcuSetTargetEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetTargetEnabled( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.Bool)] bool isEnabled); [DllImport( DllName, EntryPoint = "zcuIsTargetEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsTargetEnabled( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isEnabled); [DllImport( DllName, EntryPoint = "zcuIsTargetVisible", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsTargetVisible( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isEnabled); [DllImport( DllName, EntryPoint = "zcuSetTargetMoveEventThresholds", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetTargetMoveEventThresholds( IntPtr targetHandle, float time, float distance, float angle); [DllImport( DllName, EntryPoint = "zcuGetTargetMoveEventThresholds", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetTargetMoveEventThresholds( IntPtr targetHandle, out float time, out float distance, out float angle); [DllImport( DllName, EntryPoint = "zcuGetTargetPose", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetTargetPose( IntPtr targetHandle, out ZPose pose); [DllImport( DllName, EntryPoint = "zcuGetNumTargetButtons", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetNumTargetButtons( IntPtr targetHandle, out int numButtons); [DllImport( DllName, EntryPoint = "zcuIsTargetButtonPressed", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsTargetButtonPressed( IntPtr targetHandle, int buttonId, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isButtonPressed); [DllImport( DllName, EntryPoint = "zcuSetTargetLedEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetTargetLedEnabled( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.Bool)] bool isLedEnabled); [DllImport( DllName, EntryPoint = "zcuIsTargetLedEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsTargetLedEnabled( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isLedEnabled); [DllImport( DllName, EntryPoint = "zcuSetTargetLedColor", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetTargetLedColor( IntPtr targetHandle, float r, float g, float b); [DllImport( DllName, EntryPoint = "zcuGetTargetLedColor", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetTargetLedColor( IntPtr targetHandle, out float r, out float g, out float b); [DllImport( DllName, EntryPoint = "zcuSetTargetVibrationEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetTargetVibrationEnabled( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.Bool)] bool isVibrationEnabled); [DllImport( DllName, EntryPoint = "zcuIsTargetVibrationEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsTargetVibrationEnabled( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isVibrationEnabled); [DllImport( DllName, EntryPoint = "zcuIsTargetVibrating", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsTargetVibrating( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isVibrating); [DllImport( DllName, EntryPoint = "zcuStartTargetVibration", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError StartTargetVibration( IntPtr targetHandle, float onPeriod, float offPeriod, int numTimes, float intensity); [DllImport( DllName, EntryPoint = "zcuStopTargetVibration", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError StopTargetVibration( IntPtr targetHandle); [DllImport( DllName, EntryPoint = "zcuIsTargetTapPressed", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsTargetTapPressed( IntPtr targetHandle, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isTapPressed); [DllImport( DllName, EntryPoint = "zcuSetTargetTapThreshold", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetTargetTapThreshold( IntPtr targetHandle, float seconds); [DllImport( DllName, EntryPoint = "zcuGetTargetTapThreshold", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetTargetTapThreshold( IntPtr targetHandle, out float seconds); [DllImport( DllName, EntryPoint = "zcuSetMouseEmulationEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetMouseEmulationEnabled( IntPtr context, [param: MarshalAs(UnmanagedType.Bool)] bool isEnabled); [DllImport( DllName, EntryPoint = "zcuIsMouseEmulationEnabled", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError IsMouseEmulationEnabled( IntPtr context, [param: MarshalAs(UnmanagedType.Bool), Out()] out bool isEnabled); [DllImport( DllName, EntryPoint = "zcuSetMouseEmulationTarget", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetMouseEmulationTarget( IntPtr context, IntPtr targetHandle); [DllImport( DllName, EntryPoint = "zcuGetMouseEmulationTarget", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetMouseEmulationTarget( IntPtr context, out IntPtr targetHandle); [DllImport( DllName, EntryPoint = "zcuSetMouseEmulationMaxDistance", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetMouseEmulationMaxDistance( IntPtr context, float maxDistance); [DllImport( DllName, EntryPoint = "zcuGetMouseEmulationMaxDistance", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetMouseEmulationMaxDistance( IntPtr context, out float maxDistance); [DllImport( DllName, EntryPoint = "zcuSetMouseEmulationButtonMapping", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError SetMouseEmulationButtonMapping( IntPtr context, int buttonId, ZMouseButton mouseButton); [DllImport( DllName, EntryPoint = "zcuGetMouseEmulationButtonMapping", CallingConvention = CallingConvention.StdCall)] internal static extern ZPluginError GetMouseEmulationButtonMapping( IntPtr context, int buttonId, out ZMouseButton mouseButton); [DllImport( DllName, EntryPoint = "zcuCreateXROverlay", CallingConvention = CallingConvention.StdCall)] public static extern bool CreateXROverlay(); [DllImport( DllName, EntryPoint = "zcuDestroyXROverlay", CallingConvention = CallingConvention.StdCall)] public static extern bool DestroyXROverlay(); [DllImport( DllName, EntryPoint = "zcuSetXROverlayParentWindowHandle", CallingConvention = CallingConvention.StdCall)] public static extern void SetXROverlayParentWindowHandle( IntPtr hWnd); [DllImport( DllName, EntryPoint = "zcuSetXROverlayOnDestroyCallback", CallingConvention = CallingConvention.StdCall)] public static extern void SetXROverlayOnDestroyCallback( IntPtr callback); [DllImport( DllName, EntryPoint = "zcuIsXROverlayActive", CallingConvention = CallingConvention.StdCall)] public static extern bool IsXROverlayActive(); [DllImport( DllName, EntryPoint = "zcuIsXROverlayEnabled", CallingConvention = CallingConvention.StdCall)] public static extern bool IsXROverlayEnabled(); [DllImport( DllName, EntryPoint = "zcuSetXROverlayEnabled", CallingConvention = CallingConvention.StdCall)] public static extern void SetXROverlayEnabled( bool isEnabled); [DllImport( DllName, EntryPoint = "zcuSetXROverlayDimensions", CallingConvention = CallingConvention.StdCall)] public static extern void SetXROverlayDimensions( int x, int y, int width, int height); [DllImport( DllName, EntryPoint = "zcuSetXROverlayPosition", CallingConvention = CallingConvention.StdCall)] public static extern void SetXROverlayPosition( int x, int y); [DllImport( DllName, EntryPoint = "zcuSetXROverlaySize", CallingConvention = CallingConvention.StdCall)] public static extern void SetXROverlaySize( int width, int height); [DllImport( DllName, EntryPoint = "zcuSetXROverlayTextures", CallingConvention = CallingConvention.StdCall)] public static extern void SetXROverlayTextures( IntPtr leftTexturePtr, IntPtr rightTexturePtr); //////////////////////////////////////////////////////////////////////// // Private Methods //////////////////////////////////////////////////////////////////////// private static void LoggerCallback(int severity, string message) { message = $"[{DllName}.dll] {message}"; switch (severity) { case 0: Debug.Log(message); break; case 1: Debug.LogWarning(message); break; case 2: Debug.LogError(message); break; default: break; } } //////////////////////////////////////////////////////////////////////// // Private Types //////////////////////////////////////////////////////////////////////// private delegate void LoggerCallbackDelegate( int level, string message); //////////////////////////////////////////////////////////////////////// // Private Constants //////////////////////////////////////////////////////////////////////// private const string DllName = "zCoreUnity"; //////////////////////////////////////////////////////////////////////// // Private Members //////////////////////////////////////////////////////////////////////// private static LoggerCallbackDelegate s_loggerCallback = new LoggerCallbackDelegate(LoggerCallback); } }