Skip to content

Commit

Permalink
Tweaks to sphere generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanhogg committed Jun 10, 2024
1 parent 7746719 commit 87efee6
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/flitter/render/window/models.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -540,22 +540,29 @@ cdef class Sphere(PrimitiveModel):
cdef float x, y, z, r, th, u, v
cdef int64_t row, col, i=0, j=0
for row in range(nrows + 1):
v = <float>row/nrows
if row == 0:
v = 0
r, z = 0, -1
elif row == nrows:
v = 1
r, z = 0, 1
else:
v = <float>row / nrows
th = Tau*(v-0.5)/2
r, z = cos(th), sin(th)
for col in range(ncols+1):
u = (col+0.5)/ncols if row == 0 else ((col-0.5)/ncols if row == nrows else <float>col/ncols)
if col == 0:
x, y = r, 0
elif col == ncols:
x, y = r, 0
if row == 0:
x = y = 0
u = (col + 0.5) / ncols
elif row == nrows:
x = y = 0
u = (col - 0.5) / ncols
else:
x, y = r*cos(Tau*u), r*sin(Tau*u)
u = <float>col / ncols
if col == 0 or col == ncols:
x, y = r, 0
else:
x, y = r*cos(Tau*u), r*sin(Tau*u)
vertices[i, 0], vertices[i, 1], vertices[i, 2] = x, y, z
vertex_normals[i, 0], vertex_normals[i, 1], vertex_normals[i, 2] = x, y, z
vertex_uv[i, 0], vertex_uv[i, 1] = u, v
Expand Down

0 comments on commit 87efee6

Please sign in to comment.