2020年6月20日 星期六

week18

今天是程式設計克的最後一節上課,今天老師教我們3D建模
因為原本的實在是太小了,所以我們要用scale把它放大
程式碼:
PShape gundam;
void setup(){
  size(500,500,P3D);
  gundam=loadShape("Gundam.obj");
}
void draw(){
  scale(10,10,10);
  shape(gundam); 
}

可是現在鋼彈只有左半身而已,所以現在要用translate把它往右移
程式碼:
PShape gundam;
void setup(){
  size(500,500,P3D);
  gundam=loadShape("Gundam.obj");
}
void draw(){
  translate(250,0,0);
  scale(10,10,10);
  shape(gundam); 
}

現在鋼但是在上下顛倒的狀態,所以我們要把它用rotate旋轉一下,不過rotate是用弧度在旋轉,所以它現在看起來怪怪的
程式碼:
PShape gundam;
void setup(){
  size(500,500,P3D);
  gundam=loadShape("Gundam.obj");
}
void draw(){
  rotate(1);
  translate(250,0,0);
  scale(10,10,10);
  shape(gundam); 
}
最後,讓他在Y軸旋轉然後把它翻過來再調一下Y軸的位子就好了
程式碼:
PShape gundam;
void setup(){
  size(500,500,P3D);
  gundam=loadShape("Gundam.obj");
}
void draw(){
  background(128);
  translate(250,400,0);
  scale(10,-10,10);
  rotateY(radians(frameCount));
  shape(gundam); 
}
現在我們要做地球,總之先把圖讀進來
程式碼:
PImage img;
void setup(){
  size(300,300,P3D);
  img=loadImage("earth.jpg");
}
void draw(){
  image(img,0,0); 
}
創造一個圓形,等等要把地球包上去
程式碼:
PImage img;
PShape globe;
void setup(){
  size(300,300,P3D);
  img=loadImage("earth.jpg");
  globe=createShape(SPHERE,100);
}
void draw(){
  image(img,0,0);
  shape(globe);
}
用新增的程式碼把地球的圖片給貼上去
程式碼:
PImage img;
PShape globe;
void setup(){
  size(300,300,P3D);
  img=loadImage("earth.jpg");
  globe=createShape(SPHERE,100);
  globe.setTexture(img);
}
void draw(){
  shape(globe);
}
移到中間

最後把線清掉、背景清掉、旋轉就完成了
程式碼:
PImage img;
PShape globe;
void setup(){
  size(300,300,P3D);
  img=loadImage("earth.jpg");
  globe=createShape(SPHERE,100);
  globe.setStroke(false);
  globe.setTexture(img);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  rotateY(radians(frameCount));
  shape(globe);
}
自轉不夠,我還想讓它公轉
程式碼:
PImage img;
PShape globe;
void setup(){
  size(300,300,P3D);
  img = loadImage("earth.jpg");
  globe = createShape(SPHERE, 100);
  globe.setStroke(false);
  globe.setTexture(img);
}
void draw(){
  background(128);
  noStroke();
  rotateY(radians(frameCount));
  translate(width/2,height/2);
  rotateY(radians(frameCount)*10);
  shape(globe);
}

沒有留言:

張貼留言