📄 atlast.dxt
字号:
f> if ( ... x )
xMax 2! ( ... )
else ( ... x )
2dup ( ... x x )
xMin 2@ ( ... x x xMin )
f< if ( ... x )
xMin 2! ( ... )
else ( ... x )
2drop ( ... )
then
then
;
\ Stack on entering: Stack on leaving:
: resetExtents ( ... ) ( ... )
0 0 extentsMinSave element 2@ xMin 2!
0 1 extentsMinSave element 2@ yMin 2!
0 2 extentsMinSave element 2@ zMin 2!
0 0 extentsMaxSave element 2@ xMax 2!
0 1 extentsMaxSave element 2@ yMax 2!
0 2 extentsMaxSave element 2@ zMax 2!
;
: dxf:*:ray
"x" option if
1 delitem !
else
\ Bug in the interpreter makes multiple calls on one ray entity.
\ The following code stops that.
0 group "LINE" strcmp 0= if
exit
then
setExtents
initbignumrange
"LINE" 0 setgroup \ Turn a RAY into a line
iterator 0 do
11 group \ Get the X,Y,Z components of the unit direction vector
bignummean 2scalarmult
addOffset
setHiLoRange
goodenough if
leave
then
loop
11 group
bignummean 2scalarmult
addOffset
11 setgroup
resetExtents
then
;
: dxf:*:xline
"x" option if
1 delitem !
else
setExtents
initbignumrange
"LINE" 0 setgroup \ Turn an XLINE into a line
iterator 0 do
11 group \ Get the X,Y,Z components of the unit direction vector
bignummean fnegate 2scalarmult
addOffset
setHiLoRange
goodenough if
leave
then
loop
11 group
bignummean fnegate 2scalarmult
addOffset
\ Hold the results in the stack for later ...
initbignumrange
iterator 0 do
11 group \ Get the X,Y,Z components of the unit direction vector
bignummean 2scalarmult
addOffset
setHiLoRange
goodenough if
leave
then
loop
11 group
bignummean 2scalarmult
addOffset
11 setgroup \ Set the end point
\ ... OK, we can now set the 10 group
10 setgroup \ Set the start point
resetExtents
then
;
\ Compute the length of a 3D vector which has one endpoint at 0,0,0.
\ Stack on entering: Stack on leaving:
: vectorLength ( ... x y z ) ( ... len )
2.0 pow ( ... x y z**2 )
2swap 2.0 pow ( ... x z**2 y**2 )
f+ ( ... x z**2+y**2 )
2swap 2.0 pow ( ... z**2+y**2 x**2 )
f+ ( ... z**2+y**2+x**2 )
sqrt ( ... len )
;
\ angle = atan2(sin(p) * radiusRatio, cos(p))
\ Stack on entering: Stack on leaving:
: ellipseparamtoangle ( ... p ) ( ... a )
2dup ( ... p p )
sin ( ... p sin[p] )
40 group f* ( ... p r*sin[p] )
2swap ( ... r*sin[p] p )
cos ( ... r*sin[p] cos[p] )
atan2 ( ... a )
;
\ Stack on entering: Stack on leaving:
: vector2dup ( ... x y z ) ( ... x y z x y z )
2 2pick ( ... x y z x )
2 2pick ( ... x y z x y )
2 2pick ( ... x y z x y z )
;
\ Stack on entering: Stack on leaving:
: vector2swap ( ... x1 y1 z1 x2 y2 z2 ) ( ... x2 y2 z2 x1 y1 z1 )
5 2roll ( ... y1 z1 x2 y2 z2 x1 )
5 2roll ( ... z1 x2 y2 z2 x1 y1 )
5 2roll ( ... x2 y2 z2 x1 y1 z1 )
;
\ Dot product of u and v: u . v
\ Stack on entering: Stack on leaving:
: dotProduct ( ... x1 y1 z1 x2 y2 z2 ) ( ... x1x2+y1y2+z1z2 )
2 2roll ( ... x1 y1 z1 y2 z2 x2 )
5 2roll f* ( ... y1 z1 y2 z2 x2x1 )
2 2roll ( ... y1 z1 z2 x2x1 y2 )
4 2roll f* f+ ( ... z1 z2 x2x1+y2y1 )
2swap ( ... z1 x2x1+y2y1 z2 )
2 2roll f* f+ ( ... x2x1+y2y1+z2z1 )
;
\ Cross product of u and v: u x v
\ Stack on entering: Stack on leaving:
: crossProduct ( ... u1 u2 u3 v1 v2 v3 ) ( ... u2v3-u3v2 u3v1-u1v3 u1v2-u2v1 )
4 2pick ( ... u1 u2 u3 v1 v2 v3 u2 )
1 2pick f* ( ... u1 u2 u3 v1 v2 v3 u2v3 )
4 2pick ( ... u1 u2 u3 v1 v2 v3 u2v3 u3 )
3 2pick f* f- ( ... u1 u2 u3 v1 v2 v3 u2v3-u3v2 )
4 2roll ( ... u1 u2 v1 v2 v3 u2v3-u3v2 u3 )
4 2pick f* ( ... u1 u2 v1 v2 v3 u2v3-u3v2 u3v1 )
6 2pick ( ... u1 u2 v1 v2 v3 u2v3-u3v2 u3v1 u1 )
3 2roll f* f- ( ... u1 u2 v1 v2 u2v3-u3v2 u3v1-u1v3 )
5 2roll ( ... u2 v1 v2 u2v3-u3v2 u3v1-u1v3 u1 )
3 2roll f* ( ... u2 v1 u2v3-u3v2 u3v1-u1v3 u1v2 )
4 2roll ( ... v1 u2v3-u3v2 u3v1-u1v3 u1v2 u2 )
4 2roll f* f- ( ... u2v3-u3v2 u3v1-u1v3 u1v2-u2v1 )
;
\ Given a vector, scale its components to make it a unit vector.
\ Stack on entering: Stack on leaving:
: makeUnitVector ( ... x y z ) ( ... x1 y1 z1 )
vector2dup ( ... x y z x y z )
vectorLength ( ... x y z len )
2scalarDiv ( ... x1 y1 z1 )
;
\ Angle between 2 vectors, where both vectors have one endpoint at 0,0,0
\ Use the dot product of these 2 vectors to calculate the angle between them.
\ u.v = ||u|| ||v|| cos(theta)
\ Stack on entering: Stack on leaving:
: vectorangle ( ... ux uy uz vx vy vz ) ( ... theta )
vector2dup ( ... ux uy uz vx vy vz vx vy vz )
8 2pick ( ... ux uy uz vx vy vz vx vy vz ux )
8 2pick ( ... ux uy uz vx vy vz vx vy vz ux uy )
8 2pick ( ... ux uy uz vx vy vz vx vy vz ux uy uz )
vector2swap ( ... ux uy uz vx vy vz ux uy uz vx vy vz )
dotProduct ( ... ux uy uz vx vy vz u.v )
6 2roll ( ... uy uz vx vy vz u.v ux )
6 2roll ( ... uz vx vy vz u.v ux uy )
6 2roll ( ... vx vy vz u.v ux uy uz )
vectorLength ( ... vx vy vz u.v ulen )
4 2roll ( ... vy vz u.v ulen vx )
4 2roll ( ... vz u.v ulen vx vy )
4 2roll ( ... u.v ulen vx vy vz )
vectorLength f* f/ ( ... u.v / ulen*vlen )
acos ( ... theta )
;
\ Is this 3D point 0,0,0 ?
\ Stack on entering: Stack on leaving:
: isZeroVector ( ... x y z ) ( ... x y z t/f )
2dup ( ... x y z z )
0.0 f= if ( ... x y z )
1 2pick ( ... x y z y )
0.0 f= if ( ... x y z )
2 2pick ( ... x y z x )
0.0 f= if ( ... x y z )
true ( ... x y z t )
else ( ... x y z )
false ( ... x y z f )
then
else ( ... x y z )
false ( ... x y z f )
then
else ( ... x y z )
false ( ... x y z f )
then
;
: 2pi
2.0 pi f*
;
\ Stack on entering: Stack on leaving:
: normalizeEllipseAngle ( ... a1 ) ( ... a2 )
2dup 0.0 f< if ( ... a1 )
\ If angle is less than 0 add 2pi radians to make it positive.
2pi f+ ( ... a2 )
then
2dup ( ... a1 a1 )
2pi f>= if ( ... a1 )
\ If angle is greater than or equal to 2pi, subtract 2pi.
2pi f-
then
;
\ Stack on entering: Stack on leaving:
: ellipseStepToPoint ( ... i ) ( ... x y z )
float ellipseangleincr 2@ f* ( ... angle )
ellipseStartAngle 2@ f+
normalizeEllipseAngle
2dup ( ... angle angle )
cos ellipsea 2@ f* ( ... angle x )
2swap ( ... x angle )
sin ellipseb 2@ f* 0.0 ( ... x y 0.0 )
;
\ Stack on entering: Stack on leaving:
: resulttovector ( ... ) ( ... )
0 0 result element 2@
0 0 vector element 2!
0 1 result element 2@
0 1 vector element 2!
0 2 result element 2@
0 2 vector element 2!
;
\ Stack on entering: Stack on leaving:
: ellipseApplyTransform ( ... x y z ) ( ... x y z )
0 2 vector element 2! ( ... x y )
0 1 vector element 2! ( ... x )
0 0 vector element 2! ( ... )
vector rotationMatrix 1x33x3multiply
\ Apply offset
0 0 result element 2@ ( ... x )
0 1 result element 2@ ( ... x y )
0 2 result element 2@ ( ... x y z )
0 0 offset element 2@ ( ... x y z x )
0 1 offset element 2@ ( ... x y z x y )
0 2 offset element 2@ ( ... x y z x y z )
2pointadd ( ... x2 y2 z2 )
;
\ Put a 16-bit short in file.
\ Not to be confused with FPUTS which operates on a string, not a short.
\ Stack on entering: Stack on leaving:
: fputshort ( ... s file ) ( ... stat )
\ First byte
over ( ... s file s )
over ( ... s file s file )
fputc drop ( ... s file )
\ Second byte
swap ( ... file s )
\ Shift right
-8 shift ( ... file s2 )
swap ( ... s2 file )
fputc ( ... stat )
;
\ Put a 32-bit word in file.
\ Stack on entering: Stack on leaving:
: fputw ( ... l file ) ( ... stat )
over ( ... l file l )
over ( ... l file l file )
fputshort drop ( ... l file )
swap ( ... file l )
\ Shift right
-16 shift ( ... file l1 )
swap ( ... l1 file )
fputshort ( ... stat )
;
\ Put a 64-bit double word in file.
\ Stack on entering: Stack on leaving:
: fputd ( ... w2 w1 file ) ( ... stat )
rot ( ... w1 file w2 )
over ( ... w1 file w2 file )
fputw drop ( ... w1 file )
fputw ( ... stat )
;
\ Leave 'nexthandle' with the next valid handle to use.
\ Stack on entering: Stack on leaving:
: addHandle ( ... ) ( ... )
handleson @ if
\ Handles are in hex.
nexthandle @ "%lX" edbuf strform
inbinary @ if
5 ofile fputc drop
edbuf strlen 1+
edbuf ofile fwrite drop
else
" 5" ofile fputs drop
edbuf ofile fputs drop
then
1 nexthandle +!
true needToRewind !
then
;
\ Stack on entering: Stack on leaving:
: saveLayer ( ... ) ( ... )
8 group? if
8 group strlen 31 > if
8 group 0 31 layer substr
else
8 group layer strcpy
then
else
"0" layer strcpy
then
;
\ Stack on entering: Stack on leaving:
: saveColor
62 group? if
62 group
color !
true
else
false
then
62group !
;
\ Stack on entering: Stack on leaving:
: addLayer ( ... ) ( ... )
inbinary @ if
8 ofile fputc drop
layer strlen 1+
layer ofile fwrite drop
else
" 8" ofile fputs drop
layer ofile fputs drop
then
;
\ Stack on entering: Stack on leaving:
: addVertexHeader ( ... ) ( ... )
\ Add a new vertex.
"VERTEX" edbuf strcpy
inbinary @ if
0 ofile fputc drop
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -