コード例 #1
0
        }   // end of MaterialPicker SetDefaultSelection()

        public bool TouchIsOverMaterialSelection(TouchContact touch, Camera camera)
        {
            Matrix mat;

            BoundingSphere sphere;      // Sphere we wrap around elements for hit testing.
            float?         dist = null; // Dist to sphere bounds hit.

            // Test in-focus element for hit.
            UIGridMaterialElement e = grid.SelectionElement as UIGridMaterialElement;

            if (e != null)
            {
                Vector2 touchHit = touch.position;
                Ray     ray      = new Ray(camera.From, camera.ScreenToWorldCoords(touchHit));

                mat    = e.HitWorldMatrix;
                sphere = new BoundingSphere(mat.Translation, 2.5f * mat.M33);
                dist   = ray.Intersects(sphere);

                if (dist != null)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
        public override void Render(Camera camera)
        {
            if (active && !hidden)
            {
                // Render reticule around selected material.
                CameraSpaceQuad       quad = CameraSpaceQuad.GetInstance();
                UIGridMaterialElement e    = (UIGridMaterialElement)grid.SelectionElement;
                Vector2 position           = new Vector2(e.Position.X, e.Position.Y);
                position.X += grid.WorldMatrix.Translation.X;
                position.Y += grid.WorldMatrix.Translation.Y;
                Vector2 size = 2.0f * new Vector2(e.Size.X, e.Size.Y);
                quad.Render(camera, reticuleTexture, position, size, @"AdditiveBlend");

                // Trigger icons?
                double curTime = Time.WallClockTotalSeconds;
                double dTime   = curTime - lastChangedTime;
                if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad && dTime > kPreFadeTime)
                {
                    dTime -= kPreFadeTime;

                    float   alpha  = Math.Min((float)(dTime / kFadeTime), 1.0f);
                    Vector2 offset = size * 0.4f;
                    size *= 0.4f;
                    // Note the 12/64 in the positioning accounts for the fact that the
                    // button textures only use the upper 40x40 out of the 64x64 space they allocate.
                    // The 12 is actually (64-40)/2.
                    quad.Render(camera, ButtonTextures.RightTrigger, alpha, position + offset + size * 12.0f / 64.0f, size, @"TexturedRegularAlpha");
                    offset.X = -offset.X;
                    quad.Render(camera, ButtonTextures.LeftTrigger, alpha, position + offset + size * 12.0f / 64.0f, size, @"TexturedRegularAlpha");
                }
            }

            base.Render(camera);

            /*
             * // Debug code to show spherical bounding hits.
             * Vector4 red = new Vector4(1, 0, 0, 0.5f);
             * if (active && !hidden)
             * {
             *  for (int i = 0; i < grid.ActualDimensions.X; i++)
             *  {
             *      UIGridMaterialElement e = grid.Get(i, 0) as UIGridMaterialElement;
             *
             *      // Don't bother if offscreen.
             *      Vector3 position = e.WorldMatrix.Translation;
             *      float radius = 2.0f;
             *      Frustum.CullResult cullResult = camera.Frustum.CullTest(position, radius);
             *      if (cullResult == Frustum.CullResult.TotallyOutside)
             *          continue;
             *
             *      Utils.DrawSolidSphere(camera, e.HitWorldMatrix.Translation, 2.5f * e.HitWorldMatrix.M33, red);
             *  }
             * }
             */
        } // end of MaterialPicker Render()
コード例 #3
0
        // c'tor
        public MaterialPicker(OnSetMaterial onSet, OnGetMaterial onGet)
            : base(onSet, onGet)
        {
            helpOverlay    = @"MaterialPicker";
            altHelpOverlay = @"MaterialFilterPicker";

            // Create material elements for the grid.
            // Start with a blob of common parameters.
            UIGridElement.ParamBlob blob = new UIGridElement.ParamBlob();
            blob.width         = 1.0f;
            blob.height        = 1.0f;
            blob.edgeSize      = 0.1f;
            blob.selectedColor = Color.White;
            Vector4 transparentWhite = new Vector4(1.0f, 1.0f, 1.0f, 0.5f);

            blob.unselectedColor = new Color(transparentWhite);
            blob.normalMapName   = @"QuarterRound4NormalMap";

            // Create and populate grid.
            grid = new UIGrid(OnSelect, OnCancel, new Point(TerrainMaterial.MaxNum, 1), "TerrainEdit.MaterialPicker");

            numMaterials = 0;

            UIGridMaterialElement e = null;

            for (int i = 0; i < TerrainMaterial.MaxNum; i++)
            {
                e = new UIGridMaterialElement(i);
                e.SelectedScale   = 0.8f;
                e.UnselectedScale = 0.5f;
                grid.Add(e, numMaterials++, 0);
            }

            // Set grid properties.
            grid.IgnoreInput = true;    // We'll control the grid selection from here instead of internally.
            grid.Spacing     = new Vector2(0.25f, 0.0f);
            grid.Scrolling   = true;
            grid.Wrap        = false;
            grid.LocalMatrix = Matrix.CreateTranslation(0.0f, -2.5f, 0.0f);

            OnSampleType = SampleType;
        }   // end of MaterialPicker c'tor
コード例 #4
0
        public override bool HandleMouseInput(Camera camera)
        {
            Matrix mat;

            BoundingSphere sphere;      // Sphere we wrap around elements for hit testing.
            float?         dist = null; // Dist to sphere bounds hit.

            bool handled = false;

            // Test in-focus element for hit.
            UIGridMaterialElement e = grid.SelectionElement as UIGridMaterialElement;

            if (e != null)
            {
                Vector2 mouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);
                Ray     ray      = new Ray(camera.From, camera.ScreenToWorldCoords(mouseHit));

                mat    = e.HitWorldMatrix;
                sphere = new BoundingSphere(mat.Translation, 2.5f * mat.M33);
                dist   = ray.Intersects(sphere);

                if (dist != null)
                {
                    if (MouseInput.Left.WasPressed)
                    {
                        MouseInput.ClickedOnObject = e;
                        handled = true;
                    }
                    if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e)
                    {
                        SelectCurrentChoice();
                        Foley.PlayPressA();
                        return(true);
                    }
                }

                // Test elements not in focus.  If one is hit, bring it to the fore.
                // Need to test inside out so that if any overlap we test the front
                // ones first and react to them.  If we find a UV hit with a tile
                // we break to skip testing the rest.
                // Left side first.
                for (int i = grid.SelectionIndex.X - 1; i >= 0; i--)
                {
                    e = grid.Get(i, 0) as UIGridMaterialElement;

                    mat    = e.HitWorldMatrix;
                    sphere = new BoundingSphere(mat.Translation, 2.5f * mat.M33);
                    dist   = ray.Intersects(sphere);

                    if (dist != null)
                    {
                        if (MouseInput.Left.WasPressed)
                        {
                            MouseInput.ClickedOnObject = e;
                            handled = true;
                        }
                        if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e)
                        {
                            int steps = grid.SelectionIndex.X - i;
                            while (steps > 0)
                            {
                                DecrementFocus();
                                --steps;
                            }
                            handled = true;
                        }
                        break;
                    }
                }
                // Now the right side.
                for (int i = grid.SelectionIndex.X + 1; i < grid.ActualDimensions.X; i++)
                {
                    e = grid.Get(i, 0) as UIGridMaterialElement;

                    mat    = e.HitWorldMatrix;
                    sphere = new BoundingSphere(mat.Translation, 2.5f * mat.M33);
                    dist   = ray.Intersects(sphere);

                    if (dist != null)
                    {
                        if (MouseInput.Left.WasPressed)
                        {
                            MouseInput.ClickedOnObject = e;
                            handled = true;
                        }
                        if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e)
                        {
                            int steps = i - grid.SelectionIndex.X;
                            while (steps > 0)
                            {
                                IncrementFocus();
                                --steps;
                            }
                            handled = true;
                        }
                        break;
                    }
                }
            }

            return(handled);
        }   // end of HandleMouseInput()