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); }