Help-trig for sphere z points

BlitzMax Forums/BlitzMax OpenGL Programming/Help-trig for sphere z points

I've been trying for the past two days to get my draw sphere routing working. My problem comes with drawing the z value of the points. My function has seperate values for the horizontal and verticle divisions needed to define a sphere. I just want to get the z part working.

(X and Y values are working nicely)


my code ( I have set the z to zero for now, fix it if you can please.)
Function draw_sphere(x#,y#,z#,x_divisions#,y_divisions#,radius#)
	glLoadIdentity()
	glTranslatef x,y,z
	glRotatef rtri,1,1,1
	
	glBegin GL_POINTS
	For Local a#=0 To y_divisions
		For Local b#=0 To x_divisions
			Local direction#=a*(180.0/y_divisions)' diection for x and y
			Local variable_radius=Sin(b*(360.0/x_divisions))*radius ' make x move in towards tips
			Local variable_radius2=Cos(b*(360.0/x_divisions))*radius
			Local POINT_X#=Cos(direction-90)*variable_radius
			Local POINT_Y#=Sin(direction-90)*radius
			glVertex3f POINT_X,POINT_Y,0
	        Next	
	Next
	glEnd
End Function


give us some working code, rather that expecting us to write some support code just so we can run your function and you might get some help...

I've tried about 10 times and this code draws POINTS I would like the faces. I might have done this a stupid way but the points are correctly drawn, :)

Function draw_sphere(x#,y#,z#,x_divisions#,y_divisions#,radius#)

	
	Local sub#=180/y_divisions
	Local sub2#=360/x_divisions
	Local base=0
	For Local a#=0 To x_divisions
		glLoadIdentity()
		glTranslatef x,y,z
		glRotatef a*sub2+rtri,0,1,0
			glBegin GL_points
		For Local i#=0 To y_divisions
			' first point
			Local POINT_X#=Cos((i*sub)-90)*radius
			Local POINT_Y#=Sin((i*sub)-90)*radius
			
			glColor3f 1,1,1
			' draw points
			glVertex3f POINT_X,POINT_Y,0
			
	

			
		Next
		glEnd
	
	Next
	
End Function


give us some working code, rather that expecting us to write some support code just so we can run your function and you might get some help...



The second code block I posted works. Did you TRY it?
I posted a working code, it just draws the points, I need faces drawn. I don't know how to define the faces. I had assumed that somebody could make the jump from drawn vertices to drawn faces.

Here is a complete program showing it.
Strict
GLGraphics 640,480
glEnable GL_DEPTH_TEST								'Enables Depth Testing
glMatrixMode GL_PROJECTION						'Select The Projection Matrix
glLoadIdentity										'Reset The Projection Matrix

 glOrtho(0,640,480,0,-1000,1000)				'Setup The Projection Matrix Frustum

glMatrixMode GL_MODELVIEW							'Select The ModelView Matrix
glLoadIdentity										'Reset The ModelView Matrix


Function draw_sphere(x#,y#,z#,x_divisions#,y_divisions#,radius#)

	
	Local sub#=180/y_divisions
	Local sub2#=360/x_divisions
	Local base=0
	For Local a#=0 To x_divisions
		glLoadIdentity()
		glTranslatef x,y,z
		glRotatef a*sub2,0,1,0
			glBegin GL_points
		For Local i#=0 To y_divisions
			' first point
			Local POINT_X#=Cos((i*sub)-90)*radius
			Local POINT_Y#=Sin((i*sub)-90)*radius
			
			glColor3f 1,1,1
			' draw points
			glVertex3f POINT_X,POINT_Y,0
			
	

			
		Next
		glEnd
	
	Next
	
End Function

While Not KeyHit( KEY_ESCAPE )

	glClear GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT		'Clear The Screen And The Depth Buffer
draw_sphere(320,240,0,20,20,100)
	Flip

Wend


If you want triangle faces you can use this:
glBegin(GL_TRIANGLES)
  ' first triangle
  glVertex3f(0.0,1.0,0.0)
  glVertex3f(1.0,1.0,0.0)
  glVertex3f(1.0,0.0,0.0)
  ' second triangle
 glVertex3f ....
  etc...
glEnd()
If you want quads it's the same except you should use glBegin(GL_QUADS) and have 4 vertices defined per face.

Did you TRY it?

expecting us to write some support code


bin away, came back, started playing with some old C code I had floating around, then adapted it to max, then though really should stop messing around with this....

Some points to remember, calculating coords using sine and cosine each frame is fairly slow, better to pre-calculate a vertex list of a sphere radius 1 and then scale it

In this case I've even used an opengl display list which on most hardware *really* improve speed as it will optimise the list of opengl calls

I've added texture mapping as UV cords can be a nightmare, each vertex has a slightly different colour too, normally you'd just use white and the texture would colour the whole thing but handily with vertex colouring you can have different coloured textures (quite handy for multiple skins....)


SuperStrict
GLGraphics 640,480
glEnable GL_DEPTH_TEST								'Enables Depth Testing
glEnable(GL_TEXTURE_2D)
glMatrixMode GL_PROJECTION						'Select The Projection Matrix
glLoadIdentity										'Reset The Projection Matrix

' are you sure you want orthograpic and not perspective....?
glOrtho(0,640,480,0,-1000,1000)				'Setup The Projection Matrix Frustum

glMatrixMode GL_MODELVIEW							'Select The ModelView Matrix
glLoadIdentity										'Reset The ModelView Matrix

Global mySphere:Tlist = New Tlist
makeSphere(mySphere)

Global pixmap:Tpixmap = LoadPixmap("./doc/bmax120.png")
Global texture:Int = GLTexFromPixmap(pixmap)

Global SphereDisplayList:Int = glGenLists ( 1 )
glNewList ( SphereDisplayList , GL_COMPILE )
drawSphere(mySphere)
glEndList()

Local a#=0
While Not KeyDown( KEY_ESCAPE )

	glClear GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT		'Clear The Screen And The Depth Buffer

	glLoadIdentity()
	glTranslatef 320 , 240 , 0
	glrotatef(a*2,0,1,0)
	glrotatef(-a,1,0,0)
	glscalef(200,200,200)
	glCallList(SphereDisplayLIst)
	
	glLoadIdentity()
	glTranslatef 60 , 60 , 0
	glrotatef(a,0,1,0)
	glrotatef(-a,1,0,0)
	glscalef(50,50,50)
	glCallList(SphereDisplayLIst)

	a:+.6

	Flip

Wend

Function DrawSphere (vl:Tlist)

	glBindTexture (GL_TEXTURE_2D, texture)
	glBegin (GL_TRIANGLE_STRIP)

	For Local v:vert = EachIn vl
		nextColour()
		glTexCoord2f (-v.u,v.v)
		glVertex3f (v.x , v.y , v.z)
	Next

	For Local v:vert = EachIn vl
		nextColour()
		glTexCoord2f (v.u,v.v)
		glVertex3f (v.x , v.y , -v.z)
	Next

	glEnd()

EndFunction

Global cc:Int=0
Function nextColour()
	cc:+ 1
	If cc = 4 Then cc = 0
	Select cc
		Case 0
			glcolor3f .8,1,.8
		Case 1
			glcolor3f 1,.8,.8
		Case 2
			glcolor3f .8,.8,1
		Case 3
			glcolor3f 1,1,1
	End Select
EndFunction

Type vert
	Field x# , y# , z# , u# , v#
EndType

Function makeSphere(vertList:Tlist)
	Const astep#=15
	For Local b# = 0 Until 90 Step astep
		For Local a# = 0 Until 360 Step astep
			Local v:vert = New vert
			v.x=Sin(a ) * Sin(b ) 	
			v.y = Cos( a ) * Sin(b )
			v.z = Cos( b ) 
			v.u = (2 * b) / 360
			v.v = a / 360
			ListAddLast vertList , v
			v = New vert
			v.x=Sin(a ) * Sin((b+astep) ) 	
			v.y = Cos( a ) * Sin( (b+astep) )
			v.z = Cos( (b+astep) )
			v.u = (2 * (b+astep)) / 360
			v.v = a / 360
			ListAddLast vertList , v
			v = New vert
			v.x=Sin((a+astep) ) * Sin(b ) 	
			v.y = Cos( (a+astep) ) * Sin(b )
			v.z = Cos( b )
			v.u = (2 * b) / 360
			v.v = (a+astep) / 360
			ListAddLast vertList , v
			v = New vert
			v.x=Sin((a+astep) ) * Sin((b+astep) ) 	
			v.y = Cos( (a+astep) ) * Sin((b+astep) )
			v.z = Cos( (b+astep) ) 
			v.u = (2 * (b+astep)) / 360
			v.v = (a+astep) / 360
			ListAddLast vertList , v
		Next
	Next
EndFunction


Enjoy!

Nice! Still there are some faces inside the sphere, binding the apex of the first half to the middle of the second half.
This solves it although not elegantly...

SuperStrict
GLGraphics 640,480
glEnable GL_DEPTH_TEST								'Enables Depth Testing
glEnable(GL_TEXTURE_2D)
glMatrixMode GL_PROJECTION						'Select The Projection Matrix
glLoadIdentity										'Reset The Projection Matrix

' are you sure you want orthograpic and not perspective....?
glOrtho(0,640,480,0,-1000,1000)				'Setup The Projection Matrix Frustum

glMatrixMode GL_MODELVIEW							'Select The ModelView Matrix
glLoadIdentity										'Reset The ModelView Matrix

Global mySphere:TList = New TList
makeSphere(mySphere)

Global pixmap:TPixmap = LoadPixmap("icon.BMP")
Global texture:Int = GLTexFromPixmap(pixmap)

Global SphereDisplayList:Int = glGenLists ( 1 )
glNewList ( SphereDisplayList , GL_COMPILE )
drawSphere(mySphere)
glEndList()
Global SphereDisplayList2:Int = glGenLists ( 1 )
glNewList ( SphereDisplayList2 , GL_COMPILE )
drawSphere2(mySphere)
glEndList()

Local a#=0
While Not KeyDown( KEY_ESCAPE )

	glClear GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT		'Clear The Screen And The Depth Buffer
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
	glLoadIdentity()
	glTranslatef 320 , 240 , 0
	glrotatef(a*2,0,1,0)
	glrotatef(-a,1,0,0)
	glscalef(200,200,200)
	glCallList(SphereDisplayLIst)
	glCallList(SphereDisplayLIst2)
	glLoadIdentity()
	glTranslatef 60 , 60 , 0
	glrotatef(a,0,1,0)
	glrotatef(-a,1,0,0)
	glscalef(50,50,50)
	glCallList(SphereDisplayLIst)
	glCallList(SphereDisplayLIst2)
	a:+.6

	Flip

Wend

Function DrawSphere (vl:TList)

	'glBindTexture (GL_TEXTURE_2D, texture)
	glBegin (GL_TRIANGLE_STRIP)
	

	For Local v:vert = EachIn vl
		nextColour()
		glTexCoord2f (-v.u,v.v)
		glVertex3f (v.x , v.y , v.z)
	Next

	glEnd()

EndFunction

Function DrawSphere2 (vl:TList)

	'glBindTexture (GL_TEXTURE_2D, texture)
	glBegin (GL_TRIANGLE_STRIP)
	

	For Local v:vert = EachIn vl
		nextColour()
		glTexCoord2f (-v.u,v.v)
		glVertex3f (v.x , v.y , -v.z)
	Next

	glEnd()

EndFunction

Global cc:Int=0
Function nextColour()
	cc:+ 1
	If cc = 4 Then cc = 0
	Select cc
		Case 0
			glcolor3f 0,1,0
		Case 1
			glcolor3f 1,0,0
		Case 2
			glcolor3f 0,0,1
		Case 3
			glcolor3f 1,1,1
	End Select
EndFunction

Type vert
	Field x# , y# , z# , u# , v#
EndType

Function makeSphere(vertList:TList)
	Const astep#=-15
	For Local b# = 90 Until 0 Step astep
		For Local a# = 360 Until 0 Step astep
			Local v:vert = New vert
			v.x=Sin(a ) * Sin(b ) 	
			v.y = Cos( a ) * Sin(b )
			v.z = Cos( b ) 
			v.u = (2 * b) / 360
			v.v = a / 360
			ListAddLast vertList , v
			v = New vert
			v.x=Sin(a ) * Sin((b+astep) ) 	
			v.y = Cos( a ) * Sin( (b+astep) )
			v.z = Cos( (b+astep) )
			v.u = (2 * (b+astep)) / 360
			v.v = a / 360
			ListAddLast vertList , v
			v = New vert
			v.x=Sin((a+astep) ) * Sin(b ) 	
			v.y = Cos( (a+astep) ) * Sin(b )
			v.z = Cos( b )
			v.u = (2 * b) / 360
			v.v = (a+astep) / 360
			ListAddLast vertList , v
			v = New vert
			v.x=Sin((a+astep) ) * Sin((b+astep) ) 	
			v.y = Cos( (a+astep) ) * Sin((b+astep) )
			v.z = Cos( (b+astep) ) 
			v.u = (2 * (b+astep)) / 360
			v.v = (a+astep) / 360
			ListAddLast vertList , v
		Next
	Next
EndFunction



These work well thanks for taking the time to help me.

np,

ps dont forget to post a complete example if you are posting code again...

Could some please explain which bits of this code make which bits of the sphere. it's useful code, but i don't understand the maths behind the constuction of the sphere.


Function makeSphere(vertList:Tlist)
	Const astep#=15
	For Local b# = 0 Until 90 Step astep
		For Local a# = 0 Until 360 Step astep
			Local v:vert = New vert
			v.x=Sin(a ) * Sin(b ) 	
			v.y = Cos( a ) * Sin(b )
			v.z = Cos( b ) 
			v.u = (2 * b) / 360
			v.v = a / 360
			ListAddLast vertList , v
			v = New vert
			v.x=Sin(a ) * Sin((b+astep) ) 	
			v.y = Cos( a ) * Sin( (b+astep) )
			v.z = Cos( (b+astep) )
			v.u = (2 * (b+astep)) / 360
			v.v = a / 360
			ListAddLast vertList , v
			v = New vert
			v.x=Sin((a+astep) ) * Sin(b ) 	
			v.y = Cos( (a+astep) ) * Sin(b )
			v.z = Cos( b )
			v.u = (2 * b) / 360
			v.v = (a+astep) / 360
			ListAddLast vertList , v
			v = New vert
			v.x=Sin((a+astep) ) * Sin((b+astep) ) 	
			v.y = Cos( (a+astep) ) * Sin((b+astep) )
			v.z = Cos( (b+astep) ) 
			v.u = (2 * (b+astep)) / 360
			v.v = (a+astep) / 360
			ListAddLast vertList , v
		Next
	Next
EndFunction


Cheers
Charlie



Ok it's a little rushed, but I'll show what I have so far...
Right now, this demo uses the blitzmax lists to store point objects but common sence would dictate the use of the gl lists.
Basically there is one list called sphere_list. This list is what the create functions throw their data into and the objects get drawn in the while loop.

Don't be too harsh, I just started OpenGL recently and dont understand the more complex features.

also please not that the lofted cone command without the x,y and z points if for drawing the other lofted cone2 command is used for belts in the spheres and tori. The sphere and torus were the most difficult shapes for me because finding points for them meant moving along all 3 axes.

If you change the draw command to line loop in the sphere and torius commands you will notice that an extra set of lines happens, it the problem lies within the second draw lofted cone command.

I have really enjoyed the puzzles and challanged of constructing these shapes. They still have a minor problem with the draw lofted cone2 command in the sphere and torus though as stated previously.

I have written a set color hsv command too!

the code:
PLEASE NOTE THAT THE SPHERE AND TORUS ROUTINES USE THE SHPERE_LIST FOR DRAWING THE OTHERS DON'T YET.

Strict
GLGraphics 800,600

glEnable GL_DEPTH_TEST								'Enables Depth Testing
glMatrixMode GL_PROJECTION						'Select The Projection Matrix
glLoadIdentity										'Reset The Projection Matrix
glOrtho(0,640,480,0,-1000,1000)				'Setup The Projection Matrix Frustum
glMatrixMode GL_MODELVIEW							'Select The ModelView Matrix
glLoadIdentity	
' set some rotation values for  checking
Global rotx%=0
Global roty%=0

Global sphere_list:TList = New TList
Function setdaycolor(r#,g#,b#,r2#,g2#,b2#,percent#)
	Local r_dif#=r2-r
	Local g_dif#=g2-g
	Local b_dif#=b2-b
	glColor3f r+(r_dif*percent),g+(g_dif*percent),b+(b_dif*percent)
End Function
Function setHSV(H#,S#,V#)
'H=0-360
'S=0-1
'v=0-255


While H < 0
	H:+360
Wend
While H> 360
	H:-360
Wend
While S <0
	s:+1
Wend
While s>1
	s:-1
Wend
While V<0
	V:+255
Wend
While V> 255
	v:-255
Wend

Local Hi%=(H/60) Mod 6.0

Local f#=(H/60)-Hi
Local p#=V*(1-S)
Local q#=V*(1-(f*S))
Local t#=V*(1-((1-f)*s))
Local R#=0
Local G#=0
Local B#=0

If Hi = 0
	R=V
	G=t
	B=P
EndIf

If Hi = 1
	R=q
	G=V
	B=P
EndIf

If Hi = 2
	R=p
	G=V
	B=t
EndIf

If Hi = 3
	R=p
	G=q
	B=V
EndIf

If Hi = 4
	R=t
	G=p
	B=V
EndIf

If Hi = 5
	R=V
	G=p
	B=q
EndIf
glcolor3f R/255.0,g/255.0,b/255.0

EndFunction
Global thing_list:TList = New TList
Function create_cuboid(width#,height#,depth#)
	Local half_width#=width/2.0
	Local half_height#=height/2.0
	Local half_depth#=depth/2
	'save first point
	Local a:point = New point
	a.x=-half_width
	a.y=-half_height
	a.z=-half_depth
	' save second point
	Local b:point = New point
	b.x=half_width
	b.y=-half_height
	b.z=-half_depth
	' save thrid point
	Local c:point = New point
	c.x=half_width
	c.y=-half_height
	c.z=half_depth
	' save the foruth point
	Local d:point = New point
	d.x=half_width
	d.y=half_height
	d.z=half_depth
	' save the fifth point
	Local e:point = New point
	e.x=-half_width
	e.y=half_height
	e.z=half_depth
	'save the sixth point
	Local f:point = New point
	f.x=-half_width
	f.y=half_height
	f.z=-half_depth
	' save the seventh point
	Local g:point = New point
	g.x=half_width
	g.y=half_height
	g.z=-half_depth
	'save the eigth point
	Local h:point = New point
	h.x=-half_width
	h.y=-half_height
	h.z=half_depth
	


	
	glBegin GL_QUADS
	
	'face 1
	glVertex3f a.x,a.y,a.z
	glVertex3f b.x,b.y,b.z
	glVertex3f g.x,g.y,g.z
	glVertex3f f.x,f.y,f.z
	'face 2
	glVertex3f a.x,a.y,a.z
	glVertex3f h.x,h.y,h.z
	glVertex3f e.x,e.y,e.z
	glVertex3f f.x,f.y,f.z
	' face 3
	glVertex3f h.x,h.y,h.z
	glVertex3f c.x,c.y,c.z
	glVertex3f d.x,d.y,d.z
	glVertex3f e.x,e.y,e.z
	' face 4
	glVertex3f b.x,b.y,b.z
	glVertex3f c.x,c.y,c.z
	glVertex3f d.x,d.y,d.z
	glVertex3f g.x,g.y,g.z
	'face 5
	glVertex3f g.x,g.y,g.z
	glVertex3f d.x,d.y,d.z
	glVertex3f e.x,e.y,e.z
	glVertex3f f.x,f.y,f.z
	' face 6
	glVertex3f a.x,a.y,a.z
	glVertex3f b.x,b.y,b.z
	glVertex3f c.x,c.y,c.z
	glVertex3f h.x,h.y,h.z
	glend
End Function
Function create_cone(width#,height#,sides#,cap#)
	Local sub_angle#=360.0/sides

		For Local i#=0 To sides-1
			
			Local x1#=Cos(i*sub_angle)*(width/2.0)
			Local y1#= height/2.0
			Local z1#=Sin(i*sub_angle)*(width/2.0)
			Local x2#=Cos((i+1)*sub_angle)*(width/2.0)
			Local z2#=Sin((i+1)*sub_angle)*(width/2.0)
			Local color#=(i*sub_angle)/360
			glBegin GL_TRIANGLES
				glcolor3f 1,1,0
				glVertex3f x1,-y1,z1
				' second line point 2
				glcolor3f 1,0,1
				glVertex3f x2,-y1,z2
				glVertex3f 0,y1,0
				glEnd
				' take care of cap
				If cap <> 0
					glBegin GL_triangles
				glcolor3f 1,1,0
				glVertex3f x1,-y1,z1
				' second line point 2
				glcolor3f 0,0,1
				glVertex3f x2,-y1,z2
				glVertex3f 0,-y1,0
				glEnd
				End If
		Next
EndFunction
Function create_tube(width#,height#,sides#,cap#)
	Local sub_angle#=360.0/sides

	
		
		For Local i#=0 To sides-1
			glBegin GL_QUADS
			Local x1#=Cos(i*sub_angle)*(width/2.0)
			Local y1#= height/2.0
			Local z1#=Sin(i*sub_angle)*(width/2.0)
			Local x2#=Cos((i+1)*sub_angle)*(width/2.0)
			Local z2#=Sin((i+1)*sub_angle)*(width/2.0)
			' first  line point 1
			glcolor3f 1,0,0
			glVertex3f x1,y1,z1
			'first line point 2
			glcolor3f 1.0,1.0,0
			glVertex3f x1,-y1,z1
			
			' second line point 2
			glVertex3f x2,-y1,z2
			' second line point 1
			glVertex3f x2,y1,z2
			glEnd
			
			If cap <> 0
			glBegin GL_TRIANGLES
				glcolor3f 1,1,0
				glVertex3f x1,-y1,z1
				' second line point 2
				glcolor3f 0,0,1
				glVertex3f x2,-y1,z2
				glVertex3f 0,-y1,0
				glEnd
				
				glBegin GL_TRIANGLES
				glcolor3f 1,0,0
			glVertex3f x1,y1,z1
				' second line point 2
				glcolor3f 0,0,1
				glVertex3f x2,y1,z2
				glVertex3f 0,y1,0
				glEnd	
			EndIf
		Next
		
	
End Function
Function create_lofted_cone(height#,sides#,radius1#,radius2#,cap#)
Local sub_angle#=360.0/sides
	
	glBegin GL_line_loop
		For Local i#=0 To sides
			
			Local x1#=Cos(sub_angle*i)*radius1
			Local y1#=height/2
			Local z1#=Sin(sub_angle*i)*radius1
			Local x2#=Cos(sub_angle*(i+1))*radius2
			Local y2#=height/-2
			Local z2#=Sin(sub_angle*(i+1))*radius2
			' create a point and save it to the list
			Local a:point = New point
			a.x=x1
			a.y=y1
			a.z=z1
			ListAddLast(sphere_list,a)
			glcolor3f i/sides,1,1
			glVertex3f x1,y1,z1
			Local b:point = New point
			b.x=x2
			b.y=y2
			b.z=z2
			ListAddLast(sphere_list,b)
			glcolor3f 0,0,i/sides
			glVertex3f x2,y2,z2
			
		Next
	glEnd
EndFunction
Function create_lofted_cone2(x#,y#,z#,height#,sides#,radius1#,radius2#)
' this is made for other drawing commands do not use it on it's own
Local sub_angle#=360.0/sides
	
	
		For Local i#=0 To sides
			
			Local x1#=Cos(sub_angle*i)*radius1
			Local y1#=height/2.0
			Local z1#=Sin(sub_angle*i)*radius1
			Local x2#=Cos(sub_angle*(i+1))*radius2
			Local y2#=height/-2.0
			Local z2#=Sin(sub_angle*(i+1))*radius2
			Local x3#=Cos(sub_angle*(i+2))*radius1
			Local x4#=Cos(sub_angle*(i+2))*radius2
			' create a point and save it to the list
			Local a:point = New point
			a.x=x+x1
			a.y=y+y1
			a.z=z+z1
			ListAddLast(sphere_list,a)
			
			Local b:point = New point
			b.x=x+x2
			b.y=y+y2
			b.z=z+z2
			ListAddLast(sphere_list,b)
	
			
		Next
	glEnd
EndFunction
Function create_sphere(x_divisions#,y_divisions#,radius#)
	Local small_angle#=180.0/y_divisions ' this is the angle used for y divisions
	Local belt_height#=(radius*2.0)/y_divisions
	Local start_y#=-radius+(belt_height/2.0) ' the first point for the first cone
	' now we find the y value for all the belts and their radii
	Local last_width#=0.0
	For Local i=0 To y_divisions-1
		Local height#=Abs(Cos(i*small_angle)*radius-Cos((i+1.0)*small_angle)*radius)
		Local first_radius#=Sin(i*small_angle)*radius
		Local second_radius#=Sin((i+1)*small_angle)*radius
		Local y_location#=-radius+last_width+(height/2.0) ' use this one to test
		glLoadIdentity
		
		
		create_lofted_cone2(0,y_location,0,height,x_divisions,second_radius,first_radius)
		glEnd
		last_width:+height
	Next
End Function
Function create_torus(x_divisions#,y_divisions#,radius#,radius2#)
	

	Local small_angle#=360.0/y_divisions ' this is the angle used for y divisions
	Local belt_height#=(radius*2.0)/y_divisions
	
	' now we find the y value for all the belts and their radii
	Local last_width#=0.0
	For Local i=0 To y_divisions-1
		Local height#=Cos(i*small_angle)*radius-Cos((i+1.0)*small_angle)*radius
		Local first_radius#=Sin(i*small_angle)*radius
		Local second_radius#=Sin((i+1)*small_angle)*radius
		Local y_location#=-radius+last_width+(height/2.0) ' use this one to test
		glLoadIdentity
		
		
		create_lofted_cone2(0,y_location,0,height,x_divisions,second_radius+radius2,first_radius+radius2)
		glEnd
		last_width:+height
	Next
End Function
Type thing
	Field x#,y#,zrot#
	Function create(x#,y#,zrot#)
		Local temp:thing = New thing
		temp.x=x
		temp.y=y
		temp.zrot=zrot
		ListAddLast(thing_list,temp)
	End Function
	Method draw()
	glLoadIdentity
	glTranslatef x,y,0
	glrotatef rotx,1,0,0
	glrotatef roty,0,1,0
	glcolor3f 1,1,1
	glBegin GL_triangle_strip
	
	Local b=0
For Local i:point = EachIn(sphere_list)
Local listlength#=CountList(sphere_list)
'normally this would be a dumb wat to calculate colors but for these few triangles it works
setHSV((b/listlength)*360,33,255)
glVertex3f i.x,i.y,i.z
b:+1
Next

glEnd
	
	
	
	

	

	End Method
End Type
Type point
	Field x#,y#,z
End Type

' create a test ring

	create_torus(24,10,32,256)

	thing.create (320,240,0)






While Not KeyHit( KEY_ESCAPE )
	rotx:+(KeyDown(key_up)-KeyDown(key_down))*3
	roty:+(KeyDown(key_right)-KeyDown(key_left))*3


	glClear GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT
	
	For Local i:thing = EachIn(thing_list)
		
		i.draw()
	Next


glend
	Flip

Wend



Don't be too harsh, I just started OpenGL recently and dont understand the more complex features.


At least you're man enough to share, which ranks you higher than some of the precious Uber haxors here... >:)

I'd drop the lists altogether, I just ended up using them cause I was aping some old C code I found lying around.

@jkrankie
have a play with max2d and coords like....

for local a#=0 until 360 step 7.5
x#=50+sin(a#)*40
y#=50+cos(a#)*40
plot x,y ' errm away from a machine with max on it(plot a pixel here) !!!!
next

try changing a differently ( cos(a*2) ) and generally mess with it

also look at http://www.euclideanspace.com/maths/index.htm
(a real gem that one...!)

thanks Chris.

Cheers
Charlie