C# 可以帮我修复一个vb XNA结构来处理位置、颜色和法线吗。内例

C# 可以帮我修复一个vb XNA结构来处理位置、颜色和法线吗。内例,c#,vb.net,struct,xna,C#,Vb.net,Struct,Xna,这更像是将一些c#文档和语法翻译成visual basic的问题。我用Visual basic编写,并使用4.0 XNA刷新平台 我正在学习c#教程,但在复制他处理顶点、位置、颜色和法线的结构时遇到了一些困难。我已经能够使用预构建的vertexositioncolor和.VertexDeclaration很好地运行程序 这个问题的C代码是: public struct VertexPositionColorNormal { public Vector3 Po

这更像是将一些c#文档和语法翻译成visual basic的问题。我用Visual basic编写,并使用4.0 XNA刷新平台

我正在学习c#教程,但在复制他处理顶点、位置、颜色和法线的结构时遇到了一些困难。我已经能够使用预构建的vertexositioncolor和.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”:

'公共子DrawUserIndexedPrimitives(VertexPositionColorNormal的)(原语类型为 Microsoft.Xna.Framework.Graphics.PrimitiveType,vertexData()作为 VertexPositionColorNormal,vertexOffset为整数,numVertices为 整数,indexData()为短,indexOffset为整数,primitiveCount 作为整数,顶点声明为 Microsoft.Xna.Framework.Graphics.VertexDeclaration)“:类型的值 “整数的一维数组”无法转换为“一维数组” “Short”的数组,因为“Integer”不是从“Short”派生的。

'公共子DrawUserIndexedPrimitives(VertexPositionColorNormal的)(原语类型为 Microsoft.Xna.Framework.Graphics.PrimitiveType,vertexData()作为 VertexPositionColorNormal,vertexOffset为整数,numVertices为 整数,indexData()为短,indexOffset为整数,primitiveCount 作为整数,顶点声明为 Microsoft.Xna.Framework.Graphics.VertexDeclaration)“:类型的值 “1维数组” 无法将Microsoft.Xna.Framework.Graphics.VertexElement“”转换为 “Microsoft.Xna.Framework.Graphics.VertexDeclaration”。

'公共子DrawUserIndexedPrimitives(VertexPositionColorNormal的)(原语类型为 Microsoft.Xna.Framework.Graphics.PrimitiveType,vertexData()作为 VertexPositionColorNormal,vertexOffset为整数,numVertices为 整数,indexData()为整数,indexOffset为整数, primitiveCount为整数,vertexDeclaration为 Microsoft.Xna.Framework.Graphics.VertexDeclaration)“:类型的值 “1维数组” 无法将Microsoft.Xna.Framework.Graphics.VertexElement“”转换为 “Microsoft.Xna.Framework.Graphics.VertexDeclaration”。

C:\Users\Xheis overlard\Documents\Visual Studio 2010\Projects\Test\u Terrains2\Test\u Terrains2\Test\u Terrains2\Game1.vb 416 13 Test\u Terrains2


我对VB不是很精通,但根据错误消息,我认为这一行有部分错误:

Public Shared ReadOnly VertexDeclaration As VertexElement() = New VertexElement() _
在您包含的C#中,
VertexDeclaration
对象的类型实际上是
VertexDeclaration
。但是,在VB中,将其视为类型
VertexElement
array

还有,什么是
索引


这里有一个MSDN文章的链接供参考。这个方法有四个重载,它们都非常相似。仔细检查您的参数类型。

我对VB不是很精通,但根据错误消息,我认为这一行有部分错误:

Public Shared ReadOnly VertexDeclaration As VertexElement() = New VertexElement() _
在您包含的C#中,
VertexDeclaration
对象的类型实际上是
VertexDeclaration
。但是,在VB中,将其视为类型
VertexElement
array

还有,什么是
索引


这里有一个MSDN文章的链接供参考。这个方法有四个重载,它们都非常相似。仔细检查参数类型。

原始参数不是数组,但在转换过程中是数组。试试这个:

 Public Structure VertexPositionColorNormal
     Public Position As Vector3
     Public Color As Color
     Public Normal As Vector3

     Public ReadOnly Shared VertexDeclaration As New VertexDeclaration( _
        New VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), _
        New VertexElement(Len(New Single) * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0), _
        New VertexElement(Len(New Single) * 3 + 4, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0))
 End Structure

原始数据不是数组,但在转换过程中它是数组。试试这个:

 Public Structure VertexPositionColorNormal
     Public Position As Vector3
     Public Color As Color
     Public Normal As Vector3

     Public ReadOnly Shared VertexDeclaration As New VertexDeclaration( _
        New VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), _
        New VertexElement(Len(New Single) * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0), _
        New VertexElement(Len(New Single) * 3 + 4, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0))
 End Structure

谢谢你,这就是问题所在——谢天谢地,戴夫也解决了这个问题。非常感谢。谢谢你,这就是问题所在——谢天谢地,戴夫也解决了这个问题。非常感谢。这很有效,非常感谢戴夫。我们到底在这里干什么。我们是使用参数初始化vertexDeclaration还是设置要解析到vertexDeclaration中的参数?看起来您正在调用vertexDeclaration的构造函数,该构造函数有3个VertexElement作为参数。这非常有效,非常感谢Dave。我们到底在这里干什么。我们是用参数初始化vertexDeclaration还是设置要解析到vertexDeclaration中的参数?看起来您正在调用vertexDeclaration的构造函数,该构造函数有3个VertexElement作为参数。