/* allows natural object color, can choose color for blade, set size of spot */ /* orientate = 0 is along x axis, 1 is y, 2 is z */ surface rotatingmetal ( float Ka = 1, Kd = .5, Ks = .5, roughness = .1; color specularcolor = 1; string texturename = ""; color bladecolor = color (1, 0, 0); float bladewidth = 1; float orientate = 0; float bladerot = 0; /* -1 <= bladerot <= 1 (-90 -- 90 degrees) */ float direction = 1; /* 1 = clockwise, 0 = counterclockwise */ float blurrot = 0; float xmin = 0; float ymin = 0; float zmin = 0; float xmax = 1; float ymax = 1; float zmax = 1;) { normal Nf; vector V; color Ct; point objectP, centP, offset; vector basedirect; float len; bladerot = mod((bladerot+1),2) - 1; if (texturename != "") Ct = color texture (texturename); else Ct = 1; objectP = transform("object", P); setxcomp(centP, (xmax+xmin)/2); setycomp(centP, (ymax+ymin)/2); setzcomp(centP, (zmax+zmin)/2); /* printf(" cent %f %f %f \n", xcomp(centP), ycomp(centP), zcomp(centP)); */ offset = objectP - centP; /* if (falloff < 0) { /* Normalize falloff by lengths of I and N */ falloff = falloff * falloff / (I.I * N.N); falloff = pow (falloff, attenuation); Ci = Cs * falloff; Oi = falloff; } else Oi = 0; */ if (orientate == 1){ setxcomp(offset,0); basedirect = vector(0,0,1); } else if (orientate == 2){ setzcomp(offset,0); basedirect = vector(0,1,0); } else { setycomp(offset,0); basedirect = vector(0,0,1) } float dotprod = offset.basedirect; /* Direct incidence has cosine closer to 1. */ /* len = length(offset); if(len < (spotsize/2)) Cs = dotcolor; */ Nf = faceforward (normalize(N),I); V = -normalize(I); Oi = Os; Ci = Os * ( Cs * Ct * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * Ks*specular(Nf,V,roughness)); }