/*! * Shuts down 3D processing and releases all 3D resources. * This routine is called automatically when the window closes. */ public virtual void StopVixen() { SharedWorld world = SharedWorld.Get(); if (world != null) { Scene scene = world.GetScene(); if (scene != null) { scene.Window = 0; } world.StopEvents(); if (UsePhysics) { Physics.Shutdown(); } } }
/*! * Events are moved from the Vixen SharedWorld to the C# * application through a shared event queue. Events * observed and handled by the Vixen SharedWorld object * are put into a queue. The Canvas3D class maintains a separate * thread which waits on this queue and converts any Vixen Events * it finds into C# Vixen.EventArgs and raises a .NET event * which can be handled in the C# application. */ protected void EventLoop() { SharedWorld world = SharedWorld.Get(); StopEvents = false; if (world.FileName != null) { world.LoadAsync(world.FileName, world.GetScene()); } while (!StopEvents && (SharedWorld.Get() != null)) { try { Event ev = SharedWorld.Get().NextEvent(); if (ev == null) { break; } if (ev.GetType() == typeof(TrackEvent)) { if (ev.Code != Event.TRACK) { Console.Write("ERROR: TrackEvent has bad opcode"); } } string name = ev.GetName(); EventArgs args = new VixenEventArgs(ev); object[] list = { this, args }; VixenEventHandler handler = new VixenEventHandler(PostVixenEvent); Trace("Canvas3D:Event " + name + "\n"); Invoke(handler, list); } catch (Exception ex) { LogError("exception in event loop " + ex.Message); } } if (SharedWorld.Get() != null) { SharedWorld.Get().Stop(); } }
/*! * Routes a mouse event from this window to Vixen. * Any Vixen objects which observe Event.MOUSE will get these events. * If DispatchMouseEvents is false, this functionality is disabled. * @see DispatchMouseEvents */ protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { const int WM_LBUTTONDBLCLK = 0x203; const int WM_RBUTTONDBLCLK = 0x206; const int WM_MBUTTONDBLCLK = 0x209; const int WM_MOUSEMOVE = 0x0200; const int WM_LBUTTONDOWN = 0x0201; const int WM_LBUTTONUP = 0x0202; const int WM_RBUTTONDOWN = 0x0204; const int WM_RBUTTONUP = 0x0205; const int WM_MBUTTONDOWN = 0x0207; const int WM_MBUTTONUP = 0x0208; const int WM_MOVE = 0x0003; const int WM_SIZE = 0x0005; const int WM_DISPLAYCHANGE = 0x007E; const int WM_ERASEBKGND = 0x0014; int x, y; int buttons = (int)wParam & 0X1F; if ((_world == null) || !_world.IsRunning()) { return(IntPtr.Zero); } switch (msg) { case WM_ERASEBKGND: handled = true; return(IntPtr.Zero); case WM_MOVE: case WM_SIZE: if (_scene == null) { _scene = _world.GetScene(); if (_scene == null) { return(IntPtr.Zero); } } _scene.Suspend(); _scene.OnResize(); _scene.Resume(); handled = true; return(IntPtr.Zero); case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: case WM_MBUTTONDBLCLK: buttons |= MouseEvent.DOUBLE; break; case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MOUSEMOVE: break; default: handled = false; return(IntPtr.Zero); } x = (int)((long)lParam & (long)0x0000ffff); // LOWORD = x y = (int)((long)lParam >> 16); // HIWORD = y _world.OnMouse(x, y, buttons, 0.0f); OnMouse(x, y, buttons, 0); handled = true; return(IntPtr.Zero); }
/*! * Start up Vixen 3D display and event processing. * This function should not be called until the * underlying Window has been created and the * OS window handle is available. Vixen will display * the 3D content in this window. */ public virtual bool RunVixen() { SharedWorld world = SharedWorld.Get(); IntPtr windowHandle = Handle; Scene scene = null; try { if (windowHandle == null) { LogError("Cannot get window handle for parent window"); return(false); } if ((world != null) && world.IsRunning()) { return(false); } //world.SetDebugLevel(1); world.Run((uint)windowHandle); } catch (Exception ex) { LogError("exception starting 3D " + ex.Message); } if (world.IsRunning()) { ThreadStart eventloop = new ThreadStart(EventLoop); Thread thread = new Thread(eventloop); bool loadasync = World.DoAsyncLoad; if (MediaDir != null) { world.SetMediaDir(MediaDir); } if (ContentFile != null) { world.FileName = GetMediaPath(ContentFile); } else { loadasync = false; } thread.Start(); if (!loadasync) { try { scene = MakeScene(); if (scene != null) { world.SetScene(scene); } } catch (Exception ex) { SharedWorld.LogError("exception making initial scene " + ex.Message); } } scene = world.GetScene(); if (scene != null) { scene.OnResize(); } return(true); } return(false); }