示例#1
0
        public void Start(GLWinFormControl glwfc)
        {
            this.glwfc = glwfc;

            matrixcalc = new GLMatrixCalc();
            matrixcalc.PerspectiveNearZDistance = 1f;
            matrixcalc.PerspectiveFarZDistance  = worldsize * 2;
            matrixcalc.InPerspectiveMode        = true;
            matrixcalc.ResizeViewPort(this, glwfc.Size);

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");                         // create a matrix uniform block

            displaycontrol           = new GLControlDisplay(items, glwfc, matrixcalc); // hook form to the window - its the master, it takes its size from mc.ScreenCoordMax
            displaycontrol.Focusable = true;                                           // we want to be able to focus and receive key presses.
            displaycontrol.Name      = "displaycontrol";
            displaycontrol.Font      = new Font("Arial", 12);

            gl3dcontroller = new Controller3Dd();
            gl3dcontroller.PaintObjects          = ControllerDraw;
            gl3dcontroller.ZoomDistance          = 20e6 * 1000 * mscaling; // zoom 1 is X km
            gl3dcontroller.PosCamera.ZoomMin     = 0.001f;
            gl3dcontroller.PosCamera.ZoomMax     = 300f;
            gl3dcontroller.PosCamera.ZoomScaling = 1.08f;
            gl3dcontroller.Start(matrixcalc, displaycontrol, new Vector3d(0, 0, 0), new Vector3d(135f, 0, 0f), 0.025F, registermouseui: false, registerkeyui: true);
            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                double eyedistr = Math.Pow(eyedist, 1.0);
                float  v        = (float)Math.Max(eyedistr / 1200, 0);
                //System.Diagnostics.Debug.WriteLine("Speed " + eyedistr + " "+ v);
                return((float)ms * v);
            };

            for (int i = 1; i <= 10; i++)
            {
                int    v = i * i;
                double f = (gl3dcontroller.PosCamera.ZoomMax - gl3dcontroller.PosCamera.ZoomMin) * v / 100.0 + gl3dcontroller.PosCamera.ZoomMin;
                System.Diagnostics.Debug.WriteLine($"{i} {v} {f}");
            }

            displaycontrol.Paint += (o, ts) =>        // subscribing after Controller start means we paint over the scene
            {
                // MCUB set up by Controller3DDraw which did the work first
                //     System.Diagnostics.Debug.WriteLine("Controls Draw");
                displaycontrol.Render(glwfc.RenderState, ts);
            };

            displaycontrol.MouseClick += MouseClickOnMap;       // grab mouse UI
            displaycontrol.MouseUp    += MouseUpOnMap;
            displaycontrol.MouseDown  += MouseDownOnMap;
            displaycontrol.MouseMove  += MouseMoveOnMap;
            displaycontrol.MouseWheel += MouseWheelOnMap;

            double  startspeed = 60 * 60 * 6; // in sec
            GLImage minus      = new GLImage("timeplus1y", new Rectangle(0, 0, 32, 32), Properties.Resources.GoBackward);

            minus.MouseClick += (e1, m1) => { currentjd -= 365; };
            displaycontrol.Add(minus);
            GLImage back = new GLImage("timeback", new Rectangle(40, 0, 32, 32), Properties.Resources.Backwards);

            back.MouseClick += (e1, m1) => { if (jdscaling > 0)
                                             {
                                                 jdscaling /= 2;
                                             }
                                             else if (jdscaling < 0)
                                             {
                                                 jdscaling *= 2;
                                             }
                                             else
                                             {
                                                 jdscaling = -startspeed;
                                             } };
            displaycontrol.Add(back);
            GLImage pause = new GLImage("timepause", new Rectangle(80, 0, 32, 32), Properties.Resources.Pause);

            pause.MouseClick += (e1, m1) => { jdscaling = 0; };
            displaycontrol.Add(pause);
            GLImage fwd = new GLImage("timefwd", new Rectangle(120, 0, 32, 32), Properties.Resources.Forward);

            fwd.MouseClick += (e1, m1) => { if (jdscaling < 0)
                                            {
                                                jdscaling /= 2;
                                            }
                                            else if (jdscaling > 0)
                                            {
                                                jdscaling *= 2;
                                            }
                                            else
                                            {
                                                jdscaling = startspeed;
                                            } };
            displaycontrol.Add(fwd);
            GLImage plus = new GLImage("timeplus1y", new Rectangle(160, 0, 32, 32), Properties.Resources.GoForward);

            plus.MouseClick += (e1, m1) => { currentjd += 365; };
            displaycontrol.Add(plus);

            GLImage sysleft = new GLImage("sysleft", new Rectangle(200, 0, 32, 32), Properties.Resources.GoBackward);

            sysleft.MouseClick += (e1, m1) => { DisplayNode(-1); };
            displaycontrol.Add(sysleft);

            mastersystem           = new GLLabel("sysname", new Rectangle(230, 6, 70, 20), "All", Color.DarkOrange);
            mastersystem.TextAlign = ContentAlignment.MiddleCenter;
            displaycontrol.Add(mastersystem);

            GLImage sysright = new GLImage("sysright", new Rectangle(300, 0, 32, 32), Properties.Resources.GoForward);

            sysright.MouseClick += (e1, m1) => { DisplayNode(1); };
            displaycontrol.Add(sysright);

            timedisplay = new GLLabel("state", new Rectangle(340, 6, 800, 20), "Label", Color.DarkOrange);
            displaycontrol.Add(timedisplay);

            datalabel           = new GLLabel("datalabel", new Rectangle(0, 40, 400, 100), "", Color.DarkOrange);
            datalabel.TextAlign = ContentAlignment.TopLeft;
            displaycontrol.Add(datalabel);

            status           = new GLLabel("Status", new Rectangle(0, 0, 2000, 24), "x");
            status.Dock      = DockingType.BottomLeft;
            status.ForeColor = Color.Orange;
            status.BackColor = Color.FromArgb(50, 50, 50, 50);
            displaycontrol.Add(status);

            rightclickmenubody = new GLContextMenu("RightClickMenuBody",
                                                   new GLMenuItem("RCMInfo", "Information")
            {
                MouseClick = (s, e) =>
                {
                }
            },
                                                   new GLMenuItem("RCMZoomIn", "Track")
            {
                MouseClick = (s, e) =>
                {
                    track = (int)rightclickmenubody.Tag;
                }
            },
                                                   new GLMenuItem("RCMZoomIn", "Track Central Body")
            {
                MouseClick = (s, e) =>
                {
                    int body = (int)rightclickmenubody.Tag;
                    if (bodyinfo[body].parentindex >= 0)
                    {
                        track = bodyinfo[body].parentindex;
                    }
                }
            },
                                                   new GLMenuItem("RCMZoomIn", "Zoom In")
            {
            },
                                                   new GLMenuItem("RCMUntrack", "Untrack")
            {
                MouseClick = (s1, e1) =>
                {
                    track = -1;
                }
            }
                                                   );

            rightclickmenubody.Opening += (ms, tag) =>
            {
                ms["RCMUntrack"].Enabled = track != -1;
            };

            rightclickmenuscreen = new GLContextMenu("RightClickMenuBody",
                                                     new GLMenuItem("RCMSysDisplay", "System Display")
            {
                MouseClick = (s, e) =>
                {
                }
            },
                                                     new GLMenuItem("RCMUntrack", "Untrack")
            {
                MouseClick = (s1, e1) =>
                {
                    track = -1;
                }
            }
                                                     );

            rightclickmenuscreen.Opening += (ms, tag) =>
            {
                ms["RCMUntrack"].Enabled = track != -1;
            };

            if (true)
            {
                var shader = new GLColorShaderWorld();
                items.Add(shader);

                GLRenderState lines = GLRenderState.Lines(1);
                lines.DepthTest = false;

                int gridsize   = (int)(worldsize * mscaling);
                int gridoffset = (int)(gridlines * mscaling);
                int nolines    = gridsize / gridoffset * 2 + 1;

                Color gridcolour = Color.FromArgb(80, 80, 80, 80);
                rObjects.Add(shader,
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-gridsize, -0, -gridsize), new Vector3(-gridsize, -0, gridsize), new Vector3(gridoffset, 0, 0), nolines),
                                                                  new Color4[] { gridcolour })
                             );


                rObjects.Add(shader,
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-gridsize, -0, -gridsize), new Vector3(gridsize, -0, -gridsize), new Vector3(0, 0, gridoffset), nolines),
                                                                  new Color4[] { gridcolour }));

                Size bmpsize = new Size(128, 30);
                var  maps    = new GLBitmaps("bitmap1", rObjects, bmpsize, 3, OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, false, false);
                using (StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap)
                {
                    Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center
                })
                {
                    float hsize = 40e6f * 1000 * mscaling; // million km -> m -> scaling
                    float vsize = hsize * bmpsize.Height / bmpsize.Width;

                    Font f   = new Font("MS sans serif", 12f);
                    long pos = -nolines / 2 * (gridlines / 1000);
                    for (int i = -nolines / 2; i < nolines / 2; i++)
                    {
                        if (i != 0)
                        {
                            double v = Math.Abs(pos * 1000);
                            long   p = Math.Abs(pos);

                            maps.Add(i, (p).ToString("N0"), f, Color.White, Color.Transparent, new Vector3(i * gridoffset + hsize / 2, 0, vsize / 2),
                                     new Vector3(hsize, 0, 0), new Vector3(0, 0, 0), fmt);
                            maps.Add(i, (v / oneAU_m).ToString("N1") + "AU", f, Color.White, Color.Transparent, new Vector3(i * gridoffset + hsize / 2, 0, -vsize / 2),
                                     new Vector3(hsize, 0, 0), new Vector3(0, 0, 0), fmt);
                            maps.Add(i, (p).ToString("N0"), f, Color.White, Color.Transparent, new Vector3(hsize / 2, 0, i * gridoffset + vsize / 2),
                                     new Vector3(hsize, 0, 0), new Vector3(0, 0, 0), fmt);
                            maps.Add(i, (v / oneAU_m).ToString("N1") + "AU", f, Color.White, Color.Transparent, new Vector3(hsize / 2, 0, i * gridoffset - vsize / 2),
                                     new Vector3(hsize, 0, 0), new Vector3(0, 0, 0), fmt);
                        }
                        pos += 50000000;
                    }
                }
            }

            var orbitlinesvertshader = new GLPLVertexShaderModelWorldUniform(new Color[] { Color.FromArgb(128, 128, 0, 0), Color.FromArgb(128, 128, 128, 0) });

            orbitlineshader = new GLShaderPipeline(orbitlinesvertshader, new GLPLFragmentShaderVSColor());
            bodyplaneshader = new GLShaderPipeline(orbitlinesvertshader, new GLPLFragmentShaderVSColor());  // model pos in, with uniform world pos, vectors out, with vs_colour selected by worldpos.w

            // set up ARB IDs for all images we are going to use..
            var tbs   = items.NewBindlessTextureHandleBlock(arbblock);
            var texs  = items.NewTexture2D(null, Properties.Resources.golden, SizedInternalFormat.Rgba8);
            var texp  = items.NewTexture2D(null, Properties.Resources.moonmap1k, SizedInternalFormat.Rgba8);
            var texb  = items.NewTexture2D(null, Properties.Resources.dotted, SizedInternalFormat.Rgba8);
            var texs2 = items.NewTexture2D(null, Properties.Resources.wooden, SizedInternalFormat.Rgba8);

            tbs.WriteHandles(new IGLTexture[] { texs, texp, texb, texs2 });

            // using 0 tex coord, 4 image id and arb text binding
            var bodyfragshader = new GLPLFragmentShaderBindlessTexture(arbblock, discardiftransparent: true, useprimidover2: false);

            // takes 0:Vector4 model, 1: vec2 text, 4:matrix, out is 0:tex, 1: modelpos, 2: instance, 4 = matrix[3][3]
            var bodyvertshader = new GLPLVertexShaderModelMatrixTexture(1000000 * 1000 * mscaling, useeyedistance: false);

            bodyshader = new GLShaderPipeline(bodyvertshader, bodyfragshader);
            items.Add(bodyshader);

            // hold shape
            var sphereshape = GLSphereObjectFactory.CreateTexturedSphereFromTriangles(3, 1.0f);

            spherebuffer = items.NewBuffer();      // fill buffer with model co-ords
            spherebuffer.AllocateFill(sphereshape.Item1);
            spheretexcobuffer = items.NewBuffer(); // fill buffer with tex coords
            spheretexcobuffer.AllocateFill(sphereshape.Item2);

            bodymatrixbuffer = items.NewBuffer();    // this holds the matrix to set position and size

            GLStorageBlock findbufferresults = items.NewStorageBlock(findblock);
            var            geofind           = new GLPLGeoShaderFindTriangles(findbufferresults, 16); // pass thru normal vert/tcs/tes then to geoshader for results

            findshader = items.NewShaderPipeline(null, bodyvertshader, null, null, geofind, null, null, null);
        }
示例#2
0
        public void CreateObjects(GLItemsList items, GLRenderProgramSortedList rObjects, GalacticMapping galmap, GLStorageBlock findbufferresults, bool depthtest)
        {
            this.galmap = galmap;

            // first gets the images and make a 2d array texture for them

            Bitmap[] images = galmap.RenderableMapTypes.Select(x => x.Image as Bitmap).ToArray();
            // 256 is defined normal size
            var        objtex   = new GLTexture2DArray(images, bmpmipmaplevels: 1, wantedmipmaplevels: 3, texturesize: new Size(256, 256), internalformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, alignment: ContentAlignment.BottomCenter);
            IGLTexture texarray = items.Add(objtex, "GalObjTex");

            // now build the shaders

            const int texbindingpoint = 1;
            var       vert            = new GLPLVertexScaleLookat(rotatetoviewer: dorotate, rotateelevation: doelevation, // a look at vertex shader
                                                                  autoscale: 500, autoscalemin: 1f, autoscalemax: 20f);   // below 500, 1f, above 500, scale up to 20x
            var tcs = new GLPLTesselationControl(40f);

            tes = new GLPLTesselationEvaluateSinewave(1f, 2f);                  // this uses the world position from the vertex scaler to position the image, w controls image + animation (b16)
            var frag = new GLPLFragmentShaderTexture2DDiscard(texbindingpoint); // binding - takes image pos from tes. imagepos < 0 means discard

            objectshader = new GLShaderPipeline(vert, tcs, tes, null, frag);
            items.Add(objectshader);

            objectshader.StartAction += (s, m) =>
            {
                texarray.Bind(texbindingpoint);   // bind tex array to, matching above
            };

            // now the RenderControl for the objects

            GLRenderState rt = GLRenderState.Patches(4);

            rt.DepthTest = depthtest;

            // create a quad and all entries of the renderable map objects, zero at this point, with a zero instance count. UpdateEnables will fill it in later
            // but we need to give it the maximum buffer length at this point

            const float objsize = 10.0f;        // size of object on screen

            ridisplay = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Patches, rt,
                                                              GLShapeObjectFactory.CreateQuadTriStrip(objsize, objsize), // quad2 4 vertexts
                                                              new Vector4[galmap.RenderableMapObjects.Length],           // world positions
                                                              ic: 0, seconddivisor: 1);

            modelworldbuffer = items.LastBuffer();
            int modelpos = modelworldbuffer.Positions[0];

            worldpos = modelworldbuffer.Positions[1];

            rObjects.Add(objectshader, "galmapobj", ridisplay);

            // add a find shader to look them up

            var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16);

            findshader = items.NewShaderPipeline(null, vert, tcs, tes, geofind, null, null, null);


            // hook to modelworldbuffer, at modelpos and worldpos.  UpdateEnables will fill in instance count
            rifind = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Patches, GLRenderState.Patches(4), modelworldbuffer, modelpos, ridisplay.DrawCount,
                                                           modelworldbuffer, worldpos, null, ic: 0, seconddivisor: 1);

            GLStatics.Check();

            // Text renderer for the labels

            textrenderer = new GLBitmaps("bm-galmapobjects", rObjects, new Size(128, 40), depthtest: depthtest, cullface: false, textureformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8);
            items.Add(textrenderer);

            // now make the text up for all the objects above

            using (Font fnt = new Font("Arial", 8.5F))
            {
                using (StringFormat fmt = new StringFormat())
                {
                    fmt.Alignment = StringAlignment.Center;

                    var renderablegalmapobjects = galmap.RenderableMapObjects; // list of enabled entries

                    List <Vector3> posset = new List <Vector3>();

                    float offscale = objsize * (0.5f + (float)textrenderer.BitmapSize.Height / (float)textrenderer.BitmapSize.Width / 2);       // this is the nominal centre of the text bitmap, offset in Y to the object

                    for (int i = 0; i < renderablegalmapobjects.Length; i++)
                    {
                        var   o      = renderablegalmapobjects[i];
                        float offset = -offscale;

                        for (int j = 0; j < i; j++)     // look up previous ones and see if we labeled it before
                        {
                            var d1   = new Vector3(o.points[0].X, o.points[0].Y + offset, o.points[0].Z);
                            var d2   = posset[j];   // where it was placed.
                            var diff = d1 - d2;

                            if (diff.Length < offscale) // close
                            {
                                if (offset > 0)         // if offset is positive, flip below and increase again
                                {
                                    offset = -offset - offscale;
                                }
                                else
                                {
                                    offset *= -1;       // flip over top
                                }
                                // System.Diagnostics.Debug.WriteLine($"close {renderablegalmapobjects[i].name} {d1} to {renderablegalmapobjects[j].name} {d2} {diff} select {offset}");
                            }
                        }

                        Vector3 pos = new Vector3(o.points[0].X, o.points[0].Y + offset, o.points[0].Z);
                        posset.Add(pos);
                        //System.Diagnostics.Debug.WriteLine($"{renderablegalmapobjects[i].name} at {pos} {offset}");

                        textrenderer.Add(o.id, o.name, fnt,
                                         Color.White, Color.FromArgb(0, 255, 0, 255),
                                         pos,
                                         new Vector3(objsize, 0, 0), new Vector3(0, 0, 0), textformat: fmt, rotatetoviewer: dorotate, rotateelevation: doelevation,
                                         alphafadescalar: -100, alphafadepos: 500); // fade in, alpha = 0 at >500, 1 at 400
                    }
                }
            }

            UpdateEnables();      // fill in worldpos's and update instance count, taking into
        }
示例#3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 1f;
            gl3dcontroller.MatrixCalc.PerspectiveFarZDistance  = 1000f;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(110f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 20.0f);
            };

            items.Add(new GLTexturedShaderObjectTranslation(), "TEXOT");
            items.Add(new GLTexturedShaderObjectTranslation(), "TEXOTNoRot");
            items.Add(new GLColorShaderWorld(), "COSW");
            items.Add(new GLColorShaderObjectTranslation(), "COSOT");
            items.Add(new GLFixedColorShaderObjectTranslation(Color.Goldenrod), "FCOSOT");
            items.Add(new GLTexturedShaderObjectCommonTranslation(), "TEXOCT");

            items.Add(new GLTexture2D(Properties.Resources.dotted, SizedInternalFormat.Rgba8), "dotted");
            items.Add(new GLTexture2D(Properties.Resources.Logo8bpp, SizedInternalFormat.Rgba8), "logo8bpp");
            items.Add(new GLTexture2D(Properties.Resources.dotted2, SizedInternalFormat.Rgba8), "dotted2");
            items.Add(new GLTexture2D(Properties.Resources.wooden, SizedInternalFormat.Rgba8), "wooden");
            items.Add(new GLTexture2D(Properties.Resources.shoppinglist, SizedInternalFormat.Rgba8), "shoppinglist");
            items.Add(new GLTexture2D(Properties.Resources.golden, SizedInternalFormat.Rgba8), "golden");
            items.Add(new GLTexture2D(Properties.Resources.smile5300_256x256x8, SizedInternalFormat.Rgba8), "smile");
            items.Add(new GLTexture2D(Properties.Resources.moonmap1k, SizedInternalFormat.Rgba8), "moon");

            #region coloured lines

            if (true)
            {
                GLRenderState lines = GLRenderState.Lines(1);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(-100, -0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed })
                             );


                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(100, -0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed }));
            }
            if (false)
            {
                GLRenderState lines = GLRenderState.Lines(1);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 10, -100), new Vector3(-100, 10, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Yellow, Color.Orange, Color.Yellow, Color.Orange })
                             );

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 10, -100), new Vector3(100, 10, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Yellow, Color.Orange, Color.Yellow, Color.Orange })
                             );
            }

            #endregion

            #region Coloured triangles
            if (true)
            {
                GLRenderState rc = GLRenderState.Tri();
                rc.CullFace = false;

                rObjects.Add(items.Shader("COSOT"), "scopen",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  GLCubeObjectFactory.CreateSolidCubeFromTriangles(2f),
                                                                  new Color4[] { Color4.Red, Color4.Green, Color4.Blue, Color4.White, Color4.Cyan, Color4.Orange },
                                                                  new GLRenderDataTranslationRotation(new Vector3(0, 0, 0))
                                                                  ));
                rObjects.Add(items.Shader("COSOT"), "scopen2",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  GLCubeObjectFactory.CreateSolidCubeFromTriangles(2f),
                                                                  new Color4[] { Color4.Red, Color4.Green, Color4.Blue, Color4.White, Color4.Cyan, Color4.Orange },
                                                                  new GLRenderDataTranslationRotation(new Vector3(10, 10, 10))
                                                                  ));
            }

            #endregion

            #region bitmap Renderer

            if (true)
            {
                using (StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap)
                {
                    Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                })
                {
                    Size    bitmapsize = new Size(128, 40);
                    Vector3 bannersize = new Vector3(20, 0, 0);
                    Font    f          = new Font("MS sans serif", 8f);

                    tim = new GLBitmaps("bitmap1", rObjects, bitmapsize, 3, OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, false, true, 2);      // group 2
                    items.Add(tim);
                    tim.Add("T1", "SingleTest", f, Color.White, Color.Red, new Vector3(10, 10, 10),
                            bannersize, new Vector3(0, 0, 0), fmt, alphafadescalar: 10, alphafadepos: 5, rotatetoviewer: true);
                }
            }


            if (false)
            {
                using (StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap)
                {
                    Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                })
                {
                    Size    bitmapsize = new Size(64, 20);
                    float   width      = 2.5f;
                    Vector3 bannersize = new Vector3(width, 0, 0);
                    Font    f          = new Font("MS sans serif", 8f);

                    tim = new GLBitmaps("bitmap1", rObjects, bitmapsize, 3, OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, false, true, 2);      // group 2
                    items.Add(tim);
                    tim.Add("T1", "MFred", f, Color.White, Color.Red, new Vector3(-10, 5, -10), bannersize, new Vector3(-90F.Radians(), 0, 0), fmt, alphafadescalar: 10, alphafadepos: 5);
                    tim.Add("T2", "MJim", f, Color.White, Color.Red, new Vector3(0, 5, -10), bannersize, new Vector3(0, 0, 0), fmt, rotatetoviewer: true);
                    tim.Add("T3", "MGeorge", f, Color.White, Color.Red, new Vector3(10, 5, -10), bannersize, new Vector3(0, 0, 0), fmt, rotatetoviewer: true, rotateelevation: true);
                    tim.Remove("T2");
                    tim.Add("T2a", "M2Jim", f, Color.White, Color.Red, new Vector3(0, 5, -10), bannersize, new Vector3(0, 0, 0), fmt, rotatetoviewer: true);
                    tim.Remove("T3");       // meaning group 2 should be empty .. test it
                    // tim.Add("T3a", "M2George", f, Color.White, Color.Red, new Vector3(10, 5, -10), bannersize, new Vector3(0, 0, 0), fmt, rotatetoviewer: true, rotateelevation: true);

                    tim2 = new GLBitmaps("bitmap2", rObjects, bitmapsize, 3, OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, false, true, 25);
                    items.Add(tim2);
                    for (int i = 0; i < 50; i++)
                    {
                        tim2.Add("i" + i.ToString(), "i" + i.ToString() + "!", f, Color.White, Color.Red,
                                 new Vector3((i % 10) * 10 - 50, 5, (i / 10) * 4), bannersize, new Vector3(0, 0, 0), fmt, rotatetoviewer: true, rotateelevation: true);
                    }

                    tim2.Clear();

                    for (int i = 0; i < 10000; i++)
                    {
                        tim2.Add("j" + i.ToString(), "j" + i.ToString() + "!", f, Color.White, Color.Red,
                                 new Vector3((i % 10) * 10 - 50, 5, (i / 10) * 4), bannersize, new Vector3(0, 0, 0), fmt, rotatetoviewer: true, rotateelevation: true);
                    }

                    //tim.Dispose(); // for test
                }
            }


            #endregion


            #region Matrix Calc Uniform

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");     // def binding of 0

            #endregion
        }
        public void CreateObjects(string name, GLItemsList items, GLRenderProgramSortedList rObjects, GalacticMapping galmap, float sizeofname = 5000, ManualCorrections[] corr = null)
        {
            List <Vector4> vertexcolourregions      = new List <Vector4>();
            List <Vector4> vertexregionsoutlines    = new List <Vector4>();
            List <ushort>  vertexregionoutlineindex = new List <ushort>();

            Size bitmapsize = new Size(250, 22);

            textrenderer = new GLBitmaps(name + "-bitmaps", rObjects, bitmapsize, depthtest: false, yfixed: true);
            items.Add(textrenderer);

            StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap)
            {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
            };
            Font fnt = new Font("MS Sans Serif", 12F);

            int cindex = 0;

            foreach (GalacticMapObject gmo in galmap.galacticMapObjects)
            {
                if (gmo.galMapType.Group == GalMapType.GalMapGroup.Regions)
                {
                    string gmoname = gmo.name;

                    List <Vector2> polygonxz = new List <Vector2>();                              // needs it in x/z and in vector2's
                    foreach (var pd in gmo.points)
                    {
                        polygonxz.Add(new Vector2((float)pd.X, (float)pd.Z));                   // can be concave and wound the wrong way..
                        vertexregionoutlineindex.Add((ushort)(vertexregionsoutlines.Count));
                        vertexregionsoutlines.Add(new Vector4((float)pd.X, 0, (float)pd.Z, 1));
                    }

                    vertexregionoutlineindex.Add(0xffff);                                             // primitive restart to break polygon

                    List <List <Vector2> > polys = PolygonTriangulator.Triangulate(polygonxz, false); // cut into convex polygons first - because we want the biggest possible area for naming purposes

                    Vector2 avgcentroid    = new Vector2(0, 0);
                    int     pointsaveraged = 0;

                    if (polys.Count > 0)                                                 // just in case..
                    {
                        foreach (List <Vector2> points in polys)                         // now for every poly
                        {
                            List <List <Vector2> > polytri;
                            if (points.Count == 3)                                    // already a triangle..
                            {
                                polytri = new List <List <Vector2> >()
                                {
                                    new List <Vector2>()
                                    {
                                        points[0], points[1], points[2]
                                    }
                                }
                            }
                            ;
                            else
                            {
                                polytri = PolygonTriangulator.Triangulate(points, true);    // cut into triangles not polygons
                            }
                            foreach (List <Vector2> pt in polytri)
                            {
                                vertexcolourregions.Add(pt[0].ToVector4XZ(w: cindex));
                                vertexcolourregions.Add(pt[2].ToVector4XZ(w: cindex));
                                vertexcolourregions.Add(pt[1].ToVector4XZ(w: cindex));

                                var cx = (pt[0].X + pt[1].X + pt[2].X) / 3;
                                var cy = (pt[0].Y + pt[1].Y + pt[2].Y) / 3;
                                avgcentroid = new Vector2(avgcentroid.X + cx, avgcentroid.Y + cy);
                                pointsaveraged++;

                                //foreach (var pd in pt) // debug
                                //{
                                //    vertexregionoutlineindex.Add((ushort)(vertexregionsoutlines.Count));
                                //    vertexregionsoutlines.Add(new Vector4((float)pd.X, 0, (float)pd.Y, 1));
                                //}
                                //vertexregionoutlineindex.Add(0xffff);       // primitive restart to break polygon
                            }
                        }

                        cindex = (cindex + 1) % array.Length;

                        Vector2 centeroid = PolygonTriangulator.WeightedCentroids(polys);

                        if (corr != null)   // allows the centeroid to be nerfed slightly
                        {
                            var entry = Array.Find(corr, x => gmo.name.Contains(x.name, StringComparison.InvariantCultureIgnoreCase));
                            if (entry != null)
                            {
                                centeroid = new Vector2(centeroid.X + entry.x, centeroid.Y + entry.y);
                            }
                        }

                        var final = PolygonTriangulator.FitInsideConvexPoly(polys, centeroid, new Vector2(sizeofname, sizeofname * (float)bitmapsize.Height / (float)bitmapsize.Width));

                        Vector3 bestpos  = new Vector3(final.Item1.X, 0, final.Item1.Y);
                        Vector3 bestsize = new Vector3(final.Item2.X, 1, final.Item2.Y);

                        textrenderer.Add(null, gmo.name, fnt, Color.White, Color.Transparent, bestpos, bestsize, new Vector3(0, 0, 0), fmt, alphafadescalar: 5000, alphafadepos: 500);
                    }
                }
            }

            fmt.Dispose();
            fnt.Dispose();

            // regions

            var vertregion = new GLPLVertexShaderWorldPalletColor(array.ToVector4(0.1f), true);
            var fragregion = new GLPLFragmentShaderVSColor();

            regionshader = new GLShaderPipeline(vertregion, fragregion, null, null);
            items.Add(regionshader);

            GLRenderState rt = GLRenderState.Tri();

            rt.DepthTest = false;
            var ridisplay = GLRenderableItem.CreateVector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, rt, vertexcolourregions.ToArray());

            rObjects.Add(regionshader, name + "-regions", ridisplay);

            // outlines

            var vertoutline = new GLPLVertexShaderWorldCoord(true);
            var fragoutline = new GLPLFragmentShaderFixedColor(Color.Cyan);

            outlineshader = new GLShaderPipeline(vertoutline, fragoutline, null, null);
            items.Add(outlineshader);

            GLRenderState ro = GLRenderState.Lines();

            ro.DepthTest        = false;
            ro.PrimitiveRestart = 0xffff;
            var rioutline = GLRenderableItem.CreateVector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.LineStrip, ro, vertexregionsoutlines.ToArray());

            rioutline.CreateElementIndexUShort(items.NewBuffer(), vertexregionoutlineindex.ToArray());

            rObjects.Add(outlineshader, name + "-outlines", rioutline);

            renderstate = 7;
        }
示例#5
0
        private void OtherKeys(GLOFC.Controller.KeyboardMonitor kb)
        {
            if (kb.HasBeenPressed(Keys.F5, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                gl3dcontroller.PanZoomTo(new Vector3(0, 0, 0), 1, 2);
            }

            if (kb.HasBeenPressed(Keys.F6, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                gl3dcontroller.PanZoomTo(new Vector3(4, 0, 0), 1, 2);
            }

            if (kb.HasBeenPressed(Keys.F7, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                gl3dcontroller.PanZoomTo(new Vector3(10, 0, -10), 1, 2);
            }

            if (kb.HasBeenPressed(Keys.F8, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                gl3dcontroller.PanZoomTo(new Vector3(50, 0, 50), 1, 2);
            }

            if (kb.HasBeenPressed(Keys.F4, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                gl3dcontroller.ChangePerspectiveMode(!gl3dcontroller.MatrixCalc.InPerspectiveMode);
            }

            if (kb.HasBeenPressed(Keys.F2, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                tim2.SetVisiblityRotation("j1", false);
                gl3dcontroller.Redraw();
            }
            if (kb.HasBeenPressed(Keys.F2, GLOFC.Controller.KeyboardMonitor.ShiftState.Shift))
            {
                tim2.SetVisiblityRotation("j1", true);
                gl3dcontroller.Redraw();
            }

            if (kb.HasBeenPressed(Keys.F10, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                System.Diagnostics.Debug.WriteLine("F10");
                using (StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap)
                {
                    Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                })
                {
                    Font f = new Font("MS sans serif", 8f);
                    tim.Add("T2g", "M3George", f, Color.White, Color.Blue, new Vector3(10, 5, -10), new Vector3(2.5f, 0, 0), new Vector3(0, 0, 0), fmt, rotatetoviewer: true);
                    gl3dcontroller.Redraw();
                }
            }

            if (kb.HasBeenPressed(Keys.F11, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                System.Diagnostics.Debug.WriteLine("F11");
                tim.Remove("T2g");
                gl3dcontroller.Redraw();
            }

            //tbd why losing focus? why no key

            if (kb.HasBeenPressed(Keys.O, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                System.Diagnostics.Debug.WriteLine("Order to 90");
                gl3dcontroller.Pan(new Vector2(90, 0), 3);
            }
            if (kb.HasBeenPressed(Keys.P, GLOFC.Controller.KeyboardMonitor.ShiftState.None))
            {
                System.Diagnostics.Debug.WriteLine("Order to -180");
                gl3dcontroller.Pan(new Vector2(90, 180), 3);
            }

            //System.Diagnostics.Debug.WriteLine("kb check");
        }