1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
#include <glut.h>
#include <Windows.h>
double year = 0;
double month = 0;
double day = 0;
double roundTheMercury = 0;
double roundTheVenus = 0;
double roundTheMars = 0;
double roundTheJupiter = 0;
double roundTheSaturn = 0;
double roundTheUranus = 0;
void Display() {
glClearColor(0, 0, 0, 1);
// 배경 색깔
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// 프레임마다 새로그리기때문에(60프레임)
// 화면을 초기화 시켜주기 위해서
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
GLfloat ambient[] = { 0,0,0,0 };
GLfloat diffuse[] = { 1,0,0,0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glClearDepth(1.0f);
//glBegin(GL_POLYGON);
// 그리는 값들이 begin, end 사이에 들어감
//glVertex3f(-0.5, -0.5, 0);// 1
//glVertex3f(0.5, -0.5, 0);// 2
//glVertex3f(0.5, 0.5, 0);// 3
//glVertex3f(-0.5, 0.5, 0);// 4
// 123 -> 143 삼각형 2개 만들어서 합침
//glEnd();
glLoadIdentity();
// matrix초기화
glColor3f(1, 0, 0);
// 색정하기
gluLookAt(0, -30, -10, 0, 0, 1, 0, 1, 0);
// 카메라 위치 지정해주기
glutWireSphere(1.5, 50, 10); // 태양
glPushMatrix(); {
glColor3f(1, 1, 1);
glutWireTorus(1, 4, 1, 30); // 지구
glutWireTorus(1, 1, 1, 30); // 수성
glutWireTorus(1, 2.5, 1, 30); // 금성
glutWireTorus(1, 5.5, 1, 30); // 화성
glutWireTorus(1, 7, 1, 30); // 목성
glutWireTorus(1, 8.5, 1, 30); // 토성
glutWireTorus(1, 10, 1, 30); // 천왕성
}
glPopMatrix();
glPushMatrix(); {// 이전에 넣어주었던 값들을 가져온다. 기준점 잡기
glRotatef(year, 0, 0, 1); // 지구 공전
// Rotate
glTranslatef(5, 0, 0);
// Translate
glutSolidSphere(0.5, 30, 30);
glPushMatrix(); {
glRotatef(month, 0, 0, 1); // 달 공전
glTranslatef(1, 0, 0);
glRotatef(day, 0, 0, 1); // 달 자전
glColor3f(1, 1, 0);
glutWireSphere(0.1, 50, 50);
glutSolidCube(0.5);
}
}
glPopMatrix();
glPopMatrix();
glPushMatrix(); {
glColor3f(0.7, 0.8, 0.8);
glRotatef(roundTheMercury, 0, 0, 1); // 수성 공전
glTranslatef(2, 0, 0);
glutSolidSphere(0.15, 30, 30);
}
glPopMatrix();
glPushMatrix(); {
glColor3f(0.8, 0.6, 0.5);
glRotatef(roundTheVenus, 0, 0, 1); // 금성 공전
glTranslatef(3.5, 0, 0);
glutSolidSphere(0.45, 30, 30);
}
glPopMatrix();
glPushMatrix(); {
glColor3f(0.8, 0.6, 0.5);
glRotatef(roundTheMars, 0, 0, 1); // 화성 공전
glTranslatef(6.5, 0, 0);
glutSolidSphere(0.25, 30, 30);
}
glPopMatrix();
glPushMatrix(); {
glColor3f(0.8, 0.6, 0.2);
glRotatef(roundTheMars, 0, 0, 1); // 화성 공전
glTranslatef(6.5, 0, 0);
glutSolidSphere(0.25, 30, 30);
}
glPopMatrix();
glPushMatrix(); {
glColor3f(0.7, 0.3, 0.1);
glRotatef(roundTheJupiter, 0, 0, 1); // 목성 공전
glTranslatef(8, 0, 0);
glutSolidSphere(1, 30, 30);
}
glPopMatrix();
glPushMatrix(); {
glColor3f(0.2, 0.5, 0.3);
glRotatef(roundTheMars, 0, 0, 1); // 토성 공전
glTranslatef(9.5, 0, 0);
glutSolidSphere(0.7, 30, 30);
glutWireTorus(1, 0.2, 1, 30);
}
glPopMatrix();
glPushMatrix(); {
glColor3f(0.7, 0.8, 0.8);
glRotatef(roundTheUranus, 0, 0, 1); // 해왕성 공전
glTranslatef(11, 0, 0);
glutSolidSphere(0.7, 30, 30);
}
glPopMatrix();
glFlush();
}
double speed = 0;
void idle() {
if (GetAsyncKeyState(VK_ADD)) {
speed += 0.001f;
}
else if(GetAsyncKeyState(VK_SUBTRACT)) {
speed -= 0.001f;
} else if (GetAsyncKeyState(VK_ADD) && 0x0001){
year += speed;
}
month += 0.1;
day += 0.2;
roundTheMercury += 0.002;
roundTheVenus += 0.006;
roundTheMars += 0.019;
roundTheJupiter += 0.12;
roundTheSaturn += 0.29;
roundTheUranus += 0.1;
Display();
}
void reShape(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 1.5, 50);
glMatrixMode(GL_MODELVIEW);
}
void main() {
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
// RGB모드 , 싱글버퍼
glShadeModel(GL_FLAT);
// 쉐이딩모드 ex)FLAT 보다 SMOOTH 가 더부드러움
glutInitWindowSize(1000, 1000);// 창크기
glutCreateWindow("hello world");// 창생성
glutDisplayFunc(Display);
glutReshapeFunc(reShape);
glutIdleFunc(idle);
glutMainLoop();
}
| cs |
2016년 8월 15일 월요일
OpenGL - 태양계
피드 구독하기:
댓글 (Atom)
What is the casino? - SEPT
답글삭제The best casino online is septcasino the One of the main reasons 바카라 why people are spending money on a game ventureberg.com/ is by having https://vannienailor4166blog.blogspot.com/ a few options. One wooricasinos.info of the reasons