Ejemplo n.º 1
0
//-----------------------------------------------------------------------------------
// レンダリング
//-----------------------------------------------------------------------------------
void display(void)
{
    // クロックの更新, 1秒でdayが1ずつ増える
    clock_pre = clock_now;
    clock_now = get_clock_now();
    day += (clock_now - clock_pre); 

    // フレームバッファのクリア
    glClear (GL_COLOR_BUFFER_BIT);

    // 視点の設定
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(panx, pany, 0);
    gluLookAt(0.0, 0.0, distance, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    // 惑星の軌道を描く
    DrawCircle(cos(clock_now), sin(clock_now), 1.0);

    int i;
    glPointSize(1.0);
    glBegin(GL_POINTS);
    for (i = 0; i < 100; i++) {
        glVertex2f((rand()%100)*0.01, (rand()%100)*0.01);
    }
    glEnd();

    glutSwapBuffers();
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------------
// 初期化
//-----------------------------------------------------------------------------------
void init(void)
{
    // クリアの値の設定
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glClearDepth( 1.0 );

    // デプステストを行う
    glEnable( GL_DEPTH_TEST );
    glDepthFunc( GL_LESS );

    glShadeModel(GL_SMOOTH);

    // デフォルトライト
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_ambient);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    // デフォルトマテリアル
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_default_color);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_default_color);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_default_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_default_shininess);

    // クロックの初期化
    clock_now = clock_pre = get_clock_now();
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------------
// 初期化
//-----------------------------------------------------------------------------------
void init(void)
{
    // クリアの値の設定
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glClearDepth( 1.0 );

    glDepthFunc( GL_LESS );

    glShadeModel(GL_FLAT);

    // クロックの初期化
    clock_now = clock_pre = get_clock_now();
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------------
// レンダリング
//-----------------------------------------------------------------------------------
void display(void)
{
    // クロックの更新
    clock_pre = clock_now;
    clock_now = get_clock_now();

    // 1秒で1日分動くとする
    if( flg_play )
        day += (clock_now - clock_pre);

    // フレームバッファのクリア
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // 視点の設定
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0, 0.0, distance, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    glRotatef( -pitch, 1.0, 0.0, 0.0 );
    glRotatef( -yaw, 0.0, 1.0, 0.0 );

    // 惑星の軌道を描く
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_default_color);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_default_color);
    DrawCircle( orbit_radius_earth );
    //惑星を描く
    glPushMatrix();
    {
        // 太陽
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_color_sun);
        glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_color_sun);

        glPushMatrix();
        {
            // 太陽の自転の計算式
            glRotatef (  day * rot_vel_sun , 0.0, 1.0, 0.0);
            DrawPlanet( radius_sun );
        }
        glPopMatrix();

        // 水星
        glPushMatrix();
        {
            glRotatef (  day * rev_vel_mercury, 0.0, 1.0, 0.0); glTranslatef (orbit_radius_mercury, 0.0, 0.0); 
            glRotatef (  day * rot_vel_mercury, 0.0, 1.0, 0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_color_mercury); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_color_mercury); 
            DrawPlanet( planet_radius_mercury );
        }
        glPopMatrix();

        // 金星
        glPushMatrix();
        {
            glRotatef (  day * rev_vel_venus, 0.0, 1.0, 0.0); glTranslatef (orbit_radius_venus, 0.0, 0.0); 
            glRotatef (  day * rot_vel_venus, 0.0, 1.0, 0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_color_venus); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_color_venus); 
            DrawPlanet( planet_radius_venus );
        }
        glPopMatrix();

        // 地球
        glPushMatrix();
        {
            glRotatef (  day * rev_vel_earth, 0.0, 1.0, 0.0); glTranslatef (orbit_radius_earth, 0.0, 0.0); 
            glRotatef (  day * rot_vel_earth, 0.0, 1.0, 0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_color_earth); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_color_earth); 
            DrawPlanet( planet_radius_earth );

            // 月
            glPushMatrix();
            {
                glRotatef (  day * rev_vel_moon, 0.0, 1.0, 0.0); glTranslatef (orbit_radius_moon, 0.0, 0.0); 
                glRotatef (  day * rot_vel_moon, 0.0, 1.0, 0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_color_moon); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_color_moon); 
                DrawPlanet( planet_radius_moon );
            }
            glPopMatrix();
        }
        glPopMatrix();

        //火星
        glPushMatrix();
        {
            glRotatef (  day * rev_vel_mars, 0.0, 1.0, 0.0); glTranslatef (orbit_radius_mars, 0.0, 0.0); 
            glRotatef (  day * rot_vel_mars, 0.0, 1.0, 0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_color_mars); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_color_mars); 
            DrawPlanet( planet_radius_mars );
        }
        glPopMatrix();
    }
    glPopMatrix();

    glutSwapBuffers();
}