2018年1月11日 星期四
2017年12月14日 星期四
蔡陳杰的計圖筆記week14

RASTERIZATION(光柵化)
實做老師的程式
size(600,600,P3D);
background(255);
beginShape(TRIANGLE);
fill(255,0,0);vertex(300,100);
fill(255,255,0);vertex(500,500);
fill(0,0,255);vertex(100,500);
endShape();

void setup(){
size(600,600,P3D);
}
void draw(){
background(255);
beginShape(TRIANGLE);
fill(255,0,0);vertex(300,100,0);
fill(255,255,0);vertex(500,500,100); Z值表示該點在圖層的哪個位置 Z較大的會在圖層最上方
fill(0,0,255);vertex(100,500,0);
endShape();
beginShape(TRIANGLE);
fill(255,200,0);vertex(500,100,0);
fill(100,255,0);vertex(500,500,20);
fill(0,0,20);vertex(100,500,0);
endShape();
}
2017年12月7日 星期四
蔡陳杰的計圖筆記week13
1.第一堂課 老師要我們去玩 google 的 coding game
我在家裡已經玩過了
2.條色彩
size(255,255);
colorMode(RGB,255);
for(int x=0;x<255;x++)
{
for(int y=0;y<255;y++)
{
stroke(x,y,255); //呈現顏色
point(x,y); //畫一個點
}
}
3.看老師給的roach檔
還有fb上的影片
老師給了許多對專題有用的建議
有等速移動跟光劍特效
我在家裡已經玩過了
2.條色彩
size(255,255);
colorMode(RGB,255);
for(int x=0;x<255;x++)
{
for(int y=0;y<255;y++)
{
stroke(x,y,255); //呈現顏色
point(x,y); //畫一個點
}
}
3.看老師給的roach檔
還有fb上的影片
老師給了許多對專題有用的建議
有等速移動跟光劍特效
2017年11月30日 星期四
蔡陳杰的計圖筆記week 12
2017年11月23日 星期四
蔡陳杰的圖學筆記Week11
這禮拜所教的是如何播音樂
#include<mmsystem.h> 這行要include 否則PlaySoundA不能用
檔名 不等 下一行馬上繼續
PlaySoundA("file.wav",NULL,SND_ASYNC);
等這個跑完 才跑下一行
SND_SYNC
接下來可以用老師給的函式庫 CMP3_MCI.h
音樂檔要丟在freeglut 的 bin 裡面
可以使用mp3來播音樂
#include<GL/glut.h>
#include<mmsystem.h>
#include<stdio.h>
#include"CMP3_MCI.h"
CMP3_MCI mp3;
int main()
{
mp3.Load("file.mp3");//讀入音樂
mp3.Play(); //播音樂
int a;
scanf("%d",&a);
}
使用p語言也可做出
先下載 minim
#include<mmsystem.h> 這行要include 否則PlaySoundA不能用
檔名 不等 下一行馬上繼續
PlaySoundA("file.wav",NULL,SND_ASYNC);
等這個跑完 才跑下一行
SND_SYNC
接下來可以用老師給的函式庫 CMP3_MCI.h
音樂檔要丟在freeglut 的 bin 裡面
可以使用mp3來播音樂
#include<GL/glut.h>
#include<mmsystem.h>
#include<stdio.h>
#include"CMP3_MCI.h"
CMP3_MCI mp3;
int main()
{
mp3.Load("file.mp3");//讀入音樂
mp3.Play(); //播音樂
int a;
scanf("%d",&a);
}
使用p語言也可做出
先下載 minim
2017年11月9日 星期四
蔡陳杰的計算機圖學筆記 week09
首先 先下載老師給的軟體 processing-3.3.6-windows64.zip
接著也可以自己做圖形
進化成比較有程式風格的寫法
最後能用這程式寫一個類似馬力歐的程式
int [][]map={{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,2,2,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
PImage imgMragon,imgBrick,imgBrick2;
void setup()
{
size(800,760);
imgMario=loadImage("mario.png");
imgBrick=loadImage("brick.png");
imgBrick2=loadImage("brick2.png");
}
float marioX=200, marioY=100, marioVX=0, marioVY=0;
boolean marioOnFloor=false;
void draw()
{
background(255);
//for(int x=0;x<20;x++) image(imgBrick,x*50,500,50,50);
for(int x=0;x<14;x++){
for(int y=0;y<11;y++){
if(map[y][x]==1) image(imgBrick,x*50,y*50,50,50);
if(map[y][x]==2) image(imgBrick2,x*50,y*50,50,50);
}
}
image(imgMario,marioX,marioY,100,100);
marioY += marioVY;
marioX += marioVX;
marioVY += 0.98;
if(marioY>=500-100)
{
marioY=500-100;
marioVY=0;
marioOnFloor=true;
}
}
void keyPressed()
{
if(keyCode==UP && marioOnFloor) { marioVY=-15; marioOnFloor=false;}
if(keyCode==RIGHT) marioVX=5;
if(keyCode==LEFT) marioVX=-5;
}
void keyReleased()
{
if(keyCode==RIGHT || keyCode==LEFT) marioVX=0;
}
int [][]map={{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,2,2,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
PImage imgMragon,imgBrick,imgBrick2;
void setup()
{
size(800,760);
imgMario=loadImage("mario.png");
imgBrick=loadImage("brick.png");
imgBrick2=loadImage("brick2.png");
}
float marioX=200, marioY=100, marioVX=0, marioVY=0;
boolean marioOnFloor=false;
void draw()
{
background(255);
//for(int x=0;x<20;x++) image(imgBrick,x*50,500,50,50);
for(int x=0;x<14;x++){
for(int y=0;y<11;y++){
if(map[y][x]==1) image(imgBrick,x*50,y*50,50,50);
if(map[y][x]==2) image(imgBrick2,x*50,y*50,50,50);
}
}
image(imgMario,marioX,marioY,100,100);
marioY += marioVY;
marioX += marioVX;
marioVY += 0.98;
if(marioY>=500-100)
{
marioY=500-100;
marioVY=0;
marioOnFloor=true;
}
}
void keyPressed()
{
if(keyCode==UP && marioOnFloor) { marioVY=-15; marioOnFloor=false;}
if(keyCode==RIGHT) marioVX=5;
if(keyCode==LEFT) marioVX=-5;
}
void keyReleased()
{
if(keyCode==RIGHT || keyCode==LEFT) marioVX=0;
}
2017年11月2日 星期四
蔡陳杰的計算機圖學筆記 week08
2017年10月26日 星期四
蔡陳杰的計算機圖學week07
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f }; 的const給刪掉 因為下面會改到值
加入motion函式
void motion(int x,int y)
{
light_position[0]= (x-150.0)/150.0*2;
light_position[1]= -(y-150.0)/150.0*2;
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glutPostRedisplay();
}
最後在main加入
glutMotionFunc(motion);
即可完成打光
加入motion函式
void motion(int x,int y)
{
light_position[0]= (x-150.0)/150.0*2;
light_position[1]= -(y-150.0)/150.0*2;
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glutPostRedisplay();
}
最後在main加入
glutMotionFunc(motion);
即可完成打光
2017年10月19日 星期四
蔡陳杰的計算機圖學筆記week06
使用上禮拜老師下載的 "week05" 並加入下列幾行 已達成打光效果
GLfloat pos[] = { 0.0, 0.0, -1.0, 0.0 };
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, pos);

接著加入鍵盤與滑鼠功能
先加入這2個函式
void keyboard(unsigned char key,int x,int y)
{
printf("now: %c(%d %d)\n",key,x,y);
}
void mouse(int button,int state,int x,int y)
{
}
接著在 glutDisplayFunc(display);這行下加入
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
這樣使用鍵盤時 便能印出位置

加入 這幾行 使他可以案1往x軸轉 案2往y軸轉 案3往z軸轉
if(key=='1') rotateX++;
if(key=='2') rotateY++;
if(key=='3') rotateZ++;
glPushMatrix();
glRotatef(rotateX,1,0,0);
glRotatef(rotateY,0,1,0);
glRotatef(rotateZ,0,0,1);
drawmodel();
glPopMatrix();

加入這幾行 可以用滑鼠旋轉
void mouse(int button,int state,int x,int y)
{
printf("%d %d",x,y);
if(state==GLUT_DOWN)
{
oldX=x;
oldY=y;
}
}
void motion(int x,int y)
{
rotateY += -(x-oldX);
rotateX +=-(y-oldY);
oldX=x;
oldY=y;
glutPostRedisplay();
}
glutMotionFunc(motion);
GLfloat pos[] = { 0.0, 0.0, -1.0, 0.0 };
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, pos);

接著加入鍵盤與滑鼠功能
先加入這2個函式
void keyboard(unsigned char key,int x,int y)
{
printf("now: %c(%d %d)\n",key,x,y);
}
void mouse(int button,int state,int x,int y)
{
}
接著在 glutDisplayFunc(display);這行下加入
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
這樣使用鍵盤時 便能印出位置

加入 這幾行 使他可以案1往x軸轉 案2往y軸轉 案3往z軸轉
if(key=='1') rotateX++;
if(key=='2') rotateY++;
if(key=='3') rotateZ++;
glPushMatrix();
glRotatef(rotateX,1,0,0);
glRotatef(rotateY,0,1,0);
glRotatef(rotateZ,0,0,1);
drawmodel();
glPopMatrix();

加入這幾行 可以用滑鼠旋轉
void mouse(int button,int state,int x,int y)
{
printf("%d %d",x,y);
if(state==GLUT_DOWN)
{
oldX=x;
oldY=y;
}
}
void motion(int x,int y)
{
rotateY += -(x-oldX);
rotateX +=-(y-oldY);
oldX=x;
oldY=y;
glutPostRedisplay();
}
glutMotionFunc(motion);
2017年10月12日 星期四
蔡陳杰的計算機圖學筆記 week 5
1.複習上禮拜的內容
去jsyeh.org/3dcg10 下載 win32 data 和glut32.dll
把win32解壓縮 把data解壓縮到win32還有把glut32.dll丟進去
並執行Transformation.exe 複習上周所學的 translatef rotatef scalef

2.學習投影
開啟Projection.exe
(1)gluPerspective(foxy, aspect, zNear, zFar)
視野,y/x比例

(2) glOrth( 左, 右, 下, 上, 近, 遠)
glFrustum(SAME AS ABOVE)
(3)gluLookAt(eyeX ,eyeY,eyeZ -->眼睛的位置
centerX, centerY,centerZ --->物體的位置
upX , upY, upZ --->相機的角度(使用向量))
3 strdup !!! naming C/C++版本問題
使用這個解決


去jsyeh.org/3dcg10 下載 win32 data 和glut32.dll
把win32解壓縮 把data解壓縮到win32還有把glut32.dll丟進去
並執行Transformation.exe 複習上周所學的 translatef rotatef scalef

2.學習投影
開啟Projection.exe
(1)gluPerspective(foxy, aspect, zNear, zFar)
視野,y/x比例

(2) glOrth( 左, 右, 下, 上, 近, 遠)
glFrustum(SAME AS ABOVE)
(3)gluLookAt(eyeX ,eyeY,eyeZ -->眼睛的位置
centerX, centerY,centerZ --->物體的位置
upX , upY, upZ --->相機的角度(使用向量))
3 strdup !!! naming C/C++版本問題
使用這個解決


2017年10月5日 星期四
蔡陳杰的計算機圖學 week04
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = t*90.0;
glPushMatrix(); 備份矩陣
glTranslated(-2.4,1.2,-6); 移到(X,Y,Z)的位置
(double)
glRotated(60,1,0,0); 全部先照X軸繞60度 (為了美觀
glRotated(a,0,0,1); 繞著Z軸轉 a角度會跟著啟動時間而改變因此行成轉動
//glutSolidSphere(1,slices,stacks); 畫一個實心圓形 不過被我注解掉了
glutWireTeapot(1); 畫一個空心茶壺
glPopMatrix(); 還原矩陣
const double a = t*90.0;
glPushMatrix(); 備份矩陣
glTranslated(-2.4,1.2,-6); 移到(X,Y,Z)的位置
(double)
glRotated(60,1,0,0); 全部先照X軸繞60度 (為了美觀
glRotated(a,0,0,1); 繞著Z軸轉 a角度會跟著啟動時間而改變因此行成轉動
//glutSolidSphere(1,slices,stacks); 畫一個實心圓形 不過被我注解掉了
glutWireTeapot(1); 畫一個空心茶壺
glPopMatrix(); 還原矩陣
glPushMatrix();
glTranslated(-2.4,1.2,-6);
///glRotated(60,1,0,0);
glRotated(a,1,1,0);
glScalef(0.5,0.5,0.5); X縮小0.5倍 Y縮小0.5倍 Z縮小0.5倍
glutSolidSphere(1,slices,stacks); 畫實心圓
glutSolidTeapot(1); 畫實心茶壺
glPopMatrix();
2017年9月28日 星期四
蔡陳杰的計算機圖學筆記 Week 3
第一節課 學姊的小小兵
glPointSize(10.0f); 把點放大 10倍 可避免把圖拉大後破圖
minion.txt 使用筆記本把每個點的顏色存起來 並用讀檔方式讀進去
學姊的 glClear(GL_COLOR_BUFFER_BIT); 這行可能有問題
應改成 glClear(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT);
第二節課 足球
下載 3D EXPLORATION
去 jsyeh.org/3dcg10 網站 下載DATA
找一個喜歡的圖案(我是選足球) 使用 3D EXPLORATION 另存成 cpp檔案 存成sample APP
開啟opengl 專案 並把 main.c 改成main.cpp
把轉過來的cpp檔 程式碼丟到 main裡面
接著把不能執行的地方隱藏起來
glPointSize(10.0f); 把點放大 10倍 可避免把圖拉大後破圖
minion.txt 使用筆記本把每個點的顏色存起來 並用讀檔方式讀進去
學姊的 glClear(GL_COLOR_BUFFER_BIT); 這行可能有問題
應改成 glClear(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT);
第二節課 足球
下載 3D EXPLORATION
去 jsyeh.org/3dcg10 網站 下載DATA
找一個喜歡的圖案(我是選足球) 使用 3D EXPLORATION 另存成 cpp檔案 存成sample APP
開啟opengl 專案 並把 main.c 改成main.cpp
把轉過來的cpp檔 程式碼丟到 main裡面
接著把不能執行的地方隱藏起來
2017年9月21日 星期四
蔡陳杰的WEEK2
1.畫一個面
#include <GL/glut.h>
void display(void)
{
glClearColor(1,0,0,0);設置背景的顏色 :紅色
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 把背景設成上述的顏色
glColor3f(0,0,0);設置顏色為黑色
glBegin(GL_POLYGON);開始畫一個多邊形
glVertex3f(0,0,0);
glVertex3f(0,1,0);
glVertex3f(1,0,0); 設置3個頂點
glEnd(); 結束畫
glutSwapBuffers(); 將緩衝區互換
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv); 開始使用GLUT程式
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);設定顯示模式
glutCreateWindow("GLUT Shapes"); 建立glut 3D模式
glutDisplayFunc(display); 使用上述函式
glutMainLoop();結束迴圈
}

2 畫茶壺
glutSolidTeapot(0.3); 使用這個外掛程式化一個茶壺
#include <GL/glut.h>
void display(void)
{
glClearColor(1,0,0,0);設置背景的顏色 :紅色
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 把背景設成上述的顏色
glColor3f(0,0,0);設置顏色為黑色
glBegin(GL_POLYGON);開始畫一個多邊形
glVertex3f(0,0,0);
glVertex3f(0,1,0);
glVertex3f(1,0,0); 設置3個頂點
glEnd(); 結束畫
glutSwapBuffers(); 將緩衝區互換
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv); 開始使用GLUT程式
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);設定顯示模式
glutCreateWindow("GLUT Shapes"); 建立glut 3D模式
glutDisplayFunc(display); 使用上述函式
glutMainLoop();結束迴圈
}

2 畫茶壺
glutSolidTeapot(0.3); 使用這個外掛程式化一個茶壺
2017年9月14日 星期四
訂閱:
文章 (Atom)


















