POV-Ray : Newsgroups : povray.text.scene-files : hf_normal_at macro : hf_normal_at macro Server Time
28 Jul 2024 12:26:27 EDT (-0400)
  hf_normal_at macro  
From: Christoph Hormann
Date: 13 Jun 2000 11:18:04
Message: <394650AD.B02457B1@gmx.de>
This is the code for the hf_normal_at (refer to thread in p.b.i)

It is called like the hf_height_at function, the additional c-parameter
specifies the scale, at which the normal is calculated.  You should keep
it above the HF's resolution and can increase it to have a smoothing
effect.  

As Bob Hughes wrote in p.b.i. the trace function already does this job
and is probably faster and more flexible.  ntl, I decided to post this
for studying purposes.  

// ---------- begin pov-code -----------

#macro hf_normal_at(X, Y, HF, c)

  #local swap=false;

  #local hx = hf_height_at(X, Y, HF);
  #if ((X+c)<1)
    #local h1 = hf_height_at(X+c, Y, HF);
    #local v1 = < c, h1-hx, 0>;
  #else
    #local h1 = hf_height_at(X-c, Y, HF);
    #local v1 = <-c, h1-hx, 0>;
    #if (swap=true)
       #declare swap=false;
    #else
       #declare swap=true;
    #end
  #end
  #if ((Y+c)<1)
    #local h2 = hf_height_at(X, Y+c, HF);
    #local v2 = <0, h2-hx,  c>;
  #else
    #local h2 = hf_height_at(X, Y-c, HF);
    #local v2 = <0, h2-hx, -c>;
    #if (swap=true)
       #declare swap=false;
    #else
       #declare swap=true;
    #end
  #end


  #if (swap=true)
    (vnormalize(vcross(v1, v2)))
  #else
    (vnormalize(vcross(v2, v1)))
  #end

#end

// ---------- end pov-code -----------

--
Christoph Hormann <chr### [at] gmxde>
Homepage: http://www.schunter.etc.tu-bs.de/~chris/


Post a reply to this message

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