/* This is my first try at animating a 3D light trail Here is my test ini file: [512x384, Animation] Width=512 Height=384 Antialias=On Sampling_Method=1 Antialias_Depth=2 Jitter=Off Antialias_Threshold=0.3 Initial_Frame = 1 Final_Frame = 41 Initial_Clock = 0.0 Final_Clock = 1.0 Subset_Start_Frame = 1 Subset_End_Frame = 41 */ global_settings { assumed_gamma 1.0 } #include "math.inc" #include "colors.inc" #include "transforms.inc" #declare path1_num = 5; //number of points used to define spline (one more then the number of segments) #declare path1_start_time = 0; #declare path1_end_time = 1; #declare path1_time = path1_end_time - path1_start_time; //time used to travel length of spline #declare path1 = array[path1_num][3] { {<0,0,0>,<0,0,1>,<0,1,0>}, //first point of spline, forward for first segment of spline, up for first segment of spline {<0,0,1>,<1,0,0>,<0,1,0>}, //second point of spline, forward for second segment of spline, up for second segment of spline {<2,0,1>,<0,1,0>,<-1,0,0>}, //third point of spline, forward for third segment of spline, up for third segment of spline {<2,3,1>,<0,0,1>,<-1,0,0>}, //forth point of spline, forward for last segment of spline, up for last segment of spline {<2,3,5>,<0,0,1>,<-1,0,0>} //last point of spline, forward at end of spline, up at end of spline }; #declare path1_seg_length = array[path1_num - 1] #declare path1_seg_time = array[path1_num] #declare ctr = 0; #declare path1_length = 0; #while (ctr < path1_num - 1.5) #declare path1_seg_length[ctr] = VDist(path1[ctr+1][0], path1[ctr][0]); // calculate length of each segment of spline #declare path1_length = path1_length + path1_seg_length[ctr]; // calculate total length of spline #declare path1_seg_time[ctr] = 0; // initialize segment time array #declare ctr = ctr + 1; #end #declare ctr = 1; #while (ctr < path1_num - 0.5) #declare path1_seg_time[ctr] = path1_seg_time[ctr-1] + path1_seg_length[ctr-1]*path1_time/path1_length; //time taken to travel first n segments #declare ctr = ctr + 1; #end #declare ctr = 0; #while (ctr < path1_num - 0.5) #debug str(path1_seg_time[ctr],5,5) #debug "\n" #declare ctr = ctr + 1; #end #declare path1_spline = spline { linear_spline path1_seg_time[0], path1[0][0], path1_seg_time[1], path1[1][0], path1_seg_time[2], path1[2][0], path1_seg_time[3], path1[3][0], path1_seg_time[4], path1[4][0] } //this needs to be updated my hand if more points are added to path1 camera {location <-50,50,-20> look_at <1,1.5,2.5> angle 7} light_source {<4,6,-6> White} light_source {<-60,30,10> 0.5*White} #declare path1_radius = 0.3; //radius of light trail #declare path1_offset = 0.3*path1_time/path1_length; //offset to place object in front of light trail //find current forward direction #declare forward1 = path1[path1_num-1][1]; #declare ctr = 1; #while (ctr < path1_num - 0.5) #if (clock + path1_offset < path1_seg_time[ctr] & clock + path1_offset > path1_seg_time[ctr-1]) #declare forward1 = path1[ctr-1][1]; #end #declare ctr = ctr + 1; #end //find current upward direction #declare up1 = path1[path1_num-1][2]; #declare ctr = 1; #while (ctr < path1_num - 0.5) #if (clock + path1_offset < path1_seg_time[ctr] & clock + path1_offset > path1_seg_time[ctr-1]) #declare up1 = path1[ctr-1][2]; #end #declare ctr = ctr + 1; #end //object starts with up in y direction #declare object_up = y; //define transformation to point object forward and to keep track of object's up direction #declare path1_trans = transform { #if (forward1.x = -1) rotate 180*y #declare object_up = vaxis_rotate(object_up,y,180); #end #if (forward1.z = -1) rotate 90*y #declare object_up = vaxis_rotate(object_up,y,90); #end #if (forward1.z = 1) rotate -90*y #declare object_up = vaxis_rotate(object_up,y,-90); #end #if (forward1.y = -1) rotate -90*z #declare object_up = vaxis_rotate(object_up,z,-90); #end #if (forward1.y = 1) rotate 90*z #declare object_up = vaxis_rotate(object_up,z,90); #end } //define light trail #declare path1_shape = merge{ #declare ctr = 1; #while (ctr < path1_num - 0.5) #if (clock < path1_seg_time[ctr] & clock > path1_seg_time[ctr-1]) cylinder {path1[ctr-1][0], path1_spline(clock+0.001), path1_radius} sphere {path1_spline(clock), path1_radius} #end #if (clock >= path1_seg_time[ctr]) cylinder {path1[ctr-1][0], path1[ctr][0], path1_radius} sphere {path1[ctr][0], path1_radius} #end #declare ctr = ctr + 1; #end } //draw light trail object {path1_shape pigment{Red}} //define text object. Its a "T" with a noise to define forward. #declare flyer = merge{ box {<0,-0.3,-0.1>, <0.2,0.3,0.1>} cylinder {<0.1,0.2,-0.3>, <0.1,0.2,0.3>, 0.1} cylinder {<0.1,0.2,0>, <0.3,0.2,0> 0.1} } //draw object pointing forward with up in the up direction object {flyer transform path1_trans Reorient_Trans(object_up, up1) translate path1_spline(clock+path1_offset) pigment{Blue}}