Archive: confused by tunnel code of UnConeD and el-vis


19th June 2003 20:32 UTC

confused by tunnel code of UnConeD and el-vis
when I attempt to create my own simple* tunnel code I get (for movement):

x=constant1*r;
y=constant2/d;

but looking at the simple tunnel code in el-vis's "last exit" preset (he says in the comment that it's UnConeD's code with some changes) which achieves basically the same effect there's:

dr=sqrt(x*x+y*y);
dx=(x)/dr;dy=(y)/dr;dz=1/dr-6;
e=dx*dx+dy*dy;
k=-0.2*sqrt(8*e)/e;
ix=dx*k;iy=dy*k;iz=oz+dz*k;
x=iz/4;y=atan2(ix,-iy)/3.14;

this was what i was looking at to help me figure out how people make tunnels until i decided it was too confusing and came up with the uppermost code. This code still confuses me and since UnConeD and el-vis made it I figgure that it can't be that complex for no reason. First of all, isn't dr the same as d? why isn't d used? And since dr is d, dx must be cos(theta) and dy must be sin(theta) correct? and that means that for all points, e=1. this means that k is always apprx. -0.5656. Also, what is the purpose of dz, iz, and oz? does this code have a different effect than mine that I am not noticing? thank you for any help.

* when i say simple i mean that the viewpoint doesn't rotate around inside the tunnel on the x or y axis and travels straight through the center of it.


19th June 2003 23:09 UTC

this is done with raytracing. i do not understand it, but it has been addressed before. search the forums.

because x, y, d, and r are the only "set" variables used in DM, ox, oy, dx, dy...have no direct effect...that is, you cannot make a DM by just typing ox=x*2;oy=y*2;.

For his code, UnConeD posted an explanation of variables he commonly uses

cx,sx,cy,sy,sz,sz: cosine/sine of rx,ry,rz (rotation angles)
cr,cg,cb: red,green,blue color used as the basis for the scope
ip: alternating 1,0 or 1,-1 variable
ox,oy,oz: camera position in a world-fixed 3D SSC or a 3D DM.
ot: usually used to normalize/equalize ox,oy,oz
k, dx, dy, dz (and k2, dx3, ...): used for raytracing a DM
ix,iy,iz: raytracing DM, coordinates of intersection of ray with object
af: aspect-ratio correction multiply factor
sd1, sd2, sd3: random generator registers
t, ti: time and timeshift (onbeat)

In complicated scopes I sometimes reuse a variable as a temporary variable (not enough variables in AVS) so you'll have to watch out for that. Red,green,blue are often used as temporary vars if they appear near the top of a scope's per-point.

tpi: 2*pi
u is often a scaled value of i, used for evaluating paths (e.g. rollercoaster, da-traced logo, ...)
th,ph: often used as "theta, phi" for 3D polar coordinates
ph: sometimes used as phase for controlling the camera in a 3D dm. for example in Wolf3D, the camera can be in one of several 'modes' depending on where it is and what it has to do (face corridor, move ahead, stop and rotate, ...). Ph will have the values 1,2,3,4, for each possible phase a value.
bc: sometimes a beatcounter, when it will appear as bc=(bc+1)%8 (or different constant) in onbeat

20th June 2003 02:00 UTC

wow, ray tracing is neat, although it may have been a tad overkill for last exit... there really should be a link to ray tracing in the FAQ or something, it helps a lot with DMs. Thank you for the help.


20th June 2003 03:24 UTC

13373571: elvis made a static version of one of my tunnel movements... because mine are coded for any viewpoint and any direction, the static version is indeed quite bloated and can be optimized a lot.


20th June 2003 08:19 UTC

If you want an explanation on raytracing, UnConeD did a massive explanation here. I haven't waded through it yet, but I mean to at some point.


12th July 2003 16:44 UTC

Dont jump straight into understaing raytracing,its damn hard.Try making a tunnel with your code,experiments some more then take a look at UnConeD`s explanation( it also has drawings :) )


12th July 2003 17:31 UTC

For me, its quite easy now, the formula for a tunel is:

x^2+y^2=r^2
therefore,
(k*dx+ox)^2+(k*dy+oy)^2=r^2
k^2(dx^2+dy^2)+2k(dx*ox+dy*oy)+(ox^2+oy^2-r^2)=0
as this one is a quadratic equation,
a=dx^2+dy^2;b=2*(dx*ox+dy*oy);c=(ox^2+oy^2-r^2)

k=(-b+(or-)sqrt(b^2+4*a*c))/(2*a)
simple.


13th July 2003 03:26 UTC

Phaze: Don't revive threads.

Raytracing is simple enough to understand, I just wasn't aware that it existed back then because I was a complete newb.


13th July 2003 03:42 UTC

HAHAHA

Sorry, I couldn't resist. The DR is NOT D. D is an actual pixel distance, DR is just relative to (x,y) [-1..1]. The purpose of most of the formula is to perform aspect ratio correction (incorrection?).


13th July 2003 04:30 UTC

umm, what?

all your saying is that dr doesn't have correct aspect ratio while d does?

why is this funny?


24th July 2003 10:57 UTC

its funny because zevensoft is the local fonze..
anything he says should be laffed at purely because he is the fonze.

"hey fonze"
fonze: "eeeeeeeeeyy!"

24th July 2003 23:43 UTC

:D