120 likes | 282 Views
Chap 05 3D. The Programmer ’ s Interface. OpenGL(Open Graphics Library) Cross-platform Windows Unix/Linux Mac Java SGI, 1992 Professional graphics http://www.opengl.org. The Programmer ’ s Interface. DirectX Windows-platform / XBOX Microsoft, 1995 Computer Game 前身為 WinG
E N D
The Programmer’s Interface • OpenGL(Open Graphics Library) • Cross-platform • Windows • Unix/Linux • Mac • Java • SGI, 1992 • Professional graphics • http://www.opengl.org
The Programmer’s Interface • DirectX • Windows-platform / XBOX • Microsoft, 1995 • Computer Game • 前身為WinG • 較為常見的版本為DX3(support 3D), DX6, DX9
OpenGL The Programmer’s Interface • Library • DirectGraphic(Direct3D & DirectDraw) • DirectPlay • DirectSound • DirectInput • http://www.microsoft.com/windows/directx
JOGL 注意:外部Library import processing.opengl.*; • Java OpenGL • https://jogl.dev.java.net/
3D的座標系統 size(X, Y, P3D) / size(X, Y, OPENGL) X軸 (0,0) Z軸 <想想看> 沒指定Z的範圍 Y軸 <想想看> P3D和OPENGL差別 (X, Y)
size(Width, Height, P3D); • translate(X, Y, Z) -位移 • 請畫出右邊的場景 • rotateX(Num), rotateY(Num), rotateZ(Num) -旋轉, Num為弧度 • pushMatrix() 、popMatrix() • lights() -光源
2D指令 • sphere(Radius) • box(Length, Width, Height)
size(320,200,P3D); noStroke(); lights(); pushMatrix(); translate(160,100); fill(255,0,0); sphere(40); popMatrix(); pushMatrix(); translate(100,100); rotateX(0.6); fill(0,255,0); box(20,20,30); popMatrix();
translate,rotate先後順序有差嗎 <試試看> 自轉 vs 公轉
import processing.opengl.*; float boxr; void setup() { size(320,200,P3D); noStroke(); boxr=0; } void draw() { background(0); lights(); pushMatrix(); translate(160,100); fill(255,0,0); sphere(20); translate(40,0); rotateY(boxr); fill(0,255,0); box(10,10,10); popMatrix(); boxr+=0.01; }
課堂作業 • 地球繞太陽,月亮繞地球