void CreateCubeMap()
        {
            // create the camera used to render to our cubemap
            _cubeCamera             = _sceneManager.CreateCamera("CubeMapCamera", true, true);
            _cubeCamera.FOVy        = new Degree(90);
            _cubeCamera.AspectRatio = 1.0f;
            _cubeCamera.SetFixedYawAxis(false);
            _cubeCamera.NearClipDistance = 5.0f;
            _cubeCamera.FarClipDistance  = /*100*/ 10000;

            var tex = TextureManager.Singleton.CreateManual("dyncubemap", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_CUBE_MAP, 512, 512, 0, PixelFormat.PF_R8G8B8, (int)TextureUsage.TU_RENDERTARGET);
            CompositorManager2 compositorManager = _root.CompositorManager2;
            const string       workspaceName     = "CompositorSampleCubemap_cubemap";

            if (!compositorManager.HasWorkspaceDefinition(workspaceName))
            {
                CompositorWorkspaceDef workspaceDef = compositorManager.AddWorkspaceDefinition(workspaceName);
                //"CubemapRendererNode" has been defined in scripts.
                //Very handy (as it 99% the same for everything)
                workspaceDef.ConnectOutput("CubemapRendererNode", 0);
            }

            CompositorChannel channel = new CompositorChannel
            {
                target = tex.GetBuffer(0).GetRenderTarget()
            };

            channel.textures.Add(tex);
            _cubemapWorkspace = compositorManager.AddWorkspace(_sceneManager, channel, _cubeCamera, workspaceName, false);
        }
Beispiel #2
0
        protected virtual CompositorWorkspace SetupCompositor()
        {
            CompositorManager2 compositorManager = _root.CompositorManager2;
            string             workspaceName     = GetType().Name + "Workspace";

            if (!compositorManager.HasWorkspaceDefinition(workspaceName))
            {
                compositorManager.CreateBasicWorkspaceDef(workspaceName, _backgroundColor);
            }

            return(compositorManager.AddWorkspace(_sceneManager, _window, _camera, workspaceName));
        }
Beispiel #3
0
        protected override void CreateScene()
        {
            // setup some basic lighting for our scene
            _sceneManager.AmbientLight = new ColourValue(0.3f, 0.3f, 0.3f);
            var lightNode = _sceneManager.RootSceneNode.CreateChildSceneNode();

            lightNode.SetPosition(20, 80, 50);
            lightNode.AttachObject(_sceneManager.CreateLight());

            _sceneManager.SetSkyBox(true, "Examples/SpaceSkyBox");

            // create an ogre head entity and attach it to a node
            Entity head = _sceneManager.CreateEntity("ogrehead.mesh");

            head.Name = "Head";
            SceneNode headNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode();

            headNode.Translate(0, 40, 0);
            headNode.AttachObject(head);

            // create a camera node and attach camera to it
            SceneNode camNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode();

            _camera.DetachFromParent();
            camNode.AttachObject(_camera);

            // set up a 10 second animation for our camera, using spline interpolation for nice curves
            Animation anim = _sceneManager.CreateAnimation("CameraTrack", 10);

            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);

            // create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(camNode);

            // create keyframes for our track
            track.CreateNodeKeyFrame(0).Translate    = new Vector3(200, 0, 0);
            track.CreateNodeKeyFrame(2.5f).Translate = new Vector3(0, -50, 100);
            track.CreateNodeKeyFrame(5).Translate    = new Vector3(-500, 100, 0);
            track.CreateNodeKeyFrame(7.5f).Translate = new Vector3(0, 200, -300);
            track.CreateNodeKeyFrame(10).Translate   = new Vector3(200, 0, 0);

            // create a new animation state to track this
            _animState         = _sceneManager.CreateAnimationState("CameraTrack");
            _animState.Enabled = true;

            // Now create another scene manager with only
            _rttSceneManager = CreateSceneManager();

            // Create the RenderTargetTexture
            _rttCamera          = _rttSceneManager.CreateCamera("RttCamera");
            _rttCamera.Position = new Vector3(0f, 10f, 500f);
            _rttCamera.LookAt(new Vector3(0f, 0f, -300f));
            _rttCamera.AutoAspectRatio  = true;
            _rttCamera.NearClipDistance = 5.0f;

            // Penguin
            Entity penguin = _rttSceneManager.CreateEntity("penguin.mesh");

            _penguinNode = _rttSceneManager.RootSceneNode.CreateChildSceneNode();
            _penguinNode.AttachObject(penguin);
            penguin.Name = "Penguin";

            MaterialPtr penguinMaterial = MaterialManager.Singleton.Create("PenguinMaterial", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

            penguinMaterial.GetTechnique(0).GetPass(0).LightingEnabled = false;
            penguinMaterial.GetTechnique(0).GetPass(0).CreateTextureUnitState("penguin.jpg");
            penguin.SetMaterialName(penguinMaterial.Name);

            var screenTexture0 = TextureManager.Singleton.CreateManual(
                "screenTexture0",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                TextureType.TEX_TYPE_2D,
                640,
                480,
                0,
                PixelFormat.PF_R8G8B8,
                (int)TextureUsage.TU_RENDERTARGET
                );

            CompositorManager2 compositorManager = _root.CompositorManager2;
            string             workspaceName     = GetType().Name + "RttWorkspace";

            if (!compositorManager.HasWorkspaceDefinition(workspaceName))
            {
                compositorManager.CreateBasicWorkspaceDef(workspaceName, new ColourValue(1.0f, 0.0f, 0.0f, 1.0f));
            }

            _rttWorkspace = _root.CompositorManager2.AddWorkspace(
                _rttSceneManager,
                screenTexture0.GetBuffer().GetRenderTarget(),
                _rttCamera,
                workspaceName,
                true);

            MaterialPtr renderMat = MaterialManager.Singleton.Create("RttMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
            var         pass      = renderMat.GetTechnique(0).GetPass(0);

            pass.LightingEnabled = false;
            var textureUnit = pass.CreateTextureUnitState();

            textureUnit.SetContentType(TextureUnitState.ContentType.CONTENT_COMPOSITOR);
            textureUnit.SetTextureName("screenTexture0", TextureType.TEX_TYPE_2D);
            textureUnit.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_WRAP);

            Plane plane = new Plane(Vector3.UNIT_Y, 0);

            MeshManager.Singleton.CreatePlane(
                "planeMesh",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                plane,
                700.0f, 1300.0f,
                10, 10, true, 1,
                4.0f, 4.0f,
                Vector3.UNIT_Z);

            Entity planeEntity = _sceneManager.CreateEntity("planeMesh");

            planeEntity.SetMaterialName("RttMat");
            planeEntity.CastShadows = false;
            _sceneManager.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity);
        }
        protected override void CreateScene()
        {
            // setup some basic lighting for our scene
            _sceneManager.AmbientLight = new ColourValue(0.3f, 0.3f, 0.3f);
            var lightNode = _sceneManager.RootSceneNode.CreateChildSceneNode();

            lightNode.SetPosition(20, 80, 50);
            lightNode.AttachObject(_sceneManager.CreateLight());

            _sceneManager.SetSkyBox(true, "Examples/SpaceSkyBox");

            // create an ogre head entity and attach it to a node
            Entity head = _sceneManager.CreateEntity("ogrehead.mesh");

            head.Name = "Head";
            SceneNode headNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode();

            headNode.Translate(0, 40, 0);
            headNode.AttachObject(head);

            // create a camera node and attach camera to it
            SceneNode camNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode();

            _camera.DetachFromParent();
            camNode.AttachObject(_camera);

            // set up a 10 second animation for our camera, using spline interpolation for nice curves
            Animation anim = _sceneManager.CreateAnimation("CameraTrack", 10);

            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);

            // create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(camNode);

            // create keyframes for our track
            track.CreateNodeKeyFrame(0).Translate    = new Vector3(200, 0, 0);
            track.CreateNodeKeyFrame(2.5f).Translate = new Vector3(0, -50, 100);
            track.CreateNodeKeyFrame(5).Translate    = new Vector3(-500, 100, 0);
            track.CreateNodeKeyFrame(7.5f).Translate = new Vector3(0, 200, -300);
            track.CreateNodeKeyFrame(10).Translate   = new Vector3(200, 0, 0);

            // create a new animation state to track this
            _animState         = _sceneManager.CreateAnimationState("CameraTrack");
            _animState.Enabled = true;

            // Now create another scene manager with only
            _rttSceneManager = CreateSceneManager();

            // Create the RenderTargetTexture
            _rttCamera          = _rttSceneManager.CreateCamera("RttCamera");
            _rttCamera.Position = new Vector3(0f, 10f, 500f);
            _rttCamera.LookAt(new Vector3(0f, 0f, -300f));
            _rttCamera.AutoAspectRatio  = true;
            _rttCamera.NearClipDistance = 5.0f;

            // Penguin
            Entity penguin = _rttSceneManager.CreateEntity("penguin.mesh");

            _penguinNode = _rttSceneManager.RootSceneNode.CreateChildSceneNode();
            _penguinNode.AttachObject(penguin);
            penguin.Name = "Penguin";

            MaterialPtr penguinMaterial = MaterialManager.Singleton.Create("PenguinMaterial", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

            penguinMaterial.GetTechnique(0).GetPass(0).LightingEnabled = false;
            penguinMaterial.GetTechnique(0).GetPass(0).CreateTextureUnitState("penguin.jpg");
            penguin.SetMaterialName(penguinMaterial.Name);

            var screenTexture0 = TextureManager.Singleton.CreateManual(
                "screenTexture0",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                TextureType.TEX_TYPE_2D,
                640,
                480,
                0,
                PixelFormat.PF_R8G8B8,
                (int)TextureUsage.TU_RENDERTARGET
                );

            CompositorManager2 compositorManager = _root.CompositorManager2;
            string             workspaceName     = GetType().Name + "RttWorkspace";

            if (!compositorManager.HasWorkspaceDefinition(workspaceName))
            {
                compositorManager.CreateBasicWorkspaceDef(workspaceName, new ColourValue(1.0f, 0.0f, 0.0f, 1.0f));
            }

            _rttWorkspace = _root.CompositorManager2.AddWorkspace(
                _rttSceneManager,
                screenTexture0.GetBuffer().GetRenderTarget(),
                _rttCamera,
                workspaceName,
                true);

            MaterialPtr renderMat = MaterialManager.Singleton.Create("RttMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
            var         pass      = renderMat.GetTechnique(0).GetPass(0);

            pass.LightingEnabled = false;
            var textureUnit = pass.CreateTextureUnitState();

            textureUnit.SetContentType(TextureUnitState.ContentType.CONTENT_COMPOSITOR);
            textureUnit.SetTextureName("screenTexture0", TextureType.TEX_TYPE_2D);
            textureUnit.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_WRAP);

            Plane plane = new Plane(Vector3.UNIT_Y, 0);

            MeshManager.Singleton.CreatePlane(
                "planeMesh",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                plane,
                700.0f, 1300.0f,
                10, 10, true, 1,
                4.0f, 4.0f,
                Vector3.UNIT_Z);

            Entity planeEntity = _sceneManager.CreateEntity("planeMesh");

            planeEntity.SetMaterialName("RttMat");
            planeEntity.CastShadows = false;
            _sceneManager.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity);

            // Test Miyagi
            // Init MiyagiSystem
            _miyagiSystem = new MiyagiSystem("Mogre", (int)_window.Width, (int)_window.Height);
            //const string PluginPath = @"..\..\..\debug\Plugins";
            //this.miyagiSystem.PluginManager.LoadPlugin(Path.Combine(PluginPath, "Miyagi.Plugin.Input.Mois.dll"), this.inputKeyboard, this.inputMouse);

            Resources.Create(_miyagiSystem);
            //Utilities.CreateCursor(system.GUIManager);

            // create a default GUI
            var gui = new GUI();


            // A Button is a simple skinned control capable of changing its current texture automatically on certain mouse events
            // (MouseDown/MouseEnter/MouseLeave/MouseUp). Those subskins are optinal, if a subskin is not defined, Miyagi will fall
            // back to an appropriate alternative.
            // Since Button inherits from Label it provides the same TextStyle options.
            var button1 = new Miyagi.UI.Controls.Button
            {
                Text      = "HELLO WORLD",
                Location  = new Point(140, 140),
                Size      = new Size(200, 50),
                Skin      = Resources.Skins["ButtonSkin"],
                TextStyle =
                {
                    Alignment        = Alignment.MiddleCenter,
                    ForegroundColour = Colours.White
                }
            };

            // add the Buttons to the GUI
            gui.Controls.Add(button1);
            //gui.Controls.Add(button2);

            var pictureBox = new Miyagi.UI.Controls.PictureBox
            {
                Name     = "testingPictureBox",
                Location = new Point(380, 140),
                Size     = new Size(400, 100),
            };

            pictureBox.Bitmap = new System.Drawing.Bitmap(new System.Drawing.Bitmap(400, 100));

            // add the Buttons to the GUI
            gui.Controls.Add(pictureBox);

            // add the GUI to the GUIManager
            _miyagiSystem.GUIManager.GUIs.Add(gui);
            gui.SpriteRenderer.CacheToTexture = true;

            System.Windows.Forms.Timer dummyTimer = new System.Windows.Forms.Timer();
            dummyTimer.Interval = 2000;
            dummyTimer.Tick    += dummyTimer_Tick;
            dummyTimer.Start();
        }