private GlobalState() { // Initialize the zSpace Unity plugin. PluginError error = zcuInitialize(out _context); if (error == PluginError.Ok) { // Create the viewport. error = zcuCreateViewport(_context, out _viewportHandle); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to create viewport: ({0})", error)); } // Grab a reference to the viewport's frustum. error = zcuGetFrustum(_viewportHandle, out _frustumHandle); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to find frustum: ({0})", error)); } else { // Set portal mode to "Angle" by default. zcuSetFrustumPortalMode(_frustumHandle, (int)PortalMode.Angle); } // Grab a reference to the default head target (glasses). error = zcuGetTargetByType(_context, TargetType.Head, 0, out _targetHandles[(int)TargetType.Head]); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to find head target: ({0})", error)); } // Grab a reference to the default primary target (stylus). error = zcuGetTargetByType(_context, TargetType.Primary, 0, out _targetHandles[(int)TargetType.Primary]); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to find primary target: ({0})", error)); } else { // Set stylus vibrations to be enabled by default. zcuSetTargetVibrationEnabled(_targetHandles[(int)TargetType.Primary], true); } // Initalize mouse emulation target and button mappings. error = zcuSetMouseEmulationTarget(_context, _targetHandles[(int)TargetType.Primary]); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to initialize mouse emulation target: ({0})", error)); } error = zcuSetMouseEmulationButtonMapping(_context, 0, MouseButton.Left); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to map target button 0 to left mouse button: ({0})", error)); } error = zcuSetMouseEmulationButtonMapping(_context, 1, MouseButton.Right); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to map target button 1 to right mouse button: ({0})", error)); } error = zcuSetMouseEmulationButtonMapping(_context, 2, MouseButton.Center); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to map target button 2 to center mouse button: ({0})", error)); } _isInitialized = true; } else { Debug.LogError(string.Format("Failed to initialize zSpace Core SDK: ({0})", error)); _isInitialized = false; } this.AutoStereoState = ZCore.AutoStereoState.IdleStereo; }
private GlobalState() { // Initialize the zSpace Unity plugin. PluginError error = zcuInitialize(out _context); if (error == PluginError.Ok) { // Create the stereo buffer for LR detect. error = zcuCreateStereoBuffer(_context, ZCRenderer.Custom, IntPtr.Zero, out _stereoBufferHandle); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to create stereo buffer: ({0})", error)); } // Create the viewport. error = zcuCreateViewport(_context, out _viewportHandle); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to create viewport: ({0})", error)); } // Grab a reference to the viewport's frustum. error = zcuGetFrustum(_viewportHandle, out _frustumHandle); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to find frustum: ({0})", error)); } else { // Set portal mode to "Angle" by default. zcuSetFrustumPortalMode(_frustumHandle, (int)PortalMode.Angle); } // Grab a reference to the default head target (glasses). error = zcuGetTargetByType(_context, TargetType.Head, 0, out _targetHandles[(int)TargetType.Head]); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to find head target: ({0})", error)); _targetHandles[(int)TargetType.Head] = IntPtr.Zero; } // Grab a reference to the default primary target (stylus). error = zcuGetTargetByType(_context, TargetType.Primary, 0, out _targetHandles[(int)TargetType.Primary]); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to find primary target: ({0})", error)); _targetHandles[(int)TargetType.Primary] = IntPtr.Zero; } else { // Set stylus vibrations to be enabled by default. zcuSetTargetVibrationEnabled(_targetHandles[(int)TargetType.Primary], true); } // Initalize mouse emulation target and button mappings. error = zcuSetMouseEmulationTarget(_context, _targetHandles[(int)TargetType.Primary]); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to initialize mouse emulation target: ({0})", error)); } error = zcuSetMouseEmulationButtonMapping(_context, 0, MouseButton.Left); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to map target button 0 to left mouse button: ({0})", error)); } error = zcuSetMouseEmulationButtonMapping(_context, 1, MouseButton.Right); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to map target button 1 to right mouse button: ({0})", error)); } error = zcuSetMouseEmulationButtonMapping(_context, 2, MouseButton.Center); if (error != PluginError.Ok) { Debug.LogError(string.Format("Failed to map target button 2 to center mouse button: ({0})", error)); } _isInitialized = true; } else { Debug.LogError(string.Format("Failed to initialize zSpace Core SDK: ({0})", error)); _isInitialized = false; } this.AutoStereoState = ZCore.AutoStereoState.IdleStereo; // Register the logger callback function. LoggerCallbackDelegate callbackDelegate = new LoggerCallbackDelegate(LoggerCallback); IntPtr callbackDelegatePtr = Marshal.GetFunctionPointerForDelegate(callbackDelegate); zcuSetLoggerFunction(callbackDelegatePtr); }