public Action<Vector3, bool>[] CreateRenderables(int count)
 {
     var ids = Dynamight.ImageProcessing.CameraCalibration.Range.OfInts(count);
     objects = ids.Select(_ => new Renderable()
     {
         Shape = new Quad(new Vector3(0, 0.0f, 0f), 0.25f, defaultE1, defaultE2, (v) => textures.Transform(v, 0)),
         Animatable = translator = new Translator() // new RadialSpin(new Vector3(0.2f,0,0))
     }).ToArray();
     renderer = new Renderer(null, objects);
     renderer.Load();
     renderer.Start();
     return ids.Select(i =>
     {
         return (Action<Vector3, bool>)((v, visible) =>
         {
             var r = objects[i];
             (r.Animatable as Translator).SetPosition(v);
             r.Visible = visible;
         });
     }).ToArray();
 }
示例#2
0
        public override void Load(ProgramWindow parent)
        {
            parent.MakeCurrent();
            base.Load(parent);
            GL.Disable(EnableCap.Dither);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.DstAlpha);
            GL.ClearColor(System.Drawing.Color.FromArgb(0,0,0,0));
            var vs = parent.CreateShader(ShaderType.VertexShader, VSLighting);
            var fs = parent.CreateShader(ShaderType.FragmentShader, FSLighting);
            program = parent.CreateProgram(vs, fs);
            GL.DeleteShader(vs);
            GL.DeleteShader(fs);
            dynamicProgram.Load();

            textures = new MultipleTextures(this);
            Bitmap white = new Bitmap(101, 101);
            QuickDraw.Start(white)
                .Fill(Color.White).Finish();
            Bitmap gridBot = new Bitmap(101, 101);
            QuickDraw.Start(gridBot)
                .All((x, y) =>
                {
                    var lpp = 10;
                    var xm = x % lpp;
                    var ym = y % lpp;
                    if (xm == 0 || ym == 0)
                        return Color.Gray;
                    return Color.FromArgb(150, 50, 50, 50);
                }, false).Finish();
            Bitmap[] maps = new Bitmap[] {
                white, gridBot
            };
            textures.Load(maps);

            if (lightStudio != null)
                lights = lightStudio.Lights;
            else
                lights = new MoveableLights(8);

            dynamicRenderer = new Renderer(dynamics = (Dynamight.ImageProcessing.CameraCalibration.Range.OfInts(6)).Select(_ => new DynamicRenderable()).ToArray());
            staticRenderer = new Renderer(null, (new Renderable[] {
                Grid = new Renderable() {
                    Visible = false,
                    Shape = new Quad(new Vector3(0,0,0), 10, new Vector3(1,0,0), new Vector3(0,0,1), (v) => textures.Transform(v, 1)),
                    Animatable = new Translator()
                },
            }).Concat(LightsObjects = lights.Select(l => new LightRenderable(l, (v) => textures.Transform(v, 0))).ToArray()).ToArray());
            windowSize = parent.Size;
            SetupCamera();

            staticRenderer.Load();
            dynamicRenderer.Load();
            staticRenderer.Start();
            dynamicRenderer.Start();

            keyl = new KeyboardListener(parent.Keyboard);

            keyl.AddAction(() => Selection = (Selection == null ? (int?)1 : null), Key.C);

            keyl.AddAction(() => Grid.Visible = !Grid.Visible, Key.G);

            keyl.AddBinaryAction(0.01f, -0.01f, Key.Right, Key.Left, null, (f) => MoveX(f));
            keyl.AddBinaryAction(0.01f, -0.01f, Key.Down, Key.Up, null, (f) => MoveY(f));
            keyl.AddBinaryAction(0.01f, -0.01f, Key.Down, Key.Up, new Key[] { Key.ShiftLeft }, (f) => MoveZ(f));

            keyl.AddBinaryAction(0.05f, -0.05f, Key.Right, Key.Left, new Key[] { Key.ControlLeft }, (f) => MoveX(f));
            keyl.AddBinaryAction(0.05f, -0.05f, Key.Down, Key.Up, new Key[] { Key.ControlLeft }, (f) => MoveY(f));
            keyl.AddBinaryAction(0.05f, -0.05f, Key.Down, Key.Up, new Key[] { Key.ShiftLeft, Key.ControlLeft }, (f) => MoveZ(f));

            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Light0);
            GL.Enable(EnableCap.Light1);
            GL.Enable(EnableCap.Light2);
            GL.Enable(EnableCap.Light3);
            GL.Enable(EnableCap.Light4);
            GL.Enable(EnableCap.Light5);
            GL.Enable(EnableCap.Light6);
            GL.Enable(EnableCap.Light7);
        }
        public override void Load(ProgramWindow parent)
        {
            base.Load(parent);

            // Setup parameters for Points
            GL.Enable(EnableCap.Blend);
            GL.Disable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.CullFace(CullFaceMode.Back);
            textures = new MultipleTextures(this);
            Bitmap[] maps = new Bitmap[4];
            {
                var bitmap = new Bitmap(300, 300);

                QuickDraw.Start(bitmap).All((xp, yp) =>
                {
                    var x = 0.5 - xp;
                    var y = 0.5 - yp;
                    var i = Math.Sqrt(x * x + y * y);
                    if (i > 1)
                        i = 1;
                    i = Math.Pow(1 - i, 1);
                    i += 0.4;
                    if (i > 1)
                        i = 1;
                    else
                        i = Math.Pow(i, 29);
                    byte ii = (byte)(i * 255);
                    return Color.FromArgb(ii, 245, 150, 135);
                }).Finish();
                maps[0] = bitmap;
            }
            {
                var bitmap = new Bitmap(300, 300);

                QuickDraw.Start(bitmap).All((xp, yp) =>
                {
                    var x = 0.5 - xp;
                    var y = 0.5 - yp;
                    var i = Math.Sqrt(x * x + y * y);
                    i = (Math.Sin(i * Math.PI * 8) + 1) / 2.0;
                    byte ii = (byte)(i * 255);
                    return Color.FromArgb(ii, 245, 150, 135);
                }).Finish();
                maps[1] = bitmap;
                maps[2] = bitmap;
                maps[3] = bitmap;
            }

            textures.Load(maps);
            renderer = new Renderer();
        }