一段时间以来,我一直在这方面失去理智。只需忽略被注释掉的部分(不是问题)。我正在尝试进行 360 度经度和 180 度经度扫描,然后进行射线投射。但显然方向向量(在本例中为 Dir)停留在 (0, 0, -1)。我检查了 xy 和 z 值,它们工作正常。我现在不知道出了什么问题。在我自杀之前请回答。叹
{
Vector3 Dir = new Vector3(0.0f, 0.0f, 0.0f);
Output = new Texture2D(2160, 1080);
for (int i = 0; i < 1080; i++)
{
float theta = (Mathf.Deg2Rad * i * 1.0f) / 6.0f;
for (int j = 0; j < 2160; j++)
{
float phi = (Mathf.Deg2Rad * j) / 6.0f;
float x = Mathf.Sin(theta) * Mathf.Cos(phi);
float y = Mathf.Sin(theta) * Mathf.Sin(phi);
float z = Mathf.Cos(theta);
Dir = new Vector3(x, y, z);
Debug.Log(x + " " + y + " " + z);
/* RaycastHit raycastHit;
if (Physics.Raycast(transform.position, Dir, out raycastHit))
{
Renderer rend = raycastHit.transform.GetComponent<MeshRenderer>();
Texture2D tex = rend.material.mainTexture as Texture2D;
Vector2 pCoord = raycastHit.textureCoord;
pCoord.x *= tex.width;
pCoord.y *= tex.height;
Color color = tex.GetPixel((int)(pCoord.x * rend.material.mainTextureScale.x), (int)(pCoord.y * rend.material.mainTextureScale.y));
Output.SetPixel(j, i, color);
Debug.Log("Ray hit an object! @ theta " + i.ToString() + " phi " + j.ToString() + " Color: " + color.ToString() + "Hit Coordinate x: " + pCoord.x + " y: " + pCoord.y);
}
*/
}
}
//System.IO.File.WriteAllBytes("D:\\FYProject\\WebcamSnaps\\" + naming + ".png", Output.EncodeToPNG());
}