Browse Source

Restored trace dir calculation to original, flipped left-vector instead

I completely overlooked the fact that I treated x/y coordinates as having
top-left be 0,0 when in the original values are written out starting in
the bottom right, to a format (netpbm / *.ppm) that also takes values as
starting in the top-left. So in order to be able to write "backwards"
(probably to save 3 characters in the two for-loops) aek intentionally
calculated his "left" vector backwards, i.e. rotated by 90 degrees to the
right. And via the cross-product that means up will be down.

But now left shall be left, and up shall be up, always.

(Oh and also I reverted modifications to the original source in min.c
and moved it to min.cpp so that gcc hopefully won't complain anymore)
master
rf 1 year ago
parent
commit
ae393756b5
2 changed files with 9 additions and 4 deletions
  1. +8
    -3
      main.cpp
  2. +1
    -1
      min.cpp

+ 8
- 3
main.cpp View File

@@ -399,7 +399,12 @@ public:
Vector3 position(-22, 5, 25);
Vector3 goal = Vector3(-3, 4, 0) - position;
goal.Normalize();
Vector3 left = Vector3(goal.z_, 0, -goal.x_).Normalized() / w_;

// this vector is actually to the right of goal... flipped signs of x and z for left.
// Up is down. Hence the subtractions instead of additions for trace directions
// Note to self: Yes, it was rendering upside-down, but only because originally it
// wrote values for y = h .. 0 and x = w .. 0, so from bottom right to top left, sequentially
Vector3 left = Vector3(-goal.z_, 0, goal.x_).Normalized() / w_;

// Cross-product to get the up vector
Vector3 up = goal.CrossProduct(left);
@@ -411,8 +416,8 @@ public:
Vector3 color;
for (int p = samplesCount_; p--;) {
// this was the second Trace argument as both lines in one:
// !(goal - left * (x - w_ / 2 + randomVal()) - up * (y_ - h_ / 2 + randomVal()))
trace_dir = goal - left * (x - w_ / 2 + randomVal()) - up * (y_ - h_ / 2 + randomVal());
// !(goal + left * (x - w_ / 2 + randomVal()) + up * (y_ - h_ / 2 + randomVal()))
trace_dir = goal + left * (x - w_ / 2 + randomVal()) + up * (y_ - h_ / 2 + randomVal());
trace_dir.Normalize();

color = color + Trace(position, trace_dir);


min.c → min.cpp View File

@@ -23,7 +23,7 @@ n%d*-2);o=h+d*.1;t=t*.2;}if(m==2){F i=n%l,p=6.283185*U(),c=U(),s=sqrtf(1-c),
g=n.z<0?-1:1,u=-1/(g+n.z),v=n.x*n.y*u;d=V(v,g+n.y*n.y*u,-n.y)*(cosf(p)*s)+V(
1+g*n.x*n.x*u,g*v,-g*n.x)*(sinf(p)*s)+n*sqrtf(c);o=h+d*.1;t=t*.2;if(i>0&&M(h
+n*.1,l,h,n)==3)r=r+t*V(500,400,100)*i;}if(m==3){r=r+t*V(50,80,100);break;}}
R r;}I main(){I w=960/3,h=540/3,s=8;V e(-22,5,25),g=!(V(-3,4,0)+e*-1),l=!V(g.z,
R r;}I main(){I w=960,h=540,s=16;V e(-22,5,25),g=!(V(-3,4,0)+e*-1),l=!V(g.z,
0,-g.x)*(1./w),u(g.y*l.z-g.z*l.y,g.z*l.x-g.x*l.z,g.x*l.y-g.y*l.x);printf("P\
6 %d %d 255 ",w,h);for(I y=h;y--;)for(I x=w;x--;){V c;for(I p=s;p--;)c=c+T(e
,!(g+l*(x-w/2+U())+u*(y-h/2+U())));c=c*(1./s)+14./241;V o=c+1;c=V(c.x/o.x,c.

Loading…
Cancel
Save