WP7 XNA — отрисовка только половины моей модели сферы

#c# #opengl #windows-phone-7 #3d

#c# #opengl #windows-phone-7 #3D

Вопрос:

У меня возникла очень странная проблема с XNA / OpenGL на Windows Phone 7. Я рисую сферу, используя следующий код:

  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):
Странная сфера

Есть предложения?

Комментарии:

1. Я использую библиотеку OpenTK для OpenGL

2. Когда вы на самом деле выполняете вызов для отрисовки вершин, вы уверены, что указываете правильное количество треугольников?

Ответ №1:

Попробуйте использовать это. Поскольку это скорее проблема с OpenGL, чем с Android, попробуйте поискать алгоритм для ручной генерации sphere. Возможно, стоит также проверить, правильный ли порядок вершин.

Комментарии:

1. Это не Android-телефон, это WP7, и я использую OpenGL, а не DirectX