一.要點
繪製立方體(或其他3d圖形)的方法與繪製三角形的方法類似,任何乙個3d圖形的輪廓都有一系列三角形構成.為減少資料冗餘,在繪製複雜3d圖形時,應使用
graphicsdevice.drawindexedprimitives()方法,而不是繪製三角形時所使用的graphicsdevice.drawuserprimitives()。
二.實現**
1.為game類新增成員變數:
1: vertexpositioncolor vertexlist;
2: vertexbuffer vertexbuffer;
3: ushortindexlist;
4: indexbuffer indexbuffer;
2.在loadcontent()方法中定義立方體六個頂點的座標
1: vertexlist = newvertexpositioncolor
2: ;
12: vertexbuffer = new vertexbuffer(
13: graphicsdevice,
14: typeof(vertexpositioncolor),
15: vertexlist.length,
16: bufferusage.none);
17: vertexbuffer.setdata(vertexlist);
3.定義頂點索引陣列:
1: indexlist = new ushort
2: ;
10: indexbuffer = new indexbuffer(
11: graphicsdevice,
12: typeof(ushort),
13: indexlist.length,
14: bufferusage.none);
15: indexbuffer.setdata(indexlist);
4.在draw()方法中新增繪製**:
1: graphicsdevice.setvertexbuffer(vertexbuffer);
2: graphicsdevice.indices = indexbuffer;
3:
4: int primitivecount = indexlist.length / 3;
5: foreach (var pass inbasiceffect.currenttechnique.passes)
6:
DirectX3D中繪製立方體
idirect3ddevice9 g device null idirect3dvertexbuffer9 g vb 0 立方體頂點 idirect3dindexbuffer9 g ib 0 索引資料 struct vertex vertex float x,float y,float z floa...
Qt使用QPainter繪製3D立方體
1.實現思路 網上有另一篇類似的,不過他不是用的 qt 自帶的矩陣運算類 實現思路有點類似使用 opengl 畫立方體,先準備頂點資料 立方體前後四個頂點,從右上角開始順時針 vertexarr qvector,qvector3d,qvector3d,qvector3d,qvector3d,qvec...
OpenGL WebGL 繪製立方體
include 繪製立方體 將立方體的八個頂點儲存到乙個陣列裡面 static const float vertex list 3 將要使用的頂點的序號儲存到乙個陣列裡面 static const glint index list 2 繪製立方體 void drawcube void glend s...