Beispiel #1
0
        protected virtual void mouseDownHandler(object sender, MouseButtonEventArgs e)
        {
            if (!base.Focused)
            {
                return;
            }

            this.mouseButtonDown = true;

            // cast ray for mouse click
            var     clientRect = new System.Drawing.Size(ClientRectangle.Width, ClientRectangle.Height);
            Vector2 mouseLoc   = new Vector2(e.X, e.Y);

            SSRay ray = OpenTKHelper.MouseToWorldRay(
                this.main3dScene.renderConfig.projectionMatrix, this.main3dScene.renderConfig.invCameraViewMatrix, clientRect, mouseLoc);

            // Console.WriteLine("mouse ({0},{1}) unproject to ray ({2})",e.X,e.Y,ray);
            // scene.addObject(new SSObjectRay(ray));

            float    nearestMain, nearestAlpha;
            SSObject selectedObjMain  = main3dScene.Intersect(ref ray, out nearestMain);
            SSObject selectedObjAlpha = alpha3dScene.Intersect(ref ray, out nearestAlpha);

            selectedObject = nearestMain < nearestAlpha ? selectedObjMain : selectedObjAlpha;

            updateTextDisplay();
        }
Beispiel #2
0
        public void setupInput()
        {
            // hook mouse drag input...
            this.MouseDown += (object sender, MouseButtonEventArgs e) => {
                this.mouseButtonDown = true;

                // cast ray for mouse click
                var     clientRect = new System.Drawing.Size(ClientRectangle.Width, ClientRectangle.Height);
                Vector2 mouseLoc   = new Vector2(e.X, e.Y);

                SSRay ray = OpenTKHelper.MouseToWorldRay(
                    this.scene.ProjectionMatrix, this.scene.InvCameraViewMatrix, clientRect, mouseLoc);

                // Console.WriteLine("mouse ({0},{1}) unproject to ray ({2})",e.X,e.Y,ray);
                // scene.addObject(new SSObjectRay(ray));

                selectedObject = scene.Intersect(ref ray);
            };
            this.MouseUp += (object sender, MouseButtonEventArgs e) => {
                this.mouseButtonDown = false;
            };
            this.MouseMove += (object sender, MouseMoveEventArgs e) => {
                if (this.mouseButtonDown)
                {
                    // Console.WriteLine("mouse dragged: {0},{1}",e.XDelta,e.YDelta);
                    this.scene.ActiveCamera.MouseDeltaOrient(e.XDelta, e.YDelta);
                    // this.activeModel.MouseDeltaOrient(e.XDelta,e.YDelta);
                }
            };
            this.MouseWheel += (object sender, MouseWheelEventArgs e) => {
                // Console.WriteLine("mousewheel {0} {1}",e.Delta,e.DeltaPrecise);
                SSCameraThirdPerson ctp = scene.ActiveCamera as SSCameraThirdPerson;
                if (ctp != null)
                {
                    ctp.followDistance += -e.DeltaPrecise;
                }
            };

            this.KeyPress += (object sender, KeyPressEventArgs e) => {
                switch (e.KeyChar)
                {
                case 'w':
                    scene.DrawWireFrameMode = SSRenderConfig.NextWireFrameMode(scene.DrawWireFrameMode);
                    updateWireframeDisplayText(scene.DrawWireFrameMode);

                    // if we need single-pass wireframes, set the GLSL uniform variable
                    shaderPgm.Activate();
                    shaderPgm.u_ShowWireframes = (scene.DrawWireFrameMode == WireframeMode.GLSL_SinglePass);
                    break;
                }
            };
        }