/* How to make an IK leg v1.2 - by Rune S. Johansen This scene can be rendered as a small cyclic animation with the clock going from 0 to 1. */ // First the basic scene elements... camera {location 2.4*x look_at 0} light_source {<3,2,1>*1000, color 1} background {color rgb 1} /* Just specify HipPoint and AnklePoint, and the entire leg will follow. You also need to specify the length of the thigh and the shin as well as the direction in which the knee should be pointing. */ #declare HipPoint = +0.8*y; #declare AnklePoint = -0.6*y + vrotate(0.3*y,360*x*clock); #declare ThighLength = 1.0; #declare ShinLength = 1.0; #declare KneeDirection = z; /* Now specify the objects used for the thigh and the shin. */ #declare ThighObject = union { sphere {0, 0.20} sphere {0, 1 scale <0.25,0.60,0.25> translate <0,-0.5,0.05>} sphere {-1*y, 0.17} texture {pigment {color rgb 1} normal {bumps 0.5 scale 0.1}} } #declare ShinObject = union { sphere {0, 1 scale <0.20,0.60,0.20> translate <0,-0.5,0.05>} sphere {-1*y, 0.15} texture {pigment {color rgb 1} normal {bumps 0.5 scale 0.1}} } // Knee calculates the point of the knee given these input: // pA: Point of the ankle. // pH: Point of the hip. // LT: Length of thigh. // LS: Length of shin. // vD: Direction in which the knee is pointing. #macro Knee(pA,pH,LT,LS,vD) // by Tor Olav Kristensen #local vB=pA-pH; #local LB=vlength(vB); #if(LB>LT+LS) #error "Ankle and hip are too far apart.\n" #end #if(LB #end /* Now do the calculations to find the transformations used to place the thigh and shin. */ #declare KneeVector = Perpendiculize(KneeDirection,HipPoint-AnklePoint); #declare KneePoint = Knee(HipPoint,AnklePoint,ShinLength,ThighLength,KneeVector); #declare ThighY = vnormalize(HipPoint-KneePoint); #declare ThighZ = Perpendiculize(KneeVector,ThighY); #declare ThighX = vcross(ThighY,ThighZ); #declare ThighP = HipPoint; #declare ThighTransform = transform{Vectors2Matrix(ThighX,ThighY,ThighZ,ThighP)} #declare ShinY = vnormalize(KneePoint-AnklePoint); #declare ShinZ = Perpendiculize(KneeVector,ShinY); #declare ShinX = vcross(ShinY,ShinZ); #declare ShinP = KneePoint; #declare ShinTransform = transform{Vectors2Matrix(ShinX,ShinY,ShinZ,ShinP)} // And here we go... object {ThighObject transform ThighTransform} object {ShinObject transform ShinTransform} /* Hope that helps! Rune */