2. Define the coordinates of the six vertices of the cube in the loadcontent () method.
1: vertexlist =NewVertexpositioncolor []
2 :{
3:NewVertexpositioncolor (NewVector3 (1f, 1f,-1f), color. Red ),
4:NewVertexpositioncolor (NewVector3 (1f,-1f,-1f), color. Red ),
5:NewVertexpositioncolor (NewVector3 (-1f,-1f,-1f), color. Red ),
6:NewVertexpositioncolor (NewVector3 (-1f, 1f,-1f), color. Red ),
7:NewVertexpositioncolor (NewVector3 (1f, 1f, 1f), color. Red ),
8:NewVertexpositioncolor (NewVector3 (1f,-1f, 1f), color. Red ),
9:NewVertexpositioncolor (NewVector3 (-1f,-1f, 1f), color. Red ),
10:NewVertexpositioncolor (NewVector3 (-1f, 1f, 1f), color. Red)
11 :};
12: vertexbuffer =NewVertexbuffer (
13: graphicsdevice,
14:Typeof(Vertexpositioncolor ),
15: vertexlist. length,
16: bufferusage. None );
17: vertexbuffer. setdata <vertexpositioncolor> (vertexlist );
3. Define the vertex index array:
1: indexlist = new ushort []
2 :{
3,
4: 7, 4, 5, 7, 5, 6,
5,
6,
7,
8: 2, 1, 5, 2, 5, 6
9 :};
10: indexbuffer = new indexbuffer (
11: graphicsdevice,
12: typeof (ushort ),
13: indexlist. length,
14: bufferusage. None );
15: indexbuffer. setdata <ushort> (indexlist );
4. Add the drawing code in the draw () method:
1: graphicsdevice. setvertexbuffer (vertexbuffer );
2: graphicsdevice. Indices = indexbuffer;
3:
4:IntPrimitivecount = indexlist. Length/3;
5:Foreach(VAR passInBasiceffect. currenttechnique. Passes)
6 :{
7: Pass. Apply ();
8: graphicsdevice. drawindexedprimitives (
9: primitivetype. trianglelist,
10: 0,
11: 0,
12: vertexlist. length,
13: 0,
14: primitivecount );
15 :}