// Persistence of Vision Ray Tracer 3.5(beta) Include File // File: rope.inc // Ver.: 0.5 // Desc: Macros for ropes and twisted wires // Date: 01/21/2002 // Auth: Ryoichi Suzuki // #version 3.5; #include "functions.inc" // ROPE MACROS // Rope_Spline(Spline, N_Sample, N, Pr, R, R_s, R_c, ops) // Spline: spline identifier // N_Sample: integer : Number of sampling points // N: integer : Number of threads // Pr: float : Period (in POV unit) // R: float : Radius of rope // R_s: float : Radius of threads // R_c: float : Maximum arc radius // ops: option macros // // Rope_Fixed_Rc(Ar1, NMax, N, Pr, R, R_s, R_c, ops) // Ar1: array identifier // N_Sample: integer : Number of sampling points // N: integer : Number of threads // Pr: float : Period (in POV unit) // R: float : Radius of rope // R_s: float : Radius of threads // R_c: float : Arc radius // ops: option macros // // Rope_Auto_Rc(Ar, NMax, N, Pr, R, R_s, R_c, ops) // Ar1: array identifier // N_Sample: integer : Number of sampling points // N: integer : Number of threads // Pr: float : Period (in POV unit) // R: float : Radius of rope // R_s: float : Radius of threads // R_c: float : Maximum arc radius // ops: option macros // OPTION MACROS p:float, n:integer, vec:vector, // Rope_Period(p) // Rope_N_String(n) // Rope_R_Rope(p) // Rope_N_Color(n) // Rope_R_String(p) // Rope_R_Corner(p) // Rope_Texture_No(n) // Rope_Texture(texture) // Rope_Rot(vec) // Rope_Trans(vec) // Rope_Obj(n) // OTHER MACROS // Rope_Init(i) // Rope_Calc_Init() // Rope_Set_Option(o) // Rope_CONNECT1(vec,vec,vec) // //------------------------------------------- #macro Rope_Init(n) #declare _Rope_ISO_intersect=off; #declare _Rope_MaxG=1.5; #declare _Rope_C1_Flag=false; #declare _Rope_Flg_Shadow=true; #declare _Rope_Freq=4; #declare _Rope_FreqST=6; #declare _Rope_RST=0.04; #declare _Rope_R=0.15; #declare _Rope_RC=0.5; #declare _Rope_NVec2=0; #declare _Rope_L2=0; #declare _Rope_ofs=0; #declare _Rope_N_Col=3; #declare _Rope_Scl=1; #declare _Rope_Col_W=0.2; #declare _Rope_Texture_No=0; #declare _Rope_Rot=<0,0,0>; #declare _Rope_Trans=<0,0,0>; #declare _Rope_Obj=false; #end //------------------------------------------- #macro Rope_Calc_Init() #declare _Rope_C1_Flag=false; #declare _Rope_NVec2=0; #declare _Rope_L2=0; #declare _Rope_ofs=0; #end //------------------------------------------- #macro Rope_Set_Option(n) Rope_Calc_Init() #end //------------------------------------------- #declare Rope_Default= 1 ; #declare Rope_Previous= 0 ; #macro Rope_Period(p) #declare _Rope_Freq=2*pi/p; 0 #end #macro Rope_N_String(n) #declare _Rope_FreqST=n; 0 #end #macro Rope_R_Rope(p) #declare _Rope_R=p; 0 #end #macro Rope_N_Color(n) #declare _Rope_N_Col=n; 0 #end #macro Rope_R_String(p) #declare _Rope_RST=p; 0 #end #macro Rope_R_Corner(p) #declare _Rope_RC=p; 0 #end #macro Rope_Texture_No(n) #declare _Rope_Texture_No=n; 0 #end #macro Rope_Texture(tex) #declare _Rope_Texture=texture{tex}; 0 #end #macro Rope_Rot(vec) #declare _Rope_Rot=vec; 0 #end #macro Rope_Trans(vec) #declare _Rope_Trans=vec; 0 #end #macro Rope_Obj(n) #declare _Rope_Obj=n; 0 #end //------------------------------------------- #macro Rope_CONNECT1(P1,P2,P3) #local _Rope_NVec2_s=_Rope_NVec2; #local _Rope_L2_s=_Rope_L2; #local _Rope_NVec1=vnormalize(P2-P1); #declare _Rope_NVec2=vnormalize(P3-P2); #local AVec=vnormalize(-_Rope_NVec1+_Rope_NVec2); #local TH=acos(vdot(_Rope_NVec1,_Rope_NVec2)); #local _Rope_L=_Rope_RC/cos(TH/2); #local _Rope_PR=P2+AVec*_Rope_L; #local V12=vnormalize(vcross(_Rope_NVec1,_Rope_NVec2)); //#debug concat("V.x:",str(V12.x,7,2),"V.z:",str(V12.z,7,2), "\n") #local TH12=atan2(V12.y,sqrt(V12.x^2+V12.z^2)+0.00001); #local PH12=atan2(V12.x,V12.z+0.00001); #declare _Rope_L2=_Rope_L*sin(TH/2); #local L=vlength(P2-P1)-_Rope_L2-_Rope_L2_s; #if (L<-1e-6) #warning concat("L:",str(L,7,2), "\n", "\n") #end //#debug concat("L:",str(L,7,2), "L2:",str(_Rope_L2,7,2), "\n") #local CVec=P2-_Rope_NVec1*_Rope_L2 - P1 -_Rope_NVec2_s*_Rope_L2_s; #local CVecPH=atan2(CVec.x,CVec.z+0.00001)*180/pi; #local CVecTH=atan2(CVec.y,sqrt(CVec.x^2+CVec.z^2)+0.00001)*180/pi; #local CVecL=vlength(CVec); #if (_Rope_C1_Flag=false) #declare _Rope_V0=vnormalize(P2-_Rope_NVec1*_Rope_L2-_Rope_PR); #end #declare _Rope_C1_Flag=true; #if (CVecL>0.00001) #if (_Rope_FreqST) isosurface{function{f_helix1(x,z,y, _Rope_FreqST, _Rope_Freq, _Rope_RST, _Rope_R-_Rope_RST, 1.42/_Rope_Freq*6/(_Rope_R/0.15),1,0)} contained_by{box{<-_Rope_R,-_Rope_R,0> <_Rope_R,_Rope_R, CVecL>}} max_gradient _Rope_MaxG evaluate off,1,1 #if (mod(_Rope_ISO_intersect,2)) all_intersections #end #local v1=vrotate(<1,0,0>, <-CVecTH,CVecPH,0>); #local vang=acos(vdot(v1, _Rope_V0))*180/pi; #local v1=vrotate(<1,0,0>, <0,0,vang>); #local v1=vrotate(v1, <-CVecTH,CVecPH,0>); #local SGN=vdot(v1,_Rope_V0); #if (SGN,<0,0,-(CVecL)*_Rope_Freq*180/pi+vang*SGN>); #declare _Rope_V0=vrotate(_Rope_V0,<-CVecTH,CVecPH,0>); rotate z*(vang*SGN) #else cylinder {0, <0,0,CVecL>, _Rope_R #end #if (_Rope_Texture_No=0) texture{_Rope_TEX0(_Rope_ofs,1,0)} #else #if (_Rope_Texture_No=1) texture{_Rope_TEX1(_Rope_ofs,1,0)} #else texture{_Rope_TEX2(_Rope_ofs,1,0)} #end #end rotate <-CVecTH,CVecPH,0> translate P1+_Rope_NVec2_s*_Rope_L2_s scale _Rope_Scl rotate _Rope_Rot translate _Rope_Trans #if (_Rope_Flg_Shadow=off) no_shadow #end } #end #declare _Rope_ofs=_Rope_ofs+CVecL; #local v1=vrotate(<0,0,1>, <90-TH12*180/pi,PH12*180/pi,0>); #local v2=vnormalize(P2-_Rope_NVec1*_Rope_L2-_Rope_PR); #local vang=acos(vdot(v1,v2))*180/pi; #local v12a=vcross(v1,v2); #local SGN2=((vdot(v12a,V12)>0)? 1: -1); #local VRang= vang*SGN2; #local v1=vrotate(<0,0,1>, y*VRang ); #local v1=vrotate(v1, <90-TH12*180/pi,PH12*180/pi,0>); #local vang01=acos(vdot(v1,_Rope_V0))*180/pi; #local v1=vrotate(<0,0,1>, <-vang01,0,0>); #local v1=vrotate(v1, y*VRang ); #local v1=vrotate(v1, <90-TH12*180/pi,PH12*180/pi,0>); #local SGN=vdot(v1,_Rope_V0); #if (SGN,<-(TH*_Rope_RC)*_Rope_Freq*180/pi-vang01*SGN,0 ,0>); #declare _Rope_V0=vrotate(_Rope_V0, y*(VRang+TH*180/pi) ); #declare _Rope_V0=vrotate(_Rope_V0,<90-TH12*180/pi,PH12*180/pi,0>); #local RotY=((-vang01)/_Rope_Freq/_Rope_RC*SGN + 90/_Rope_Freq/_Rope_RC)*pi/180; #if (_Rope_RC>0.00001) difference{ #if (_Rope_FreqST) isosurface { function { f_helical_torus(x*cos(RotY)-z*sin(RotY),y,x*sin(RotY)+z*cos(RotY), _Rope_RC, _Rope_Freq*_Rope_FreqST*_Rope_RC, _Rope_FreqST, 0, _Rope_RST, _Rope_R-_Rope_RST, 1/36/2/_Rope_FreqST/_Rope_FreqST*_Rope_R/0.15, 0, 0,0 )} #if ((0 <_Rope_RC+_Rope_R,_Rope_R,_Rope_RC+_Rope_R> } } #else contained_by { box { -<0,_Rope_R,_Rope_RC+_Rope_R> <_Rope_RC+_Rope_R,_Rope_R,_Rope_RC+_Rope_R> } } #end max_gradient _Rope_MaxG evaluate off,1,1 #if (_Rope_ISO_intersect) all_intersections #end } #else torus{_Rope_RC, _Rope_R} plane { x, .0 } #end plane { x, .0 rotate -y*(180-TH*180/pi) } //#debug concat("TH:",str(TH/pi*180,7,2), "\n") #if (_Rope_Texture_No=0) texture{_Rope_TEX0(_Rope_ofs,0,_Rope_RC)} #else #if (_Rope_Texture_No=1) texture{_Rope_TEX1(_Rope_ofs,0,_Rope_RC)} #else texture{_Rope_TEX2(_Rope_ofs,0,_Rope_RC)} #end #end rotate y*VRang rotate <(90-TH12*180/pi), PH12*180/pi, 0> translate _Rope_PR scale _Rope_Scl rotate _Rope_Rot translate _Rope_Trans #if (_Rope_Flg_Shadow=off) no_shadow #end } #end #declare _Rope_ofs=_Rope_ofs+TH*_Rope_RC; //#debug concat("ofs:",str(ofs/pi*180/RC,7,2), "\n", "\n") #end // ---------------------------------------- #macro Rope_Fixed_Rc(Ar1, NMax, N, Pr, R, R_s, R_c, ops) #if (ops) Rope_Init(0) #end #declare _Rope_FreqST=N; #declare _Rope_Freq=2*pi/Pr; #declare _Rope_R=R-R_s; #declare _Rope_RST=R_s; #declare _Rope_RC=R_c; #declare _Rope_Scl=_Rope_R/0.15; #declare _Rope_R=0.15; #declare _Rope_RST=_Rope_RST/_Rope_Scl; #declare _Rope_RC=_Rope_RC/_Rope_Scl; #declare _Rope_Freq=_Rope_Freq*_Rope_Scl; #if (_Rope_Obj) merge{ #end #local i=0; #while (i+MySpl(i/NMax)*2; // sphere {Ar[i],0.1 pigment{color rgb 1}} #local i = i + 1; #end Rope_Auto_Rc(Ar,NMax, N, Pr, R, R_s, R_c, ops) #end // ---------------------------------------- #macro Rope_Auto_Rc(Ar, NMax, N, Pr, R, R_s, R_c, ops) #if (ops) Rope_Init(0) #end #declare _Rope_FreqST=N; #declare _Rope_Freq=2*pi/Pr; #declare _Rope_R=R-R_s; #declare _Rope_RST=R_s; #local Rc_max=R_c; #declare _Rope_Scl=_Rope_R/0.15; #declare _Rope_R=0.15; #declare _Rope_RST=_Rope_RST/_Rope_Scl; #declare _Rope_RC=_Rope_RC/_Rope_Scl; #local Rc_max=R_c/_Rope_Scl; #declare _Rope_Freq=_Rope_Freq*_Rope_Scl; #local Ar_R= array[NMax+2]; #local Ar_R[0]=0; #local TH_s=pi; #local NVec2=<0,0,0>; #local i=0; #while (i] [0.2 rgb <0.6,0.6,0.6>] [0.2 rgb <0.6,0.2,0.2>][0.4 rgb <0.6,0.2,0.2>] [0.4 rgb <0.1,0.5,0.1>][0.6 rgb <0.1,0.5,0.1>] [0.6 rgb <0.7,0.5,0.2>][0.8 rgb <0.7,0.5,0.2>] [0.8 rgb <0.1,0.5,0.5>][1 rgb <0.1,0.5,0.5>]} #declare _Rope_Fin= finish {phong 0.7 brilliance 0.25 ambient 0.2} Rope_Init(0)