POV-Ray : Newsgroups : povray.binaries.images : Yet more boulders : Re: Yet more boulders Server Time
2 Aug 2024 02:24:14 EDT (-0400)
  Re: Yet more boulders  
From: Bill Pragnell
Date: 29 Feb 2008 06:45:01
Message: <web.47c7eeeee40b9a04731f01d10@news.povray.org>
"Thomas de Groot" <t.d### [at] internlDOTnet> wrote:
> Seems an interesting method. If you have time to port
> that out to the community, I (at least) would be very grateful. I can
> imagine a lot of applications.

Here you go. It should be quite self-explanatory. If you don't want a smooth
finish then use triangle instead of smooth_triangle.

// begin code

#macro ballpoint(vangle, rangle, rad)
  #local yp = rad*cos(vangle);
  #local locrad = rad*sin(vangle);
  #local xp = locrad*sin(rangle);
  #local zp = locrad*cos(rangle);
  (<xp, yp, zp>)
#end

#macro meshball(obj, res)
  mesh {
  #local vang = 0;
  #local ang  = 0;
  #local dvang = pi/res;
  #local dang = 2*pi/res;
  #local n1 = <0,0,0>;
  #local n2 = <0,0,0>;
  #local n3 = <0,0,0>;
  #local n4 = <0,0,0>;
  #while (vang < pi)
    #while (ang < 2*pi)
      #local v1 = trace(obj, <0,0,0>, ballpoint(vang, ang, 1), n1);
      #local v2 = trace(obj, <0,0,0>, ballpoint(vang+dvang, ang, 1), n2);
      #local v3 = trace(obj, <0,0,0>, ballpoint(vang, ang+dang, 1), n3);
      #local v4 = trace(obj, <0,0,0>, ballpoint(vang+dvang, ang+dang, 1), n4);
      smooth_triangle { v1, n1, v2, n2, v3, n3 }
      smooth_triangle { v2, n2, v3, n3, v4, n4 }
      #local ang = ang + dang;
    #end
    #local ang = 0;
    #local vang = vang + dvang;
  #end }
#end

// end code


Just call meshball(obj, res) where obj is your pre-declared object (centred on
the origin) and res is the triangle resolution (it's pretty fast with 100-200
and looks ok).

Bill


Post a reply to this message

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