Exemplo n.º 1
0
        protected override void CreateScene()
        {
            mLog = LogManager.Singleton.createLog("RSQTest.log", false, true);
            mLog.LogMessage(string.Format("RSQTest log {0}", System.DateTime.Now));

            create4LineDebugOverLay();
            Show4LineDebugOverLay();

            //setup RenderTargetListenerDirector
            mRTListener = new RenderTargetListenerDirector();
            mRTListener.SubscribeEvents();
            mRTListener.evtPreRenderTargetUpdate  += new RenderTargetListenerDirector.RTLD_Delegate_RenderTargetUpdate(event_PreRenderTargetUpdate);
            mRTListener.evtPostRenderTargetUpdate += new RenderTargetListenerDirector.RTLD_Delegate_RenderTargetUpdate(event_PostRenderTargetUpdate);

            mSceneManager.SetAmbientLight(Converter.GetColor(0.2f, 0.2f, 0.2f));

            mSceneManager.SetSkyBox(true, "Examples/MorningSkyBox");

            // Create a light
            Light l = mSceneManager.CreateLight("MainLight");

            l.SetLightType(OgreDotNet.Light.LightTypes.Directional);
            Math3D.Vector3 dir = new Vector3(0.5f, -1.0f, 0.0f);
            dir.Normalize();
            l.SetDirection(dir);
            l.SetDiffuseColour(1.0f, 1.0f, 0.8f);
            l.SetSpecularColour(1.0f, 1.0f, 1.0f);

            // Create a prefab plane
            mPlane        = new MovablePlane("ReflectPlane");
            mPlane.D      = 0;
            mPlane.Normal = OgreVector3.FromVector3(Math3D.Vector3.UnitY);
            MeshManager.GetSingleton().CreatePlane("ReflectionPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                                                   mPlane, 2000, 2000, 1, 1, true, 1, 1, 1, Vector3.UnitZ);
            mPlaneEnt = mSceneManager.CreateEntity("Plane", "ReflectionPlane");

            // Create an entity from a model (will be loaded automatically)
            Entity knotEnt = mSceneManager.CreateEntity("Knot", "knot.mesh");

            // Create an entity from a model (will be loaded automatically)
            Entity ogreHead = mSceneManager.CreateEntity("Head", "ogrehead.mesh");

            knotEnt.SetMaterialName("Examples/TextureEffect2");

            // Attach the rtt entity to the root of the scene
            SceneNode rootNode = mSceneManager.GetRootSceneNode();

            mPlaneNode = rootNode.CreateChildSceneNode();

            // Attach both the plane entity, and the plane definition
            mPlaneNode.AttachObject(mPlaneEnt);

            //multi Inheritence problem, use the static Get*From function to convert
            MovableObject mo = MovableObject.GetMovableObjectFrom(mPlane);

            mPlaneNode.AttachObject(mo);

            mPlaneNode.Translate(0.0f, -10.0f, 0.0f);

            // Tilt it a little to make it interesting
            //mPlaneNode.Roll( new Radian( new Degree( 5.0f)) );
            mPlaneNode.Roll(5.0f);

            rootNode.CreateChildSceneNode("Head").AttachObject(ogreHead);


            RenderTexture rttTex = mRoot.GetRenderSystem().CreateRenderTexture("RttTex", 512, 512,
                                                                               TextureType.TEX_TYPE_2D, PixelFormat.PF_R8G8B8);

            {            //new scope for some reason
                mReflectCam = mSceneManager.CreateCamera("ReflectCam");
                mReflectCam.SetNearClipDistance(mCamera.GetNearClipDistance());
                mReflectCam.SetFarClipDistance(mCamera.GetFarClipDistance());
                mReflectCam.SetAspectRatio(
                    (float)mRenderWindow.GetViewport(0).ActualWidth /
                    (float)mRenderWindow.GetViewport(0).ActualHeight);

                Viewport v = rttTex.AddViewport(mReflectCam);
                v.ClearEveryFrame = true;
                v.BackgroundColor = System.Drawing.Color.Black;                 //Converter.ToColor( ColourValue.Black );

                ResourcePtr resPtr = MaterialManager.Instance.Create("RttMat",
                                                                     ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

                MaterialPtr mat = new MaterialPtr(ResourcePtr.getCPtr(resPtr).Handle, false);

                TextureUnitState t = mat.Get().GetTechnique(0).getPass(0).createTextureUnitState("RustedMetal.jpg");
                t = mat.Get().GetTechnique(0).getPass(0).createTextureUnitState("RttTex");
                // Blend with base texture
                t.setColourOperationEx(LayerBlendOperationEx.LBX_BLEND_MANUAL, LayerBlendSource.LBS_TEXTURE,
                                       LayerBlendSource.LBS_CURRENT, Color.White,
                                       Color.White, 0.25f);
                t.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_CLAMP);
                t.setProjectiveTexturing(true, mReflectCam);
                rttTex.AddListener(mRTListener);

                // set up linked reflection
                mReflectCam.EnableReflection(mPlane);
                // Also clip
                mReflectCam.EnableCustomNearClipPlane(mPlane);
            }

            // Give the plane a texture
            mPlaneEnt.SetMaterialName("RttMat");


            // Add a whole bunch of extra transparent entities
            Entity cloneEnt;

            for (int n = 0; n < 10; ++n)
            {
                // Create a new node under the root
                SceneNode node = mSceneManager.CreateSceneNode();
                // Random translate
                Vector3 nodePos;
                nodePos.x = OgreMath.SymmetricRandom() * 750.0f;
                nodePos.y = OgreMath.SymmetricRandom() * 100.0f + 25.0f;
                nodePos.z = OgreMath.SymmetricRandom() * 750.0f;
                node.SetPosition(nodePos);
                rootNode.AddChild(node);
                // Clone knot
                string cloneName = string.Format("Knot{0}", n);
                cloneEnt = knotEnt.Clone(cloneName);
                // Attach to new node
                node.AttachObject(cloneEnt);
            }


            mCamera.SetPosition(new Vector3(-50.0f, 100.0f, 500.0f));
            mCamera.LookAt = new Vector3(0, 0, 0);
        }
Exemplo n.º 2
0
        protected override void CreateScene()
        {
            mLog = LogManager.Singleton.createLog("DemoCompositor.log", false, true);
            mLog.LogMessage(string.Format("DemoCompositor log {0}", System.DateTime.Now));
            this.DebugOverlayVisible = false;

            mSceneManager.SetShadowTechnique(ShadowTechnique.ShadowTypeTextureModulative);
            mSceneManager.SetShadowFarDistance(1000.0f);

            // setup GUI system
            mGuiRenderer = new OgreCEGUIRenderer(mRenderWindow,
                                                 (byte)RenderQueueGroupID.RENDER_QUEUE_OVERLAY,
                                                 false, 3000, mSceneManager);
            mGuiRenderer.Initialise();                  //tell the CeguiNet proxy class the IntPtr to the CPP object

            // load scheme and set up defaults
            mGuiSystem = new GuiSystem(mGuiRenderer, (CeguiDotNet.ScriptModule)null,
                                       (CeguiDotNet.ResourceProvider)null, "CompositorDemoCegui.config");

            mGuiSystem.SetDefaultMouseCursor("TaharezLook", "MouseArrow");

            OgreDotNet.MovableObject.setDefaultVisibilityFlags(0x00000001);



            // Set ambient light
            mSceneManager.SetAmbientLight(Converter.GetColor(0.3f, 0.3f, 0.2f));

            Light   l   = mSceneManager.CreateLight("Light2");
            Vector3 dir = new Vector3(-1.0f, -1.0f, 0.0f);

            dir.Normalize();
            l.Type      = Light.LightTypes.Directional;
            l.Direction = dir;
            l.SetDiffuseColour(1.0f, 1.0f, 0.8f);
            l.SetSpecularColour(1.0f, 1.0f, 1.0f);


            Entity pEnt;

            // House
            pEnt = mSceneManager.CreateEntity("1", "tudorhouse.mesh");
            SceneNode n1 = mSceneManager.GetRootSceneNode().CreateChildSceneNode(new Vector3(350.0f, 450.0f, -200.0f));

            n1.AttachObject(pEnt);

            pEnt = mSceneManager.CreateEntity("2", "tudorhouse.mesh");
            SceneNode n2 = mSceneManager.GetRootSceneNode().CreateChildSceneNode(new Vector3(-350.0f, 450.0f, -200.0f));

            n2.AttachObject(pEnt);

            pEnt    = mSceneManager.CreateEntity("3", "knot.mesh");
            mSpinny = mSceneManager.GetRootSceneNode().CreateChildSceneNode(new Vector3(0.0f, 0.0f, 300.0f));
            mSpinny.AttachObject(pEnt);
            pEnt.SetMaterialName("Examples/MorningCubeMap");

            mSceneManager.SetSkyBox(true, "Examples/MorningSkyBox");


            Plane plane = new Plane();

            plane.Normal = OgreVector3.FromVector3(Math3D.Vector3.UnitY);
            plane.D      = 100.0f;
            MeshPtr m = MeshManager.Instance.CreatePlane("Myplane",
                                                         ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane,
                                                         1500.0f, 1500.0f, 10, 10, true, 1, 5.0f, 5.0f, Vector3.UnitZ);
            Entity pPlaneEnt = mSceneManager.CreateEntity("plane", "Myplane");

            pPlaneEnt.SetMaterialName("Examples/Rockwall");
            pPlaneEnt.SetCastShadows(false);
            mSceneManager.GetRootSceneNode().CreateChildSceneNode().AttachObject(pPlaneEnt);
            m.SetNull();
            m = null;

            mCamera.SetPosition(-400.0f, 50.0f, 900.0f);
            mCamera.LookAt = new Vector3(0.0f, 80.0f, 0.0f);

            connectMainEventHandlers();

            /// Create a couple of hard coded postfilter effects as an example of how to do it
            /// but the preferred method is to use compositor scripts.
            createEffects();
        }