확인을 발생하는 좌표를, I는 마침내 알아 낸 것. 나는 이전에 작동했던 코드를 가지고 있었지만 정확히 내가 원하지 않는 코드를 가지고 있었다. http://channel9.msdn.com/coding4fun/articles/Ask-the-ZMan-Applying-Textures-Part-3
어쨌든, 나는 몇 가지 수정 작업을 수행했다.
Google에서 도착한 사람들을 위해 참조하십시오.
public static float ComputeBoundingSphere(Mesh mesh, out Microsoft.DirectX.Vector3 center)
{
// Lock the vertex buffer
Microsoft.DirectX.GraphicsStream data = null;
try
{
data = mesh.LockVertexBuffer(LockFlags.ReadOnly);
// Now compute the bounding sphere
return Geometry.ComputeBoundingSphere(data, mesh.NumberVertices,
mesh.VertexFormat, out center);
}
finally
{
// Make sure to unlock the vertex buffer
if (data != null)
mesh.UnlockVertexBuffer();
}
}
private static Mesh SetSphericalTexture(Mesh mesh)
{
Microsoft.DirectX.Vector3 vertexRay;
Microsoft.DirectX.Vector3 meshCenter;
double phi;
float u;
Microsoft.DirectX.Vector3 north = new Microsoft.DirectX.Vector3(0f, 0f, 1f);
Microsoft.DirectX.Vector3 equator = new Microsoft.DirectX.Vector3(0f, 1f, 0f);
Microsoft.DirectX.Vector3 northEquatorCross = Microsoft.DirectX.Vector3.Cross(north, equator);
ComputeBoundingSphere(mesh, out meshCenter);
using (VertexBuffer vb = mesh.VertexBuffer)
{
CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])vb.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.None, mesh.NumberVertices);
try
{
for (int i = 0; i < verts.Length; i++)
{
//For each vertex take a ray from the centre of the mesh to the vertex and normalize so the dot products work.
vertexRay = Microsoft.DirectX.Vector3.Normalize(verts[i].Position - meshCenter);
phi = Math.Acos((double)vertexRay.Z);
if (vertexRay.Z > -0.9)
{
verts[i].Tv = 0.121f; //percentage of the image being the top side
}
else
verts[i].Tv = (float)(phi/Math.PI);
if (vertexRay.Z == 1.0f || vertexRay.Z == -1.0f)
{
verts[i].Tu = 0.5f;
}
else
{
u = (float)(Math.Acos(Math.Max(Math.Min((double)vertexRay.Y/Math.Sin(phi), 1.0), -1.0))/(2.0 * Math.PI));
//Since the cross product is just giving us (1,0,0) i.e. the xaxis
//and the dot product was giving us a +ve or -ve angle, we can just compare the x value with 0
verts[i].Tu = (vertexRay.X > 0f) ? u : 1 - u;
}
}
}
finally
{
vb.Unlock();
}
}
return mesh;
}
그냥 텍스처 좌표를 계산하십시오. 이것은 똑바로 보인다. 당신이 겪고있는 정확한 문제는 무엇입니까? 실패한 결과를 게시 할 수 있습니까? –
나는 그것을 지금 이해했다. 문제는 내가 수학에 빠져서 DirectX를 사용하여 자동으로 메쉬를 생성했기 때문에 메쉬가 어떻게 생성되었거나 레이아웃되었는지를 알 수 없었습니다;) 아래에 새로운 작업 코드를 게시했습니다. –
그것은 정신입니다! 그래픽 프로그래밍을 원한다면 수학을 다듬어야합니다. 주위를 둘러 볼 방법이 없습니다. –