2 |
|
{ |
3 |
|
Compute patterns for ambient position markers |
4 |
|
} |
5 |
+ |
odd(n) : .5*n - floor(.5*n) - .25; |
6 |
+ |
posangle(a) : if(-a, a + 2*PI, a) / DEGREE; |
7 |
|
{ Relative hit point } |
8 |
|
rpx = Px - arg(1); |
9 |
|
rpy = Py - arg(2); |
12 |
|
{ Calculation of directional gradient pattern } |
13 |
|
ndx = arg(4); ndy = arg(5); ndz = arg(6); |
14 |
|
dgx = arg(7); dgy = arg(8); dgz = arg(9); |
15 |
< |
dg = sqrt(dgx*dgx + dgy*dgy + dgz*dgz); |
16 |
< |
dux = (ndy*dgz - ndz*dgy)/dg; |
17 |
< |
duy = (ndz*dgx - ndx*dgz)/dg; |
18 |
< |
duz = (ndx*dgy - ndy*dgx)/dg; |
19 |
< |
dsine = (dux*rpx + duy*rpy + duz*rpz)/sqrt(rpx*rpx + rpy*rpy + rpz*rpz); |
18 |
< |
dirfunc = bound(0, 1 + dg*dsine, 2); |
15 |
> |
rdx = ndy*rpz - ndz*rpy; |
16 |
> |
rdy = ndz*rpx - ndx*rpz; |
17 |
> |
rdz = ndx*rpy - ndy*rpx; |
18 |
> |
dgrad = (rdx*dgx + rdy*dgy + rdz*dgz)/sqrt(rpx*rpx + rpy*rpy + rpz*rpz); |
19 |
> |
dirfunc = bound(0, 1 + dgrad, 2); |
20 |
|
|
21 |
|
{ Calculation of positional gradient pattern } |
22 |
|
pgx = arg(4); pgy = arg(5); pgz = arg(6); |
23 |
|
posfunc = bound(0, 1 + (pgx*rpx + pgy*rpy + pgz*rpz), 2); |
24 |
+ |
{ corral flags and associated pattern } |
25 |
+ |
ux = arg(4); uy = arg(5); uz = arg(6); |
26 |
+ |
cflags = arg(7); |
27 |
+ |
vx = Ny*uz - Nz*uy; |
28 |
+ |
vy = Nz*ux - Nx*uz; |
29 |
+ |
vz = Nx*uy - Ny*ux; |
30 |
+ |
cflg(i) = if(odd(floor( cflags / 2^i )), 1, -1); |
31 |
+ |
corralled = cflg(floor(32/360*posangle( |
32 |
+ |
atan2(rpx*vx+rpy*vy+rpz*vz, rpx*ux+rpy*uy+rpz*uz) ))); |
33 |
|
|
34 |
|
{ Calculation of ellipse stencil for base } |
35 |
|
usx = arg(4); usy = arg(5); usz = arg(6); |