其他分享
首页 > 其他分享> > CNA XNA 4.0自定义顶点声明

CNA XNA 4.0自定义顶点声明

作者:互联网

我目前正在尝试进行自定义顶点声明.

将位置,颜色和整数传递给效果的一种.我在确定将使用哪个VertexElementUsage枚举来传递整数时遇到问题,并且在声明VertexElements时如何确定偏移量?

public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
{
    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
    new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0),
    new VertexElement(?, VertexElementFormat.Byte4, ?, 0)
};

(请注意最后一个VertexElement中的?)

解决方法:

这将是Vector2的大小,即颜色的大小.
基本上是这样想的
在普通数组中,只有一种类型的对象,因此知道跳到下一个项目要跳多少.
这是不同的,因为它们都有不同的大小.
使用sizeof()很好,所以就像:

public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
{
    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
    new VertexElement(sizeof(Vector3), VertexElementFormat.Color, VertexElementUsage.Color, 0),
    new VertexElement(sizeof(Vector3)+sizeof(Color), VertexElementFormat.Byte4, ?, 0)
};

或类似.

否则,您可以找到颜色对象的大小并将其添加到Vector3对象的大小(这将是偏移量).

标签:xna,c
来源: https://codeday.me/bug/20191201/2082421.html