コード例 #1
0
        void RenderModelWithEffect(Graphics.Content.Model9 model, SlimDX.Matrix world, Matrix viewProjection, Matrix halfPixelOffset,
                                   Graphics.Content.MetaResource <Graphics.Content.Model9, Graphics.Content.Model10> metaResource)
        {
            if (model == null)
            {
                return;
            }

            interfaceRenderer9Effect.SetTexture(EHTexture, model.Texture);
            //StateManager.SetTexture(0, model.Texture);

            //Device.SetSamplerState(4, SamplerState.MagFilter, TextureFilter.Anisotropic);
            //e.Scale = new Vector3((int)e.Scale.X, (int)e.Scale.Y, (int)e.Scale.Z);

            var g = metaResource as Graphics.Content.Graphic;

            if (g != null)
            {
                world = Matrix.Translation(g.Position) * world;
                //world = world * halfPixelOffset;
                world.M41 = (float)((int)world.M41) - 0.5f;
                world.M42 = (float)((int)world.M42) - 0.5f;
                StateManager.SetSamplerState(0, SamplerState.AddressU, g.TextureAdressMode);
                StateManager.SetSamplerState(0, SamplerState.AddressV, g.TextureAdressMode);
                interfaceRenderer9Effect.SetValue(EHOpacity, g.Alpha);
            }
            else
            {
                world = ((Graphics.Content.MetaModel)metaResource).World * world;

                StateManager.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp);
                StateManager.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp);

                interfaceRenderer9Effect.SetValue(EHOpacity, 1);
            }
            //Forces

            if (model.XMesh != null)
            {
                interfaceRenderer9Effect.SetValue(EHWorldViewProjection,
                                                  world * Scene.Camera.View * Matrix.PerspectiveFovLH(((LookatCamera)Scene.Camera).FOV, ((LookatCamera)Scene.Camera).AspectRatio, 1, 50));
            }
            else
            {
                interfaceRenderer9Effect.SetValue(EHWorldViewProjection, world * viewProjection);
            }
            interfaceRenderer9Effect.CommitChanges();
            //device.SetTransform(TransformState.World, world);
            if (model.Mesh != null)
            {
                model.Mesh.Draw(device);
                intermediateTrianglesPerFrame += model.Mesh.NFaces;
            }
            else if (model.XMesh != null)
            {
                model.XMesh.DrawSubset(0);
                intermediateTrianglesPerFrame += model.XMesh.FaceCount;
            }
        }
コード例 #2
0
        void RenderModel(Graphics.Content.Model9 model, SlimDX.Matrix world, Matrix halfPixelOffset,
                         Graphics.Content.MetaResource <Graphics.Content.Model9, Graphics.Content.Model10> metaResource)
        {
            if (model == null)
            {
                return;
            }

            var device = Scene.View.Device9;

            StateManager.SetTexture(0, model.Texture);

            //Device.SetSamplerState(4, SamplerState.MagFilter, TextureFilter.Anisotropic);
            //e.Scale = new Vector3((int)e.Scale.X, (int)e.Scale.Y, (int)e.Scale.Z);

            var g = metaResource as Graphics.Content.Graphic;

            if (g != null)
            {
                world = Matrix.Translation(g.Position) * world;
                //world = world * halfPixelOffset;
                world.M41 = (float)((int)world.M41) - 0.5f;
                world.M42 = (float)((int)world.M42) - 0.5f;
                StateManager.SetSamplerState(0, SamplerState.AddressU, g.TextureAdressMode);
                StateManager.SetSamplerState(0, SamplerState.AddressV, g.TextureAdressMode);
            }
            else
            {
                world = ((Graphics.Content.MetaModel)metaResource).World * world;

                StateManager.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp);
                StateManager.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp);
            }
            device.SetTransform(TransformState.World, world);
            if (model.Mesh != null)
            {
                model.Mesh.Draw(device);
                intermediateTrianglesPerFrame += model.Mesh.NFaces;
            }
            else if (model.XMesh != null)
            {
                model.XMesh.DrawSubset(0);
                intermediateTrianglesPerFrame += model.XMesh.FaceCount;
            }
        }