Пример #1
0
        public static void Main()
        {
            var form = new RenderForm("SimpleD3D9 by C#") { ClientSize = new Size(1024, 768) };

            var device = new D3D9Device(
                new Direct3D(),
                CUDADevice.Default.ID,
                DeviceType.Hardware,
                form.Handle,
                CreateFlags.HardwareVertexProcessing,
                new PresentParameters(form.ClientSize.Width, form.ClientSize.Height));

            var vertices = new VertexBuffer(device, Utilities.SizeOf<Vector4>()*Total, Usage.WriteOnly,
                VertexFormat.None, Pool.Default);

            var vertexElems = new []
            {
                new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                new VertexElement(0, 12, DeclarationType.Ubyte4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                VertexElement.VertexDeclarationEnd
            };

            var vertexDecl = new VertexDeclaration(device, vertexElems);

            var worker = Worker.CreateByFunc(() => Generate(device));
            var updater = new SimpleD3D9(GPUModuleTarget.Worker(worker));

            var view = Matrix.LookAtLH(
                new Vector3(0.0f, 3.0f, -2.0f), // the camera position
                new Vector3(0.0f, 0.0f, 0.0f),  // the look-at position
                new Vector3(0.0f, 1.0f, 0.0f)); // the up direction

            var proj = Matrix.PerspectiveFovLH(
                (float) (Math.PI/4.0), // the horizontal field of view
                1.0f,
                1.0f,
                100.0f);

            device.SetTransform(TransformState.View, view);
            device.SetTransform(TransformState.Projection, proj);
            device.SetRenderState(RenderState.Lighting, false);

            var vbres = RegisterVerticesResource(vertices);
            var clock = System.Diagnostics.Stopwatch.StartNew();

            RenderLoop.Run(form, () =>
            {
                var time = (float) (clock.Elapsed.TotalMilliseconds)/300.0f;
                updater.Update(vbres, time);

                // Now normal D3D9 rendering procedure.
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new ColorBGRA(0, 40, 100, 0), 1.0f, 0);
                device.BeginScene();

                device.VertexDeclaration = vertexDecl;
                device.SetStreamSource(0, vertices, 0, Utilities.SizeOf<Vector4>());
                // we use PointList as the graphics primitives
                device.DrawPrimitives(SharpDX.Direct3D9.PrimitiveType.PointList, 0, Total);

                device.EndScene();
                device.Present();
            });

            UnregisterVerticesResource(vbres);

            updater.Dispose();
            worker.Dispose();
            vertexDecl.Dispose();
            vertices.Dispose();
            device.Dispose();
            form.Dispose();
        }
Пример #2
0
            public static void DrawCircle(Vector3 position, float radius, Color color, int width = 1, bool zDeep = false)
            {
                if (_vertices == null)
                {
                    const float x = 6000f;
                    _vertices = new VertexBuffer(
                        Drawing.Direct3DDevice, Utilities.SizeOf<Vector4>() * 2 * 6, Usage.WriteOnly, VertexFormat.None,
                        Pool.Managed);

                    _vertices.Lock(0, 0, LockFlags.None).WriteRange(
                        new[]
                        {
                            //T1
                            new Vector4(-x, 0f, -x, 1.0f), new Vector4(), new Vector4(-x, 0f, x, 1.0f), new Vector4(),
                            new Vector4(x, 0f, -x, 1.0f), new Vector4(),

                            //T2
                            new Vector4(x, 0f, x, 1.0f), new Vector4(), new Vector4(-x, 0f, x, 1.0f), new Vector4(),
                            new Vector4(x, 0f, -x, 1.0f), new Vector4()
                        });
                    _vertices.Unlock();

                    _vertexElements = new[]
                    {
                        new VertexElement(
                            0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                        new VertexElement(
                            0, 16, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                        VertexElement.VertexDeclarationEnd
                    };

                    _vertexDeclaration = new VertexDeclaration(Drawing.Direct3DDevice, _vertexElements);

                    #region Effect

                    try
                    {
                        /*
                        _effect = Effect.FromString(Drawing.Direct3DDevice, @"
                        struct VS_S
                         {
                             float4 Position : POSITION;
                             float4 Color : COLOR0;
                             float4 Position3D : TEXCOORD0;
                         };

                         float4x4 ProjectionMatrix;
                         float4 CircleColor;
                         float Radius;
                         float Border;
                         bool zEnabled;
                         VS_S VS( VS_S input )
                         {
                             VS_S output = (VS_S)0;

                             output.Position = mul(input.Position, ProjectionMatrix);
                             output.Color = input.Color;
                             output.Position3D = input.Position;
                             return output;
                         }

                         float4 PS( VS_S input ) : COLOR
                         {
                             VS_S output = (VS_S)0;
                             output = input;

                             float4 v = output.Position3D;
                             float distance = Radius - sqrt(v.x * v.x + v.z*v.z); // Distance to the circle arc.

                             output.Color.x = CircleColor.x;
                             output.Color.y = CircleColor.y;
                             output.Color.z = CircleColor.z;

                             if(distance < Border && distance > -Border)
                             {
                                 output.Color.w = (CircleColor.w - CircleColor.w * abs(distance * 1.75 / Border));
                             }
                             else
                             {
                                 output.Color.w = 0;
                             }

                             if(Border < 1 && distance >= 0)
                             {
                                 output.Color.w = CircleColor.w;
                             }

                             return output.Color;
                         }

                         technique Main {
                             pass P0 {
                                 ZEnable = zEnabled;
                                 AlphaBlendEnable = TRUE;
                                 DestBlend = INVSRCALPHA;
                                 SrcBlend = SRCALPHA;
                                 VertexShader = compile vs_2_0 VS();
                                 PixelShader  = compile ps_2_0 PS();
                             }
                         }", ShaderFlags.None);
                        */
                        var compiledEffect = new byte[]
                        {
                            0x01, 0x09, 0xFF, 0xFE, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
                            0x02, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00,
                            0x00, 0x00, 0x50, 0x72, 0x6F, 0x6A, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x4D, 0x61, 0x74,
                            0x72, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
                            0xA4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
                            0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x43, 0x69, 0x72, 0x63, 0x6C,
                            0x65, 0x43, 0x6F, 0x6C, 0x6F, 0x72, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0xD4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
                            0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x52, 0x61,
                            0x64, 0x69, 0x75, 0x73, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
                            0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x42, 0x6F, 0x72,
                            0x64, 0x65, 0x72, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x01,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x7A, 0x45, 0x6E, 0x61,
                            0x62, 0x6C, 0x65, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
                            0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
                            0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
                            0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05,
                            0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
                            0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0F,
                            0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x50, 0x30, 0x00, 0x00, 0x05, 0x00, 0x00,
                            0x00, 0x4D, 0x61, 0x69, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00,
                            0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
                            0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00,
                            0x00, 0xD0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00,
                            0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
                            0x01, 0x00, 0x00, 0x28, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0xF4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xEC, 0x01, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x3C, 0x01, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x5C, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x06, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x01, 0x00, 0x00, 0x9C, 0x01, 0x00, 0x00, 0x92, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0xBC, 0x01, 0x00, 0x00, 0x93,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x01, 0x00, 0x00, 0xD4, 0x01, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4C, 0x04,
                            0x00, 0x00, 0x00, 0x02, 0xFF, 0xFF, 0xFE, 0xFF, 0x38, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1C,
                            0x00, 0x00, 0x00, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00,
                            0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xA3, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00,
                            0x00, 0x02, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x70, 0x00,
                            0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x8C,
                            0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00,
                            0x01, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x42, 0x6F, 0x72,
                            0x64, 0x65, 0x72, 0x00, 0xAB, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x69, 0x72, 0x63, 0x6C, 0x65, 0x43, 0x6F,
                            0x6C, 0x6F, 0x72, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x52, 0x61, 0x64, 0x69, 0x75, 0x73, 0x00, 0x70, 0x73, 0x5F,
                            0x32, 0x5F, 0x30, 0x00, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x28,
                            0x52, 0x29, 0x20, 0x48, 0x4C, 0x53, 0x4C, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20,
                            0x43, 0x6F, 0x6D, 0x70, 0x69, 0x6C, 0x65, 0x72, 0x20, 0x39, 0x2E, 0x32, 0x39, 0x2E, 0x39,
                            0x35, 0x32, 0x2E, 0x33, 0x31, 0x31, 0x31, 0x00, 0xAB, 0xFE, 0xFF, 0x7C, 0x00, 0x50, 0x52,
                            0x45, 0x53, 0x01, 0x02, 0x58, 0x46, 0xFE, 0xFF, 0x30, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1C,
                            0x00, 0x00, 0x00, 0x8B, 0x00, 0x00, 0x00, 0x01, 0x02, 0x58, 0x46, 0x02, 0x00, 0x00, 0x00,
                            0x1C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x88, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00,
                            0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x4C, 0x00, 0x00, 0x00, 0x5C, 0x00,
                            0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x78,
                            0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x00, 0x42, 0x6F, 0x72, 0x64, 0x65, 0x72, 0x00, 0xAB,
                            0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x43, 0x69, 0x72, 0x63, 0x6C, 0x65, 0x43, 0x6F, 0x6C, 0x6F, 0x72, 0x00, 0x01,
                            0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x74, 0x78, 0x00, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x28, 0x52,
                            0x29, 0x20, 0x48, 0x4C, 0x53, 0x4C, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43,
                            0x6F, 0x6D, 0x70, 0x69, 0x6C, 0x65, 0x72, 0x20, 0x39, 0x2E, 0x32, 0x39, 0x2E, 0x39, 0x35,
                            0x32, 0x2E, 0x33, 0x31, 0x31, 0x31, 0x00, 0xFE, 0xFF, 0x0C, 0x00, 0x50, 0x52, 0x53, 0x49,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE,
                            0xFF, 0x1A, 0x00, 0x43, 0x4C, 0x49, 0x54, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0xFE, 0xFF, 0x1F, 0x00, 0x46, 0x58, 0x4C, 0x43, 0x03, 0x00, 0x00, 0x00, 0x01,
                            0x00, 0x30, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
                            0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x01, 0x00, 0x40, 0xA0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
                            0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
                            0x03, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00,
                            0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0x00, 0x00, 0x51,
                            0x00, 0x00, 0x05, 0x06, 0x00, 0x0F, 0xA0, 0x00, 0x00, 0xE0, 0x3F, 0x00, 0x00, 0x00, 0x80,
                            0x00, 0x00, 0x80, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
                            0x80, 0x00, 0x00, 0x07, 0xB0, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08, 0x80, 0x00, 0x00,
                            0xAA, 0xB0, 0x00, 0x00, 0xAA, 0xB0, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x80, 0x00,
                            0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0xB0, 0x00, 0x00, 0xFF, 0x80, 0x07, 0x00, 0x00, 0x02,
                            0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80, 0x06, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01,
                            0x80, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00,
                            0x00, 0x81, 0x04, 0x00, 0x00, 0xA0, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x80, 0x00,
                            0x00, 0x00, 0x81, 0x05, 0x00, 0x00, 0xA1, 0x58, 0x00, 0x00, 0x04, 0x00, 0x00, 0x02, 0x80,
                            0x00, 0x00, 0x55, 0x80, 0x06, 0x00, 0x55, 0xA0, 0x06, 0x00, 0xAA, 0xA0, 0x02, 0x00, 0x00,
                            0x03, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x00, 0x80, 0x05, 0x00, 0x00, 0xA1, 0x58, 0x00,
                            0x00, 0x04, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0xAA, 0x80, 0x06, 0x00, 0x55, 0xA0, 0x00,
                            0x00, 0x55, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x00, 0x80,
                            0x06, 0x00, 0x00, 0xA0, 0x58, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00,
                            0x80, 0x06, 0x00, 0xAA, 0xA0, 0x06, 0x00, 0x55, 0xA0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00,
                            0x08, 0x80, 0x06, 0x00, 0x55, 0xA0, 0x58, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x80, 0x01,
                            0x00, 0x00, 0xA0, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x80, 0x05, 0x00, 0x00, 0x03,
                            0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0xAA, 0x80, 0x00, 0x00, 0x00, 0xA0, 0x23, 0x00, 0x00,
                            0x02, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0xAA, 0x80, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00,
                            0x04, 0x80, 0x03, 0x00, 0xFF, 0xA0, 0x00, 0x00, 0xAA, 0x81, 0x03, 0x00, 0xFF, 0xA0, 0x58,
                            0x00, 0x00, 0x04, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x55, 0x80, 0x06, 0x00, 0xFF, 0xA0,
                            0x00, 0x00, 0xAA, 0x80, 0x58, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x00,
                            0x80, 0x00, 0x00, 0x55, 0x80, 0x03, 0x00, 0xFF, 0xA0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00,
                            0x07, 0x80, 0x02, 0x00, 0xE4, 0xA0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0F, 0x80, 0x00,
                            0x00, 0xE4, 0x80, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0xFF, 0xFF, 0xFF, 0xFF, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4C, 0x01, 0x00,
                            0x00, 0x00, 0x02, 0xFE, 0xFF, 0xFE, 0xFF, 0x34, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1C, 0x00,
                            0x00, 0x00, 0x9B, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFE, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x1C,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x94, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
                            0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00,
                            0x00, 0x50, 0x72, 0x6F, 0x6A, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x4D, 0x61, 0x74, 0x72,
                            0x69, 0x78, 0x00, 0xAB, 0xAB, 0xAB, 0x03, 0x00, 0x03, 0x00, 0x04, 0x00, 0x04, 0x00, 0x01,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x73, 0x5F, 0x32,
                            0x5F, 0x30, 0x00, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x28, 0x52,
                            0x29, 0x20, 0x48, 0x4C, 0x53, 0x4C, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43,
                            0x6F, 0x6D, 0x70, 0x69, 0x6C, 0x65, 0x72, 0x20, 0x39, 0x2E, 0x32, 0x39, 0x2E, 0x39, 0x35,
                            0x32, 0x2E, 0x33, 0x31, 0x31, 0x31, 0x00, 0x1F, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80,
                            0x00, 0x00, 0x0F, 0x90, 0x1F, 0x00, 0x00, 0x02, 0x0A, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0F,
                            0x90, 0x09, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0xE4, 0x90, 0x00, 0x00,
                            0xE4, 0xA0, 0x09, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0xC0, 0x00, 0x00, 0xE4, 0x90, 0x01,
                            0x00, 0xE4, 0xA0, 0x09, 0x00, 0x00, 0x03, 0x00, 0x00, 0x04, 0xC0, 0x00, 0x00, 0xE4, 0x90,
                            0x02, 0x00, 0xE4, 0xA0, 0x09, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08, 0xC0, 0x00, 0x00, 0xE4,
                            0x90, 0x03, 0x00, 0xE4, 0xA0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0F, 0xD0, 0x01, 0x00,
                            0xE4, 0x90, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0xE4, 0x90, 0xFF,
                            0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x02, 0x58,
                            0x46, 0xFE, 0xFF, 0x25, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1C, 0x00, 0x00, 0x00, 0x5F, 0x00,
                            0x00, 0x00, 0x00, 0x02, 0x58, 0x46, 0x01, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
                            0x01, 0x00, 0x20, 0x5C, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
                            0x01, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x4C, 0x00, 0x00, 0x00, 0x7A, 0x45, 0x6E,
                            0x61, 0x62, 0x6C, 0x65, 0x64, 0x00, 0xAB, 0xAB, 0xAB, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
                            0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x78, 0x00, 0x4D,
                            0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4C,
                            0x53, 0x4C, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6F, 0x6D, 0x70, 0x69,
                            0x6C, 0x65, 0x72, 0x20, 0x39, 0x2E, 0x32, 0x39, 0x2E, 0x39, 0x35, 0x32, 0x2E, 0x33, 0x31,
                            0x31, 0x31, 0x00, 0xFE, 0xFF, 0x02, 0x00, 0x43, 0x4C, 0x49, 0x54, 0x00, 0x00, 0x00, 0x00,
                            0xFE, 0xFF, 0x0C, 0x00, 0x46, 0x58, 0x4C, 0x43, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
                            0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
                            0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0x00, 0x00
                        };
                        _effect = Effect.FromMemory(Drawing.Direct3DDevice, compiledEffect, ShaderFlags.None);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        return;
                    }

                    #endregion

                    _technique = _effect.GetTechnique(0);

                    Drawing.OnPreReset += delegate { _effect.OnLostDevice(); };
                    Drawing.OnPostReset += delegate { _effect.OnResetDevice(); };
                    AppDomain.CurrentDomain.DomainUnload += delegate
                    {
                        _effect.Dispose();
                        _vertices.Dispose();
                        _vertexDeclaration.Dispose();
                    };
                }

                if (_vertices.IsDisposed || _vertexDeclaration.IsDisposed || _effect.IsDisposed)
                {
                    return;
                }

                var olddec = Drawing.Direct3DDevice.VertexDeclaration;

                _effect.Technique = _technique;

                _effect.Begin();
                _effect.BeginPass(0);
                _effect.SetValue(
                    "ProjectionMatrix", Matrix.Translation(position.SwitchYZ()) * Drawing.View * Drawing.Projection);
                _effect.SetValue(
                    "CircleColor", new Vector4(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f));
                _effect.SetValue("Radius", radius);
                _effect.SetValue("Border", 2f + width);
                _effect.SetValue("zEnabled", zDeep);

                Drawing.Direct3DDevice.SetStreamSource(0, _vertices, 0, Utilities.SizeOf<Vector4>() * 2);
                Drawing.Direct3DDevice.VertexDeclaration = _vertexDeclaration;

                Drawing.Direct3DDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);

                _effect.EndPass();
                _effect.End();

                Drawing.Direct3DDevice.VertexDeclaration = olddec;
            }
Пример #3
0
        /// <summary>
        /// Draws a filled Circle
        /// </summary>
        /// <param name="x">Position X</param>
        /// <param name="y">Position Y</param>
        /// <param name="rad">Radius</param>
        /// <param name="rotate">Rotation 0 - 360</param>
        /// <param name="type">Circle Type</param>
        /// <param name="smoothing">Smooth Antialiasing</param>
        /// <param name="resolution">Real smooth value</param>
        /// <param name="color">Color</param>
        public static void DrawCircleFilled(float x, float y, float rad, float rotate, CircleType type, bool smoothing, int resolution, Color color)
        {
            VertexBuffer vertices = new VertexBuffer(
             Drawing.Direct3DDevice, Utilities.SizeOf<Vector4>() * 2 * (resolution + 4), Usage.WriteOnly, VertexFormat.Diffuse | VertexFormat.PositionRhw, Pool.Default);

            double angle = rotate * Math.PI / 180d;
            double pi = 0.0d;

            if (type == CircleType.Full) pi = Math.PI;        // Full circle
            if (type == CircleType.Half) pi = Math.PI / 2d;      // 1/2 circle
            if (type == CircleType.Quarter) pi = Math.PI / 4d;   // 1/4 circle

            List<Vector4> data = new List<Vector4>(new []
                                                        {
                                                            new Vector4(x, y, 0f, 1f), color.ToVector4() 
                                                        });

            for (int i = 1; i < resolution + 4; i++)
            {
                float x1 = (float)(x - rad * Math.Cos(pi * ((i - 1) / (resolution / 2.0f))));
                float y1 = (float)(y - rad * Math.Sin(pi * ((i - 1) / (resolution / 2.0f))));
                data.AddRange(new[]
                    {
                        new Vector4(x1, y1, 0f, 1.0f), color.ToVector4()
                    });
            }

            // Rotate matrix
            int res = 2 * resolution + 4;
            for (int i = 0; i < res; i = i + 2)
            {
                data[i] = new Vector4((float)(x + Math.Cos(angle) * (data[i].X - x) - Math.Sin(angle) * (data[i].Y - y)),
                    (float)(y + Math.Sin(angle) * (data[i].X - x) + Math.Cos(angle) * (data[i].Y - y)),
                    data[i].Z, data[i].W);
            }

            vertices.Lock(0, Utilities.SizeOf<Vector4>() * 2 * (resolution + 4), LockFlags.None).WriteRange(data.ToArray());
            vertices.Unlock();

            VertexElement[] vertexElements = {
                    new VertexElement(
                        0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                    new VertexElement(
                        0, 16, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                    VertexElement.VertexDeclarationEnd
            };

            VertexDeclaration vertexDeclaration = new VertexDeclaration(Drawing.Direct3DDevice, vertexElements);

            if (smoothing)
            {
                Drawing.Direct3DDevice.SetRenderState(RenderState.MultisampleAntialias, true);
                Drawing.Direct3DDevice.SetRenderState(RenderState.AntialiasedLineEnable, true);
            }
            else
            {
                Drawing.Direct3DDevice.SetRenderState(RenderState.MultisampleAntialias, false);
                Drawing.Direct3DDevice.SetRenderState(RenderState.AntialiasedLineEnable, false);
            }

            var olddec = Drawing.Direct3DDevice.VertexDeclaration;
            Drawing.Direct3DDevice.SetStreamSource(0, vertices, 0, Utilities.SizeOf<Vector4>() * 2);
            Drawing.Direct3DDevice.VertexDeclaration = vertexDeclaration;
            Drawing.Direct3DDevice.DrawPrimitives(PrimitiveType.TriangleFan, 0, resolution);
            Drawing.Direct3DDevice.VertexDeclaration = olddec;

            vertexDeclaration.Dispose();
            vertices.Dispose();
        }
Пример #4
0
        /// <summary>
        ///     Draws a Gradient.
        /// </summary>
        /// <param name="x">Position X</param>
        /// <param name="y">Position Y</param>
        /// <param name="width">Width</param>
        /// <param name="height">Height</param>
        /// <param name="startCol">Starting Color</param>
        /// <param name="endCol">Ending Color</param>
        /// <param name="orientation">Orientation</param>
        public void GradientRect(
            float x,
            float y,
            float width,
            float height,
            ColorBGRA startCol,
            ColorBGRA endCol,
            Orientation orientation)
        {
            var vertices = new VertexBuffer(
                Drawing.Direct3DDevice,
                SharpDX.Utilities.SizeOf<Vector4>() * 2 * 4,
                Usage.WriteOnly,
                VertexFormat.Diffuse | VertexFormat.PositionRhw,
                Pool.Default);

            vertices.Lock(0, 0, LockFlags.None)
                .WriteRange(
                    new[]
                        {
                            new Vector4(x, y, 0f, 1.0f), startCol.ToVector4(), new Vector4(x + width, y, 0f, 1.0f),
                            orientation == Orientation.Vertical ? endCol.ToVector4() : startCol.ToVector4(),
                            new Vector4(x, y + height, 0f, 1.0f),
                            orientation == Orientation.Vertical ? startCol.ToVector4() : endCol.ToVector4(),
                            new Vector4(x + width, y + height, 0f, 1.0f), endCol.ToVector4()
                        });
            vertices.Unlock();

            VertexElement[] vertexElements =
                {
                    new VertexElement(
                        0,
                        0,
                        DeclarationType.Float4,
                        DeclarationMethod.Default,
                        DeclarationUsage.Position,
                        0),
                    new VertexElement(
                        0,
                        16,
                        DeclarationType.Float4,
                        DeclarationMethod.Default,
                        DeclarationUsage.Color,
                        0),
                    VertexElement.VertexDeclarationEnd
                };

            var vertexDeclaration = new VertexDeclaration(Drawing.Direct3DDevice, vertexElements);

            var olddec = Drawing.Direct3DDevice.VertexDeclaration;
            Drawing.Direct3DDevice.SetStreamSource(0, vertices, 0, SharpDX.Utilities.SizeOf<Vector4>() * 2);
            Drawing.Direct3DDevice.VertexDeclaration = vertexDeclaration;
            Drawing.Direct3DDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            Drawing.Direct3DDevice.VertexDeclaration = olddec;

            vertexDeclaration.Dispose();
            vertices.Dispose();
        }
Пример #5
0
        private static void Main(string[] args)
        {
            #region Variables
            if (args.Length == 3 && args[0] == "-r" && int.TryParse(args[1], out resolution[0]) &&
                int.TryParse(args[2], out resolution[1])) { }
            int menu_running = 1;
            // 0 -> jeu en cours
            // 1 -> menu de demarrage
            // 2 -> menu de jeu
            #endregion

            #region Fenêtre
            form = new RenderForm("Underground - Horror game");
            form.Width = resolution[0];
            form.Height = resolution[1];

            // Intro
            panel1 = new Panel();
            panel1.Name = "panel1";
            panel1.Size = new System.Drawing.Size(resolution[0], resolution[1]);
            panel1.TabIndex = 1;
            form.Controls.Add(panel1);

            m_play = new DxPlay(panel1, @"Ressources\Video\UndergroundPS.avi");
            //m_play = new DxPlay(panel1, @"Ressources\Video\UndergrounFinal_Introduction_vidonly.avi");

            // Fonction à éxécuter après
            m_play.StopPlay += new DxPlay.DxPlayEvent(MediaPlayer.Fin_intro);

            Direct3D direct3D = new Direct3D();
            PresentParameters Parametres = new PresentParameters(
                form.Width,
                form.Height,
                Format.X8R8G8B8,
                1,
                MultisampleType.None,
                0,
                SwapEffect.Discard,
                IntPtr.Zero,
                true,
                true,
                Format.D24X8,
                PresentFlags.None,
                0,
                PresentInterval.Immediate);
            input = new Input(form);
            device = new Device(direct3D, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, Parametres);
            vertexElems3D = new[] {
                new VertexElement(0, // POSITION
                    0,
                    DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                new VertexElement(0, // TEXCOORD0
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()),
                    DeclarationType.Float2, DeclarationMethod.Default,DeclarationUsage.TextureCoordinate,0),
                new VertexElement(0, // COLOR0
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector2>()),
                    DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                new VertexElement(0, // NORMAL0
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector2>()+Utilities.SizeOf<Vector4>()),
                    DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
                new VertexElement(0, // TANGENT
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector2>()+Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector4>()),
                    DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
                VertexElement.VertexDeclarationEnd,
                new VertexElement(0, // booléen de bump mapping
                    Convert.ToInt16(Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector2>()+Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector4>()+Utilities.SizeOf<Vector4>()),
                    DeclarationType.Float1, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                VertexElement.VertexDeclarationEnd,
            };
            vertexElems2D = new[] {
                new VertexElement(0,0,DeclarationType.Float4,DeclarationMethod.Default,DeclarationUsage.PositionTransformed,0),
                new VertexElement(0,16,DeclarationType.Float2,DeclarationMethod.Default,DeclarationUsage.TextureCoordinate,0),
                VertexElement.VertexDeclarationEnd
            };

            VertexDeclaration3D = new VertexDeclaration(Program.device, Program.vertexElems3D);
            VertexDeclaration2D = new VertexDeclaration(Program.device, Program.vertexElems2D);
            VertexBufferZero = new VertexBuffer(IntPtr.Zero);

            device.VertexDeclaration = VertexDeclaration3D;

            Program.device.SetRenderState(RenderState.AlphaBlendEnable, true); // graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true;
            Program.device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); // graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One;
            Program.device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); // graphics.GraphicsDevice.RenderState.SourceBlend = Blend.One;
            Program.device.SetRenderState(RenderState.AlphaFunc, BlendOperation.Maximum); // graphics.GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add;
            Program.device.SetRenderState(RenderState.AlphaTestEnable, true);
            Program.device.SetRenderState(RenderState.MinTessellationLevel, 8);
            #endregion

            Liste_textures = new List<structTexture>();
            Liste_binaires = new List<structBinary>();
            Liste_OBJ = new List<structOBJ>();
            Liste_Lights = new Light[2];
            Liste_Lights[0].Type = LightType.Point;
            Liste_Lights[0].Position = new Vector3(0, 0, 0);
            Liste_Lights[0].Ambient = new Color4(0.5f, 0.5f, 0.5f, 1);
            Liste_Lights[0].Range = 30f * 70;
            Liste_Lights[1].Type = LightType.Point;
            Liste_Lights[1].Position = new Vector3(-100, -100, -100);
            Liste_Lights[1].Ambient = new Color4(0.5f,0,0,1);
            Liste_Lights[1].Range = 5f * 70;
            Liste_textures.Add(new structTexture("null.bmp", Texture.FromFile(device, "null.bmp")));
            //Ingame.Slender.doit_etre_recharge = true;

            // Creation du fichier effect de référence
            Macro macro = new Macro("nblights", 2.ToString());
            BaseEffect = Effect.FromFile(Program.device, "Underground.fx", new Macro[] { macro }, null, "", ShaderFlags.OptimizationLevel3);
            BaseEffect.Technique = BaseEffect.GetTechnique(0);
            BaseEffect.SetValue("AmbientLightColor", new Vector4(0f, 0f, 0f, 0f));
            Matrix proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, Program.form.ClientSize.Width / (float)Program.form.ClientSize.Height, 0.1f, 7000.0f);
            BaseEffect.SetValue("Projection", proj);
            BaseEffect.SetValue("LightDiffuseColor[0]", Liste_Lights[0].Ambient);
            BaseEffect.SetValue("LightDiffuseColor[1]", Liste_Lights[1].Ambient);
            BaseEffect.SetValue("LightDistanceSquared[1]", Liste_Lights[1].Range);

            Thread ThSound = new Thread(Sound.main);
            Thread ThEvents = new Thread(Ingame.fevents);
            ThSound.Start();
            ThEvents.Start();

            Menu.Initialize_Menu();
            ObjLoader.Initialize();
            newmaze = new Maze(10, 10);
            newmaze.Initecelles();
            newmaze.Generate(newmaze.maze[0, 0]);
            newmaze.impefectGenerate();
            newmaze.Setaffichage();

            Ingame.ingame();

            Menu.Dispose();
            ThSound.Abort();
            ThEvents.Abort();
            VertexBufferZero.Dispose();
            VertexDeclaration3D.Dispose();
            VertexDeclaration2D.Dispose();
            device.Dispose();
            direct3D.Dispose();
        }
Пример #6
0
        /// <summary>
        ///     Draws a Circle (not filled)
        /// </summary>
        /// <param name="x">Position X</param>
        /// <param name="y">Position Y</param>
        /// <param name="radius">Radius</param>
        /// <param name="rotate">Rotation 0 - 360</param>
        /// <param name="type">Circle Type</param>
        /// <param name="smoothing">Smooth Antialiasing</param>
        /// <param name="resolution">Real smooth value</param>
        /// <param name="color">Color</param>
        public static void DrawCircle(
            float x,
            float y,
            float radius,
            int rotate,
            CircleType type,
            bool smoothing,
            int resolution,
            Color color)
        {
            var vertices = new VertexBuffer(
                Drawing.Direct3DDevice9,
                Utilities.SizeOf<Vector4>() * 2 * (resolution + 2),
                Usage.WriteOnly,
                VertexFormat.Diffuse | VertexFormat.PositionRhw,
                Pool.Default);

            var angle = rotate * (float)Math.PI / 180f;
            var pi = 0.0f;

            if (type == CircleType.Full)
            {
                pi = (float)Math.PI; // Full circle
            }

            if (type == CircleType.Half)
            {
                pi = (float)Math.PI / 2f; // 1/2 circle
            }

            if (type == CircleType.Quarter)
            {
                pi = (float)Math.PI / 4f; // 1/4 circle
            }

            var data = new List<Vector4>();

            for (var i = 0; i < resolution + 2; i++)
            {
                var x1 = x - (radius * (float)Math.Cos(i * (2f * pi / resolution)));
                var y1 = y - (radius * (float)Math.Sin(i * (2f * pi / resolution)));
                data.AddRange(new[] { new Vector4(x1, y1, 0f, 1.0f), color.ToVector4() });
            }

            // Rotate matrix
            var res = (2 * resolution) + 2;
            for (var i = 0; i < res; i = i + 2)
            {
                data[i] =
                    new Vector4(
                        (float)(x + (Math.Cos(angle) * (data[i].X - x)) - (Math.Sin(angle) * (data[i].Y - y))),
                        (float)(y + (Math.Sin(angle) * (data[i].X - x)) + (Math.Cos(angle) * (data[i].Y - y))),
                        data[i].Z,
                        data[i].W);
            }

            vertices.Lock(0, 0, LockFlags.None).WriteRange(data.ToArray());
            vertices.Unlock();

            VertexElement[] vertexElements =
                {
                    new VertexElement(
                        0,
                        0,
                        DeclarationType.Float4,
                        DeclarationMethod.Default,
                        DeclarationUsage.Position,
                        0),
                    new VertexElement(
                        0,
                        16,
                        DeclarationType.Float4,
                        DeclarationMethod.Default,
                        DeclarationUsage.Color,
                        0),
                    VertexElement.VertexDeclarationEnd
                };

            var vertexDeclaration = new VertexDeclaration(Drawing.Direct3DDevice9, vertexElements);

            if (smoothing)
            {
                Drawing.Direct3DDevice9.SetRenderState(RenderState.MultisampleAntialias, true);
                Drawing.Direct3DDevice9.SetRenderState(RenderState.AntialiasedLineEnable, true);
            }

            var olddec = Drawing.Direct3DDevice9.VertexDeclaration;
            Drawing.Direct3DDevice9.SetStreamSource(0, vertices, 0, Utilities.SizeOf<Vector4>() * 2);
            Drawing.Direct3DDevice9.VertexDeclaration = vertexDeclaration;
            Drawing.Direct3DDevice9.DrawPrimitives(PrimitiveType.LineStrip, 0, resolution);
            Drawing.Direct3DDevice9.VertexDeclaration = olddec;

            vertexDeclaration.Dispose();
            vertices.Dispose();
        }