Exemplo n.º 1
0
        /// <summary>
        /// Changes object visibility.
        /// (true) Creates SceneNode and checks Entity (if is null -> initializes). Calls OnDisplayed.
        /// (false) Destroys SceneNode and stored actual position.
        /// </summary>
        public virtual void ChangeVisible(bool visible)
        {
            if (visible && !this.isVisible)
            {
                // Controls if the entity is inicialized
                if (entity == null)
                {
                    entity = Game.SceneManager.CreateEntity(name, mesh);
                }

                sceneNode = Game.SceneManager.RootSceneNode.CreateChildSceneNode(name + "Node", position.Value);
                sceneNode.AttachObject(entity);
                this.isVisible = true;
                OnDisplayed();
            }
            else
            {
                if (this.isVisible)
                {
                    position.Value = sceneNode.Position;
                    Game.SceneManager.DestroySceneNode(sceneNode);
                    sceneNode = null;
                    isVisible = false;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes Mogre Entity and gets mesh from arguments. Also sets position (vector 0,0,0).
        /// </summary>
        /// <param name="name">The unique name.</param>
        /// <param name="args">The arguments (should be just one with mesh name).</param>
        public Sun(string name, object[] args)
        {
            propertyDict = new Dictionary <PropertyEnum, object>();
            this.name    = name;
            this.mesh    = (string)args[0];

            entity = Game.SceneManager.CreateEntity(name, mesh);
            propertyDict.Add(PropertyEnum.Position, position);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Destroys Mogre components. Rest will be destroyd by Garbage Collector.
 /// </summary>
 public void Destroy()
 {
     if (sceneNode != null)
     {
         Game.SceneManager.DestroySceneNode(sceneNode);
         sceneNode = null;
     }
     if (entity != null)
     {
         Game.SceneManager.DestroyEntity(entity);
         entity = null;
     }
 }
Exemplo n.º 4
0
        public bool PickGizmos(Mogre.Ray ray, ref AxisType axis)
        {
            if (this.gizmoEntities[0] == null || !this.gizmoEntities[0].IsVisible())
            {
                return(false);
            }

            float closesDistance = -1.0f;

            for (int widx = 0; widx < 3; ++widx)
            {
                // get the entity to check
                Mogre.Entity entity = this.gizmoEntities[widx];

                var hit = Mogre.Math.Intersects(ray, entity.GetWorldBoundingBox());
                if (!hit.first)
                {
                    continue;
                }

                bool newClosestFound = FindNewClosest(ray, ref closesDistance, entity);

                // if we found a new closest raycast for this object, update the
                // closestResult befor moving on to the next object
                if (newClosestFound)
                {
                    switch (widx)
                    {
                    case 0:
                        axis = AxisType.X;
                        break;

                    case 1:
                        axis = AxisType.Y;
                        break;

                    case 2:
                        axis = AxisType.Z;
                        break;
                    }
                }
            }

            return(closesDistance >= 0.0f);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Changes visibility of the sun (creates or destroys SceneNode).
        /// </summary>
        /// <param name="visible">boolean value if the sun is visible or not</param>
        public void ChangeVisible(bool visible)             //now creating
        {
            if (visible)
            {
                if (entity == null)
                {
                    entity = Game.SceneManager.CreateEntity(name, mesh);
                }
                sceneNode = Game.SceneManager.RootSceneNode.CreateChildSceneNode(name + "Node", Mogre.Vector3.ZERO);

                sceneNode.Pitch(new Mogre.Degree(-90f));
                sceneNode.AttachObject(entity);
            }
            else
            {
                Game.SceneManager.DestroySceneNode(sceneNode);
                sceneNode = null;
            }
        }