这更像是将一些 c# 文档和语法翻译成视觉基本内容的问题。我正在用 Visual basic 编写,并使用 4.0 XNA 刷新平台。
我在Riemers.net上关注 ac# 教程,但在重现他处理顶点、位置、颜色和法线的结构时遇到了一些困难。我已经能够使用预建的 VertexPositionColor & .VertexDeclaration 很好地运行程序。
这个问题的 C# 代码是这样的:
public struct VertexPositionColorNormal
{
public Vector3 Position;
public Color Color;
public Vector3 Normal;
public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(sizeof(float) * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0),
new VertexElement(sizeof(float) * 3 + 4, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0)
);
}
这是我的转换尝试
Public Structure VertexPositionColorNormal
Public Position As Vector3
Public Color As Color
Public Normal As Vector3
Public Shared SizeInBytes As Integer = 7 * 4
Public Shared ReadOnly VertexDeclaration As VertexElement() = New VertexElement() _
{New VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), _
New VertexElement(4 * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0), _
New VertexElement(4 * 4, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0)}
End Structure
虽然我的尝试在语法上似乎是正确的,但它在这一行产生了一个错误:
GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, indices.Length / 3, VertexPositionColorNormal.VertexDeclaration)
并给我以下错误描述:
错误 18
重载解析失败,因为无法使用这些参数调用可访问的“DrawUserIndexedPrimitives”:'Public Sub DrawUserIndexedPrimitives(Of VertexPositionColorNormal)(primitiveType As Microsoft.Xna.Framework.Graphics.PrimitiveType, vertexData() As VertexPositionColorNormal, vertexOffset As Integer, numVertices As Integer, indexData() As Short, indexOffset As Integer, primitiveCount As Integer, vertexDeclaration As Microsoft.Xna.Framework.Graphics.VertexDeclaration)':“整数的一维数组”类型的值无法转换为“Short 的一维数组”,因为“Integer”不是从“Short”派生的。
'Public Sub DrawUserIndexedPrimitives(Of VertexPositionColorNormal)(primitiveType As Microsoft.Xna.Framework.Graphics.PrimitiveType, vertexData() As VertexPositionColorNormal, vertexOffset As Integer, numVertices As Integer, indexData() As Short, indexOffset As Integer, primitiveCount As Integer, vertexDeclaration As Microsoft.Xna.Framework.Graphics.VertexDeclaration)':“Microsoft.Xna.Framework.Graphics.VertexElement 的一维数组”类型的值无法转换为“Microsoft.Xna.Framework.Graphics.VertexDeclaration”。
'Public Sub DrawUserIndexedPrimitives(Of VertexPositionColorNormal)(primitiveType As Microsoft.Xna.Framework.Graphics.PrimitiveType, vertexData() As VertexPositionColorNormal, vertexOffset As Integer, numVertices As Integer, indexData() As Integer, indexOffset As Integer, primitiveCount As Integer, vertexDeclaration As Microsoft.Xna.Framework.Graphics.VertexDeclaration)':“Microsoft.Xna.Framework.Graphics.VertexElement 的一维数组”类型的值无法转换为“Microsoft.Xna.Framework.Graphics.VertexDeclaration”。
C:\Users\Xheis-Overlord\Documents\Visual Studio 2010\Projects\Test_Terrains2\Test_Terrains2\Test_Terrains2\Game1.vb 416 13 Test_Terrains2