2024年3月14日 星期四

week04

 0. 桌面安裝 freeglut,把 lib 的l ibfreeglut.a複製成 libglut32.a

1.File-New-Project ,Glut 專案week04_mouse_glScalef記得目錄(桌面),Glut目錄(桌面/freeglut)

2.手動輸入10行程式碼

3.加上上週的week03_mouse_glRotatef的部分程式

4.void motion()你可以貼上

#include <GL/glut.h>
///float angle=0;
float s=1;
void display()
{
    glClearColor(1.0,0.0,0.9,1.0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        ///glRotatef(angle,0,0,1);
        glScalef(s,s,s);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    ///angle=x;
    s=1+(x-150)/150.0;
    display();
}
int main(int argc, char*argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04_mouse_glScalef");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}


##week04_keyboard_mouse_motion

1.File-New-Project ,Glut 專案week04_keyboard_mouse_motion記得目錄(桌面),Glut目錄(桌面/freeglut)

2.輸入10行程式碼

3.修改程式碼

#include <GL/glut.h>

#include <stdio.h>

float angle=0,oldX=0;

void display()

{

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotatef(angle,0,0,1);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

}

void mouse(int button,int state,int x,int y){

    oldX=x;


}

void motion(int x,int y){

     angle+=(x-oldX);

     oldX=x;

     display();

}

void keyboard(unsigned char key,int x,int y){

    printf("key: %c x: %d y: %d\n",key,x,y);

}


int main(int argc, char*argv[])

{

    glutInit(&argc, argv);

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week04_keyboard_mouse_motion");

    glutDisplayFunc(display);

    glutKeyboardFunc(keyboard);

    glutMouseFunc(mouse);

    glutMotionFunc(motion);

    glutMainLoop();

}




1.下載課本範例https://jsyeh.org/3dcg10/



2.window.zip解壓縮

3.data.zip解壓縮





##week04_translate_scale

1.File-New-Project ,Glut 專案week04_translate_scale記得目錄(桌面),Glut目錄(桌面/freeglut)

2.輸入11行程式碼

3.修改程式碼

#include <GL/glut.h>

#include <stdio.h>

float angle=0,oldX=0;

void display()

{

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glTranslatef(0.8,0,0);

        glRotatef(angle++,0,0,1);

        glScalef(0.3,0.3,0.3);

        glColor3f(0,1,0);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

}



int main(int argc, char*argv[])

{

    glutInit(&argc, argv);

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week04_keyboard_mouse_motion");

    glutDisplayFunc(display);

    glutIdleFunc(display);

    glutMainLoop();

}

##week04_rotate_translate_scale

1.File-New-Project ,Glut 專案week04_rotate_translate_scale記得目錄(桌面),Glut目錄(桌面/freeglut)

2.輸入11行程式碼

3.修改程式碼

#include <GL/glut.h>
#include <stdio.h>
float angle=0,oldX=0;
void display()
{
    glClearColor(1.0,1.0,0.9,1.0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle++,0,0,1);
        glTranslatef(0.8,0,0);
        glScalef(0.3,0.3,0.3);
        glColor3f(0,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}


int main(int argc, char*argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04_keyboard_mouse_motion");
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMainLoop();
}
















沒有留言:

張貼留言