Exemplo n.º 1
0
        public Cube( float width, float height, float length )
        {
            this.Width = width;
            this.Height = height;
            this.Length = length;

            var cornerPoints = new [,]
                               {
                               	{ - width / 2, - height / 2, + length / 2 },
                               	{ + width / 2, - height / 2, + length / 2 },
                               	{ - width / 2, + height / 2, + length / 2 },
                               	{ + width / 2, + height / 2, + length / 2 },
                               	{ - width / 2, - height / 2, - length / 2 },
                               	{ + width / 2, - height / 2, - length / 2 },
                               	{ - width / 2, + height / 2, - length / 2 },
                               	{ + width / 2, + height / 2, - length / 2 },
                               };

            Fill( 0, cornerPoints, 0, 1, 3, 2, 0, 0, +1, 0, +1, 0, -1, 0, 0 ); // back
            Fill( 1, cornerPoints, 5, 4, 6, 7, 0, 0, -1, 0, +1, 0, +1, 0, 0 ); // front
            Fill( 2, cornerPoints, 4, 0, 2, 6, -1, 0, 0, 0, +1, 0, 0, 0, -1 ); // left
            Fill( 3, cornerPoints, 1, 5, 7, 3, +1, 0, 0, 0, +1, 0, 0, 0, +1 ); // right
            Fill( 4, cornerPoints, 4, 5, 1, 0, 0, -1, 0, 0, 0, -1, +1, 0, 0 ); // bottom
            Fill( 5, cornerPoints, 2, 3, 7, 6, 0, +1, 0, 0, 0, +1, +1, 0, 0 ); // top

            TangentVectorAttributeIndex = -1;
            BinormalVectorAttributeIndex = -1;
        }
Exemplo n.º 2
0
    TermInfo IFunction.GetTermInfo(string lang)
    {
      string funcInfo = "(Output, Name1, Prop1, Name2, Prop2, FluidName) Return a value that depends on the thermodynamic state\r\n" +
                        "Output The output parameter, one of \"T\",\"D\",\"H\",etc.\r\n" +
                        "Name1 The first state variable name, one of \"T\",\"D\",\"H\",etc.\r\n" +
                        "Prop1 The first state variable value\r\n" +
                        "Name2 The second state variable name, one of \"T\",\"D\",\"H\",etc.\r\n" +
                        "Prop2 The second state variable value\r\n" +
                        "FluidName The fluid name";

      var argsInfos = new [] {
        new ArgumentInfo(ArgumentSections.String),
        new ArgumentInfo(ArgumentSections.String),
        new ArgumentInfo(ArgumentSections.RealNumber),
        new ArgumentInfo(ArgumentSections.String),
        new ArgumentInfo(ArgumentSections.RealNumber),
        new ArgumentInfo(ArgumentSections.String)
      };

      return new TermInfo(inf.Text,
                          inf.Type,
                          funcInfo,
                          FunctionSections.Unknown,
                          true,
                          argsInfos);
    }
Exemplo n.º 3
0
        TermInfo IFunction.GetTermInfo(string lang)
        {
            string funcInfo = "(Output, Name1, Prop1, Name2, Prop2, Name3, Prop3) Return a humid air property\r\n" +
                "Output: The output parameter, one of \"T\", \"D\", \"H\", etc...\r\n" +
                "Name1: The first state variable name, one of \"T\", \"D\", \"H\", etc...\r\n" +
                "Prop1: The first state variable value\r\n" +
                "Name2: The second state variable name, one of \"T\", \"D\", \"H\", etc...\r\n" +
                "Prop2: The second state variable value\r\n" +
                "Name3: The third state variable name, one of \"T\", \"D\", \"H\", etc...\r\n" +
                "Prop3: The third state variable value";

            var argsInfos = new [] {
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.RealNumber),
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.RealNumber),
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.RealNumber),
            };

            return new TermInfo(inf.Text,
                                inf.Type,
                                funcInfo,
                                FunctionSections.Unknown,
                                true,
                                argsInfos);
        }
        TermInfo IFunction.GetTermInfo(string lang)
        {
            string funcInfo = "(ParamName) Get a globally-defined string\r\n" +
                "ParamName: A string, one of \"version\", \"errstring\", \"warnstring\", \"gitrevision\", \"FluidsList\", \"fluids_list\", \"parameter_list\",\"predefined_mixtures\"";

            var argsInfos = new [] {
                new ArgumentInfo(ArgumentSections.String)
            };

            return new TermInfo(inf.Text,
                                inf.Type,
                                funcInfo,
                                FunctionSections.Unknown,
                                true,
                                argsInfos);
        }
Exemplo n.º 5
0
        TermInfo IFunction.GetTermInfo(string lang)
        {
            string funcInfo = "(Name) Returns the index of a parameter\r\n" +
                "Name: The parameter name, one of \"Tcrit\", \"D\", \"H\", etc...";

            var argsInfos = new [] {
                new ArgumentInfo(ArgumentSections.String),
            };

            return new TermInfo(inf.Text,
                                inf.Type,
                                funcInfo,
                                FunctionSections.Unknown,
                                true,
                                argsInfos);
        }
Exemplo n.º 6
0
    TermInfo IFunction.GetTermInfo(string lang)
    {
      string funcInfo = "(FluidName, Output) Return a value that does not depend on the thermodynamic state\r\n" +
                        "FluidName The fluid name\r\n" +
                        "Output The output parameter, one of \"Tcrit\",\"D\",\"H\",etc.";

      var argsInfos = new [] {
        new ArgumentInfo(ArgumentSections.String),
      };

      return new TermInfo(inf.Text,
                          inf.Type,
                          funcInfo,
                          FunctionSections.Unknown,
                          true,
                          argsInfos);
    }
        public static void LoadContent(Device device)
        {
            //new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
            //new VertexElement(sizeof(float) * (3), VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
            //new VertexElement(sizeof(float) * (3 + 2), VertexElementFormat.Vector4, VertexElementUsage.Color, 0)

            var elements = new[] {
        		new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
        		new VertexElement(0, sizeof(float) * (3), DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                new VertexElement(0, sizeof(float) * (3 + 2), DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
				VertexElement.VertexDeclarationEnd
        	};

            m_stride = D3DX.GetDeclarationVertexSize(elements, 0);
            System.Diagnostics.Debug.Assert(m_vertexDeclaration == null);
            m_vertexDeclaration = new VertexDeclaration(device, elements);
        }
        public TermInfo GetTermInfo(string lang)
        {
            string funcInfo = "(FluidName, ReferenceState) Set the reference state based on a string representation\r\n" +
                "FluidName: The name of the fluid\r\n" +
                "ReferenceState: The reference state to use, one of \"IIR\", \"ASHRAE\", \"NBP\", \"DEF\", \"RESET\"";

            var argsInfos = new [] {
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.String)
            };

            return new TermInfo(inf.Text,
                                inf.Type,
                                funcInfo,
                                FunctionSections.Unknown,
                                true,
                                argsInfos);
        }
        public TermInfo GetTermInfo(string lang)
        {
            string funcInfo = "(FluidName, ParamName) Get a string for a value from a fluid\r\n" +
                "FluidName: The name of the fluid that is part of CoolProp, for instance \"n-Propane\"\r\n" +
                "ParamName: A string, can be in one of \"aliases\", \"CAS\", \"CAS_number\", \"ASHRAE34\", \"REFPROPName\", \"REFPROP_name\"";

            var argsInfos = new [] {
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.String)
            };

            return new TermInfo(inf.Text,
                                inf.Type,
                                funcInfo,
                                FunctionSections.Unknown,
                                true,
                                argsInfos);
        }
        public TermInfo GetTermInfo(string lang)
        {
            string funcInfo = "(Key, Output) Get a parameter information string\r\n" +
                "Key: A string\r\n" +
                "Output: A string, one of \"IO\", \"short\", \"long\", \"units\"";

            var argsInfos = new [] {
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.String)
            };

            return new TermInfo(inf.Text,
                                inf.Type,
                                funcInfo,
                                FunctionSections.Unknown,
                                true,
                                argsInfos);
        }
Exemplo n.º 11
0
        public GSSprite(Device device, DVector3 Position)
        {
            //float3 Position //12
            //half2 Size //16
            //half4 AABBTexCoord //24
            //half4 AditiveColor //32
            InputElement[] elements = new[] {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R16G16_Float, 12, 0),
                new InputElement("TEXCOORD", 1, Format.R16G16B16A16_Float, 16, 0),
                new InputElement("TEXCOORD", 2, Format.R16G16B16A16_Float, 24, 0),
            };

            BytesPerVertex = 32;
            VertexsCount = 1;

            var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true);

            vertices.Write(Conversion.ToVector3(Position));
            vertices.Write(new Half2(10, 10));
            vertices.Write(new Half4(0, 0, 1, 1));
            vertices.Write(new Half4(1, 0, 0, 1));
            vertices.Position = 0;

            Vertexs = new Buffer(device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
            binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);
            vertices.Dispose();

            this.Position = Position;
            EEEM = ContentManager.LoadEffect("Content/Shaders/GSSprite", elements);
            TexCont = ContentManager.LoadTexture2D("Content/Textures/Particl");
            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();
        }
Exemplo n.º 12
0
 public static InputLayout GetInputLayout(Device device, CompilationResult vertexShaderByteCode)
 {
     var inputElements = new[]
     {
         new InputElement
         {
             SemanticName = "POSITION",
             SemanticIndex = 0,
             Format = Format.R32G32B32_Float,
             Slot = 0,
             AlignedByteOffset = 0,
             Classification = InputClassification.PerVertexData,
             InstanceDataStepRate = 0
         },
         new InputElement
         {
             SemanticName = "TEXCOORD",
             SemanticIndex = 0,
             Format = Format.R32G32_Float,
             Slot = 0,
             AlignedByteOffset = 12,
             Classification = InputClassification.PerVertexData,
             InstanceDataStepRate = 0
         },
         new InputElement
         {
             SemanticName = "TEXCOORD",
             SemanticIndex = 1,
             Format = Format.R32_UInt,
             Slot = 0,
             AlignedByteOffset = 20,
             Classification = InputClassification.PerVertexData,
             InstanceDataStepRate = 0
         }
     };
     return new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements);
 }
    public TermInfo GetTermInfo(string lang)
    {
      string funcInfo = "(FluidName, T, rhomolar, h0, s0) Set the reference state based on a thermodynamic state point specified by temperature and molar density\r\n" +
        "FluidName The name of the fluid\r\n" +
        "T Temperature at reference state [K]\r\n" +
        "rhomolar Density at reference state [mol/m^3]\r\n" +
        "h0 Enthalpy at reference state [J/mol]\r\n" +
        "s0 Entropy at references state [J/mol/K]";

      var argsInfos = new [] {
        new ArgumentInfo(ArgumentSections.String),
        new ArgumentInfo(ArgumentSections.RealNumber),
        new ArgumentInfo(ArgumentSections.RealNumber),
        new ArgumentInfo(ArgumentSections.RealNumber),
        new ArgumentInfo(ArgumentSections.RealNumber),
      };

      return new TermInfo(inf.Text,
                          inf.Type,
                          funcInfo,
                          FunctionSections.Unknown,
                          true,
                          argsInfos);
    }
        TermInfo IFunction.GetTermInfo(string lang)
        {
            string funcInfo = "(FluidName, output, Q, input, value) Extract a value from the saturation ancillary\r\n" +
                "FluidName: The name of the fluid to be used - HelmholtzEOS backend only\r\n" +
                "output: The desired output variable (\"P\" for instance for pressure)\r\n" +
                "Q: The mass vapor quality, 0 or 1\r\n" +
                "input: The input variable name, one of \"T\", \"D\", \"H\", etc...\r\n" +
                "value: The input value";

            var argsInfos = new [] {
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.RealNumber),
                new ArgumentInfo(ArgumentSections.String),
                new ArgumentInfo(ArgumentSections.RealNumber),
            };

            return new TermInfo(inf.Text,
                                inf.Type,
                                funcInfo,
                                FunctionSections.Unknown,
                                true,
                                argsInfos);
        }
Exemplo n.º 15
0
    TermInfo IFunction.GetTermInfo(string lang)
    {
      string funcInfo = "(Name1, Prop1, Name2, Prop2, FluidName) Return a string representation of the phase\r\n" +
                        "Name1 The first state variable name, one of \"T\",\"D\",\"H\",etc.\r\n" +
                        "Prop1 The first state variable value\r\n" +
                        "Name2 The second state variable name, one of \"T\",\"D\",\"H\",etc.\r\n" +
                        "Prop2 The second state variable value\r\n" +
                        "FluidName The fluid name";

      var argsInfos = new [] {
        new ArgumentInfo(ArgumentSections.String),
        new ArgumentInfo(ArgumentSections.RealNumber),
        new ArgumentInfo(ArgumentSections.String),
        new ArgumentInfo(ArgumentSections.RealNumber),
        new ArgumentInfo(ArgumentSections.String)
      };

      return new TermInfo(inf.Text,
                          inf.Type,
                          funcInfo,
                          FunctionSections.Unknown,
                          true,
                          argsInfos);
    }
Exemplo n.º 16
0
        public static void Init(Device device, int W, int H)
        {
            #region Mesh
            _MConteints = new MeshContainer();

            _MConteints.BytesPerVertex = 12;
            _MConteints.FaceCount = 2;
            _MConteints.VertexsCount = 4;

            var vertices = new DataStream(_MConteints.BytesPerVertex * _MConteints.VertexsCount, true, true);
            vertices.Write(new Vector3(0.0f, 0.0f, 0.5f));
            vertices.Write(new Vector3(1.0f, 0.0f, 0.5f));
            vertices.Write(new Vector3(1.0f, 1.0f, 0.5f));
            vertices.Write(new Vector3(0.0f, 1.0f, 0.5f));
            vertices.Position = 0;

            _MConteints.Vertexs = new Buffer(device, vertices, _MConteints.BytesPerVertex * _MConteints.VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            var indices = new DataStream(4 * _MConteints.FaceCount * 3, true, true);
            indices.Write(0);
            indices.Write(1);
            indices.Write(2);
            indices.Write(2);
            indices.Write(3);
            indices.Write(0);
            indices.Position = 0;

            _MConteints.Indices = new Buffer(device, indices, 4 * _MConteints.FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            _MConteints.binding = new VertexBufferBinding(_MConteints.Vertexs, _MConteints.BytesPerVertex, 0);

            InputElement[] elements11 = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0) };
            EEEM = ContentManager.LoadEffect("Content/Shaders/QuadShader", elements11);

            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();
            constants.Resolution = new Vector4(W, H, 0, 0);
            constants.WM = Matrix.OrthoLH(constants.Resolution.X, constants.Resolution.Y, 0.1f, 1000);
            #endregion
            //RenderTargets
            Texture2DDescription BufDescription = new Texture2DDescription();
            BufDescription.MipLevels = 1;
            BufDescription.ArraySize = 1;
            BufDescription.Width = W/4;
            BufDescription.Height = H/4;
            BufDescription.Format = Format.R8G8B8A8_UNorm;
            BufDescription.SampleDescription = new SampleDescription(1, 0);
            BufDescription.Usage = ResourceUsage.Default;
            BufDescription.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource;
            BufDescription.CpuAccessFlags = CpuAccessFlags.None;
            BufDescription.OptionFlags = ResourceOptionFlags.None;

            BufTexture_1 = new Texture2D(device, BufDescription);
            BufTexture_2 = new Texture2D(device, BufDescription);

            BufSRV_1 = new ShaderResourceView(device, BufTexture_1);
            BufSRV_2 = new ShaderResourceView(device, BufTexture_2);

            RenderTargetViewDescription RTVD = new RenderTargetViewDescription();
            RTVD.Format = BufDescription.Format;
            RTVD.Dimension = RenderTargetViewDimension.Texture2D;
            RTVD.Texture2DArray.FirstArraySlice = 0;
            RTVD.Texture2DArray.ArraySize = 1;
            RTVD.Texture2D.MipSlice = 0;

            BufRTV_1 = new RenderTargetView(device, BufTexture_1, RTVD);
            BufRTV_2 = new RenderTargetView(device, BufTexture_2, RTVD);

            BufDescription.Width = W / 2;
            BufDescription.Height = H / 2;
            BufDescription.MipLevels = 0;

            BufDescription.OptionFlags = ResourceOptionFlags.GenerateMipMaps;
            BufDescription.Format = Format.R32G32B32A32_Float;
            RTVD.Format = BufDescription.Format;
            BufTexture_3 = new Texture2D(device, BufDescription);
            BufSRV_3 = new ShaderResourceView(device, BufTexture_3);
            BufRTV_3 = new RenderTargetView(device, BufTexture_3, RTVD);

            SamplerStateDescription sd = new SamplerStateDescription();
            sd.AddressU = TextureAddressMode.Clamp;
            sd.AddressV = TextureAddressMode.Clamp;
            sd.AddressW = TextureAddressMode.Clamp;
            sd.Filter = Filter.MinMagMipLinear;
            sd.MinimumLod = 0;
            sd.MaximumLod = 16;

            BufSS = new SamplerState(device, ref sd);

            HDRViewport = new Viewport(0, 0, W / 4, H / 4);
            DoubleHDRViewport = new Viewport(0, 0, W / 2, H / 2);

            BufDescription = new Texture2DDescription();
            BufDescription.MipLevels = 1;
            BufDescription.ArraySize = 1;
            BufDescription.Width = 1;
            BufDescription.Height = 1;
            BufDescription.Format = Format.R32G32B32A32_Float;
            BufDescription.SampleDescription = new SampleDescription(1, 0);
            BufDescription.Usage = ResourceUsage.Default;
            BufDescription.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource;
            BufDescription.CpuAccessFlags = CpuAccessFlags.None;
            BufDescription.OptionFlags = ResourceOptionFlags.None;

            RTVD = new RenderTargetViewDescription();
            RTVD.Format = BufDescription.Format;
            RTVD.Dimension = RenderTargetViewDimension.Texture2D;
            RTVD.Texture2DArray.FirstArraySlice = 0;
            RTVD.Texture2DArray.ArraySize = 1;
            RTVD.Texture2D.MipSlice = 0;

            T1x1 = new Texture2D(device, BufDescription);
            V1x1 = new Viewport(0, 0, 1, 1);
            SRV1x1 = new ShaderResourceView(device, T1x1);
            RTV1x1 = new RenderTargetView(device, T1x1, RTVD);

            device.ImmediateContext.ClearRenderTargetView(BufRTV_3, new Color4(0.0f, 0.0f, 0.0f, 1f));
        }
Exemplo n.º 17
0
        public void UserCanTypeDocumentId()
        {
            var module = GetTestModule();
            WdDocument wdDoc=MockUtils.GetDefaultDoc("00001234.DOCX");

            var invalidDocIds = new[] { "worldox://00001234.DOC" ,"worldox:////0 0  1.","worldox://  asdasd//"};
            var mockRepo = Mock.Get(module.Resolve<IWdDocumentRepository>());
            mockRepo.Setup_GetByDocId(wdDoc);

            var dp = GetNewInstance(module);

            foreach (var invalidDocId in invalidDocIds)
            {
                for (int i = 0; i < invalidDocId.Length; i++)
                {
                    tagWSDOCUMENT wsDoc;
                    var hres = dp.GetDocument(invalidDocId.Substring(0, i), (int)wsGetDocFlags.DF_INFO_ONLY, out wsDoc);
                    Assert.That(hres, Is.EqualTo(DP_HRESULTS.E_IM_INVALID_DOCID));
                }
            }
        }
Exemplo n.º 18
0
        public void Initialize()
        {
            LoadSky(0);

            Texture2DDescription descTex = new Texture2DDescription();
            descTex.ArraySize = 6;
            descTex.Width = Size;
            descTex.Height = Size;
            descTex.Usage = ResourceUsage.Default;
            descTex.CpuAccessFlags = CpuAccessFlags.None;
            descTex.Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm;
            descTex.SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0);
            descTex.MipLevels = MipLevel;
            descTex.BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget;
            descTex.OptionFlags = ResourceOptionFlags.GenerateMipMaps | ResourceOptionFlags.TextureCube;

            //Create the texture and shader view
            CubeTexture = new Texture2D(ModelViewer.Program.device, descTex);
            CubeSRV = new ShaderResourceView(ModelViewer.Program.device, CubeTexture);

            RenderTargetViewDescription RTVD = new RenderTargetViewDescription();
            RTVD.Format = descTex.Format;
            RTVD.Dimension = RenderTargetViewDimension.Texture2DArray;
            RTVD.Texture2DArray.FirstArraySlice = 0;
            RTVD.Texture2DArray.ArraySize = 1;
            RTVD.Texture2DArray.MipSlice = 0;

            CubeRenderTarget = new RenderTargetView[6];

            for (int i = 0; i < 6; i++)
            {
                RTVD.Texture2DArray.FirstArraySlice = i;
                CubeRenderTarget[i] = new RenderTargetView(ModelViewer.Program.device, CubeTexture, RTVD);
            }

            SamplerStateDescription a = new SamplerStateDescription();
            a.AddressU = TextureAddressMode.Clamp;
            a.AddressV = TextureAddressMode.Clamp;
            a.AddressW = TextureAddressMode.Clamp;
            a.Filter = Filter.MinMagMipLinear;
            SSWrapMipLinear = new SamplerState(ModelViewer.Program.device, a);

            MContains = new MeshContainer();
            MContains.BytesPerVertex = 20;
            MContains.FaceCount = 12;
            MContains.VertexsCount = 24;

            Vector3 vExtents = new Vector3(500, 500, 500);

            var vertices = new DataStream(MContains.BytesPerVertex * MContains.VertexsCount, true, true);

            //Back
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            //Front
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            //Bottom
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            //Top
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            //Left
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(-vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 0));
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            vertices.Write(new Vector3(-vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            //Right
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 1));
            vertices.Write(new Vector3(vExtents.X, -vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 1));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, vExtents.Z));
            vertices.Write(new Vector2(1, 0));
            vertices.Write(new Vector3(vExtents.X, vExtents.Y, -vExtents.Z));
            vertices.Write(new Vector2(0, 0));

            vertices.Position = 0;
            InputElement[] elements11 = new[] {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float, 0, 0) ,
                new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 12, 0)};

            MContains.Vertexs = new Buffer(ModelViewer.Program.device, vertices, MContains.BytesPerVertex * MContains.VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            var indices = new DataStream(4 * MContains.FaceCount * 3, true, true);
            for (int x = 0; x < 6; x++)
            {
                indices.Write((int)(x * 4 + 0));
                indices.Write((int)(x * 4 + 1));
                indices.Write((int)(x * 4 + 2));

                indices.Write((int)(x * 4 + 2));
                indices.Write((int)(x * 4 + 3));
                indices.Write((int)(x * 4 + 0));
            }
            indices.Position = 0;

            MContains.Indices = new Buffer(ModelViewer.Program.device, indices, 4 * MContains.FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            MContains.binding = new VertexBufferBinding(MContains.Vertexs, MContains.BytesPerVertex, 0);

            EEEM = ContentManager.LoadEffect("Content/Shaders/SkyBox", elements11);

            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(SkyShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            SkyConstantsBuffer = new Buffer(ModelViewer.Program.device, bd);
            SSC = new SkyShaderConstants();
        }
        public static void LoadContent(Device device)
        {
            var elements = new[] {
        		new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                new VertexElement(0, sizeof(float) * 3, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
				VertexElement.VertexDeclarationEnd
        	};

            m_stride = D3DX.GetDeclarationVertexSize(elements, 0);
            System.Diagnostics.Debug.Assert(m_vertexDeclaration == null);
            m_vertexDeclaration = new VertexDeclaration(device, elements);
        }
Exemplo n.º 20
0
		static DR.CallingConvention ConvertCallingConvention(CR.CallingConvention callingConvention) {
			switch (callingConvention) {
			case CR.CallingConvention.Winapi:	return DR.CallingConvention.Default;
			case CR.CallingConvention.Cdecl:	return DR.CallingConvention.C;
			case CR.CallingConvention.StdCall:	return DR.CallingConvention.StdCall;
			case CR.CallingConvention.ThisCall:	return DR.CallingConvention.ThisCall;
			case CR.CallingConvention.FastCall:	return DR.CallingConvention.FastCall;
			default: throw new ApplicationException(string.Format("Unknown CallingConvention {0}", callingConvention));
			}
		}
Exemplo n.º 21
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var form = new Form1();

            Device device;
            SwapChain swapChain;
            ShaderSignature inputSignature;
            VertexShader vertexShader;
            GeometryShader geometryShader;
            PixelShader pixelShader;

            var description = new SwapChainDescription()
            {
                BufferCount = 2,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = form.Handle,
                IsWindowed = true,
                ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, description, out device, out swapChain);

            // create a view of our render target, which is the backbuffer of the swap chain we just created
            RenderTargetView renderTarget;
            using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
                renderTarget = new RenderTargetView(device, resource);

            // setting a viewport is required if you want to actually see anything
            var context = device.ImmediateContext;
            var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
            context.OutputMerger.SetTargets(renderTarget);
            context.Rasterizer.SetViewports(viewport);

            // load and compile the vertex shader
            using (var bytecode = ShaderBytecode.CompileFromFile("Voxel.fx", "VS", "vs_4_0", ShaderFlags.None, EffectFlags.None))
            {
                inputSignature = ShaderSignature.GetInputSignature(bytecode);
                vertexShader = new VertexShader(device, bytecode);
            }

            using (var bytecode = ShaderBytecode.CompileFromFile("Voxel.fx", "GS", "gs_4_0", ShaderFlags.None, EffectFlags.None))
            {
                geometryShader = new GeometryShader(device, bytecode);
            }

            // load and compile the pixel shader
            using (var bytecode = ShaderBytecode.CompileFromFile("Voxel.fx", "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None))
                pixelShader = new PixelShader(device, bytecode);

            // create test vertex data, making sure to rewind the stream afterward
            var vertices = new DataStream(12 * 3, true, true);
            vertices.Write(new Vector3(0.0f, 0.5f, 0.5f));
            vertices.Write(new Vector3(0.5f, -0.5f, 0.5f));
            vertices.Write(new Vector3(-0.5f, -0.5f, 0.5f));
            vertices.Position = 0;

            // create the vertex layout and buffer
            var elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0) };
            var layout = new InputLayout(device, inputSignature, elements);
            var vertexBuffer = new Buffer(device, vertices, 12 * 3, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            // configure the Input Assembler portion of the pipeline with the vertex data
            context.InputAssembler.InputLayout = layout;
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 12, 0));

            // set the shaders
            context.VertexShader.Set(vertexShader);
            // context.GeometryShader.Set(geometryShader);
            context.PixelShader.Set(pixelShader);

            // prevent DXGI handling of alt+enter, which doesn't work properly with Winforms
            using (var factory = swapChain.GetParent<Factory>())
                factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAltEnter);

            // handle alt+enter ourselves
            form.KeyDown += (o, e) =>
            {
                if (e.Alt && e.KeyCode == Keys.Enter)
                    swapChain.IsFullScreen = !swapChain.IsFullScreen;
            };

            // handle form size changes
            form.Resize += (o, e) =>
            {
                renderTarget.Dispose();

                swapChain.ResizeBuffers(2, 0, 0, Format.R8G8B8A8_UNorm, SwapChainFlags.AllowModeSwitch);
                using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
                    renderTarget = new RenderTargetView(device, resource);

                context.OutputMerger.SetTargets(renderTarget);
            };

            MessagePump.Run(form, () =>
            {
                // clear the render target to a soothing blue
                context.ClearRenderTargetView(renderTarget, new Color4(0.5f, 0.5f, 1.0f));

                // draw the triangle
                context.Draw(3, 0);
                swapChain.Present(0, PresentFlags.None);
            });

            // clean up all resources
            // anything we missed will show up in the debug output
            vertices.Close();
            vertexBuffer.Dispose();
            layout.Dispose();
            inputSignature.Dispose();
            vertexShader.Dispose();
            geometryShader.Dispose();
            pixelShader.Dispose();
            renderTarget.Dispose();
            swapChain.Dispose();
            device.Dispose();
        }
Exemplo n.º 22
0
        public void TestTrainingBounce()
        {
            var perceptron = new Perceptron(2);
              perceptron.ActivationFunction = x => x >= 1 ? 1 : 0;
              var trainer = new PerceptronTrainer(perceptron);
              var rows = new []
              {
            new PerceptronTrainingRow ( new [] { 0.0, 1.0 }, 0 ),
            new PerceptronTrainingRow ( new [] { 0.5, 1.0 }, 0 ),
            new PerceptronTrainingRow ( new [] { 1.0, 0.0 }, 0 ),
            new PerceptronTrainingRow ( new [] { 1.5, 5.0 }, 0 ),
            new PerceptronTrainingRow ( new [] { 3.0, 3.0 }, 0 ),
            new PerceptronTrainingRow ( new [] { 3.5, 0.0 }, 0 ),
            new PerceptronTrainingRow ( new [] { 1.0, 6.0 }, 1 ),
            new PerceptronTrainingRow ( new [] { 2.0, 9.0 }, 1 ),
            new PerceptronTrainingRow ( new [] { 4.0, 6.0 }, 1 ),
            new PerceptronTrainingRow ( new [] { 5.5, 1.0 }, 1 ),
            new PerceptronTrainingRow ( new [] { 6.0, 4.0 }, 1 ),
            new PerceptronTrainingRow ( new [] { 9.0, 3.0 }, 1 ),
              };
              trainer.Train(rows, 0.01, 500);

              perceptron.Inputs[0] = 2.0;
              perceptron.Inputs[1] = 2.0;
              Assert.AreEqual(0, perceptron.Output);
              perceptron.Inputs[0] = 7.0;
              perceptron.Inputs[1] = 6.0;
              Assert.AreEqual(1, perceptron.Output);
        }
        public static void LoadContent(Device device)
        {
            var elements = new[] {
                new VertexElement(0, 0, DeclarationType.Short4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                new VertexElement(0, 8, DeclarationType.Short4, DeclarationMethod.Default, DeclarationUsage.Position, 1),
                new VertexElement(0, 16, DeclarationType.Ubyte4, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
                new VertexElement(0, 20, DeclarationType.Ubyte4, DeclarationMethod.Default, DeclarationUsage.Normal, 1),
                VertexElement.VertexDeclarationEnd
            };

            m_stride = D3DX.GetDeclarationVertexSize(elements, 0);
            System.Diagnostics.Debug.Assert(m_vertexDeclaration == null);
            m_vertexDeclaration = new VertexDeclaration(device, elements);
        }
        public static void LoadContent(Device device)
        {
            //new VertexElement(0, VertexElementFormat.HalfVector4, VertexElementUsage.Position, 0),
            //new VertexElement(8, VertexElementFormat.Byte4, VertexElementUsage.Normal, 0)


            var elements = new[] {
        		new VertexElement(0, 0, DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.Position, 0),
        		new VertexElement(0, 8, DeclarationType.Ubyte4, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
				VertexElement.VertexDeclarationEnd
        	};

            m_stride = D3DX.GetDeclarationVertexSize(elements, 0);
            System.Diagnostics.Debug.Assert(m_vertexDeclaration == null);
            m_vertexDeclaration = new VertexDeclaration(device, elements);
        }
        public static void LoadContent(Device device)
        {
            //new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
            //new VertexElement(12, VertexElementFormat.HalfVector4, VertexElementUsage.Color, 0),
            //new VertexElement(20, VertexElementFormat.HalfVector2, VertexElementUsage.TextureCoordinate, 0),
            //new VertexElement(24, VertexElementFormat.Byte4, VertexElementUsage.Normal, 0),
            //new VertexElement(28, VertexElementFormat.Byte4, VertexElementUsage.Tangent, 0),
            //new VertexElement(32, VertexElementFormat.HalfVector2, VertexElementUsage.TextureCoordinate, 1)

            var elements = new[] {
        		new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
        		new VertexElement(0, 12, DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                new VertexElement(0, 20, DeclarationType.HalfTwo, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                new VertexElement(0, 24, DeclarationType.Ubyte4, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
                new VertexElement(0, 28, DeclarationType.Ubyte4, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
                new VertexElement(0, 32, DeclarationType.HalfTwo, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1),
				VertexElement.VertexDeclarationEnd
        	};

            m_stride = D3DX.GetDeclarationVertexSize(elements, 0);
            System.Diagnostics.Debug.Assert(m_vertexDeclaration == null);
            m_vertexDeclaration = new VertexDeclaration(device, elements);
        }