Render triangle:
private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
{
OpenGL gL = GLControl.OpenGL;
gL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gL.LoadIdentity();
maxX = Math.Max(AX, Math.Max(BX, CX));
maxY = Math.Max(AY, Math.Max(BY, CY));
minX = Math.Min(AX, Math.Min(BX, CX));
minY = Math.Min(AX, Math.Min(BX, CX));
maxZ = Math.Max(AZ, Math.Max(BZ, CZ));
minZ = Math.Min(AZ, Math.Min(BZ, CZ));
double figureWidht = maxX - minX;
double figureHeight = maxY - minY;
double figureSquare = figureWidht * figureHeight;
double viewPortSquare = GLControl.Width * GLControl.Height;
gL.Translate(-figureWidht / 2, -figureHeight / 2, -6);
gL.Begin(OpenGL.GL_LINES);
gL.Color(1.0F, 1.0F, 1.0F);
gL.Vertex((float)AX, (float)AY, (float)AZ);
gL.Vertex((float)BX, (float)BY, (float)BZ);
gL.Vertex((float)BX, (float)BY, (float)BZ);
gL.Vertex((float)CX, (float)CY, (float)CZ);
gL.Vertex((float)CX, (float)CY, (float)CZ);
gL.Vertex((float)AX, (float)AY, (float)AZ);
gL.End();
}
How to make a figure always fit under the viewport of OpenGLControl? That is, if the figure is larger than the opengl window, then it is adjusted to this window so that all the axes have approximately the same spacing, and if less, it becomes larger accordingly.