Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        protected override CompositorWorkspace SetupCompositor()
        {
            // The compositor scripts are also part of this sample. Go to Fresnel.compositor
            // to see the sample scripts on how to setup the rendering pipeline.
            CompositorManager2 compositorManager = _root.CompositorManager2;

            const string        workspaceName = "RttSampleWorkspace";
            CompositorWorkspace workspace     = compositorManager.AddWorkspace(
                _sceneManager, _window,
                _camera, workspaceName, true);

            workspace.SetListener(new RttWorkspaceListener(this));

            return(workspace);
        }
Ejemplo n.º 3
0
 public override void WorkspacePreUpdate(CompositorWorkspace workspace)
 {
     /** CompositorWorkspaceListener::workspacePreUpdate is the best place to update other (manual)
      *      Workspaces for multiple reasons:
      *              1. It happens after Ogre issued D3D9's beginScene. If you want to update a workspace
      *                      outside beginScene/endScene pair, you will have to call Workspace::_beginUpdate(true)
      *                 and _endUpdate(true) yourself. This will add synchronization overhead in the API,
      *                 lowering performance.
      *              2. It happens before the whole scene is rendered, thus you can ensure your RTTs are
      *                 up to date.
      *
      *      One alternative that allows you to forget about this listener is to use auto-updated
      *      workspaces, but you will have to ensure this workspace is created before your main
      *      workspace (the one that outputs to the RenderWindow).
      *
      *      Another alternative is the one presented in the Fresnel demo: The rendering is fully
      *      handled inside one single workspace, and the textures are created by the Compositor
      *      instead of being manually created.
      */
     //_sample._cubemapWorkspace._beginUpdate( forceFrameBeginEnd );
     _sample._cubemapWorkspace._update();
     //_sample._cubemapWorkspace._endUpdate( forceFrameBeginEnd );
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public virtual bool Setup()
        {
            // Create root
            var pluginFileName = _fileSystemLayer.GetConfigFilePath("plugins.cfg");

            _root = new Root(pluginFileName,
                             _fileSystemLayer.GetWritablePath("ogre.cfg"),
                             _fileSystemLayer.GetWritablePath("Ogre.log"));

            // Create OverlaySystem
            _overlaySystem = new OverlaySystem();

            //
            SetupResources();
            //if (Configure() == false)
            //{
            //	return false;
            //}
            SetupDirectX();

            // Create RenderWindow
            _root.Initialise(false);
            var nameValuePairList = new NameValuePairList();

            nameValuePairList["externalWindowHandle"] = Handle.ToString();
            _window = _root.CreateRenderWindow("Mogre RenderWindow", 800, 600, false, nameValuePairList);

            TestCapabilities(_root.RenderSystem.Capabilities);

            // Now we have GPU stuff setup
            ResourceGroupManager.Singleton.AddBuiltinLocations();

            _sceneManager = CreateSceneManager();
#if INCLUDE_RTSHADER_SYSTEM
            if (!_root.RenderSystem.Capabilities.HasCapability(Capabilities.RSC_FIXED_FUNCTION))
            {
                InitializeRTShaderSystem(_sceneManager);
            }
#endif

            _overlaySystem.SceneManager = _sceneManager;
            CreateCamera();
            TextureManager.Singleton.DefaultNumMipmaps = 5;
            LoadResources();
            _workspace = SetupCompositor();
            CreateInputHandler();
            Disposed += OgreWindow_Disposed;
            CreateScene();

            // Create Frame Listeners
            _root.FrameStarted               += OnFrameStarted;
            _root.FrameRenderingQueued       += OnFrameRenderingQueued;
            _root.FrameEnded                 += OnFrameEnded;
            _sceneManager.RenderQueueStarted += _sceneManager_RenderQueueStarted;
            _trayManager = new SdkTrayManager("SampleControls", _window);
            _trayManager.ShowFrameStats(TrayLocation.BottomLeft);
            _trayManager.ShowLogo(TrayLocation.BottomRight);
            _trayManager.ShowCursor();

            return(true);
        }
Ejemplo n.º 6
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);

            // 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();
        }