home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 15 / CDACTUAL15.iso / cdactual / w95 / povray / CBRAID.ZIP / cbraid.inc next >
Encoding:
Text File  |  1996-12-15  |  5.3 KB  |  165 lines

  1. //
  2. // cbraid.inc 0.50
  3. // Generate a circular braid.
  4. //
  5. // NOTE: The calling format has changed from previous versions.  See
  6. //       example below.
  7. // 
  8. // Donated to the public domain
  9. //
  10. // Written by Michael D Johnson
  11. //         mdjohnson@voyager.net or redbeard@quark.vpplus.com
  12. //         http://quark.vpplus.com/~redbeard
  13. // 
  14. // Most recent version is available at
  15. //     http://quark.vpplus.com/~redbeard/raytrace/POVRay-Util.html
  16. //
  17. // The braid is generated as an object named Braid.
  18. // The braids generated by this program are angular.  That is, the 'cords'
  19. // used are not smooth, but are instead formed of cylindrical sections.
  20. // 
  21. // Please send me any comments or suggestions.  And let me know how you
  22. // like this file.  If you make any changes, let me know, I will try to
  23. // incorporate them in the official version.
  24. //
  25. // This file was originally created for my entry into the May/June
  26. // Internet Raytracing Competition, which never made it.
  27. // 
  28. // Usage:
  29. // Declare the following variables before including this file, and an
  30. // object will be created, centered at the origin, parallel to the
  31. // x-y plane.
  32. // 
  33. // Example (using all defaults):
  34. // #declare MyBraid = object { #include "cbraid.inc" }
  35. // 
  36. // Variables:
  37. // The defaults for all of these are given in []
  38. //   NumSteps    [48]    The number of segments to the braid.  It must be even.
  39. //   Rad1    [6]    The radius of the outer strand
  40. //   Rad2    [7]    The radius of the inner strand
  41. //   Thick    [0.3]    Thickness of the strands.  This is a DIAMETER.
  42. //   Camber    [0.2]    Total amount tilt in the z axis, measured in units.
  43. //            This is the distance from the nearest side to the
  44. //            farthest side along the z axis.  In otherwords, making
  45. //            this 0 will make the braid flat.
  46. //   Mode    [1]    Type of object. 0 = blob, 1 = union, 2 = merge
  47. //   UseTexture    [0]    Individually texture each strand if true, using
  48. //             Texture1, Texture2, and Texture3
  49. //   Texture?    none    Texture to use for each strand.
  50. //   Threshold    [0.75]    If Mode = 0 (blob) then this is the threshold value of
  51. //             the blob.
  52. //   ThreshLevel [1.0]    If Mode = 0 (blob) then this is the strength of each
  53. //             individual component
  54. // 
  55. // All other variables used have the prefix _Braid_.  Consider these variables
  56. // to have an unknown value upon return.
  57. //
  58. // To Do:
  59. //   Add smooth cords
  60. //   Add straight braids
  61. //   Allow user defined shapes to be used instead of primitives.
  62. // 
  63. // --------------------------------------------------------------------------
  64. // Revisions
  65. // ---------
  66. // 05/23/96        First official release.
  67. // 12/10/96        Changed addresses, reorganized some of the comments,
  68. //             added blob/union/merge, removed the dedicated object
  69. //             name, added individual strand texturing, added code
  70. //             to force NumSteps to be even.
  71. // 
  72.  
  73.  
  74. #ifndef (NumSteps) #declare NumSteps = 48 #end
  75. // NumSteps Must be even
  76. #if (NumSteps != (int(NumSteps/2)*2)) #declare NumSteps = NumSteps + 1 #end
  77.  
  78. #ifndef (Mode) #declare Mode = 1 #end
  79. #ifndef (Rad1) #declare Rad1 = 6 #end
  80. #ifndef (Rad2) #declare Rad2 = 5 #end
  81. #ifndef (Thick) #declare Thick = 0.3 #end
  82. #ifndef (Camber) #declare Camber = 0.2 #end
  83. #ifndef (Threshold) #declare Threshold = 0.75 #end
  84. #ifndef (ThreshLevel) #declare ThreshLevel = 1.0 #end
  85. #ifndef (UseTexture) #declare UseTexture = 0
  86. #else
  87.   #if (UseTexture)
  88.     #declare _Braid_Err = 0
  89.     #ifndef (Texture1) #declare _Braid_Err = 1 #end
  90.     #ifndef (Texture2) #declare _Braid_Err = 1 #end
  91.     #ifndef (Texture3) #declare _Braid_Err = 1 #end
  92.     #if (_Braid_Err) #error "Must define all three Texture? values"
  93.     #end
  94.   #end
  95. #end
  96.  
  97. #declare _Braid_Step = 360 / NumSteps
  98.  
  99. #switch (Mode)
  100.   #case (2) merge #break
  101.   #case (1) union #break
  102.   #case (0) blob #break
  103. #else
  104.   #error "Invalid Mode value"
  105. #end
  106. {
  107.     #if (Mode = 0) threshold Threshold #end
  108.     #declare _Braid_I = 0
  109.     #while (_Braid_I < NumSteps)
  110.       #declare _Braid_Prev = _Braid_I - 3
  111.       #declare _Braid_Y  = (mod(_Braid_I, 2) ? Rad1 : Rad2)
  112.       #declare _Braid_Y2 = (mod(_Braid_I, 2) ? Rad2 : Rad1)
  113.  
  114.       #declare _Braid_Wid = 2 * _Braid_Y * sin(radians(_Braid_Step) / 2)
  115.       #declare _Braid_Wid2 = 2 * _Braid_Y2 * sin(radians(_Braid_Step) / 2)
  116.       
  117.       #declare _Braid_Pt1 = vrotate(<-_Braid_Wid  / 2, _Braid_Y , Camber / 2>,
  118.                     z * _Braid_I * _Braid_Step)
  119.       #declare _Braid_Pt2 = vrotate(< _Braid_Wid  / 2, _Braid_Y ,-Camber / 2>,
  120.                     z * _Braid_I * _Braid_Step)
  121.       #declare _Braid_Pt3 = vrotate(<-_Braid_Wid2 / 2, _Braid_Y2, Camber / 2>,
  122.                     z * _Braid_Prev * _Braid_Step)
  123.       
  124.       #declare _Braid_T =
  125.       texture
  126.       {
  127.       #switch (mod(_Braid_I, 3))
  128.         #case (0) Texture1 #break
  129.         #case (1) Texture2 #break
  130.         #case (2) Texture3 #break
  131.       #end
  132.       }
  133.       
  134.       cylinder
  135.       {
  136.       _Braid_Pt1, _Braid_Pt2, Thick / 2 #if (Mode = 0), ThreshLevel #end
  137.       #if (UseTexture)
  138.         texture { _Braid_T }
  139.       #end
  140.       }
  141.       cylinder
  142.       {
  143.       _Braid_Pt3, _Braid_Pt2, Thick / 2 #if (Mode = 0), ThreshLevel #end 
  144.       #if (UseTexture)
  145.         texture { _Braid_T }
  146.       #end
  147.       }
  148.       #if (Mode != 0)
  149.     sphere
  150.     {
  151.         _Braid_Pt1, Thick / 2
  152.         #if (UseTexture) texture { _Braid_T } #end
  153.     }
  154.     sphere
  155.     {
  156.         _Braid_Pt2, Thick / 2 
  157.         #if (UseTexture) texture { _Braid_T } #end
  158.     }
  159.       #end
  160.       
  161.       #declare _Braid_I = _Braid_I + 1
  162.     #end
  163. }
  164.  
  165.