private void openGLHead_OpenGLDraw(object sender, SharpGL.RenderEventArgs args) { OpenGL glh = openGLHead.OpenGL; glh.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glh.LoadIdentity(); // Reset The View CalculateMinMax(); //back the camera up glh.Translate(0, 0, -maxFieldDistance); //rotate camera so heading matched fix heading in the world //glh.Rotate(glm.toDegrees(toolPos.heading), 0, 0, 1); //translate to that spot in the world glh.Translate(-fieldCenterX, -fieldCenterY, 0); //calculate the frustum for the section control window mf.CalcFrustum(glh); //to draw or not the triangle patch bool isDraw; glh.Color(0.2f, 0.5f, 0.4f); //draw patches j= # of sections for (int j = 0; j < mf.vehicle.numSuperSection; j++) { //every time the section turns off and on is a new patch int patchCount = mf.section[j].patchList.Count; if (patchCount > 0) { //for every new chunk of patch foreach (var triList in mf.section[j].patchList) { isDraw = false; int count2 = triList.Count; for (int i = 0; i < count2; i += 3) { //determine if point is in frustum or not since 2d only 4 planes required if ((mf.frustum[0] * triList[i].easting) + (mf.frustum[1] * triList[i].northing) + mf.frustum[3] <= 0) { continue;//right } if ((mf.frustum[4] * triList[i].easting) + (mf.frustum[5] * triList[i].northing) + mf.frustum[7] <= 0) { continue;//left } if ((mf.frustum[16] * triList[i].easting) + (mf.frustum[17] * triList[i].northing) + mf.frustum[19] <= 0) { continue;//bottom } if ((mf.frustum[20] * triList[i].easting) + (mf.frustum[21] * triList[i].northing) + mf.frustum[23] <= 0) { continue;//top } //point is in frustum so draw the entire patch isDraw = true; break; } if (isDraw) { //draw the triangle in each triangle strip glh.Begin(OpenGL.GL_TRIANGLE_STRIP); count2 = triList.Count; const int mipmap = 8; //if large enough patch and camera zoomed out, fake mipmap the patches, skip triangles if (count2 >= (mipmap + 2)) { int step = mipmap; for (int i = 0; i < count2; i += step) { glh.Vertex(triList[i].easting, triList[i].northing, 0); i++; glh.Vertex(triList[i].easting, triList[i].northing, 0); i++; //too small to mipmap it if (count2 - i <= (mipmap + 2)) { step = 0; } } } else { for (int i = 0; i < count2; i++) { glh.Vertex(triList[i].easting, triList[i].northing, 0); } } glh.End(); } } } } //end of section patches glh.PointSize(8.0f); glh.Begin(OpenGL.GL_POINTS); glh.Color(0.05f, 0.90f, 0.60f); #pragma warning disable CS1690 // Accessing a member on a field of a marshal-by-reference class may cause a runtime exception glh.Vertex(mf.pivotAxlePos.easting, mf.pivotAxlePos.northing, 0.0); #pragma warning restore CS1690 // Accessing a member on a field of a marshal-by-reference class may cause a runtime exception glh.End(); //set pointsize glh.PointSize(4.0f); ////draw the outside boundary int ptCount = mf.boundz.ptList.Count; if (ptCount > 0) { glh.Color(0.98f, 0.2f, 0.90f); glh.Begin(OpenGL.GL_POINTS); for (int h = 0; h < ptCount; h++) { glh.Vertex(mf.boundz.ptList[h].easting, mf.boundz.ptList[h].northing, 0); } glh.End(); } ////draw the headland line so far ptCount = mf.hl.ptList.Count; if (ptCount > 0) { glh.Color(0.9038f, 0.9892f, 0.10f); glh.Begin(OpenGL.GL_POINTS); for (int h = 0; h < ptCount; h++) { glh.Vertex(mf.hl.ptList[h].easting, mf.hl.ptList[h].northing, 0); } glh.End(); } //plot the touch points so far if (isDrawingHeadland) { ////draw the headland line so far ptCount = mf.hl.ptList.Count; if (ptCount > 0) { glh.Color(0.08f, 0.9892f, 0.2710f); glh.Begin(OpenGL.GL_LINE_STRIP); for (int h = 0; h < ptCount; h++) { glh.Vertex(mf.hl.ptList[h].easting, mf.hl.ptList[h].northing, 0); } glh.End(); glh.Color(0.978f, 0.392f, 0.10f); //the "close the loop" line glh.Begin(OpenGL.GL_LINE_STRIP); glh.Vertex(mf.hl.ptList[ptCount - 1].easting, mf.hl.ptList[ptCount - 1].northing, 0); glh.Vertex(mf.hl.ptList[0].easting, mf.hl.ptList[0].northing, 0); glh.End(); } } glh.PointSize(1.0f); }
private void openGLHead_OpenGLDraw(object sender, SharpGL.RenderEventArgs args) { OpenGL glh = openGLHead.OpenGL; glh.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glh.LoadIdentity(); // Reset The View CalculateMinMax(); //back the camera up glh.Translate(0, 0, -maxFieldDistance); //translate to that spot in the world glh.Translate(-fieldCenterX, -fieldCenterY, 0); //calculate the frustum for the section control window mf.CalcFrustum(glh); //to draw or not the triangle patch bool isDraw; glh.Color(0.2f, 0.5f, 0.4f); //draw patches j= # of sections for (int j = 0; j < mf.vehicle.numSuperSection; j++) { //every time the section turns off and on is a new patch int patchCount = mf.section[j].patchList.Count; if (patchCount > 0) { //for every new chunk of patch foreach (var triList in mf.section[j].patchList) { isDraw = false; int count2 = triList.Count; for (int i = 0; i < count2; i += 3) { //determine if point is in frustum or not since 2d only 4 planes required if ((mf.frustum[0] * triList[i].easting) + (mf.frustum[1] * triList[i].northing) + mf.frustum[3] <= 0) { continue;//right } if ((mf.frustum[4] * triList[i].easting) + (mf.frustum[5] * triList[i].northing) + mf.frustum[7] <= 0) { continue;//left } if ((mf.frustum[16] * triList[i].easting) + (mf.frustum[17] * triList[i].northing) + mf.frustum[19] <= 0) { continue;//bottom } if ((mf.frustum[20] * triList[i].easting) + (mf.frustum[21] * triList[i].northing) + mf.frustum[23] <= 0) { continue;//top } //point is in frustum so draw the entire patch isDraw = true; break; } if (isDraw) { //draw the triangle in each triangle strip glh.Begin(OpenGL.GL_TRIANGLE_STRIP); count2 = triList.Count; const int mipmap = 8; //if large enough patch and camera zoomed out, fake mipmap the patches, skip triangles if (count2 >= (mipmap + 2)) { int step = mipmap; for (int i = 0; i < count2; i += step) { glh.Vertex(triList[i].easting, triList[i].northing, 0); i++; glh.Vertex(triList[i].easting, triList[i].northing, 0); i++; //too small to mipmap it if (count2 - i <= (mipmap + 2)) { step = 0; } } } else { for (int i = 0; i < count2; i++) { glh.Vertex(triList[i].easting, triList[i].northing, 0); } } glh.End(); } } } } //end of section patches //the vehicle position glh.PointSize(8.0f); glh.Begin(OpenGL.GL_POINTS); glh.Color(0.95f, 0.90f, 0.60f); #pragma warning disable CS1690 // Accessing a member on a field of a marshal-by-reference class may cause a runtime exception glh.Vertex(mf.pivotAxlePos.easting, mf.pivotAxlePos.northing, 0.0); #pragma warning restore CS1690 // Accessing a member on a field of a marshal-by-reference class may cause a runtime exception glh.End(); ////draw the outside boundary glh.LineWidth(2); int ptCount = 0; for (int i = 0; i < FormGPS.MAXBOUNDARIES; i++) { ptCount = mf.bndArr[i].bndLine.Count; if (ptCount > 0) { glh.Color(0.98f, 0.2f, 0.90f); glh.Begin(OpenGL.GL_LINE_STRIP); for (int h = 0; h < ptCount; h++) { glh.Vertex(mf.bndArr[i].bndLine[h].easting, mf.bndArr[i].bndLine[h].northing, 0); } //the "close the loop" line //glh.LineWidth(4); glh.Color(0.0f, 0.990f, 0.0f); glh.Vertex(mf.bndArr[i].bndLine[ptCount - 1].easting, mf.bndArr[i].bndLine[ptCount - 1].northing, 0); glh.Vertex(mf.bndArr[i].bndLine[0].easting, mf.bndArr[i].bndLine[0].northing, 0); glh.End(); } } ////draw the headland line for (int i = 0; i < FormGPS.MAXHEADS; i++) { if (mf.hlArr[i].isSet) { ptCount = mf.hlArr[i].hlLine.Count; glh.PointSize(4.0f); if (ptCount > 0) { glh.Color(0.009038f, 0.9892f, 0.10f); glh.Begin(OpenGL.GL_POINTS); for (int h = 0; h < ptCount; h++) { glh.Vertex(mf.hlArr[i].hlLine[h].easting, mf.hlArr[i].hlLine[h].northing, 0); } glh.End(); } } } //plot the touch points so far if (isDrawingHeadland) { //////draw the headland line so far //ptCount = mf.hl.hlLine.Count; //if (ptCount > 0) //{ // glh.Color(0.08f, 0.9892f, 0.2710f); // glh.Begin(OpenGL.GL_LINE_STRIP); // for (int h = 0; h < ptCount; h++) glh.Vertex(mf.hl.hlLine[h].easting, mf.hl.hlLine[h].northing, 0); // glh.Color(0.978f, 0.392f, 0.10f); // //the "close the loop" line // glh.Vertex(mf.hl.hlLine[ptCount - 1].easting, mf.hl.hlLine[ptCount - 1].northing, 0); // glh.Vertex(mf.hl.hlLine[0].easting, mf.hl.hlLine[0].northing, 0); // glh.End(); //} } //draw the ABLine if (mf.ABLine.isABLineSet | mf.ABLine.isABLineBeingSet) { //Draw reference AB line glh.LineWidth(1); glh.Enable(OpenGL.GL_LINE_STIPPLE); glh.LineStipple(1, 0x00F0); glh.Begin(OpenGL.GL_LINES); glh.Color(0.9f, 0.45f, 0.87f); glh.Vertex(mf.ABLine.refABLineP1.easting, mf.ABLine.refABLineP1.northing, 0); glh.Vertex(mf.ABLine.refABLineP2.easting, mf.ABLine.refABLineP2.northing, 0); glh.End(); glh.Disable(OpenGL.GL_LINE_STIPPLE); //raw current AB Line glh.Begin(OpenGL.GL_LINES); glh.Color(0.9f, 0.0f, 0.50f); glh.Vertex(mf.ABLine.currentABLineP1.easting, mf.ABLine.currentABLineP1.northing, 0.0); glh.Vertex(mf.ABLine.currentABLineP2.easting, mf.ABLine.currentABLineP2.northing, 0.0); glh.End(); } //draw curve if there is one if (mf.curve.isCurveSet) { int ptC = mf.curve.curList.Count; if (ptC > 0) { glh.LineWidth(2); glh.Color(0.95f, 0.25f, 0.50f); glh.Begin(OpenGL.GL_LINE_STRIP); for (int h = 0; h < ptC; h++) { glh.Vertex(mf.curve.curList[h].easting, mf.curve.curList[h].northing, 0); } glh.End(); } } glh.PointSize(1.0f); }