前往→ http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/→ 下載data、win32、glut32.dll三項
解壓縮windows壓縮檔並打開
將glut32.dll移入windows資料夾內
將data解壓至windows資料夾內
(圖見Week03)
一.平移/旋轉/縮放 01.開啟Transformation,調整glTranslate(平移)的值
glTranslate(0,0,0)=glTranslate(X軸,Y軸,Z軸)

02.調整glRotatef(旋轉)的值
glRotatef(0,0,0)=glRotatef(旋轉)

03.調整glScalef(縮放)的值
glScalef(0,0,0)=glScalef(縮放)

二.配合自己的滑鼠 程式
可利用滑鼠點取坐標進而得到坐標程式


以下自己實作



反白後按Enter就能夠進行複製
滑鼠控制主要程式
#include <GL/glut.h>
#include <stdio.h>
void mouse(int button,int state,int x,int y){
if(state==GLUT_DOWN) printf("%d %d\n",x ,y);
}//滑鼠控制
void display(){
glClearColor(150/255.0,170/255.0,55/255.0,1);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("hello");//視窗名稱
glutDisplayFunc(display);
glutMouseFunc(mouse); //滑鼠控制
glutMainLoop();
}
三.運用cos及sin畫一個圓

想移動圓圈位置時
glPushMatrix();
glTranslatef(0,0,0);
glBegin(GL_POLYGON);
glEnd();
實際演練:

#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
void mouse(int button,int state,int x,int y){
if(state==GLUT_DOWN)
printf("%d %d\n",x ,y);
}
void display(){
glClearColor(150/255.0,170/255.0,55/255.0,1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3ub(175,193,81);
glBegin(GL_POLYGON);
for(float angle=0;angle<3.14159265357989 *2;angle+=0.1){ //angle的數值越小圓越圓
glVertex2f(0.5*cos(angle),0.5*sin(angle)); //上半圓+下半圓,0.5為調整圓大小的數值
}
glEnd();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("hello");//視窗名稱
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}

沒有留言:
張貼留言