2011-04-08 88 views
0

我遇到了在Windows Phone 7我使用下面的代碼繪製球體XNA/OpenGL的一個很奇怪的問題,我的球模型的一半:WP7 XNA - 只繪製

if (Radius < 0f) 
      Radius = -Radius; 
     if (Radius == 0f) 
      throw new DivideByZeroException("DrawSphere: Radius cannot be 0f."); 
     if (Precision == 0) 
      throw new DivideByZeroException("DrawSphere: Precision of 8 or greater is required."); 

     const float HalfPI = (float)(Math.PI * 0.5); 
     float OneThroughPrecision = 1.0f/Precision; 
     float TwoPIThroughPrecision = (float)(Math.PI * 2.0 * OneThroughPrecision); 

     float theta1, theta2, theta3; 
     Vector3 Normal = new Vector3(0,0,0), Position = new Vector3(); 

     for (uint j = 0; j < Precision/2; j++) 
     { 
      theta1 = (j * TwoPIThroughPrecision) - HalfPI; 
      theta2 = ((j + 1) * TwoPIThroughPrecision) - HalfPI; 

      GL.Begin(BeginMode.TriangleStrip); 
      for (uint i = 0; i <= Precision; i++) 
      { 
       theta3 = i * TwoPIThroughPrecision; 

       Normal.X = (float)(Math.Cos(theta2) * Math.Cos(theta3)); 
       Normal.Y = (float)Math.Sin(theta2); 
       Normal.Z = (float)(Math.Cos(theta2) * Math.Sin(theta3)); 
       Position.X = Center.X + Radius * Normal.X; 
       Position.Y = Center.Y + Radius * Normal.Y; 
       Position.Z = Center.Z + Radius * Normal.Z; 

       GL.Normal3(Normal); 
       GL.TexCoord2(i * OneThroughPrecision, 2.0f * (j + 1) * OneThroughPrecision); 
       GL.Vertex3(Position); 

       Normal.X = (float)(Math.Cos(theta1) * Math.Cos(theta3)); 
       Normal.Y = (float)Math.Sin(theta1); 
       Normal.Z = (float)(Math.Cos(theta1) * Math.Sin(theta3)); 
       Position.X = Center.X + Radius * Normal.X; 
       Position.Y = Center.Y + Radius * Normal.Y; 
       Position.Z = Center.Z + Radius * Normal.Z; 

       GL.Normal3(Normal); 
       GL.TexCoord2(i * OneThroughPrecision, 2.0f * j * OneThroughPrecision); 
       GL.Vertex3(Position); 
      } 
      GL.End(); 
     } 

球體最終看起來像這樣(同時在仿真器和設備(HTC HD7): Strange sphere
任何建議

+0

我正在使用OpenGL庫OpenGL – IDWMaster 2011-04-08 01:44:41

+0

當您實際進行繪製頂點的調用時,您確定指定了正確數量的三角形? – lzcd 2011-04-08 02:51:28

回答

0

嘗試使用this因爲它更OpenGL的問題比Android的,嘗試尋找爲手動的算法。球體世代,可能值得檢查如果頂點順序也是正確的。

+0

它不是Android手機,它是WP7,我使用的是OpenGL,而不是DirectX – IDWMaster 2011-04-08 20:01:08