#version 3.7; #include "colors.inc" #include "skies.inc" #include "math.inc" global_settings{assumed_gamma 1.70} #debug concat("@@F:", str(frame_number,0,0), "\n") // Move a Vector from, to, increment #macro MoveV(_from, _to, __i) <_from.x+((_to.x-_from.x)*__i), _from.y+((_to.y-_from.y)*__i), _from.z+((_to.z-_from.z)*__i)> #end // Animate this segment of the clock from 0 to 1 #macro AniSegment(_start, _end) ((myclock-_start)/(_end-_start)) #end // return a vector as a debug string (truncated precision) #macro vdebug(vec) concat("<", str(vec.x,0,2), ", ",str(vec.y,0,2), ", ", str(vec.z,0,2), ">") #end // Convert this vector into its angle #macro VtoA(V) #local _V=vnormalize(V); #local rZ=degrees(acos(_V.z)); #local rY=0; #local rX=0; #if (_V.y != 0) #local rY=degrees(atan2(_V.x,_V.y)); #else #local rX=rZ; #local rZ=0; #end #debug concat("rY/Z=", str(rY,0,3), ", ", str(rZ,0,3), "\n") <-rZ,rX,-rY> #end // new bit added here: #macro ssOffset(bar) #local newZ = vnormalize( Lookat-Camera ); #local newY = y; #local newX = vnormalize(vcross(newY,newZ)); #local newY = vnormalize(vcross(newZ,newX)); #local barOut = bar.x * newX + bar.y * newY + bar.z * newZ; #debug concat ("bar=", vdebug(bar), " Out=", vdebug(barOut), "\n") // sphere {bar, 0.51 pigment {Green} // translate Camera barOut // //} #end // scott's suggestion. It gives me another vector, not an angle. #macro ssVtoA(bar) #local newZ = vnormalize( bar ); #local newY = y; #local newX = vnormalize(vcross(newY,newZ)); #local newY = vnormalize(vcross(newZ,newX)); #local barOut = bar.x * newX + bar.y * newY + bar.z * newZ; #debug concat ("bar=", vdebug(bar), " Out=", vdebug(barOut), "\n") barOut // //} #end // from http://snipd.net/2d-and-3d-vector-normalization-and-angle-calculation-in-c #macro ac(V) #local V = vnormalize(V); #local r = vlength(V); #local theta = atan2d(sqrt(pow(V.x,2)+pow(V.y,2)),V.z); #local phi = atan2d(V.y, V.x); #local out = <0, theta, phi>; #debug concat("ac=", vdebug(out), "\n") out #end #declare myclock=clock*4; #declare Camera=<0,10,0>; #declare Lookat=<0,10,1>; // swivel up and down around the camera #local lo0=<0,0,0>; #local lo1=<2,0,0>; #local lo2=<0,2,0>; #local lo3=<0,2,2>; #local lo4=<-2,1,-2>; #local lo5=<-2,-2,2>; #switch (myclock) #range(0,0.5) #local _i=AniSegment(0,0.5); #debug concat("0,0.5 i=", str(_i,0,3), "\n") #declare Lookat=Lookat+MoveV(lo0,lo1,_i); #break #range(0.5,1) #local _i=AniSegment(0.5,1); #debug concat("0.5,1 i=", str(_i,0,3), "\n") #declare Lookat=Lookat+MoveV(lo0,lo2,_i); #break #range(1,2) #local _i=AniSegment(1,2); #debug concat("1,2 i=", str(_i,0,3), "\n") #declare Lookat=Lookat+MoveV(lo2,lo3,_i); #break #range(2,3) #local _i=AniSegment(2,3); #debug concat("2,3 i=", str(_i,0,3), "\n") #declare Lookat=Lookat+MoveV(lo3,lo4,_i); #break #range(3,4) #local _i=AniSegment(3,4); #debug concat("3,4 i=", str(_i,0,3), "\n") #declare Lookat=Lookat+MoveV(lo4,lo5,_i); #break #end #debug concat("Camera=", vdebug(Camera), " Lookat=", vdebug(Lookat), "\n") #local V=vnormalize(Lookat-Camera); #debug concat("V=", vdebug(V), "\n") sphere {V+Camera,0.02 pigment {Red}} #local cyanV=<0,0,10>; #local cyanVec=Lookat-Camera; #local cyanRot=VtoA(cyanVec); #local cyanF=vrotate(cyanV, cyanRot); #debug concat ("cyanRot=", vdebug(cyanRot), "\n") sphere {cyanF+Camera, 0.5 pigment {Cyan}} #debug concat ("cyanF=", vdebug(cyanF), "\n") #declare myCyl= union { cylinder {-1*z, 0*z, 0.5 pigment {Yellow}} sphere {0, 0.5 pigment {Red}} } object { myCyl scale 0.2 #local flOfs = <-0.4,-0.3,0.7>; translate flOfs #local A=VtoA(cyanVec); #debug concat("va=", vdebug(A), "\n") rotate translate Camera } camera { location Camera look_at Lookat } light_source {<0,20,0> rgb 1} sky_sphere { S_Cloud3 rotate y * 180} plane { y, 0 texture { checker texture { pigment {ForestGreen} }, texture { pigment{White} } } scale 12 } #debug "@@end\n"