indexbase 0
include "window.h"
SetWindow "Spinning squares",800,600,w_2
SetFont 12,24,100,"courier"
Long seed=0x12345678
'------------------------
Function RndF() as Single
'========================
'
Static As Single f, d=1/0x7fffffff
mov eax,seed
rol eax,7
imul eax,eax,13
mov seed,eax
push eax
fild dWord [esp]
add esp,4
fmul dWord d
fstp dWord f
Function=f
End Function
'TYPES
'=====
type boxF single xb,yb,zb, xt,yt,zt
type pointF single x,y,z, sys c
type projectionF single xa,ya,za, xs,ys,zs, xo,yo,zo
function LimitWithinBox(pointF*p, boxF*b)
'========================================
if p.x<b.xb then p.x=b.xb
if p.y<b.xb then p.y=b.yb
if p.z<b.xt then p.z=b.zb
if p.x>b.xt then p.x=b.xt
if p.y>b.xt then p.y=b.yt
if p.z>b.xt then p.z=b.zt
end function
sub projectPoint(pointF*p,projectionF*pr)
'========================================
single r,a
r=hypot(p.x,p.y)
a=atan(p.y,p.x)+pr.za
pixel r*cos(a)*pr.xs+pr.xo, r*sin(a)*pr.ys+pr.yo,p.c
end sub
single pi2 = pi()*2
sub RotaClamp(single*a)
'======================
if a < pi2 then
a+=pi2
elseif a > pi2 then
a-=pi2
end if
end sub
'MAIN
'====
boxF b1
pointF p1
projectionF pr1,pr2,pr3
'BOX DATA
b1<= -.5, -.5, -.5, .5, .5, .5
'PROJECTION DATA
pr1<= 0,0,.2, 200,200,200, 400,250,0
pr2<= 0,0,.3, 150,150,150, 400,300,0
pr3<= 0,0,.4, 100,100,100, 600,200,0
'
While WinExit=0
cls 0x551111
pr1.za+=.0025
pr2.za+=.005
pr3.za-=.007
RotaClamp pr1.za 'clamp angle range
RotaClamp pr2.za 'clamp angle range
'
seed=0x12345678 'reset random seed
for i=1 to 4000
p1<=rndf(),rndf(),rndf(),0xaaaaaa
ProjectPoint p1,pr1
ProjectPoint p1,pr2
LimitWithinBox p1,b1
ProjectPoint p1,pr3
next
DoEvents
SwapBuffers
FrameRate 60
'pause
Wend
WinEnd