C# 球体纹理和极点
我使用托管DirectX和C#对球体进行纹理处理(C# 球体纹理和极点,c#,geometry,directx,mdx,texture-mapping,C#,Geometry,Directx,Mdx,Texture Mapping,我使用托管DirectX和C#对球体进行纹理处理(Mesh.sphere) 我使用以下代码计算U和V: CustomVertex.PositionNormalTextured[] vertData = (CustomVertex.PositionNormalTextured[])tempMesh.VertexBuffer.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.None, tempMesh.NumberVert
Mesh.sphere
)
我使用以下代码计算U和V:
CustomVertex.PositionNormalTextured[] vertData = (CustomVertex.PositionNormalTextured[])tempMesh.VertexBuffer.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.None, tempMesh.NumberVertices);
for (int i = 0; i < vertData.Length; ++i)
{
vertData[i].Tu = (float)(1.0 - (double)(0.5f + Math.Atan2(vertData[i].Nz, vertData[i].Nx) / (Math.PI * 2)));
vertData[i].Tv = (float)(0.5 - Math.Asin(vertData[i].Ny) / Math.PI);
}
CustomVertex.PositionNormalTextured[]vertData=(CustomVertex.PositionNormalTextured[])tempMesh.VertexBuffer.Lock(0,typeof(CustomVertex.PositionNormalTextured),LockFlags.None,tempMesh.NumberTices);
对于(int i=0;i
现在我的问题是,球体的极点和纹理的极点(等矩形投影)不匹配
图片中的红点是球体的极点当前与纹理匹配的位置
有人能告诉我我能做些什么来解决这个问题吗?如果球体以原点为中心,y向上,那么上面的代码可以很好地工作。我将展示: 假设极点存在于0,1,0和0,-1,0,应用数学,给出以下极点数
u = 1.0 - (0.5 + (atan2( 0, 0 ) / (2 * PI));
=> u = 1.0 - (0.5 + (0 / (2 * PI));
=> u = 1.0 - 0.5;
=> u = 0.5
v = 0.5 - (asin( 1 ) / PI)
=> v = 0
及
u和v的正确值,即(0.5,0)和(0.5,1)
如果使用z-up,则会给出不正确的值(因为在计算中需要交换y和z),但它仍然不会给出建议的极点值:
u = 1.0 - (0.5 + (atan2( 1, 0 ) / (2 * PI));
=> u = 1.0 - (0.5 + (PI / (2 * PI)))
=> u = 1.0 - (0.5 + 0.5);
=> u = 0
v = 0.5 - (asin( 0 ) / PI)
=> v = 0.5 - (0 / PI)
=> v = 0.5
及
这样做的原因相当合理。在u方向,球体完全环绕。即u为0与u为1相同。这完全发生在您发布的方程式中的x-z平面上(u不考虑y)。这就是为什么它被2*pi或一整圈的弧度数所除。v方向不环绕。事实上,它只适用于范围的一半,因此是除法pi。您将注意到,计算中只使用y,因此,x和z不会影响v计算
希望有帮助 只是出于阴谋。。。出了什么问题?
u = 1.0 - (0.5 + (atan2( 1, 0 ) / (2 * PI));
=> u = 1.0 - (0.5 + (PI / (2 * PI)))
=> u = 1.0 - (0.5 + 0.5);
=> u = 0
v = 0.5 - (asin( 0 ) / PI)
=> v = 0.5 - (0 / PI)
=> v = 0.5
u = 1.0 - (0.5 + (atan2( -1, 0 ) / (2 * PI));
=> u = 1.0 - (0.5 + (-PI / (2 * PI)))
=> u = 1.0 - (0.5 - 0.5);
=> u = 1.0
v = 0.5 - (asin( 0 ) / PI)
=> v = 0.5 - (0 / PI)
=> v = 0.5