1
我正在使用XNA和C#,并且我正尝试创建一种基于顶点的图形系统。所以我有下面的代码到目前为止在C#中渲染2D网格
public class vertex {
private Vector2 position;
private Color color;
public vertex(Vector2 position, Color color) {
this.position = position;
this.color = color;
}
public Vector2 Position {
get { return position; }
set { position = value; }
}
public Color Color {
get { return color; }
set { color = value; }
}
}
public class mesh {
private vertex[] vertecies;
public mesh(int vertecies) {
this.vertecies = new vertex[vertecies];
for (int i = 0; i < vertecies; i++)
this.vertecies[i] = new vertex(Vector2.Zero, Color.White);
}
public vertex[] Vertecies {
get { return vertecies; }
set { vertecies = value; }
}
}
,然后我有这个功能,这使得一个点到屏幕上
private void RenderVertex(vertex v)
{
sb.Draw(world.blankTexture, v.Position, new Rectangle(1, 1, 2, 2), v.Color);
}
现在我试图创建一个名为RenderMesh功能(目m)使用RenderVertex(vertex v)函数渲染给定的网格点(vertecies)。所以基本上我想找到网格的各个顶点之间的每个点并用点填充它。有没有一个算法呢?或者我应该采取一种完全不同的方法。因为我试图让我的系统呈现和处理动态形状。所以请帮助。感谢阅读:)
你为什么不尝试阅读这样的渲染教程:http://www.riemers.net/?你基本上想重新发明轮子,或者至少是软件渲染。 – Matzi
这是什么?您想要以多边形的形状绘制一组像素大小的多边形(精灵批处理将多个精灵绘制为多边形)。为什么不直接绘制多边形?另外:XNA已经有['VertexPositionColor'](http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.vertexpositioncolor.aspx)。 –
VertexPositionColor用于3D多边形 – user1494136