HW1
覺得上周很棒的五個作品
拍拍手~~~
HW2
1. http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 到這個網站下
2.把 windows.zip 和 data.zip解壓縮
3.將data的資料夾和glut32.dll放進windows的資料夾
4.開啟Transformation 可參考他利用滑鼠改變角度和轉動方向與位置
HW2
1.利用滑鼠點擊時的位置輸出他的座標值
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
printf("glVertex2f((%d-150)/150.0,(%d-150)/150.0);\n",x,y);
}
利用GLUT函式裡的GLUT_DOWN
來判斷滑鼠按下時的動作,可以用來判斷點擊時的那個位置的座標。
HW3
利用程式畫圓
#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("glVertex2f((%d-150)/150.0,(%d-150)/150.0);\n",x,y);
}
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
glColor3f(25/255.0,123/255.0,224/255.0);
glPushMatrix();
glTranslatef(0,0,0); //改變初始位置(x,y,z),打在glBegin(GL_POLYGON)前
glBegin(GL_POLYGON);
for(float angle=0; angle<3.1415926535 *2; angle+=0.1) //畫圓的數學程式,利用COS和SIN的 角度關係來畫圓
{
glVertex2f(0.4*cos(angle), 0.4*sin(angle));
}
glEnd();
glTranslatef(-0.45,0.45,0);
glBegin(GL_POLYGON);
for(float angle=0; angle<3.1415926535 *2; angle+=0.1)
{
glVertex2f(0.3*cos(angle), 0.3*sin(angle));
}
glEnd();
glTranslatef(0.9,0,0);
glBegin(GL_POLYGON);
for(float angle=0; angle<3.1415926535 *2; angle+=0.1)
{
glVertex2f(0.3*cos(angle), 0.3*sin(angle));
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);//開啟
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//雙重顯示模式
glutCreateWindow("Hello 3D");//開視窗
glutMouseFunc(mouse);
glutDisplayFunc(display);//執行display程式
glutMainLoop();
}




沒有留言:
張貼留言