PDA

View Full Version : Quite a spiky sphere.



Swiftless
11-29-2005, 11:38 PM
I am trying to create a sphere generation function, but my 'sphere' keeps rendering quite spikily.

I am using visual basic atm, so don't worry about the odd looking code. With a few changes it is interchangeable with c++.
My code to create it as is:


Dim phi As Double
Dim theta As Double
Dim n As Double

n = 0

glBegin bmPoints
For phi = 0 To 90 - space Step space
For theta = 0 To 90 - space Step space

VERTEX(n).x = R * Cos(theta) * Sin(phi) - H
VERTEX(n).y = R * Sin(theta) * Sin(phi) - K
VERTEX(n).z = R * Cos(phi) - z
VERTEX(n).u = n / VertexCount + 1
VERTEX(n).v = n / VertexCount
n = n + 1

VERTEX(n).x = R * Cos(theta) * Sin(phi + space) - H
VERTEX(n).y = R * Sin(theta) * Sin(phi + space) - K
VERTEX(n).z = R * Cos(phi + space) - z
VERTEX(n).u = n / VertexCount
VERTEX(n).v = n / VertexCount + 1
n = n + 1

VERTEX(n).x = R * Cos(theta + space) * Sin(phi) - H
VERTEX(n).y = R * Sin(theta + space) * Sin(phi) - K
VERTEX(n).z = R * Cos(phi) - z
VERTEX(n).u = n / VertexCount + 1
VERTEX(n).v = n / VertexCount + 1
n = n + 1

If phi > -90 And phi < 90 Then
VERTEX(n).x = R * Cos(theta + space) * Sin(phi + space) - H
VERTEX(n).y = R * Sin(theta + space) * Sin(phi + space) - K
VERTEX(n).z = R * Cos(phi + space) - z
VERTEX(n).u = n / VertexCount + 1
VERTEX(n).v = n / VertexCount
n = n + 1
End If

Next theta
Next phi
glEnd
And then I am displaying it as such:



glBindTexture glTexture2D, texture(0)
glBegin bmTriangles
For b = 0 To VertexCount
glTexCoord2f VERTEX(b).u, VERTEX(b).v
glVertex3f VERTEX(b).x, VERTEX(b).y, VERTEX(b).z
Next b
glEnd Now it looks fine using points, but now its all spiky when rendered as triangles or a triangle strip. Maybe I am making it create the vertices in the wrong order?

Any help would be appreciated.