Post by 3D Star Shape Demo on Aug 20, 2005 16:58:24 GMT -5
Fooling around this afternoon, here's a quick and simple demo that shows you how to generate a 3D star shape. Thought someone might find this useful.
....G
....G
dim xrot#, yrot#, zrot#
dim star#(3)(11),i
glEnable (GL_CULL_FACE)
Gosub SetStar
while true
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(0.0,0.0,-5.0)
glRotatef(xrot#,1.0,0.0,0.0)
glRotatef(yrot#,0.0,1.0,0.0)
glRotatef(zrot#,0.0,0.0,1.0)
Gosub DrawStar
SwapBuffers ()
xrot# = xrot# + 0.6
yrot# = yrot# + 0.8
zrot# = zrot# + 0.5
wend
SetStar:
' set outer star points
for i = 0 to 4
star#(0)(i*2) = sind(i * 72.0)
star#(1)(i*2) = cosd (i * 72.0)
next
' set inner star points
for i = 0 to 4
star#(0)((i*2)+1) = sind((i * 72.0) + 36.0) / 2.25
star#(1)((i*2)+1) = cosd((i * 72.0) + 36.0) / 2.25
next
Return
DrawStar:
' front star shape
glBegin(GL_triangle_fan)
glcolor3f(1.0,1.0,0.0)
glVertex3f(0.0,0.0,-0.2)
glcolor3f(0.5,0.5,0.0)
for i = 0 to 9
glvertex3f(star#(0)(i),star#(1)(i),0.0)
next
glvertex3f(star#(0)(0),star#(1)(0),0.0)
glend()
' back star shape
glBegin(GL_triangle_fan)
glcolor3f(1.0,1.0,0.0)
glVertex3f(0.0,0.0,0.2)
glcolor3f(0.5,0.5,0.0)
for i = 0 to 9
glvertex3f(star#(0)(9-i),star#(1)(9-i),0.0)
next
glvertex3f(star#(0)(9),star#(1)(9),0.0)
glend()
return