我正在使用以下代码生成我的 3D 立方体,但它不会产生透明立方体。任何帮助将不胜感激。
VertexBuffer CreateCube(GraphicsDevice device)
{
var vertexCollection = new VertexPositionColor[36];
// Front coordinates
Vector3 cubeA = new Vector3(-0.75f, 0.75f, 0.75f);
Vector3 cubeB = new Vector3(0.75f, 0.75f, 0.75f);
Vector3 cubeC = new Vector3(-0.75f, -0.75f, 0.75f);
Vector3 cubeD = new Vector3(0.75f, -0.75f, 0.75f);
// Back coordinates
Vector3 cubeE = new Vector3(-0.75f, 0.75f, -0.75f);
Vector3 cubeF = new Vector3(0.75f, 0.75f, -0.75f);
Vector3 cubeG = new Vector3(-0.75f, -0.75f, -0.75f);
Vector3 cubeH = new Vector3(0.75f, -0.75f, -0.75f);
// Colors
Color cRed = Color.FromNonPremultiplied(255, 0, 0, 156);
//Color cred = new Color(new Vector4(255,0,0,150));
Color cGreen = Color.FromNonPremultiplied(0, 255, 0, 156);
Color cBlue = Color.FromNonPremultiplied(0, 0, 255, 156);
Color cYellow = Color.FromNonPremultiplied(255, 255, 0, 156);
Color cBlack = Color.FromNonPremultiplied(0, 0, 0, 156);
Color cWhite = Color.FromNonPremultiplied(255, 255, 255, 156);
// Front
vertexCollection[0] = new VertexPositionColor(cubeA, cGreen);
vertexCollection[1] = new VertexPositionColor(cubeB, cGreen);
vertexCollection[2] = new VertexPositionColor(cubeC, cGreen);
vertexCollection[3] = new VertexPositionColor(cubeB, cBlue);
vertexCollection[4] = new VertexPositionColor(cubeD, cBlue);
vertexCollection[5] = new VertexPositionColor(cubeC, cBlue);
// Back
vertexCollection[6] = new VertexPositionColor(cubeG, cBlue);
vertexCollection[7] = new VertexPositionColor(cubeF, cBlue);
vertexCollection[8] = new VertexPositionColor(cubeE, cBlue);
vertexCollection[9] = new VertexPositionColor(cubeH, cGreen);
vertexCollection[10] = new VertexPositionColor(cubeF, cGreen);
vertexCollection[11] = new VertexPositionColor(cubeG, cGreen);
// Top
vertexCollection[12] = new VertexPositionColor(cubeE, cRed);
vertexCollection[13] = new VertexPositionColor(cubeF, cRed);
vertexCollection[14] = new VertexPositionColor(cubeA, cRed);
vertexCollection[15] = new VertexPositionColor(cubeF, cYellow);
vertexCollection[16] = new VertexPositionColor(cubeB, cYellow);
vertexCollection[17] = new VertexPositionColor(cubeA, cYellow);
// Bottom
vertexCollection[18] = new VertexPositionColor(cubeH, cRed);
vertexCollection[19] = new VertexPositionColor(cubeG, cRed);
vertexCollection[20] = new VertexPositionColor(cubeC, cRed);
vertexCollection[21] = new VertexPositionColor(cubeD, cYellow);
vertexCollection[22] = new VertexPositionColor(cubeH, cYellow);
vertexCollection[23] = new VertexPositionColor(cubeC, cYellow);
// Left
vertexCollection[24] = new VertexPositionColor(cubeC, cBlack);
vertexCollection[25] = new VertexPositionColor(cubeG, cBlack);
vertexCollection[26] = new VertexPositionColor(cubeA, cBlack);
vertexCollection[27] = new VertexPositionColor(cubeA, cWhite);
vertexCollection[28] = new VertexPositionColor(cubeG, cWhite);
vertexCollection[29] = new VertexPositionColor(cubeE, cWhite);
// Right
vertexCollection[30] = new VertexPositionColor(cubeH, cWhite);
vertexCollection[31] = new VertexPositionColor(cubeD, cWhite);
vertexCollection[32] = new VertexPositionColor(cubeB, cWhite);
vertexCollection[33] = new VertexPositionColor(cubeH, cBlack);
vertexCollection[34] = new VertexPositionColor(cubeB, cBlack);
vertexCollection[35] = new VertexPositionColor(cubeF, cBlack);
var vb = new VertexBuffer(device,
VertexPositionColor.VertexDeclaration,
vertexCollection.Length, BufferUsage.WriteOnly);
vb.SetData(0, vertexCollection, 0, vertexCollection.Length, 0);
return vb;
}