POV-Ray : Newsgroups : povray.binaries.images : Strange results when averaging normals on a spherical mesh2 : Re: Strange results when averaging normals on a spherical mesh2 Server Time
5 Nov 2024 18:23:19 EST (-0500)
  Re: Strange results when averaging normals on a spherical mesh2  
From: Jaap
Date: 15 Jun 2005 17:45:01
Message: <web.42b0a100b5960a30a8399d8d0@news.povray.org>
i took teh liberty to change your code a bit:

#declare a=0;
#while (a<zdem)
  #declare b=0;
  #while (b<xdem)
    #declare ep=vertices[a][b];
    #declare av=<0,0,0>;
    #declare c=0;
    #while (c<8)
      #declare svp=ep+(sp/2)*<int(sin(c*45)*(pi/180)), 10,
int(cos(c*45)*(pi/180))>;
      #declare svt=trace(relief, svp, -y, norm);
      #if (norm.x!=0 | norm.y!=0 | norm.z!=0)
        #warning "OK!"
        #declare av=av+norm;
      #end
      #declare c=c+1;
    #end
    #if (vlength(av)!=0)
      #declare normals[a][b]=vnormalize(av);
    #else
      #declare normals[a][b]=<0,0,0>;
    #end
    #declare b=b+1;
  #end
  #declare a=a+1;
#end

- you don't need seperate x,y and zet av, (just use av.x when needed)
- the divide by number of normals is replaced by vnormalize()
- added check for <0,0,0> sum of normals.
- you seem to check wether the trace() function missed the object,
but normals like <0,0,1> and <0,1,0> are valid, so use something like:
      #if (norm.x!=0 | norm.y!=0 | norm.z!=0)
or:
      #if (vlength(norm)!=0)
or:
      #if ((abs(norm.x)+abs(norm.y)+abs(norm.z))!=0)

jaap.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.