コード例 #1
0
        private void Keyboard_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.F12:     // toggle graph debugger
                showGraphDebugger = !showGraphDebugger;

                if (showGraphDebugger)
                {
                    X3DGraphDebugger.Display(scene.SceneGraph);
                }
                else
                {
                    X3DGraphDebugger.Hide();
                }
                break;

            case Key.F1:     // toggle wireframe
                wireframe = !wireframe;
                if (wireframe)
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                }
                else
                {
                    if (points_only)
                    {
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Point);
                    }
                    else
                    {
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                    }
                }
                break;

            case Key.F2:     // toggle points
                points_only = !points_only;
                if (points_only)
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Point);
                }
                else
                {
                    if (wireframe)
                    {
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                    }
                    else
                    {
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                    }
                }
                break;

            case Key.F3:     // halt special effects
                fx_enable = !fx_enable;
                break;

            case Key.F4:     // halt rotate
                rotate_enable = !rotate_enable;
                break;

            case Key.F5:     // reload current scene
                Reload();
                break;

            case Key.F:
                if (window.WindowState == OpenTK.WindowState.Normal)
                {
                    window.WindowState = WindowState.Fullscreen;
                    lockMouseCursor    = true;
                }
                else
                {
                    window.WindowState = WindowState.Normal;
                    lockMouseCursor    = false;
                }

                isFullscreen = !isFullscreen;

                ToggleCursor();

                break;

            case Key.O:

                NavigationInfo.HeadlightEnabled = !NavigationInfo.HeadlightEnabled;

                break;

            case Key.V:
                // View all viewpoints
                string text = "";
                foreach (Viewpoint v in Viewpoint.ViewpointList)
                {
                    text += "[" + v.description + "] ";
                }

                // Integrate this into HUD
                System.Windows.Forms.MessageBox.Show("Viewpoints: " + text.TrimEnd());
                break;

                #region Viewpoint Key Bindings

            case Key.Home:
                // Goto Initial Viewpoint
                Viewpoint.CurrentIndex     = (Viewpoint.InitialViewpoint == null ? -1 : 0);
                Viewpoint.CurrentViewpoint = Viewpoint.InitialViewpoint;
                break;

            case Key.PageDown:
                // Goto Next Viewpoint
                if (Viewpoint.ViewpointList.Count > 0)
                {
                    if (Viewpoint.CurrentIndex + 1 == Viewpoint.ViewpointList.Count)
                    {
                        Viewpoint.CurrentIndex = 0;
                    }
                    else
                    {
                        Viewpoint.CurrentIndex++;
                    }
                    Viewpoint.CurrentViewpoint = Viewpoint.ViewpointList[Viewpoint.CurrentIndex];
                }
                break;

            case Key.PageUp:
                // Goto Previous viewpoint
                if (Viewpoint.ViewpointList.Count > 0)
                {
                    if (Viewpoint.CurrentIndex - 1 < 0)
                    {
                        Viewpoint.CurrentIndex = Viewpoint.ViewpointList.Count - 1;
                    }
                    else
                    {
                        Viewpoint.CurrentIndex--;
                    }
                    Viewpoint.CurrentViewpoint = Viewpoint.ViewpointList[Viewpoint.CurrentIndex];
                }
                break;

            case Key.End:
                // Goto Final Viewpoint
                Viewpoint.CurrentIndex     = Viewpoint.ViewpointList.Count - 1;
                Viewpoint.CurrentViewpoint = Viewpoint.FinalViewpoint;
                break;
                #endregion
            }
        }
コード例 #2
0
        public void Init(string url, string mime_type)
        {
            Console.WriteLine("LOAD <" + BaseMIME + "> " + BaseURL);
            this.time_at_init = DateTime.Now;
            Console.Title     = AppInfo;
            int[] t = new int[2];
            GL.GetInteger(GetPName.MajorVersion, out t[0]);
            GL.GetInteger(GetPName.MinorVersion, out t[1]);
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("OpenGL Version " + t[0] + "." + t[1]);

            //ShowSupportMatrix();

#if GAME_INIT_MODE && FULLSCREEN
            window.WindowState = WindowState.Minimized;
            ConsoleVisibility  = true;
#endif

            // INITILISE SCENE

            GL.Disable(EnableCap.Normalize);
            GL.ClearColor(ClearColor.X, ClearColor.Y, ClearColor.Z, ClearColor.W);
            GL.ClearDepth(1.0f);                                            // Depth Buffer Setup
            GL.Enable(EnableCap.DepthTest);                                 // Enables Depth Testing
            GL.DepthFunc(DepthFunction.Lequal);                             // The Type Of Depth Testing To Do
            //GL.Enable(EnableCap.CullFace); // causes bugs if enabled i.e. nehe10 wont render properly
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); // Really Nice Perspective Calculations

            DateTime time_before = DateTime.Now;

            if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(mime_type))
            {
                View view = View.CreateViewFromWindow(this.window);

                Viewpoint.ViewpointList.Clear();

                SceneManager.BaseURL  = BaseURL;
                SceneManager.BaseMIME = SceneManager.GetMIMEType(BaseMIME);

                if (_cachedGraph != null)
                {
                    scene = SceneManager.fromSceneGraph(_cachedGraph);
                }
                else
                {
                    scene = SceneManager.fromURL(url, mime_type);
                }

                X3DGraphDebugger.UpdateSceneGraph(scene.SceneGraph);

                Viewpoint.Initilize(ActiveCamera, view);

                if (showCrosshair)
                {
                    //Set crosshair
                    _crosshair = new Crosshair();
                    _crosshair.Load();
                }
            }

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("loading time: " + DateTime.Now.Subtract(time_before).TotalMilliseconds.ToString() + "ms");
            Console.ForegroundColor = ConsoleColor.Yellow;

#if GAME_INIT_MODE && FULLSCREEN
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("Sleeping for 5 secs so you can read me");
            Console.ForegroundColor = ConsoleColor.DarkCyan;
            System.Threading.Thread.Sleep(5000);
            window.WindowState = WindowState.Fullscreen;
#elif FULLSCREEN
            window.WindowState = WindowState.Fullscreen;
#endif
        }