|
本帖最后由 hellboyxxx 于 2022-10-22 10:33 编辑
pAn:
上午看bili学代数
下午磕磕碰碰做了一个甜甜圈的3D渲染
用c.basic实现的,据说是比自带的basic快十倍
虽然最终显示效果超级慢。。。。。
不知道是不是sh3性能问题,麻烦高手指出代码中可以优化的地方
如图
1
2
3
4
5
视频放在附件里了,有兴趣可以看看
7.mp4
(13.23 MB, 下载次数: 39)
8.mp4
(4.68 MB, 下载次数: 21)
原理非常简单
就是先做出甜甜圈的截面圆
分别经过yxz轴的变换并投射xy点在屏幕上即可
下面是草稿
6
以下是c.basic代码,每一部分都加了注释,可以仔细看看
'ProgramMode:RUN
'init
ViewWindow (-)24,128,0,(-)8,64,0
Screen.G
Deg
Local Theta,a,b,c,x,y,m,n,p,q,R1,R2,K1,K2,D1,D2,D3,D4,S1,S2
'donut radient
30->R1
'donut thickness
10->R2
'distance from screen to camera
30->K1
'distance from donut to screen
30->K2
'startangle for xyz axes rotation
(-)90->D1
(-)60->D2
(-)60->D3
(-)30->D4
'step,drawing precision
30->S1
20->S2
{3,3}->Dim Mat A
{3,3}->Dim Mat B
{3,3}->Dim Mat C
{3,1}->Dim Vct E
{3,1}->Dim Vct F
Cls
'start loop
While 1
'rotation on z axes 4th
For D4->c To D4+360 Step S2
'rotation on x axes 3rd
For D3->a To D3+360 Step S2
Cls
'rotation on y axes 2nd
For D2->b To D2+360 Step S2
'rotate donut ring 1st
For D1->Theta To D1+360 Step S1
'donut ring
[[R1+R2cos Theta,R2sin Theta,0]]->Vct E
'xyz translation
[[1,0,0][0,cos a,(-)sin a][0,sin a,cos a]]->Mat A
[[cos b,0,sin b][0,1,0][(-)sin b,0,cos b]]->Mat B
[[cos c,(-)sin c,0][sin c,cos c,0][0,0,1]]->Mat C
'input all translation at once
Vct E*Mat B*Mat A*Mat C->Vct F
'output real donut location
Vct F[1,1]->x
Vct F[1,2]->y
'save last location
m->p
n->q
'output the screen location,frac means divide by
x*K1frac(K1+K2-R2)+64->m
y*K1frac(K1+K2-R2)+32->n
'option to draw dots
'__Pixel _m,n,1
'option to draw lines from last location to current location
_Line p,q,m,n,1
'info print on screen
Text 0,0,"R1:"+ToStr(R1)
Text 7,0,"R2:"+ToStr(R2)
Text 14,0,"K1:"+ToStr(K1)
Text 21,0,"K2:"+ToStr(K2)
Text 28,0,"_Theta_:"+ToStr(Theta)
Text 35,0,"b:"+ToStr(b)
Text 42,0,"a:"+ToStr(a)
Text 49,0,"c:"+ToStr(c)
Text 0,28,"a 3d donut basic render"
Text 7,43,"in super slow motion"
Text 57,75,"pAn signature."
'start drawing
_DispVram
Next
Next
'enjoy the view
TicksWait 128
Next
Next
WhileEnd
|
|