Please show me or explain the code of box-like(room) dynamic movement. I cant understand such a code 😢
Example Presets:
Tuggummi - Let me out!
UnConeD - Cubic Flower
How to create cubic room DM
4 posts
Example Code (UnConeD - Watercolorcube):
This is a box-like(or Cube Surface) code
Init:
t=rand(100);rx=1.57;ry=1.57;rx=0;ry=0;pt=0;bt=0
Frame:
sd=sd*.9+getspec(0,.1,0)*.1;
sd2=sd2*.9+getspec(0,.05,0)*.1;
t=t+0.19+sd*.75;pt=pt+.25+sd2*.5;
ox=sin(pt*.1231);oy=sin(pt*.1);oz=cos(pt*.0913);
ol=-bt*.5+3/sqrt(sqr(ox)+sqr(oy)+sqr(oz));
ox=ox*ol;oy=oy*ol;oz=oz*ol;
rxo=sin(t*.0373)*cos(t*0.0563)*sin(cos(t*.0631))*.5;
ryo=sin(t*.0511)*cos(t*0.071)*sin(cos(t*.0415))*.5;
ry=-atan2(ox,oz)+ryo;
rx=-atan2(oy,sqrt(sqr(ox)+sqr(oz)))+rxo;
rz=sin(t*.053)*cos(t*.117)*sin(cos(t*.0651));
cx=cos(rx);sx=sin(rx);cy=cos(ry);sy=sin(ry);cz=cos(rz);sz=sin(rz);
bt=bt*.9;af=h/w
Beat:
pt=pt+55*max(0,getspec(0,.1,0)*3-1.5);
bt=1
Pixel:
y=y*af;
dx1=x*cz-y*sz;
dy1=x*sz+y*cz;
dy2=dy1*cx-1.2*sx;
dz2=dy1*sx+1.2*cx;
dx3=dx1*cy-dz2*sy;
dz3=dx1*sy+dz2*cy;
k1=((oz-sign(dz3))/dz3);
k1=if(below(k1,0),-1000,k1);
k2=((oy-sign(dy2))/dy2);
k2=if(below(k2,0),-1000,k2);
k3=((ox-sign(dx3))/dx3);
k3=if(below(k3,0),-1000,k3);
k=max(max(k1,k2),k3);
ix=-ox+dx3*k;iy=-oy+dy2*k;iz=-oz+dz3*k;
alpha=bnot(equal(k,-100));
x=if(equal(k,k3),iy,ix)*.9;
y=if(equal(k,k1),iy,iz)*.9;
d=max(abs(x),abs(y));
alpha=if(bor(above(k,10),below(k,0)),0,1.8-sqr(d+.5)+.2);
this code performs a raytrace - with some hacks - to achieve its effect. the idea is to get the equation of a line, from a direction and start position, and intersect it with the equations of planes describing the cube to find the texture coordinates we want on the cube's surface.
ox,oy,oz are a camera position
y=y*af is aspect ratio correction
the big block of code involving sx, cx, sy... are rotations
the k = lines are solving the raytrace and picking the correct solution
x and y are then set based on the results. these are texture coordinates. alpha provides the fading to hide ugly edges.
if you try and recreate this approach from scratch without copying code you should get a good understanding of the technique and be able to apply it to arbitrary situations...
AVS code like this is not easy to pick apart or follow, the coding style we all used to use, the lack of comments and the obscurity of the problems all pile up to make it very difficult.
ox,oy,oz are a camera position
y=y*af is aspect ratio correction
the big block of code involving sx, cx, sy... are rotations
the k = lines are solving the raytrace and picking the correct solution
x and y are then set based on the results. these are texture coordinates. alpha provides the fading to hide ugly edges.
if you try and recreate this approach from scratch without copying code you should get a good understanding of the technique and be able to apply it to arbitrary situations...
AVS code like this is not easy to pick apart or follow, the coding style we all used to use, the lack of comments and the obscurity of the problems all pile up to make it very difficult.
Could you show me a general equation of k?
Does it (ray tracing) involving with calculus? (Partial Derivative, Integral, Tangent plane, etc)
Does it (ray tracing) involving with calculus? (Partial Derivative, Integral, Tangent plane, etc)