|
![](/i/fill.gif) |
"H. E. Day" wrote:
> ...
> I need a jointed leg, or code on how to produce one.
>
> This leg needs to have defineable Thigh and Shin lengths.
>
> I only want to have to move the ankle for the entire leg to
> move accordingly.
>
> The leg doesn't need to be anything fancy, just 3 spheres
> (Hip, Knee, Ankle) and 2 cylinders (Thigh, Shin).
>
> I'll replace the objects with the stuff I've already have built.
> ...
Is it something like the code below that you need ?
It's not very advanced though.
(It's "quick and dirty", but I hope it can give you some ideas.)
Tor Olav
--
mailto:tor### [at] hotmail com
http://www.crosswinds.net/~tok/tokrays.html
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#version 3.1;
#include "colors.inc"
#macro FindKnee(pHip, pAnkle, ThighLength, ShinLength, vForw)
#local vLeg = pAnkle - pHip;
#local dd = vlength(vLeg);
#local aa = (pow(dd, 2) + pow(ThighLength, 2) - pow(ShinLength, 2))/(2*dd);
#local bb = sqrt(pow(ThighLength, 2) - pow(aa, 2));
#local vRight = vcross(vForw, vLeg);
#local vFront = vcross(vLeg, vRight);
(pHip + aa*vnormalize(vLeg) + bb*vnormalize(vFront))
#end // macro FindKnee
#declare DirectionOfMovement = <-3, 0, 2>;
#declare LengthOfThigh = 50;
#declare LengthOfShin = LengthOfThigh*0.9;
#declare PositionOfpHip = <20, 100, -20>;
#declare PositionOfAnkle = <-10, 30, -10>;
/*
// Macro and code to locate the ankle
#macro FindAnkle(pHip, ThighLength, ShinLength,
vSpine, vForw, Angle, Stretch)
#local vRight = vcross(vSpine, vForw);
#local DistFromHip = ThighLength + ShinLength*(2*Stretch - 1);
(pHip + vaxis_rotate(DistFromHip*vnormalize(vSpine), vRight, Angle))
#end // macro FindAnkle
#declare DirectionOfSpine = <0, 1, 0>;
// At 0 degrees the ankle is close to the neck
// At 180 degrees the ankle is in line with the spine
#declare RotationOfLeg = 120;
// Value between 0 and 1 that tells how stretched-out
// the leg is. (1 is fully stretched out)
#declare StretchOfLeg = 0.7;
//#declare Phi = 2*pi*3/8;
//// Or you could make Phi a function of the time
//#declare RotationOfLeg = 180 + 30*sin(Phi);
//#declare StretchOfLeg = 0.8 + 0.2*cos(Phi);
#declare PositionOfAnkle = FindAnkle(
PositionOfpHip,
LengthOfThigh,
LengthOfShin,
DirectionOfSpine,
DirectionOfMovement,
RotationOfLeg,
StretchOfLeg
)
*/
#declare LegLength = LengthOfThigh + LengthOfShin;
#if (vlength(PositionOfAnkle - PositionOfpHip) > LegLength)
#debug "\n\nError: The ankle is to far away from the hip.\n\n"
#end // if
#declare PositionOfKnee = FindKnee(
PositionOfpHip,
PositionOfAnkle,
LengthOfThigh,
LengthOfShin,
DirectionOfMovement
);
#declare sr = 8;
#declare cr = sr*0.7;
sphere { // Hip
PositionOfpHip, sr
pigment { color Yellow}
}
sphere { // Ankle
PositionOfAnkle, sr
pigment { color Orange }
}
sphere { // Knee
PositionOfKnee, sr pigment { color Red }
}
cylinder { // Thigh
PositionOfpHip, PositionOfKnee, cr
pigment { color Magenta }
}
cylinder { // Shin
PositionOfKnee, PositionOfAnkle, cr
pigment { color Cyan }
}
plane { y, 0 pigment { color White } }
global_settings { ambient_light color White }
light_source { 1000*<-1, 1, -2> color 2*White }
camera {
location <0, 1, -2>*90
look_at <0, 3, 0>*20
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
Post a reply to this message
|
![](/i/fill.gif) |