當前位置:編程學習大全網 - 編程語言 - 用c或c++編壹個畫三維圖形的程序

用c或c++編壹個畫三維圖形的程序

TurboC 立方體

#include <dos.h>

#include <math.h>

#include <conio.h>

#include <stdio.h>

#include <stdlib.h>

#include <graphics.h>

void DrawCube(int color);

int cx[9], cy[9];

int CubeCorners[9][4];

int CurX, CurY;

int Angle = 0;

int step = 2;

int Radius;

const double Pi = 3.14159265358979;

int main()

{

int GraphDriver;

int GraphMode;

int a, b;

GraphDriver = DETECT;

initgraph(&GraphDriver, &GraphMode, "");

Radius = 150;

CubeCorners[1][2] = 200 / 2;

CubeCorners[2][2] = 200 / 2;

CubeCorners[3][2] = -200 / 2;

CubeCorners[4][2] = -200 / 2;

CubeCorners[5][2] = 200 / 2;

CubeCorners[6][2] = 200 / 2;

CubeCorners[7][2] = -200 / 2;

CubeCorners[8][2] = -200 / 2;

DrawCube(12);

getch();

}

void DrawCube(int color)

{

int i;

for (i = 1; i <= 3; i += 2)

{

CubeCorners[i][3] = Radius * cos((Angle) * Pi / 180);

CubeCorners[i][1] = Radius * sin((Angle) * Pi / 180);

}

for (i = 2; i <= 4; i += 2)

{

CubeCorners[i][3] = Radius * cos((Angle + 2 * 45) * Pi / 180);

CubeCorners[i][1] = Radius * sin((Angle + 2 * 45) * Pi / 180);

}

for (i = 5; i <= 7; i += 2)

{

CubeCorners[i][3] = Radius * cos((Angle + 6 * 45) * Pi / 180);

CubeCorners[i][1] = Radius * sin((Angle + 6 * 45) * Pi / 180);

}

for (i = 6; i <= 8; i += 2)

{

CubeCorners[i][3] = Radius * cos((Angle + 4 * 45) * Pi / 180);

CubeCorners[i][1] = Radius * sin((Angle + 4 * 45) * Pi / 180);

}

for (i = 1; i <= 8; i++)

{

cx[i] = 300 + CubeCorners[i][1] + CubeCorners[i][3] / 8;

if (CubeCorners[i][2] > 0)

cy[i] = 200 + CubeCorners[i][2] + CubeCorners[i][3] / 8;

else if (CubeCorners[i][2] < 0)

cy[i] = 200 + CubeCorners[i][2] - CubeCorners[i][3] / 8;

else

cy[i] = 200 + CubeCorners[i][2];

}

setcolor(color);

moveto(cx[3], cy[3]);

lineto(cx[4], cy[4]);

lineto(cx[8], cy[8]);

lineto(cx[6], cy[6]);

lineto(cx[2], cy[2]);

lineto(cx[4], cy[4]);

moveto(cx[3], cy[3]);

lineto(cx[7], cy[7]);

lineto(cx[8], cy[8]);

moveto(cx[3], cy[3]);

lineto(cx[1], cy[1]);

lineto(cx[2], cy[2]);

moveto(cx[6], cy[6]);

lineto(cx[5], cy[5]);

lineto(cx[1], cy[1]);

moveto(cx[7], cy[7]);

lineto(cx[5], cy[5]);

}

  • 上一篇:sybase數據庫遷移sqlserver2000方法
  • 下一篇:oracle9i有哪些特點和模式?
  • copyright 2024編程學習大全網