2024年3月7日 星期四

11160933_week03

 1.複製十行



#include <GL/glut.h>

void display()

{

glutSolidTeapot(0.3);

glutSwapBuffers();

}

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

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow("GLUT Shapes");

glutDisplayFunc(display);

glutMouseFunc(mouse);///+


glutMainLoop();

}

2.+一行

glutMouseFunc(mouse);///+

3.點茶壺會出現Hello Mouse

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

{

    printf("HelloMouse!\n");

}

4.print座標

 printf("%d %d %d %d\n", button, state, x, y);


5.printf 程式
    if(state==GLUT_DOWN)
        printf("glVertex2f((%d-150)/150.0, -(%d-150)/150.0;\n", x, y);
6.https://jsyeh.org/3dcg10/ 下載data\模型檔 win32\transformation

7.new file week03_mouse_glTranslatef

8.copy line46 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
line49 glPushMatrix();
line54 glPopMatrix();

9.copy glMouse

float teapotX = 0, teapotY = 0;
void mouse(int button, int state, int x, int y)
{
    teapotX = (x-150)/150.0;
    teapotY = -(y-150)/150.0;
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glPopMatrix();///偷
        glTranslatef(teapotX, teapotY, 0);
        glutSolidTeapot( 0.3 );
glutSolidTeapot(0.3);
glutSwapBuffers();
}

##理解 glRotatef(角度 ,x y, z)
1. 右手比讚
2.轉動軸為拇指
轉動方向為其他拇指的轉動方向
3.對y軸轉 比個讚
x軸 拇指向右
-y軸 倒讚
z軸 拇指向臉

10.new file week03_mouse_rotate

11. copy translatef
+float angle = 0;
glRotatef(angle, 0, 0, 1);
void motion(int x, int y)
{
    angle = x;
    display();
}

extra
12.new file week03_mouse_translate_rotate

13.copy last file
14.


























沒有留言:

張貼留言