顯示具有 Week04 標籤的文章。 顯示所有文章
顯示具有 Week04 標籤的文章。 顯示所有文章

2019年10月3日 星期四

喬 的 無 形 壓 力 日 Week4

牛頓運動

左右滾















int ballX=300, ballY=300;
int vx=-2;
void setup() {
  size(700, 400);
}
void draw() {
  background(255);
  ellipse(ballX, ballY, 30, 30);
  ballX +=vx;

  if (ballX<0) vx =+2;
  if (ballX>700) vx =-2;
}

int ballX=300, ballY=300;
int vx=-2, vy=+2;
void setup() {
  size(700, 400);
}
void draw() {
  background(255);
  ellipse(ballX, ballY, 30, 30);
  ballX +=vx;
  ballY +=vy;
  if (ballX<0 +15) vx =+2;  ///原本是球的圓心在框框內
  if (ballX>700 -15) vx =-2;   ///+-15  球的邊緣在框框內
  if(ballY<0 +15) vy =+2;
  if(ballY>400 -15) vy =-2
}

紀錄路徑




































float ballX=300, ballY=300;
float vx=-2, vy=-10;
void setup() {
  size(600, 400);
}
void draw() {
  //background(255);
  ellipse(ballX, ballY, 30, 30);
  ballX +=vx;
  ballY +=vy; println(vy);
  vy += 0.98;
  if (ballX<0 +15)      vx= -vx*0.9;
  if (ballX>700 -15)    vx= -vx*0.9;
  if (ballY<0 +15)      vy= -vy*0.9;
  if (ballY>400 -15)    vy= -vy*0.9;
}

































float ballX=300, ballY=300;
float vx=-2, vy=-10;
void setup() {
  size(600, 400);
}
void draw() {
  //background(255);
  ellipse(ballX, ballY, 30, 30);
  ballX +=vx;
  ballY +=vy; println(vy);
  vy += 0.98;
  if (ballX<0 +15)      vx= -vx*0.9;
  if (ballX>700 -15)    vx= -vx*0.9;
  if (ballY<0 +15)      vy= -vy*0.9;
  if (ballY>400 -15){
    vy = -vy+0.9;
    vx = vx*0.9;
    ballY=400-15;
  }
  vy +=0.98;
}

馬力歐
































PImage imgMario;
float marioX=100 , marioY=100;
float marioVX=0 , marioVY=0;
void setup() {
  size(500, 500);
  imgMario = loadImage("mario.png");
}
void draw() {
  //background(255); ///背景
  rect(0, 200, 500,50); ///樓梯
  image(imgMario, marioX, marioY, 100, 100);
  marioX +=marioVX;
  marioY +=marioVY;
  if(marioY<=100) marioVY +=0.9;
  else marioY = 100; ///hold on floor
}
void keyPressed(){
  if(keyCode==RIGHT) marioX+=3;
  if(keyCode==LEFT)  marioX-=3;
  if(keyCode==UP){
    marioVY = -15;
  }
}

















PImage imgMario;
float marioX=100 , marioY=100;
float marioVX=0 , marioVY=0;
void setup() {
  size(500, 500);
  imgMario = loadImage("mario.png");
}
void draw() {
  background(255);
  rect(0, 200, 500,50);  ///樓梯

  image(imgMario, marioX, marioY, 100, 100);
  marioX +=marioVX;
  marioY +=marioVY;
  if(softBrake==1) marioVX *=0.9;
  if(marioY<=100) marioVY +=0.9;
  else marioY = 100; ///hold on floor
}
int softBrake=0;
void keyReleased(){
  if(keyCode==RIGHT) softBrake=1;
  if(keyCode==LEFT)  softBrake=1;
}
void keyPressed(){
  if(keyCode==RIGHT){
    marioVX=3; ///marioX+=3;
    softBrake=0;
  }else if(keyCode==LEFT){
    marioVX=-3; ///marioX-=3;
    softBrake=0;
  }else if(keyCode==UP){
    marioVY = -15;
  }
}

2019年4月1日 星期一

week04

week04

主題 : 旋轉Rotate


一、範例

(1)到 這裡 將 data、win32、gult32.dll 下載並解壓縮
(同 week02 一、使用freeglut簡化程式)











(2)即可開啟Transformation.exe












二、滑鼠移動motion

(1)同 week01 第一個GLUT程式相同


(2)刪除原本程式,並加上以下程式碼,滑鼠即可點茶壺移動








(以下為程式碼)

#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);
    glutMotionFunc(motion);

    glutMainLoop();

}




三、滑鼠移、轉



(1)程式碼中增加rotate,即可用滑鼠將茶壺轉動









(以下為程式碼)


#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glRotatef(  x  ,0,1,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);
    glutMotionFunc(motion);



    glutMainLoop();





}




(可將中間標記地方修改一下,旋轉方向即可改變)


2019年3月29日 星期五

PJ週記-Week04之 來福薩克死洗腦♪♪♪

這幾天FB跟IG不知道在當幾點的呢
果然是來福薩克死摁摁(◉◞౪◟◉ )

但還是要好好上小葉的課啦
好好愛這世界ㄅ( ´•ω•` )


【每堂必備】

(一)
依照慣例先下載[data][win32][glut32.dll]
把資料用成下圖
(二)
複製lib裡面的freeglut.a>>複製貼上改成libglut32.a

【正課開始ヽ(✿゚▽゚)ノ】

今天也一樣玩上次的小車車


2019年3月22日 星期五

Tokoyami_world.exe_week04

今天的課程重點主要為「以滑鼠實現物件轉動」。首先將範例程式下載下來(沒錯,就跟之前一樣)(以下略......)


旋轉的範例出來啦~~

嗯......感覺就跟平移有幾分神似,應該就是建立於上周所學的程式碼之上,總之先把程式碼打上吧......


如此一來物件就能隨著滑鼠滑動了~~

接著就是重點了,該如何轉動它?

這時候就需要一點想法,如何讓它以x軸為中心旋轉?

因為這次主要是為了實現旋轉,因此先註解掉原先的平移程式碼,接著再加上旋轉指令「glRotatef(x ,0 ,1 ,0);」......


終於完成了~~

2019年3月15日 星期五

龔書霆_week04

先去這個網站http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
把data win32 glut32.dll下載下來
把windows資料夾解壓縮把data解壓縮和glut.32丟進去
像上禮拜一樣打開這個Transformation.exe


今天的程式碼茶壺要跟著滑鼠移動

#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("06160823");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

轉動程式碼
#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(x,1,1,0);
        //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("06160823");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}


huangxuuu電腦圖學week04

一.開啟Transformation模擬器




二.輸入int main(){},void display(){},void motion(){}三部份

第一二周學到int main裡面的程式以及第3行、10~18行
第三周學到紅色框框6~9行 ,是拖曳程式void motion(){}
第四周學到紫色框框,將拖曳程式完整寫完

三.拖曳程式執行結果



如果把程式碼第4行拿掉,程式就失去清除記錄的功能
結果如下



四.旋轉程式執行結果




 

week 04




 
                                              到www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10
                                                                   下載windows.zip
                                                                           data.zip
                                                                          glut32.dll
 

windows.zip解壓縮,將data放進windows裡,並且glut32.dll也放進windows裡,這樣就能開啟保時捷進行移動,旋轉,縮放
 
 
到freeglut windows下載紅線所圈的
 
在freeglut的lib裡面複製一個libglut32.a
 
先把week03所學的用滑鼠移動茶壺程式寫出來
 
移動茶壺程式碼:
 
#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_translate");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}
 
多加了這行程式碼glRotatef(x,0,1,0); 可讓茶壺旋轉
 
 


學渣的奮鬥史-4

今天一切的開始從座標開始講解
講解的方式很有趣,拿烤雞當例子,講解在空間中x,y,z的座標


所以,今天就從烤雞開始吧(好餓(。ŏ_ŏ)

接下來有介紹好用的解壓縮程式-7.z

在效率上對於winrar有明顯的差距

接著跟我們介紹另一個班做得不做的案例

其中看到幾個做得不錯的實在是讓人驚艷呢

接著

仔細的講解了上次課程中,在上次課程的最後講解了滑鼠的應用

今天再把應用拿出來,在講解一次讓我們有更深入的了解

glPushMatrix ( ) ; //備份矩陣,保護好程式


glPopMatrix ( ) ; //還原矩陣,跟上面的備份矩陣一起使用


使用方式如下


glPushMatrix();//備份矩陣,保護好程式
        glTranslated(0.2,0.2,0);//移動茶壺的程式
        glutSolidTeapot(0.3);//實心茶壺
glPopMatrix();//還原矩陣,跟上面的備份矩陣一起使用

使用後就能避免掉茶壺會重複移動的問題了

然後今天介紹了新的東西{glRotatedf(angle,x,y,z)}

glRotatedf()函數內分別是角度x座標y座標z座標

使用函式後,函式如下圖

glPushMatrix();//備份矩陣,保護好程式
        glTranslated(0.2,0.2,0);//移動茶壺的程式
       glRotatedf(angle,x,y,z)
        glutSolidTeapot(0.3);//實心茶壺
glPopMatrix();//還原矩陣,跟上面的備份矩陣一起使用

加函式進去後,程式結果如下圖


需要改變的角度可對應座標去進行修改angle


準備下課囉(好餓

吃飯去  ─=≡Σ((( つ•̀ω•́)つ





今天小葉老師的英文時間

Rotate 迴轉


week4筆記

1.滑鼠motion

(1)移動:
執行出來茶壺會隨著滑鼠移動

#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);///移動x,y,z  =>在week3有教,小畫家的座標換算:座標減掉一半除掉最大值,就變成-1~+1之間glVertex2f( (x-100)/100.0, -(y-100-100.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("translate");
    glutDisplayFunc(display);
    glutMotionFunc(motion););///負責motion的函式,乎叫motion()
    glutMainLoop();

}

 (2)轉動:



將 glTranslatef((x-150)/150.0,-(y-150)/150.0,0);改成
     glRotatef(x,0,1,0);=>左右轉動
                   or
     glRotatef(y,1,0,0);=>上下轉動

麵包超人-week04

小葉老師今天教了我們可以去移動和旋轉一個茶壺

喬巴的失控道具日 Weekfour

旋轉

























茶壺跟著滑鼠
















#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);///啟動GLUT
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);

    glutMotionFunc(motion);///現在重點在滑鼠
    glutMainLoop();
}

移動變旋轉















在void display(){}中加
glRotatef( y, 1,0,0);

這是在 中四個點任意選一個點作變異數
就可以用滑鼠控制旋轉

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣,保護好
        glRotatef( y, 1,0,0);
        ///glTranslatef( (x-150)/150.0 , -(y-150)/150.0 , 0 );
        glutSolidTeapot( 0.3 );
    glPopMatrix();///還原復原,恢復

    glutSwapBuffers();
}