Date post: | 12-Apr-2017 |
Category: |
Technology |
Upload: | ndtho8205 |
View: | 69 times |
Download: | 0 times |
Computer Graphics 1
SOLAR SYSTEMSIMULATION
Thành viên
2
- Vũ Thành Công
- Lê Quốc Huy
- Nguyễn Đức Thọ
Nội dung1. Cấu trúc chương trình
2. Planet::draw()
3. The display callback
4. Vị trí Camera
5. Phép chiếu phối cảnh
6. The global idle callback
7. The keyboard callback
3
Cấu trúc chương trình
4
- Class Planet- Class EarthSystem
- Namespace ConstantHelper
Planet::draw()
5
void Planet::draw() {
glPushMatrix();
glColor3f(r, g, b);
glRotatef(angle, angleX, angleY, angleZ);
glTranslatef(x, y, z);
drawSphere(radius, slices, stacks);
glPopMatrix();
}
The display callback
6
void drawObjects(void) {
drawAxis();
sun.draw();
sun.drawCircleLine(EARTH_SYSTEM_DISTANCE);
earthSystem.draw();
}
Vị trí camera
7
- Thiết lập vị trí, góc, hướng cameragluLookAt(
eyeX, eyeY, eyeZ,centerX, centerY, centerZ,0, 1, 0
);
- Trong đó:+ (eyeX, eyeY, eyeZ): vị trí đặt của view,
+ (centerX, centerY, centerZ): điểm nằm trên đường thẳng xuất phát từ tâm view hướng ra ngoài,
+ (0, 1, 0): vector chỉ hướng lên trên của view
Phép chiếu phối cảnh
8
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Chiế9u phố9i ca;nh, vật càng xa càng nho;
glFrustum(left, right, bottom, top, near_val, far_val);
The global idle callback
9
- sun.angle += SUN_SPEED
- earthSystem.angle += EARTH_SYSTEM_SPEED
- earth.angle += EARTH_SPEED
- moon.angle += MOON_SPEED
The keyboard callback
10