上禮拜沒上到課
結果今天第一節快尾聲才到教室 ㄨㄨ
我覺得有點難過 少學到好多圖學的東西
第一節課
問旁邊的同學一下進度
總共有三張圖給我們
這一張是上禮拜的進度
輕輕鬆鬆地做了出來
透明的線加上簍空的甜甜圈(?)
程式碼如下:
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glRotatef(angle,0,1,0);
glutWireTorus(0.3,0.7,30,30);
glFlush();
angle+=0.01;
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutCreateWindow("01160616");
glutDisplayFunc(display);
glutMainLoop();
}
第二張圖
其實他是有在旋轉的拉
你問我怎麼沒轉 ?
ㄎㄅ 你是要我節幾張圖拉 ?
在這邊的同時問了一個小問題
先看一下程式碼 :
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,1,0);
//glutWireTorus(0.3,0.7,30,30);
glBegin(GL_LINE_LOOP);
glVertex2f( 0.2, 0.2);
glVertex2f( 0.2,-0.2);
glVertex2f(-0.2,-0.2);
glVertex2f(-0.2, 0.2);
glEnd(); //這裡因為沒有加 () 所以一直跑不出畫面 謝謝小Ya老師
glPopMatrix();
glFlush();
angle+=0.01;
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutCreateWindow("01160616");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
第三張圖
我截了兩張開心了吧
因為就一直旋轉咩
因為就一直旋轉咩
阿不然你要我怎麼辦 嘖嘖
ㄇㄉ再問我沒選轉
我就怒退選= =凸
我就怒退選= =凸
程式碼如下 :
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,1,0);
glBegin(GL_LINE_LOOP);
glVertex3f( 0.2, 0.2,0.8);
glVertex3f( 0.2,-0.2,0.8);
glVertex3f(-0.2,-0.2,0.8);
glVertex3f(-0.2, 0.2,0.8);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2,-0.8);
glVertex3f(-0.2, 0.2,-0.8);
glEnd();
glPopMatrix();
glFlush();
angle+=0.01;
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutCreateWindow("01160616");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
第二節課
我畫出了一個紅紅長長的東西 ...噓
請看圖
請看圖
嘿嘿紅色長條型
有發現一個點
glPushMatrix();要對應到glPopMatrix();才OK
有發現一個點
glPushMatrix();要對應到glPopMatrix();才OK
不然他會越轉越快
不相信自己試試看 哈哈
程式碼如下 :
不相信自己試試看 哈哈
程式碼如下 :
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glPushMatrix();
glRotatef(angle,0,1,0.4);
glBegin(GL_LINE_LOOP);
glVertex3f( 0.2, 0.2,0.8);
glVertex3f( 0.2,-0.2,0.8);
glVertex3f(-0.2,-0.2,0.8);
glVertex3f(-0.2, 0.2,0.8);
glEnd();
glBegin(GL_POLYGON);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2,-0.8);
glVertex3f(-0.2, 0.2,-0.8);
glEnd();
glBegin(GL_QUAD_STRIP);
glVertex3f( 0.2, 0.2, 0.8);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2, 0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2, 0.8);
glVertex3f(-0.2,-0.2,-0.8);
glVertex3f(-0.2, 0.2, 0.8);
glVertex3f(-0.2, 0.2,-0.8);
glEnd();
glPopMatrix();
glFlush();
angle+=0.01;
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutCreateWindow("01160616");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
紅色地方是剛剛說的要對應~~
再來個厲害的
加上了黑色的線
他還是在旋轉不要再問我了 哈哈
其實都不難 只是點跟點的位置要對
他還是在旋轉不要再問我了 哈哈
其實都不難 只是點跟點的位置要對
Ya~~~~
程式碼如下 :
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0, 1, 0.4);
glColor3f(1,0,0);//畫面
glBegin(GL_POLYGON);
glVertex3f( 0.2, 0.2,0.8);
glVertex3f( 0.2,-0.2,0.8);
glVertex3f(-0.2,-0.2,0.8);
glVertex3f(-0.2, 0.2,0.8);
glEnd();
glBegin(GL_POLYGON);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2,-0.8);
glVertex3f(-0.2, 0.2,-0.8);
glEnd();
glBegin(GL_QUAD_STRIP);
glVertex3f( 0.2, 0.2, 0.8);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2, 0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2, 0.8);
glVertex3f(-0.2,-0.2,-0.8);
glVertex3f(-0.2, 0.2, 0.8);
glVertex3f(-0.2, 0.2,-0.8);
glEnd();
glColor3f(0,0,0);//畫線
glBegin(GL_LINE_LOOP);
glVertex3f( 0.2, 0.2,0.8);
glVertex3f( 0.2,-0.2,0.8);
glVertex3f(-0.2,-0.2,0.8);
glVertex3f(-0.2, 0.2,0.8);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2,-0.8);
glVertex3f(-0.2, 0.2,-0.8);
glEnd();
glBegin(GL_LINES);
glVertex3f( 0.2, 0.2, 0.8);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2, 0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2, 0.8);
glVertex3f(-0.2,-0.2,-0.8);
glVertex3f(-0.2, 0.2, 0.8);
glVertex3f(-0.2, 0.2,-0.8);
glEnd();
glPopMatrix();
glFlush();
angle+=0.01;
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutCreateWindow("01160616");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
輕輕鬆鬆
GL_POLYGON , GL_QUAD_STRIP , GL_LINE_LOOP , GL_LINES
這個很好用要好好記~~
第三節課
第三節課一開始就使用了滑鼠可以轉動
請看下圖
齁齁齁齁齁齁
我轉啊轉啊轉啊轉
其實只是給一個Void motion函數
直接拿出來使用
用到之後再主程式裡面呼叫
即可立即服用 阿不對 是使用 ㄏㄏ
程式碼如下 :
#include <GL/glut.h>
#include <stdio.h>
float angle=0 , angle2=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0, 1, 0);
glRotatef(angle2, 1, 0, 0);
glColor3f(0,1,0);//畫面
glBegin(GL_POLYGON);
glVertex3f( 0.2, 0.2,0.8);
glVertex3f( 0.2,-0.2,0.8);
glVertex3f(-0.2,-0.2,0.8);
glEnd();
glBegin(GL_POLYGON);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2,-0.8);
glEnd();
glBegin(GL_QUAD_STRIP);
glVertex3f( 0.2, 0.2, 0.8);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2, 0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2, 0.8);
glVertex3f(-0.2,-0.2,-0.8);
glEnd();
glColor3f(0,0,0);//畫線
glBegin(GL_LINE_LOOP);
glVertex3f( 0.2, 0.2,0.8);
glVertex3f( 0.2,-0.2,0.8);
glVertex3f(-0.2,-0.2,0.8);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2,-0.8);
glEnd();
glBegin(GL_LINES);
glVertex3f( 0.2, 0.2, 0.8);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2, 0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2, 0.8);
glVertex3f(-0.2,-0.2,-0.8);
glEnd();
glPopMatrix();
glFlush();
//angle+=0.01;
}
void motion(int x,int y)
{
printf("%d %d\n",x ,y);
angle = x;
angle2 = y;
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutCreateWindow("01160616");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
紅色標記的地方就是滑鼠操控的囉 =D
輕輕鬆鬆ㄎㄎ
再來一張厲害的
大家有沒有發現跟上一張圖有蝦咪不一樣嘛?
3.2.1 ......燈愣燈愣
公布答案
公布答案
差別就在於會不會看到後面的線
上一張有類似有顏色透視圖的感覺
而這一張是沒有的噢 =D
厲害吧
如果我也有透視功能就好了 ....(唯~~~~~)
程式碼如下 :
#include <GL/glut.h>
#include <stdio.h>
float angle=0 , angle2=0;
void display()
{
//要在main()裡面,glutInit之後,glutCreateWindow()之前
//加一行glutInitDisplayMode(GLUT_DEPTH);///讓顯示的window有3D深度的功能
glEnable(GL_DEPTH_TEST);//開啟DEPTH TEST深度測試, 近的會擋到遠的,遠的不會擋到近的
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0, 1, 0);
glRotatef(angle2, 1, 0, 0);
glColor3f(0,1,0);//畫面
glBegin(GL_POLYGON);
glVertex3f( 0.2, 0.2,0.8);
glVertex3f( 0.2,-0.2,0.8);
glVertex3f(-0.2,-0.2,0.8);
glEnd();
glBegin(GL_POLYGON);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2,-0.8);
glEnd();
glBegin(GL_QUAD_STRIP);
glVertex3f( 0.2, 0.2, 0.8);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2, 0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2, 0.8);
glVertex3f(-0.2,-0.2,-0.8);
glEnd();
glColor3f(0,0,0);//畫線
glBegin(GL_LINE_LOOP);
glVertex3f( 0.2, 0.2,0.8);
glVertex3f( 0.2,-0.2,0.8);
glVertex3f(-0.2,-0.2,0.8);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2,-0.8);
glEnd();
glBegin(GL_LINES);
glVertex3f( 0.2, 0.2, 0.8);
glVertex3f( 0.2, 0.2,-0.8);
glVertex3f( 0.2,-0.2, 0.8);
glVertex3f( 0.2,-0.2,-0.8);
glVertex3f(-0.2,-0.2, 0.8);
glVertex3f(-0.2,-0.2,-0.8);
glEnd();
glPopMatrix();
glFlush();
//angle+=0.01;
}
void motion(int x,int y)
{
printf("%d %d\n",x ,y);
angle = x;
angle2 = y;
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH);
glutCreateWindow("01160616");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
好囉 今天的課程又結束了
我要趕去圖書館借書了
去弄我的專研了GG
專研快GG囉 嗚嗚
沒有留言:
張貼留言