Views 7481 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
#include<Gl/glut.h>

typedef float point2[2];

point2 v[] = { {-1.0, -0.58}, {1.0, -0.58}, {0.0, 1.15} };

int n;

void triangle(point2 a, point2 b, point2 c);
void divside_triangle(point2 a, point2 b, point2 c, int m);
void display(void);
void myinit();

void triangle(point2 a, point2 b, point2 c)
{
        glBegin(GL_TRIANGLES);
                glVertex2fv(a);
                glVertex2fv(b);
                glVertex2fv(c);
        glEnd();
}

void divside_triangle(point2 a, point2 b, point2 c, int m)
{
        point2 v0, v1, v2;
        int j;
        if(m>0)
        {
                for(j=0; j<2; j++) v0[j] = (a[j]+b[j]) / 2;
                for(j=0; j<2; j++) v1[j] = (a[j]+c[j]) / 2;
                for(j=0; j<2; j++) v2[j] = (b[j]+c[j]) / 2;
                divside_triangle(a, v0, v1, m-1);
                divside_triangle(c, v1, v2, m-1);
                divside_triangle(b, v2, v0, m-1);
        }
        else(triangle(a,b,c));
}

void display(void)
{
        glClear(GL_COLOR_BUFFER_BIT);
        divside_triangle(v[0], v[1], v[2], n);
        glFlush();
}

void myinit()
{
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(-2.0, 2.0, -2.0, 2.0);
        glMatrixMode(GL_MODELVIEW);
        glClearColor(1.0, 1.0, 1.0, 1.0);
        glColor3f(0.0, 0.0, 0.0);
}

void main(int argc, char **argv)
{
        n = 5;//atoi(argv[1]);
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(500, 500);
        glutCreateWindow("3D Gasket");
        glutDisplayFunc(display);
        myinit();
        glutMainLoop();
}

?

List of Articles
No. Category Subject Author Date Views
997 System/OS RPA란? 어디에 어떻게 쓰이고 누가 만드나? file hooni 2020.01.28 1365
996 Develop [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 file hooni 2021.01.29 1388
995 System/OS SSH Passwordless Login Using SSH Keygen in 5 Easy Steps file hooni 2019.11.22 1395
994 Develop [ios] Swift 4 String, Date, DateFormatter 예제 hooni 2018.10.18 1402
993 System/OS 무료로 HTTPS 적용하기 (Let's Encrypt) file hooni 2017.10.28 1407
992 Develop What is difference between Get, Post, Put and Delete? hooni 2018.02.28 1410
991 Etc 아이폰의 터치스크린 정확도 file hooni 2015.04.01 1423
990 Etc IT감사 기법 시험 file hooni 2017.06.14 1423
989 System/OS [mac] Mac OS에서 재생되는 사운드를 녹음하는 방법 file hooni 2016.10.03 1448
988 System/OS [linux] wget 명령 사용 예제 hooni 2020.05.26 1448
987 System/OS OpenSSL로 ROOT CA 생성 및 SSL 인증서 발급하기 hooni 2017.10.28 1464
986 Database [mysql] MacOS에 MySQL 설치, 설정, 암호 재설정 file hooni 2017.12.15 1471
985 Develop [android] 레이아웃 사이즈 변경 (동적; programmatically) hooni 2016.11.07 1486
984 Develop [ios] binary를 C코드로 변환 file hooni 2015.01.03 1533
983 System/OS [mac] OS X 요세미티 사용자가 많이 겪는 버그와 몇몇 불편사항 file hooni 2015.01.04 1534
982 Develop [ios] Pod 특정 버전 설치하고 사용하기 hooni 2022.05.28 1546
Board Pagination Prev 1 ... 10 11 12 13 14 ... 74 Next
/ 74