Маленький код, который я решил немного переписать
#r=200
p1=0
t1=0
xyrot = 0
xzrot = 0
yzrot = 0
t1=0
If InitSprite() And OpenWindow(0,0,0,640,480,"dot sphere",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget) And OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)
Repeat
StartDrawing(ScreenOutput())
Box(0,0,640,480,0)
For t=-90 To 90 Step 10
For p=0 To 360 Step 9
x.l=Int( #r*Cos(t*#PI/180)*Cos(p*#PI/180) )
y.l=Int( #r*Cos(t*#PI/180)*Sin(p*#PI/180) )
z.l=Int( #r*Sin(t*#PI/180) )
x1=x*Cos(xyrot*#PI/180)-y*Sin(xyrot*#PI/180)
y1=y*Cos(xyrot*#PI/180)+x*Sin(xyrot*#PI/180)
z1=z
; // xzrot
x=x1
y=y1
;z=z1
x1=x*Cos(xzrot*#PI/180)-z*Sin(xzrot*#PI/180)
y1=y
z1=z*Cos(xzrot*#PI/180)+x*Sin(xzrot*#PI/180)
; // yzrot
x=x1
y=y1
z=z1
x1=x
y1=y*Cos(yzrot*#PI/180)+z*Sin(yzrot*#PI/180)
z1=z*Cos(yzrot*#PI/180)-y*Sin(yzrot*#PI/180)
y=y1
z=z1
;perspective
; nx := 256*x div (z-Zoff)+Xoff
; ny := 256*y div (z-Zoff)+Yoff
; If z
; nx=Int(256*x/(z-100)+320)
; ny=Int(256*y/(z-100)+200)
; EndIf
nx=x+320
ny=y+200
Box(nx,ny,2,2,$FFFFFF)
Next p
Next t
xyrot =xrot+1;0.02 / 2;
xzrot = xzrot+2;0.04 / 2;
yzrot = yzrot+1;0.03 / 2;
If xyrot>=360:xyrot=0:EndIf
If xzrot>=360:xzrot=0:EndIf
If yzrot>=360:yzrot=0:EndIf
StopDrawing()
FlipBuffers()
Until WindowEvent()=#PB_Event_CloseWindow
EndIf
; IDE Options = PureBasic 5.30 (Windows - x86)
; CursorPosition = 16
p1=0
t1=0
xyrot = 0
xzrot = 0
yzrot = 0
t1=0
If InitSprite() And OpenWindow(0,0,0,640,480,"dot sphere",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget) And OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)
Repeat
StartDrawing(ScreenOutput())
Box(0,0,640,480,0)
For t=-90 To 90 Step 10
For p=0 To 360 Step 9
x.l=Int( #r*Cos(t*#PI/180)*Cos(p*#PI/180) )
y.l=Int( #r*Cos(t*#PI/180)*Sin(p*#PI/180) )
z.l=Int( #r*Sin(t*#PI/180) )
x1=x*Cos(xyrot*#PI/180)-y*Sin(xyrot*#PI/180)
y1=y*Cos(xyrot*#PI/180)+x*Sin(xyrot*#PI/180)
z1=z
; // xzrot
x=x1
y=y1
;z=z1
x1=x*Cos(xzrot*#PI/180)-z*Sin(xzrot*#PI/180)
y1=y
z1=z*Cos(xzrot*#PI/180)+x*Sin(xzrot*#PI/180)
; // yzrot
x=x1
y=y1
z=z1
x1=x
y1=y*Cos(yzrot*#PI/180)+z*Sin(yzrot*#PI/180)
z1=z*Cos(yzrot*#PI/180)-y*Sin(yzrot*#PI/180)
y=y1
z=z1
;perspective
; nx := 256*x div (z-Zoff)+Xoff
; ny := 256*y div (z-Zoff)+Yoff
; If z
; nx=Int(256*x/(z-100)+320)
; ny=Int(256*y/(z-100)+200)
; EndIf
nx=x+320
ny=y+200
Box(nx,ny,2,2,$FFFFFF)
Next p
Next t
xyrot =xrot+1;0.02 / 2;
xzrot = xzrot+2;0.04 / 2;
yzrot = yzrot+1;0.03 / 2;
If xyrot>=360:xyrot=0:EndIf
If xzrot>=360:xzrot=0:EndIf
If yzrot>=360:yzrot=0:EndIf
StopDrawing()
FlipBuffers()
Until WindowEvent()=#PB_Event_CloseWindow
EndIf
; IDE Options = PureBasic 5.30 (Windows - x86)
; CursorPosition = 16
Теперь оптимизация
#r=200
Structure p3d
x.l
y.l
z.l
EndStructure
Dim ba.p3d(778)
xyrot.a = 0
xzrot.a = 0
yzrot.a = 0
;calc sinus
Dim s.l(255)
For i=0 To 255
s(i)=Int(64*Sin(i*#PI/128))
Next i
;precalc X,Y,Z
ii=0
For t=-90 To 90 Step 10
For p=0 To 360 Step 9
ba(ii)\x=Int( #r*Cos(t*#PI/180)*Cos(p*#PI/180) )
ba(ii)\y=Int( #r*Cos(t*#PI/180)*Sin(p*#PI/180) )
ba(ii)\z=Int( #r*Sin(t*#PI/180) )
ii+1
Next p
Next t
;Debug ii ;779
If InitSprite() And OpenWindow(0,0,0,640,480,"dot sphere",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget) And OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)
Repeat
StartDrawing(ScreenOutput())
Box(0,0,640,480,0)
For i=0 To 778
x=ba(i)\x
y=ba(i)\y
z=ba(i)\z
;x1=x*Cos(xyrot*#PI/180)-y*Sin(xyrot*#PI/180)
;;x1.l=x*s((xyrot+64)&255)/64-y*s(xyrot)/64
x1.l=( x*s((xyrot+64)&255)-y*s(xyrot) )/64
;y1=y*Cos(xyrot*#PI/180)+x*Sin(xyrot*#PI/180)
;;y1.l=y*s((xyrot+64)&255)/64+x*s(xyrot)/64
y1.l=( y*s((xyrot+64)&255)+x*s(xyrot) )/64
z1.l=z
; // xzrot
x=x1
y=y1
;z=z1
;x1=x*Cos(xzrot*#PI/180)-z*Sin(xzrot*#PI/180)
;;x1=x*s((xzrot+64)&255)/64-z*s(xzrot)/64
x1=( x*s((xzrot+64)&255)-z*s(xzrot) )/64
y1=y
;z1=z*Cos(xzrot*#PI/180)+x*Sin(xzrot*#PI/180)
;;z1=z*s((xzrot+64)&255)/64+x*s(xzrot)/64
z1=( z*s((xzrot+64)&255)+x*s(xzrot) )/64
; // yzrot
x=x1
y=y1
z=z1
x1=x
;y1=y*Cos(yzrot*#PI/180)+z*Sin(yzrot*#PI/180)
;;y1=y*s((yzrot+64)&255)/64+z*s(yzrot)/64
y1=( y*s((yzrot+64)&255)+z*s(yzrot) )/64
;;z1=z*s((yzrot+64)&255)/64-y*s(yzrot)/64
z1=( z*s((yzrot+64)&255)-y*s(yzrot) )/64
y=y1
z=z1
If z>0
Box(x+320,y+200,2,2,$FFFFFF)
EndIf
Next i
xyrot = xyrot+1
xzrot = xzrot+1
yzrot = yzrot+1
StopDrawing()
FlipBuffers()
Until WindowEvent()=#PB_Event_CloseWindow
EndIf
; IDE Options = PureBasic 5.30 (Windows - x86)
; CursorPosition = 20
; FirstLine = 9
Structure p3d
x.l
y.l
z.l
EndStructure
Dim ba.p3d(778)
xyrot.a = 0
xzrot.a = 0
yzrot.a = 0
;calc sinus
Dim s.l(255)
For i=0 To 255
s(i)=Int(64*Sin(i*#PI/128))
Next i
;precalc X,Y,Z
ii=0
For t=-90 To 90 Step 10
For p=0 To 360 Step 9
ba(ii)\x=Int( #r*Cos(t*#PI/180)*Cos(p*#PI/180) )
ba(ii)\y=Int( #r*Cos(t*#PI/180)*Sin(p*#PI/180) )
ba(ii)\z=Int( #r*Sin(t*#PI/180) )
ii+1
Next p
Next t
;Debug ii ;779
If InitSprite() And OpenWindow(0,0,0,640,480,"dot sphere",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget) And OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)
Repeat
StartDrawing(ScreenOutput())
Box(0,0,640,480,0)
For i=0 To 778
x=ba(i)\x
y=ba(i)\y
z=ba(i)\z
;x1=x*Cos(xyrot*#PI/180)-y*Sin(xyrot*#PI/180)
;;x1.l=x*s((xyrot+64)&255)/64-y*s(xyrot)/64
x1.l=( x*s((xyrot+64)&255)-y*s(xyrot) )/64
;y1=y*Cos(xyrot*#PI/180)+x*Sin(xyrot*#PI/180)
;;y1.l=y*s((xyrot+64)&255)/64+x*s(xyrot)/64
y1.l=( y*s((xyrot+64)&255)+x*s(xyrot) )/64
z1.l=z
; // xzrot
x=x1
y=y1
;z=z1
;x1=x*Cos(xzrot*#PI/180)-z*Sin(xzrot*#PI/180)
;;x1=x*s((xzrot+64)&255)/64-z*s(xzrot)/64
x1=( x*s((xzrot+64)&255)-z*s(xzrot) )/64
y1=y
;z1=z*Cos(xzrot*#PI/180)+x*Sin(xzrot*#PI/180)
;;z1=z*s((xzrot+64)&255)/64+x*s(xzrot)/64
z1=( z*s((xzrot+64)&255)+x*s(xzrot) )/64
; // yzrot
x=x1
y=y1
z=z1
x1=x
;y1=y*Cos(yzrot*#PI/180)+z*Sin(yzrot*#PI/180)
;;y1=y*s((yzrot+64)&255)/64+z*s(yzrot)/64
y1=( y*s((yzrot+64)&255)+z*s(yzrot) )/64
;;z1=z*s((yzrot+64)&255)/64-y*s(yzrot)/64
z1=( z*s((yzrot+64)&255)-y*s(yzrot) )/64
y=y1
z=z1
If z>0
Box(x+320,y+200,2,2,$FFFFFF)
EndIf
Next i
xyrot = xyrot+1
xzrot = xzrot+1
yzrot = yzrot+1
StopDrawing()
FlipBuffers()
Until WindowEvent()=#PB_Event_CloseWindow
EndIf
; IDE Options = PureBasic 5.30 (Windows - x86)
; CursorPosition = 20
; FirstLine = 9
Комментарии
Отправить комментарий