Пример #1
0
        private void InitializeSkyBox(int scale)
        {
            Transform3D transform = null;
            ModelObject clone     = null;
            ModelObject archetype = null;

            #region Plane Archetype
            transform = new Transform3D(Vector3.Zero,
                                        Vector3.Zero, scale * Vector3.One, Vector3.UnitZ, Vector3.UnitY);

            ColorParameters colorParameters = new ColorParameters(
                this.textureDictionary["checkerboard"]);

            archetype = new ModelObject("arch plane",
                                        ActorType.Decorator, transform,
                                        this.modelDictionary["plane1"],
                                        colorParameters, this.skyBoxEffect);
            #endregion

            #region Back
            clone = archetype.Clone() as ModelObject;
            clone.Transform.Translation = new Vector3(0, 0, -scale / 2.0f);
            clone.ColorParameters       = new ColorParameters(
                this.textureDictionary["back"]);
            this.object3DManager.Add(clone);
            #endregion

            #region Left
            clone = archetype.Clone() as ModelObject;
            clone.Transform.Translation = new Vector3(-scale / 2.0f, 0, 0);
            clone.Transform.Rotation    = new Vector3(0, 90, 0);
            clone.ColorParameters       = new ColorParameters(
                this.textureDictionary["left"]);
            this.object3DManager.Add(clone);
            #endregion

            #region Right
            clone = archetype.Clone() as ModelObject;
            clone.Transform.Translation = new Vector3(scale / 2.0f, 0, 0);
            clone.Transform.Rotation    = new Vector3(0, -90, 0);
            clone.ColorParameters       = new ColorParameters(
                this.textureDictionary["right"]);
            this.object3DManager.Add(clone);
            #endregion

            #region Top
            clone = archetype.Clone() as ModelObject;
            clone.Transform.Translation = new Vector3(0, scale / 2.0f, 0);
            clone.Transform.Rotation    = new Vector3(90, 270, 0);
            clone.ColorParameters       = new ColorParameters(
                this.textureDictionary["sky"]);
            this.object3DManager.Add(clone);
            #endregion

            #region Front
            clone = archetype.Clone() as ModelObject;
            clone.Transform.Translation = new Vector3(0, 0, scale / 2.0f);
            clone.Transform.Rotation    = new Vector3(0, 180, 0);
            clone.ColorParameters       = new ColorParameters(
                this.textureDictionary["front"]);
            this.object3DManager.Add(clone);
            #endregion
        }
Пример #2
0
        /// <summary>
        /// Assign items to a given list
        /// </summary>
        /// <param name="list">List to assign to</param>
        /// <param name="itemType">Item type</param>
        /// <param name="from">List to assign from</param>
        public static void Assign(IList list, Type itemType, IList from)
        {
            // Assigning null values is not supported
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }

            // Delete obsolete items
            for (int i = list.Count; i > from.Count; i--)
            {
                list.RemoveAt(i - 1);
            }

            // Update common items
            if (itemType.IsSubclassOf(typeof(ModelObject)))
            {
                for (int i = 0; i < Math.Min(list.Count, from.Count); i++)
                {
                    ModelObject item       = (ModelObject)list[i];
                    ModelObject sourceItem = (ModelObject)from[i];
                    if (item == null || sourceItem == null)
                    {
                        list[i] = sourceItem;
                    }
                    else if (sourceItem.GetType() != item.GetType())
                    {
                        list[i] = sourceItem.Clone();
                    }
                    else
                    {
                        item.Assign(sourceItem);
                    }
                }
            }
            else if (itemType.IsArray)
            {
                for (int i = 0; i < Math.Min(list.Count, from.Count); i++)
                {
                    if (list[i] == null || from[i] == null)
                    {
                        list[i] = from[i];
                    }
                    else
                    {
                        IList listItem = (IList)list[i], fromItem = (IList)from[i];
                        if (listItem.Count != fromItem.Count)
                        {
                            list[i] = from[i];
                        }
                        else
                        {
                            for (int k = 0; k < listItem.Count; k++)
                            {
                                if (!Equals(listItem[k], fromItem[k]))
                                {
                                    list[i] = from[i];
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < Math.Min(list.Count, from.Count); i++)
                {
                    if (!Equals(list[i], from[i]))
                    {
                        list[i] = from[i];
                    }
                }
            }

            // Add missing items
            for (int i = list.Count; i < from.Count; i++)
            {
                list.Add(from[i]);
            }
        }