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
        public override void CreateScene()
        {
            // Check capabilities
              RenderSystemCapabilities caps = Root.Singleton.RenderSystem.Capabilities;
            if (!caps.HasCapability(Mogre.Capabilities.RSC_VERTEX_PROGRAM) || !(caps.HasCapability(Mogre.Capabilities.RSC_FRAGMENT_PROGRAM)))
            {
                MessageBox.Show("Your card does not support vertex and fragment programs, so cannot run this demo. Sorry! CelShading::createScene");
            }

            // Create a point light
            Light l = sceneMgr.CreateLight("MainLight");
            // Accept default settings: point light, white diffuse, just set position
            // Add light to the scene node
            rootNode = sceneMgr.RootSceneNode.CreateChildSceneNode();
            rootNode.CreateChildSceneNode(new Vector3(20,40,50)).AttachObject(l);

            Entity ent = sceneMgr.CreateEntity("head", "ogrehead.mesh");

            camera.Position = new Vector3(20, 0, 100);
            camera.LookAt( new Vector3(0,0,0));

            // Set common material, but define custom parameters to change colours
            // See Example-Advanced.material for how these are finally bound to GPU parameters
            SubEntity sub;
            // eyes
            sub = ent.GetSubEntity(0);
            sub.MaterialName = ("Examples/CelShading");
            sub.SetCustomParameter(CUSTOM_SHININESS, new Vector4(35.0f, 0.0f, 0.0f, 0.0f));
            sub.SetCustomParameter(CUSTOM_DIFFUSE, new Vector4(1.0f, 0.3f, 0.3f, 1.0f));
            sub.SetCustomParameter(CUSTOM_SPECULAR, new Vector4(1.0f, 0.6f, 0.6f, 1.0f));
            // skin
            sub = ent.GetSubEntity(1);
            sub.MaterialName = ("Examples/CelShading");
            sub.SetCustomParameter(CUSTOM_SHININESS, new Vector4(10.0f, 0.0f, 0.0f, 0.0f));
            sub.SetCustomParameter(CUSTOM_DIFFUSE, new Vector4(0.0f, 0.5f, 0.0f, 1.0f));
            sub.SetCustomParameter(CUSTOM_SPECULAR, new Vector4(0.3f, 0.5f, 0.3f, 1.0f));
            // earring
            sub = ent.GetSubEntity(2);
            sub.MaterialName = ("Examples/CelShading");
            sub.SetCustomParameter(CUSTOM_SHININESS, new Vector4(25.0f, 0.0f, 0.0f, 0.0f));
            sub.SetCustomParameter(CUSTOM_DIFFUSE, new Vector4(1.0f, 1.0f, 0.0f, 1.0f));
            sub.SetCustomParameter(CUSTOM_SPECULAR, new Vector4(1.0f, 1.0f, 0.7f, 1.0f));
            // teeth
            sub = ent.GetSubEntity(3);
            sub.MaterialName = ("Examples/CelShading");
            sub.SetCustomParameter(CUSTOM_SHININESS, new Vector4(20.0f, 0.0f, 0.0f, 0.0f));
            sub.SetCustomParameter(CUSTOM_DIFFUSE, new Vector4(1.0f, 1.0f, 0.7f, 1.0f));
            sub.SetCustomParameter(CUSTOM_SPECULAR, new Vector4(1.0f, 1.0f, 1.0f, 1.0f));

            // Add entity to the root scene node
            sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

            window.GetViewport(0).BackgroundColour = (Mogre.ColourValue.White);
        }
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
        /// <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;
            }
        }