public static void DrawCylinder( this OpenGL gl, float radius, float height, bool covered = false, int partsCount = 50, bool withEdges = false) { var center = PointF.Empty; var contourPoints = GetRegularPolygonPoints(partsCount, center, radius).ToArray(); // Стенки gl.Draw(BeginMode.Quads, () => { foreach (var(point1, point2) in contourPoints.Pairs()) { gl.Vertex(point1.X, point1.Y, 0); gl.Vertex(point1.X, point1.Y, height); gl.Vertex(point2.X, point2.Y, height); gl.Vertex(point2.X, point2.Y, 0); } }, !withEdges);
public static void DrawParallelepiped( this OpenGL gl, Vector3 edges, bool withEdges = false, bool textured = false) { // грани gl.Draw(BeginMode.Quads, () => { /*задняя*/ gl.Vertex(0, 0, 0); gl.Vertex(edges.X, 0, 0); gl.Vertex(edges.X, edges.Y, 0); gl.Vertex(0, edges.Y, 0); /*левая*/ gl.Vertex(0, 0, 0); gl.Vertex(0, 0, edges.Z); gl.Vertex(0, edges.Y, edges.Z); gl.Vertex(0, edges.Y, 0); /*нижняя*/ gl.Vertex(0, 0, 0); gl.Vertex(0, 0, edges.Z); gl.Vertex(edges.X, 0, edges.Z); gl.Vertex(edges.X, 0, 0); if (textured) { gl.Color(System.Drawing.Color.White); } /*верхняя*/ if (textured) { gl.TexCoord(0, 0); } gl.Vertex(0, edges.Y, 0); if (textured) { gl.TexCoord(1, 0); } gl.Vertex(0, edges.Y, edges.Z); if (textured) { gl.TexCoord(1, 1); } gl.Vertex(edges.X, edges.Y, edges.Z); if (textured) { gl.TexCoord(0, 1); } gl.Vertex(edges.X, edges.Y, 0); if (textured) { gl.Color(currentColor); } /*передняя*/ gl.Vertex(0, 0, edges.Z); gl.Vertex(edges.X, 0, edges.Z); gl.Vertex(edges.X, edges.Y, edges.Z); gl.Vertex(0, edges.Y, edges.Z); /*правая*/ gl.Vertex(edges.X, 0, 0); gl.Vertex(edges.X, 0, edges.Z); gl.Vertex(edges.X, edges.Y, edges.Z); gl.Vertex(edges.X, edges.Y, 0); }, !withEdges); }
private static void DrawCabinet(OpenGL gl) { // середина (кабина) gl.DoTranslate(-BumperLength, 0, BaseWidth / 2f, true); // передняя и задняя наклонные gl.Repeat(() => { gl.Draw(BeginMode.Polygon, () => { gl.Vertex(Vector3.UnitZ * (-CabinetBottomWidth / 2)); gl.Vertex(Vector3.UnitZ * (CabinetBottomWidth / 2)); gl.Vertex(-CabinetSlopeLength, CabinetHeight, CabinetTopWidth / 2); gl.Vertex(-CabinetSlopeLength, CabinetHeight, -CabinetTopWidth / 2); }); }, 2, Vector3.UnitX * -BaseLength, Vector3.UnitY * 180); // боковые наклонные var zDiff = 1; gl.Repeat(() => { gl.Draw(BeginMode.Polygon, () => { gl.Vertex(Vector3.UnitZ * (CabinetBottomWidth / 2 * zDiff)); gl.Vertex(-BaseLength, 0, CabinetBottomWidth / 2 * zDiff); gl.Vertex(-(BaseLength - CabinetSlopeLength), CabinetHeight, CabinetTopWidth / 2 * zDiff); gl.Vertex(-CabinetSlopeLength, CabinetHeight, CabinetTopWidth / 2 * zDiff); }); zDiff = -1; }, 2, Vector3.Zero, Vector3.Zero); // крышка gl.Draw(BeginMode.Polygon, () => { gl.Vertex(-CabinetSlopeLength, CabinetHeight, CabinetTopWidth / 2); gl.Vertex(-(BaseLength - CabinetSlopeLength), CabinetHeight, CabinetTopWidth / 2); gl.Vertex(-(BaseLength - CabinetSlopeLength), CabinetHeight, -CabinetTopWidth / 2); gl.Vertex(-CabinetSlopeLength, CabinetHeight, -CabinetTopWidth / 2); }); // задние коробки gl.DoTranslate(-(BaseLength + 0.8f), 0, CabinetBottomWidth / 2, true); gl.Repeat(() => { gl.DrawParallelepiped(new Vector3(BackBoxLength, BackBoxHalfHeight, -BackBoxWidth), true); gl.DoTranslate(Vector3.UnitY * BackBoxHalfHeight, true); gl.DrawParallelepiped(new Vector3(BackBoxTopLength, BackBoxTopHeight, -BackBoxWidth), true); gl.DoTranslate(Vector3.UnitX * BackBoxTopLength, true); gl.Repeat(() => { gl.Draw(BeginMode.Polygon, () => { gl.Vertex(Vector3.Zero); gl.Vertex(Vector3.UnitY * BackBoxTopHeight); gl.Vertex(Vector3.UnitX * (BackBoxLength - BackBoxTopLength)); }); }, 2, Vector3.UnitZ * -BackBoxWidth, Vector3.Zero); gl.Draw(BeginMode.Polygon, () => { gl.Vertex(Vector3.UnitY * BackBoxTopHeight); gl.Vertex(0, BackBoxTopHeight, -BackBoxWidth); gl.Vertex(BackBoxLength - BackBoxTopLength, 0, -BackBoxWidth); gl.Vertex(BackBoxLength - BackBoxTopLength, 0, 0); }); gl.UndoTranslation(2); }, 2, Vector3.UnitZ * -(CabinetBottomWidth - BackBoxWidth), Vector3.Zero); gl.UndoTranslation(); }
private static void DrawTurret(OpenGL gl, Texture hatchTexture) { gl.DoTranslate(-CabinetSlopeLength - 6, CabinetHeight, 0, true); // основа башни gl.Rotate(Vector3.UnitX * -90, true); gl.DrawCylinder(TurretBaseRadius, TurretBaseHeight, partsCount: 10, withEdges: true); gl.UndoRotation(); // башня gl.DoTranslate(Vector3.UnitY * TurretBaseHeight, true); gl.Repeat(() => { // боковая средняя пластина gl.Draw(BeginMode.Polygon, () => { gl.Vertex(TurretMiddleWidth, 0, TurretBottomMiddleWidth / 2); gl.Vertex(-TurretMiddleWidth, 0, TurretBottomMiddleWidth / 2); gl.Vertex(-TurretMiddleWidth, TurretHeight, TurretTopMiddleWidth / 2); gl.Vertex(TurretMiddleWidth, TurretHeight, TurretTopMiddleWidth / 2); }); // боковая передняя пластина gl.Draw(BeginMode.Polygon, () => { gl.Vertex(TurretMiddleWidth, 0, TurretBottomMiddleWidth / 2); gl.Vertex(TurretMiddleWidth, TurretHeight, TurretTopMiddleWidth / 2); gl.Vertex(TurretLength, TurretHeight, TurretTopFrontWidth / 2); gl.Vertex(TurretLength, 0, TurretBottomFrontWidth / 2); }); // боковая задняя пластина gl.Draw(BeginMode.Polygon, () => { gl.Vertex(-TurretMiddleWidth, 0, TurretBottomMiddleWidth / 2); gl.Vertex(-TurretLength, 0, TurretBottomFrontWidth / 2); gl.Vertex(-TurretLength, TurretHeight, TurretTopFrontWidth / 2); gl.Vertex(-TurretMiddleWidth, TurretHeight, TurretTopMiddleWidth / 2); }); }, 2, Vector3.Zero, Vector3.UnitY * 180); // передняя пластина gl.Repeat(() => { gl.Draw(BeginMode.Polygon, () => { gl.Vertex(TurretLength, 0, TurretBottomFrontWidth / 2); gl.Vertex(TurretLength, TurretHeight, TurretTopFrontWidth / 2); gl.Vertex(TurretLength, TurretHeight, -TurretTopFrontWidth / 2); gl.Vertex(TurretLength, 0, -TurretBottomFrontWidth / 2); }); }, 2, Vector3.Zero, Vector3.UnitY * 180); // крышка gl.Draw(BeginMode.Polygon, () => { gl.Vertex(TurretLength, TurretHeight, TurretTopFrontWidth / 2); gl.Vertex(TurretMiddleWidth, TurretHeight, TurretTopMiddleWidth / 2); gl.Vertex(-TurretMiddleWidth, TurretHeight, TurretTopMiddleWidth / 2); gl.Vertex(-TurretLength, TurretHeight, TurretTopFrontWidth / 2); gl.Vertex(-TurretLength, TurretHeight, -TurretTopFrontWidth / 2); gl.Vertex(-TurretMiddleWidth, TurretHeight, -TurretTopMiddleWidth / 2); gl.Vertex(TurretMiddleWidth, TurretHeight, -TurretTopMiddleWidth / 2); gl.Vertex(TurretLength, TurretHeight, -TurretTopFrontWidth / 2); }, true); // люк gl.DoTranslate(-TurretLength / 2, TurretHeight, -TurretTopFrontWidth / 2, true); DrawHatch(gl, hatchTexture); gl.UndoTranslation(2); //основа ствола gl.DoTranslate(Vector3.UnitX * TurretLength, true); // нижняя и верхняя пластина gl.Repeat(() => { gl.Draw(BeginMode.Polygon, () => { gl.Vertex(BarrelBaseLength, 0, BarrelBaseWidth / 2); gl.Vertex(BarrelBaseLength, 0, -BarrelBaseWidth / 2); gl.Vertex(0, 0, -BarrelBaseWidth / 2); gl.Vertex(0, 0, BarrelBaseWidth / 2); }); }, 2, Vector3.UnitY * BarrelBaseHeight, Vector3.Zero); //боковые части gl.Repeat(() => { gl.Draw(BeginMode.Quads, () => { gl.Vertex(Vector3.UnitZ * BarrelBaseWidth / 2); gl.Vertex(0, BarrelBaseHeight, BarrelBaseWidth / 2); gl.Vertex(BarrelBaseLength, BarrelBaseHeight, BarrelBaseWidth / 2); gl.Vertex(BarrelBaseLength, 0, BarrelBaseWidth / 2); }); }, 2, Vector3.UnitX * BarrelBaseLength, Vector3.UnitY * 180); // передняя крышка gl.Draw(BeginMode.Quads, () => { gl.Vertex(BarrelBaseLength, 0, BarrelBaseWidth / 2); gl.Vertex(BarrelBaseLength, BarrelBaseHeight, BarrelBaseWidth / 2); gl.Vertex(BarrelBaseLength, BarrelBaseHeight, -BarrelBaseWidth / 2); gl.Vertex(BarrelBaseLength, 0, -BarrelBaseWidth / 2); }); // дуло gl.DoTranslate(BarrelBaseLength, BarrelBaseHeight / 2, 0, true); gl.Rotate(Vector3.UnitZ * -90, true); gl.Rotate(Vector3.UnitX * -90, true); gl.SetColor(Color.DarkSlateGray); gl.DrawCylinder(BarrelRadius, BarrelLength, partsCount: Roundness); gl.UndoRotation(2); }
private static void DrawBase(OpenGL gl) { // Основа (низ) gl.Color(Color.DarkGreen); gl.DrawParallelepiped(new Vector3(BaseLength, BaseHeight, BaseWidth)); // угловой бампер gl.DoTranslate(Vector3.UnitX * BaseLength, true); gl.SetColor(Color.Green); var plateAngle = (float)(Math.Atan2(BumperMiddleHeight, BumperLength) / Math.PI * 180); gl.Repeat(() => { //верх и ниж пластины gl.Repeat(() => { gl.Draw(BeginMode.Polygon, () => { gl.Vertex(Vector3.Zero); gl.Vertex(BumperLength, BumperMiddleHeight); gl.Vertex(BumperLength, BumperMiddleHeight, BaseWidth); gl.Vertex(Vector3.UnitZ * BaseWidth); }); }, 2, Vector3.UnitY * BaseHeight, Vector3.UnitZ * -plateAngle * 2); // стенки gl.Repeat(() => { gl.Draw(BeginMode.Triangles, () => { gl.Vertex(Vector3.Zero); gl.Vertex(BumperLength, BumperMiddleHeight); gl.Vertex(Vector3.UnitY * BaseHeight); }); }, 2, Vector3.UnitZ * BaseWidth, Vector3.Zero); }, 2, new Vector3(-BaseLength, 0, BaseWidth), Vector3.UnitY * 180); // крылья gl.Translate(BumperLength, BaseHeight, 0); var zDiff = 0f; gl.Repeat(() => { // верхняя пластина gl.Draw(BeginMode.Polygon, () => { gl.Vertex(Vector3.Zero); gl.Vertex(-(BumperLength + BaseLength), 0); gl.Vertex(-(BumperLength + BaseLength), 0, -WingsWidth); gl.Vertex(0, 0, -WingsWidth); }); // передняя наклонная gl.Draw(BeginMode.Polygon, () => { gl.Vertex(Vector3.Zero); gl.Vertex(Vector3.UnitZ * -WingsWidth); gl.Vertex(FrontWingsLength, -FrontWingsHeight, -WingsWidth); gl.Vertex(FrontWingsLength, -FrontWingsHeight); }); // задняя наклонная gl.Draw(BeginMode.Polygon, () => { gl.Vertex(Vector3.Zero); gl.Vertex(-BumperLength, -BumperMiddleHeight, 0); gl.Vertex(-BumperLength, -BumperMiddleHeight, -WingsWidth); gl.Vertex(Vector3.UnitZ * -WingsWidth); }, Vector3.UnitX * -(BaseLength + BumperLength), Vector3.Zero); // передние стенки крыльев gl.Draw(BeginMode.Polygon, () => { gl.Vertex(Vector3.UnitZ * zDiff); gl.Vertex(FrontWingsLength, -FrontWingsHeight, zDiff); gl.Vertex(0, -FrontWingsHeight, zDiff); gl.Vertex(-BumperLength, 0, zDiff); }); zDiff = -WingsWidth; }, 2, Vector3.UnitZ * (BaseWidth + WingsWidth), Vector3.Zero); }