Post by PeterMaria on Jul 19, 2015 11:32:44 GMT -5
Hello
3D with 2D.
3D with 2D.
dim ox = 320
dim oy = 240
dim cx, cy, pen=1, heading
Declare Sub Init2D(width,height)
Declare Sub Line(x0,y0,x1,y1,lsize#)
Declare Sub Pos(x,y)
Declare Sub iPoint(a#,b#,c#)
Declare Sub Cone(r#,l#)
Declare Sub Ellipsoid(r1#,r2#,r3#)
Declare Sub Cylinder(r#, l#)
Declare Sub Sphere(r#)
Init2D(640,480)
'glEnable(GL_LINE_SMOOTH)
Sphere(40)
Cone(40, 70)
Cylinder(30, 90)
Ellipsoid(60, 40, 25)
swapbuffers()
end
Sub Pos(x,y)
if pen then Line(ox+cx,oy-cy,ox+x,oy-y,1): end if
cx = x
cy = y
End Sub
Sub iPoint(a#,b#,c#)
Pos((a#-c#)*1, b#-(a#+c#)*0.5)
End Sub
Sub Cone(r#,l#)
dim h#,v#
r#= l#/2
pen=0
For h#=0 to l# step 10
For v#=0 to 360 step 20
iPoint((h#/2)*cosd(v#), h#, (h#/2)*sind(v#))
pen=1
Next
pen=0
Next
For v#=0 to 360 step 20
For h#=0 to l# step 10
iPoint((h#/2)*cosd(v#), h#, (h#/2)*sind(v#))
pen=1
Next
pen=0
Next
End Sub
Sub Ellipsoid(r1#, r2#, r3#)
dim u#, v#, l#, m#, n#
pen=0
For u#=0 to 360 step 20
For v#=0 to 180 step 20
l# = (r1# * cosd(u#)) * sind(v#)
m# = r3# * sind(u#)
n# = (r2# * cosd(u#)) * cosd(v#)
iPoint(100+l#, -30+m#, 100+n#)
pen=1
Next
pen=0
Next
For v#=0 to 180 step 20
For u#=0 to 360 step 20
l# = (r1# * cosd(u#)) * sind(v#)
m# = r3# * sind(u#)
n# = (r2# * cosd(u#)) * cosd(v#)
iPoint(100+l#, -30+m#, 100+n#)
pen=1
Next
pen=0
Next
End Sub
Sub Cylinder(r#, l#)
dim h#, v#
pen=0
For h#=0 to l# step 10
For v#=0 to 360 step 20
iPoint(120+r#*cosd(v#), -100+h#, -120+r#*sind(v#))
pen=1
Next
pen=0
Next
For v#=0 to 360 step 20
For h#=0 to l# step 10
iPoint(120+r#*cosd(v#), -100+h#, -120+r#*sind(v#))
pen=1
Next
pen=0
Next
End Sub
Sub Sphere(r#)
dim u#, v#, l#, m#, n#
pen=0
For u#=0 to 360 step 20
For v#=0 to 180 step 20
l# = (r# * cosd(u#)) * sind(v#)
m# = r# * sind(u#)
n# = (r# * cosd(u#))* cosd(v#)
iPoint(-120+l#, -100+m#, 120+n#)
pen=1
Next
pen=0
Next
For v#=0 to 180 step 20
For u#=0 to 360 step 20
l# = (r# * cosd(u#)) * sind(v#)
m# = r# * sind(u#)
n# = (r# * cosd(u#)) * cosd(v#)
iPoint(-120+l#, -100+m#, 120+n#)
pen=1
Next
pen=0
Next
End Sub
Sub Init2D(width,height)
glMatrixMode (GL_PROJECTION)
glLoadIdentity()
glOrtho(0,width,height,0,-1,1)
glMatrixMode (GL_MODELVIEW)
glDisable(GL_DEPTH_TEST)
End Sub
Sub Line(x0,y0,x1,y1,lsize#)
glLinewidth(lsize#)
glBegin(GL_LINES)
glVertex2i(x0,y0)
glVertex2i(x1,y1)
glEnd()
End Sub