2019年3月14日 星期四

老灰的電腦圖學 主題:移動

下載http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

下載 data  win32  glut32.dll
解壓縮後 win32 解壓縮成 資料夾
data放入win32資料夾內 glut32.dll也放入win32資料夾內

打開
gltranslatef(            )
可以移動位置
glrotatef (              )
可以旋轉角度
glscalef(                )
可以改變大小

https://www.transmissionzero.co.uk/software/freeglut-devel/
下載

freeglut 3.0.0 MinGW Package

解壓縮後打開lib複製libfreeglut32  改名字為 libglut32.a
打開codeblocks   專案GLUT

#include <GL/glut.h>
void display()
{
    glTranslatef(0.3,0.3,0);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);

    glutMainLoop();
}

打入程式後
茶壺就會移動了


接著做 茶壺跟著滑鼠移動

打入程式碼
#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glTranslatef((x-150)/150.0,-(y-150)/150.0,0);
    glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int nowX, int nowY)
{
    x=nowX; y=nowY;
    display();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);
    glutMotionunc(motion);

    glutMainLoop();
}

沒有留言:

張貼留言