// move macro // // returns a real value based on the clock, // smoothly transitioning from StartPt to EndPt, // from StartTime to EndTime following a sine // function. usefull for accelerating an object // smoothly from StartPt to the mid-point then // decelerating it smoothly to EndPt. // // If clock <= StartPt, StartPt is returned. // If clock >= EndPt, EndPt is returned. // // requires math.inc // // inputs: // StartPt = real: the initial value // EndPt = real: the final value // StartTime = real: the initial clock time // EndTime = real: the final clock time // // output: // ObjMoverNum = real: the value of the variable // at a particular clock time. // // example 1: //----------- // #include "math.inc" // ObjMover (0, 10, 0.25, 0.75) // #declare SphereMover = ObjMoverNum; // ObjMover (0, 1, 0.25, 0.75) // #declare ColorChng = ObjMoverNum; // sphere { // , 1 // pigment {rgb } // } //----------- // creates a sphere which sits at the origin until clock=0.25, // then moves along the x-axis, arriving at <10,0,0> when clock=0.75, // then staying at that point until clock=1. It also changes color as // it moves. // // example 2: //----------- // #include "math.inc" // #if (clock<0.5) // ObjMover (-30, 30, 0, 0.5) // #else // ObjMover (30, -30, 0.5, 1) // union { // cylinder { // <0, 0, 0>, // <0, -5, 0>, // 0.1 // } // sphere { // <0, -5, 0>, 0.3 // } // rotate <0, 0, ObjMoverNum> // } //----------- // creates a pendulum which swings smoothly from -30 degrees to 30 degrees // and back around the z-axis as the clock moves from 0 to 1. #macro ObjMover (StartPt, EndPt, StartTime, EndTime) #local Dist = EndPt - StartPt; #local Duration = EndTime - StartTime; #local ClockSc = 0.5 / Duration; #local HalfwayPt = (StartPt + EndPt) / 2; #local Clocker = ((clock - StartTime) * ClockSc) - 0.25; #if (clock>=StartTime) #if (clock<=EndTime) #declare ObjMoverNum = HalfwayPt + (sind (Clocker * 360) * (Dist / 2)); #else #declare ObjMoverNum = EndPt; #end #else #declare ObjMoverNum = StartPt; #end #end