30th January 2004 08:53 UTC
raytraced sine-cosine landscape using whittaker/newton-raphson
Dude!
One week ago I was still, enviously, looking at all those real-3d DMs and didn't even know what all those dx, oz and k stuff meant. Today I'm presenting my first 100% self made DM with raytracing.
It might be nothing special to all you elite math-aces out there, but to me it's special because it's the first sine-cosine landscape I've ever seen in a DM, and it's mine(sorry, but I feel so smart)! I've still got some questions about it, but I will start with the code.
I've seen the formula somewhere at school and didn't what it is, so I "took" it home.
Here it is:
z = sin(x)*cos(y)
Quite easy, but I was unable to solve it for "k" and so I tried to aproximate it. With the methods I've seen in this forum (UnConeD your'e so pow(skilled,infinite)) I even managed it.
Here's the DM code (newton-raphson):
All checkboxes set to active.
init:
------
dov=4;
------
frame:
-----------------------------------------------------------------------
t=gettime(0);
ox=sin(t+t); oy=sin(t); oz=sin(t*.5)+5;
rx=ox*.5; ry=oy*.5; rz=oz;
sx=sin(rx); cx=cos(rx); sy=sin(ry); cy=cos(ry); sz=sin(rz); cz=cos(rz);
-----------------------------------------------------------------------
beat:
----------
(is empty)
----------
pixel:
--------------------------------------------------------------------------------------------------
dx=sin(r)*d; dy=-cos(r)*d;
dx1=dx*cz-dy*sz; dy1=dx*sz+dy*cz; dy=dy1*cx-sx; dz1=dy1*sx+cx; dx=dx1*cy-dz1*sy; dz=dx1*sy+dz1*cy;
six=sin(dx+ox); cix=cos(dy+oy);
k=k-(six*cix-dz-oz)/(-dx*cix*dy*six-dz); six=sin(dx*k+ox); cix=cos(dy*k+oy);
k=k-(six*cix-dz*k-oz)/(-dx*cix*dy*six-dz); six=sin(dx*k+ox); cix=cos(dy*k+oy);
k=k-(six*cix-dz*k-oz)/(-dx*cix*dy*six-dz); six=sin(dx*k+ox); cix=cos(dy*k+oy);
k=k-(six*cix-dz*k-oz)/(-dx*cix*dy*six-dz); six=sin(dx*k+ox); cix=cos(dy*k+oy);
k=k-(six*cix-dz*k-oz)/(-dx*cix*dy*six-dz); six=sin(dx*k+ox); cix=cos(dy*k+oy);
ix=dx*k+ox; iy=dy*k+oy; iz=dz*k+oz;
x=ix; y=iy;
alpha=dov*2-sqrt(ix*ix+iy*iy+iz*iz); alpha=if(below(alpha,0),0,if(above(alpha,1),1,alpha));
--------------------------------------------------------------------------------------------------
As you will see, the result is quite ugly and the fogging also gets messed up. Even with twenty steps it didn't look better.
So I tried it with the whittaker method (thx to UnConeD again).
DM code (whittaker):
All checkboxes set to active, again.
init:
------
dov=4;
------
frame:
-----------------------------------------------------------------------
t=gettime(0);
ox=sin(t+t); oy=sin(t); oz=sin(t*.5)+5;
rx=ox*.5; ry=oy*.5; rz=oz;
sx=sin(rx); cx=cos(rx); sy=sin(ry); cy=cos(ry); sz=sin(rz); cz=cos(rz);
-----------------------------------------------------------------------
beat:
----------
(is empty)
----------
pixel:
--------------------------------------------------------------------------------------------------
dx=sin(r)*d; dy=-cos(r)*d;
dx1=dx*cz-dy*sz; dy1=dx*sz+dy*cz; dy=dy1*cx-sx; dz1=dy1*sx+cx; dx=dx1*cy-dz1*sy; dz=dx1*sy+dz1*cy;
k=k+(sin(dx+ox)*cos(dy+oy)-dz-oz);
k=k+(sin(dx*k+ox)*cos(dy*k+oy)-dz*k-oz);
k=k+(sin(dx*k+ox)*cos(dy*k+oy)-dz*k-oz);
k=k+(sin(dx*k+ox)*cos(dy*k+oy)-dz*k-oz);
k=k+(sin(dx*k+ox)*cos(dy*k+oy)-dz*k-oz);
ix=dx*k+ox; iy=dy*k+oy; iz=dz*k+oz;
x=ix; y=iy;
alpha=dov*2-sqrt(ix*ix+iy*iy+iz*iz); alpha=if(below(alpha,0),0,if(above(alpha,1),1,alpha));
--------------------------------------------------------------------------------------------------
Looks way better, hu?
Ok, that was the code. As you might have seen (switch of blending), in the distance everything get's messed up.
So here's my first question:
Is there a way to solve the equation for "k"?
If yes, please tell me how.
I've been thinking about refraction stuff, but I've had nothing to use it on, now I have.
I'm sure I can figure out, with trying around a bit, how to do this (I know the basics). But I really have no idea of how to calculate the normal vectors of a point on that landscape (maybe I have, but I'm not sure about it, plus it's pretty late now so I don't have time to think about it), so can someone tell me how to do this?
Well, that's it. Now it's your turn, tell me how you like the DM, or answer my questions, or do both.
Thank 'n see y'all.