home *** CD-ROM | disk | FTP | other *** search
- //
- // cbraid.inc 0.50
- // Generate a circular braid.
- //
- // NOTE: The calling format has changed from previous versions. See
- // example below.
- //
- // Donated to the public domain
- //
- // Written by Michael D Johnson
- // mdjohnson@voyager.net or redbeard@quark.vpplus.com
- // http://quark.vpplus.com/~redbeard
- //
- // Most recent version is available at
- // http://quark.vpplus.com/~redbeard/raytrace/POVRay-Util.html
- //
- // The braid is generated as an object named Braid.
- // The braids generated by this program are angular. That is, the 'cords'
- // used are not smooth, but are instead formed of cylindrical sections.
- //
- // Please send me any comments or suggestions. And let me know how you
- // like this file. If you make any changes, let me know, I will try to
- // incorporate them in the official version.
- //
- // This file was originally created for my entry into the May/June
- // Internet Raytracing Competition, which never made it.
- //
- // Usage:
- // Declare the following variables before including this file, and an
- // object will be created, centered at the origin, parallel to the
- // x-y plane.
- //
- // Example (using all defaults):
- // #declare MyBraid = object { #include "cbraid.inc" }
- //
- // Variables:
- // The defaults for all of these are given in []
- // NumSteps [48] The number of segments to the braid. It must be even.
- // Rad1 [6] The radius of the outer strand
- // Rad2 [7] The radius of the inner strand
- // Thick [0.3] Thickness of the strands. This is a DIAMETER.
- // Camber [0.2] Total amount tilt in the z axis, measured in units.
- // This is the distance from the nearest side to the
- // farthest side along the z axis. In otherwords, making
- // this 0 will make the braid flat.
- // Mode [1] Type of object. 0 = blob, 1 = union, 2 = merge
- // UseTexture [0] Individually texture each strand if true, using
- // Texture1, Texture2, and Texture3
- // Texture? none Texture to use for each strand.
- // Threshold [0.75] If Mode = 0 (blob) then this is the threshold value of
- // the blob.
- // ThreshLevel [1.0] If Mode = 0 (blob) then this is the strength of each
- // individual component
- //
- // All other variables used have the prefix _Braid_. Consider these variables
- // to have an unknown value upon return.
- //
- // To Do:
- // Add smooth cords
- // Add straight braids
- // Allow user defined shapes to be used instead of primitives.
- //
- // --------------------------------------------------------------------------
- // Revisions
- // ---------
- // 05/23/96 First official release.
- // 12/10/96 Changed addresses, reorganized some of the comments,
- // added blob/union/merge, removed the dedicated object
- // name, added individual strand texturing, added code
- // to force NumSteps to be even.
- //
-
-
- #ifndef (NumSteps) #declare NumSteps = 48 #end
- // NumSteps Must be even
- #if (NumSteps != (int(NumSteps/2)*2)) #declare NumSteps = NumSteps + 1 #end
-
- #ifndef (Mode) #declare Mode = 1 #end
- #ifndef (Rad1) #declare Rad1 = 6 #end
- #ifndef (Rad2) #declare Rad2 = 5 #end
- #ifndef (Thick) #declare Thick = 0.3 #end
- #ifndef (Camber) #declare Camber = 0.2 #end
- #ifndef (Threshold) #declare Threshold = 0.75 #end
- #ifndef (ThreshLevel) #declare ThreshLevel = 1.0 #end
- #ifndef (UseTexture) #declare UseTexture = 0
- #else
- #if (UseTexture)
- #declare _Braid_Err = 0
- #ifndef (Texture1) #declare _Braid_Err = 1 #end
- #ifndef (Texture2) #declare _Braid_Err = 1 #end
- #ifndef (Texture3) #declare _Braid_Err = 1 #end
- #if (_Braid_Err) #error "Must define all three Texture? values"
- #end
- #end
- #end
-
- #declare _Braid_Step = 360 / NumSteps
-
- #switch (Mode)
- #case (2) merge #break
- #case (1) union #break
- #case (0) blob #break
- #else
- #error "Invalid Mode value"
- #end
- {
- #if (Mode = 0) threshold Threshold #end
- #declare _Braid_I = 0
- #while (_Braid_I < NumSteps)
- #declare _Braid_Prev = _Braid_I - 3
- #declare _Braid_Y = (mod(_Braid_I, 2) ? Rad1 : Rad2)
- #declare _Braid_Y2 = (mod(_Braid_I, 2) ? Rad2 : Rad1)
-
- #declare _Braid_Wid = 2 * _Braid_Y * sin(radians(_Braid_Step) / 2)
- #declare _Braid_Wid2 = 2 * _Braid_Y2 * sin(radians(_Braid_Step) / 2)
-
- #declare _Braid_Pt1 = vrotate(<-_Braid_Wid / 2, _Braid_Y , Camber / 2>,
- z * _Braid_I * _Braid_Step)
- #declare _Braid_Pt2 = vrotate(< _Braid_Wid / 2, _Braid_Y ,-Camber / 2>,
- z * _Braid_I * _Braid_Step)
- #declare _Braid_Pt3 = vrotate(<-_Braid_Wid2 / 2, _Braid_Y2, Camber / 2>,
- z * _Braid_Prev * _Braid_Step)
-
- #declare _Braid_T =
- texture
- {
- #switch (mod(_Braid_I, 3))
- #case (0) Texture1 #break
- #case (1) Texture2 #break
- #case (2) Texture3 #break
- #end
- }
-
- cylinder
- {
- _Braid_Pt1, _Braid_Pt2, Thick / 2 #if (Mode = 0), ThreshLevel #end
- #if (UseTexture)
- texture { _Braid_T }
- #end
- }
- cylinder
- {
- _Braid_Pt3, _Braid_Pt2, Thick / 2 #if (Mode = 0), ThreshLevel #end
- #if (UseTexture)
- texture { _Braid_T }
- #end
- }
- #if (Mode != 0)
- sphere
- {
- _Braid_Pt1, Thick / 2
- #if (UseTexture) texture { _Braid_T } #end
- }
- sphere
- {
- _Braid_Pt2, Thick / 2
- #if (UseTexture) texture { _Braid_T } #end
- }
- #end
-
- #declare _Braid_I = _Braid_I + 1
- #end
- }
-
-