Пример #1
0
        public override void LayoutItems(ArrayList items)
        {
            float neededCircumference;

            // calc needed circumference
            //
            CalcLayoutInfoFromItems(out neededCircumference, out this.maxItemRadius, items, 1);

            // calc radius of the spiral
            //
            float radius = neededCircumference / MathHelper.TwoPi;
            float spacingCircumference = 0.0f; // spacing between items on the circumference
            float radiusSpiral         = this.maxItemRadius * 2.0f;

            {
                // radius is too small, must increase
                // this is assuming the center composed item is the same size as the other items
                radius = this.maxItemRadius * 2.0f;
                // and provide the extra spacing between items on the circumference
                float newCircumference = MathHelper.TwoPi * radius;
                spacingCircumference = (newCircumference - neededCircumference) / items.Count;
                neededCircumference  = newCircumference;
            }


            // layout items into position spiraling on the circumference
            //
            float headingArcLength = 0.0f;

            for (int indexItem = 0; indexItem < items.Count; indexItem++)
            {
                OrbitalSelector.ItemData itemData = items[indexItem] as OrbitalSelector.ItemData;
                IBounding  boundingItem           = itemData.item as IBounding;
                ITransform transformItem          = itemData.item as ITransform;

                // skip the first one so it is top dead center
                if (indexItem != 0)
                {
                    // update angle along arc
                    headingArcLength += boundingItem.BoundingSphere.Radius;
                }

                // create a vector to the current heading
                float   headingAngle = headingArcLength / radius;
                Vector3 heading      = new Vector3((float)(Math.Sin(headingAngle) * radiusSpiral), (float)(Math.Cos(headingAngle) * radiusSpiral), 0.0f);

                // set position
                transformItem.Local.Translation = heading;
                transformItem.Compose();

                // update angle along arc
                headingArcLength += boundingItem.BoundingSphere.Radius + spacingCircumference;
                // update the spiral radius
                radiusSpiral += boundingItem.BoundingSphere.Radius / 6.0f;
            }
            this.maxOrbit = radiusSpiral;
        }
Пример #2
0
        public override void LayoutItems(ArrayList items)
        {
            float neededCircumference;

            // calc needed circumference
            //
            CalcLayoutInfoFromItems(out neededCircumference, out this.maxItemRadius, items, 1);

            // calc radius of the pie
            //
            float radius = neededCircumference / MathHelper.TwoPi;
            float spacingCircumference = 0.0f; // spacing between items on the circumference

            if (radius < this.maxItemRadius * 2.0f)
            {
                // radius is too small, must increase
                // this is assuming the center composed item is the same size as the other items
                radius = this.maxItemRadius * 2.0f;
                // and provide the extra spacing between items on the circumference
                float newCircumference = MathHelper.TwoPi * radius;
                spacingCircumference = (newCircumference - neededCircumference) / items.Count;
                neededCircumference  = newCircumference;
            }

            this.maxOrbit = radius;
            // layout items into position on the circumference
            //
            float headingArcLength = 0.0f;

            for (int indexItem = 0; indexItem < items.Count; indexItem++)
            {
                OrbitalSelector.ItemData itemData = items[indexItem] as OrbitalSelector.ItemData;
                IBounding  boundingItem           = itemData.item as IBounding;
                ITransform transformItem          = itemData.item as ITransform;

                // skip the first one so it is top dead center
                if (indexItem != 0)
                {
                    // update angle along arc
                    headingArcLength += boundingItem.BoundingSphere.Radius;
                }

                // create a vector to the current heading
                float   headingAngle = headingArcLength / radius;
                Vector3 heading      = new Vector3((float)(Math.Sin(headingAngle) * radius), (float)(Math.Cos(headingAngle) * radius), 0.0f);

                // set position by animations
                // transformItem.Local = Matrix.CreateTranslation(heading);
                TwitchManager.GetVector3 get = delegate(Object param)
                {
                    return(Vector3.Zero);
                };
                TwitchManager.SetVector3 set = delegate(Vector3 value, Object param)
                {
                    ITransform transformObject = param as ITransform;
                    if (transformObject != null)
                    {
                        transformObject.Local.Translation = value;
                        transformObject.Compose();
                    }
                };
                TwitchManager.Vector3Twitch twitch = new TwitchManager.Vector3Twitch(
                    get,
                    set,
                    heading,
                    0.2f,
                    TwitchCurve.Shape.EaseOut,
                    transformItem);
                twitch.Play();

                // update angle along arc
                headingArcLength += boundingItem.BoundingSphere.Radius + spacingCircumference;
            }
        }
Пример #3
0
        public override void LayoutItems(ArrayList items)
        {
            float neededCircumference;
            int   rows;
            int   cols;

            // calc needed circumference
            //
            CalcLayoutInfoFromItems(out this.maxItemRadius, out rows, out cols, items);

            float itemWidth = this.maxItemRadius * 2.0f * (float)Math.Sin(Math.PI * 0.25) + 0.1f;

            this.maxOrbit            = this.maxItemRadius * (float)rows / 2.0f;
            this.maxInterItemSpacing = this.maxItemRadius * 2.0f;
            for (int indexItem = 0; indexItem < items.Count; indexItem++)
            {
                OrbitalSelector.ItemData itemData = items[indexItem] as OrbitalSelector.ItemData;
                IBounding  boundingItem           = itemData.item as IBounding;
                ITransform transformItem          = itemData.item as ITransform;

                int col = (indexItem % cols) - (cols / 2);
                int row = (indexItem / cols) - (rows / 2);

                Vector3 position = new Vector3((float)col * itemWidth, (float)row * -itemWidth, 0.0f);
                Debug.Print("[{0}][{1}] ({2,8:F},{3,8:F})", col, row, position.X, position.Y);
                this.maxOrbit = MathHelper.Max(this.maxOrbit, Math.Abs(position.X));

                // set position by animations
                // transformItem.Local = Matrix.CreateTranslation(heading);
                TwitchManager.GetVector3 get = delegate(Object param)
                {
                    return(Vector3.Zero);
                };
                TwitchManager.SetVector3 set = delegate(Vector3 value, Object param)
                {
                    ITransform transformObject = param as ITransform;
                    if (transformObject != null)
                    {
                        transformObject.Local.Translation = value;
                        transformObject.Compose();
                    }
                };
                TwitchManager.Vector3Twitch twitch = new TwitchManager.Vector3Twitch(
                    get,
                    set,
                    position,
                    0.2f,
                    TwitchCurve.Shape.EaseOut,
                    transformItem);
                twitch.Play();
            }

/*
 *          // layout items into position on a grid starting top left
 *          //
 *          int ring = 1;
 *          int cols = 3; // first ring is 3x3
 *          int colEnd = (cols / 2);
 *          int col = -(colEnd);
 *          int row = -(colEnd);
 *          int colInc = 1;
 *          int rowInc = 0;
 *
 *          float itemWidth = this.maxItemRadius * 2.0f;
 *
 *          for (int indexItem = 0; indexItem < items.Count; indexItem++)
 *          {
 *              OrbitalSelector.ItemData itemData = items[indexItem] as OrbitalSelector.ItemData;
 *              IBounding boundingItem = itemData.item as IBounding;
 *              ITransform transformItem = itemData.item as ITransform;
 *
 *
 *              Vector3 position = new Vector3((float)col * itemWidth, (float)row * -itemWidth, 0.0f);
 *              Debug.Print("[{0}][{1}] ({2,8:F},{3,8:F})", col, row, position.X, position.Y);
 *
 *              col += colInc;
 *              row += rowInc;
 *              // reached right
 *              if (col > colEnd)
 *              {
 *                  col = colEnd;
 *                  colInc = 0;
 *                  rowInc = 1;
 *                  row += rowInc;
 *              }
 *              // reached bottom
 *              if (row > colEnd)
 *              {
 *                  row = colEnd;
 *                  colInc = -1;
 *                  rowInc = 0;
 *                  col += colInc;
 *              }
 *              // reached left
 *              if (col < -colEnd)
 *              {
 *                  col = -colEnd;
 *                  colInc = 0;
 *                  rowInc = -1;
 *                  row += rowInc;
 *              }
 *              // reached top
 *              if (col == -colEnd && row == -colEnd)
 *              {
 *                  cols += 2;
 *                  colEnd = (cols / 2);
 *                  col = -(colEnd);
 *                  row = -(colEnd);
 *                  colInc = 1;
 *                  rowInc = 0;
 *              }
 *
 *              // set position by animations
 *              // transformItem.Local = Matrix.CreateTranslation(heading);
 *              TwitchManager.GetVector3 get = delegate(Object param)
 *                      {
 *                          return Vector3.Zero;
 *                      };
 *              TwitchManager.SetVector3 set = delegate(Vector3 value, Object param)
 *                      {
 *                          ITransform transformObject = param as ITransform;
 *                          if (transformObject != null)
 *                          {
 *                              transformObject.Local.Translation = value;
 *                              transformObject.Compose();
 *                          }
 *                      };
 *              TwitchManager.Vector3Twitch twitch = new TwitchManager.Vector3Twitch(
 *                      get,
 *                      set,
 *                      position,
 *                      0.2f,
 *                      TwitchCurve.Shape.EaseOut,
 *                      transformItem);
 *              twitch.Play();
 *          }
 *          this.maxOrbit = colEnd * itemWidth;
 */
        }