【发布时间】:2014-05-12 10:17:43
【问题描述】:
我有一个程序,用户可以在其中创建不同宽度和高度的框。
我还有一个纹理(512 x 512 像素),应该放在每个盒子上。
现在我遇到的问题是在 90x90 Box (Mesh.Box) 上我可以将纹理放置 4x4 次。
所以我认为我可以使用 4/90 的比率来对盒子进行纹理处理。但这不起作用
框的宽度为 28.723,高度为 56.43661
我使用以下代码计算纹理坐标:
float tex_coords_w = 4.0f / 90;
float tex_coords_h = 4.0f / 90;
mesh = Mesh.Box(d3dDevice, width, height, 0);
Mesh tempMesh = mesh.Clone(mesh.Options.Value, VertexFormats.PositionNormal | VertexFormats.Texture1, d3dDevice);
CustomVertex.PositionNormalTextured[] vertData = (CustomVertex.PositionNormalTextured[])tempMesh.VertexBuffer.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.None, tempMesh.NumberVertices);
for (int i = vertData.Length / 2; i < vertData.Length; i += 4)
{
vertData[i + 1].Tu = Convert.ToSingle(i) + 0.0f;
vertData[i + 1].Tv = Convert.ToSingle(i) + 0.0f;
vertData[i + 2].Tu = Convert.ToSingle(i) + tex_coords_w * width;
vertData[i + 2].Tv = Convert.ToSingle(i) + 0.0f;
vertData[i + 3].Tu = Convert.ToSingle(i) + tex_coords_w * width;
vertData[i + 3].Tv = Convert.ToSingle(i) + tex_coords_h * height;
vertData[i + 0].Tu = Convert.ToSingle(i) + 0.0f;
vertData[i + 0].Tv = Convert.ToSingle(i) + tex_coords_h * height;
}
tempMesh.VertexBuffer.Unlock();
mesh.Dispose();
mesh = tempMesh;
有人可以帮帮我吗?!
【问题讨论】:
标签: c# directx texture-mapping