|
|
The first rotates an object such that if it oriented in the <from>
direction vector then after the rotation it will be oriented in the <to>
direction vector
The first relies in the second.
The second rotates an object around an axis <axis> by the angle <ang>
and was obtained from the src for the function vaxis_rotate (why wasn't
this type of rotation included in POV code) - hope the team don't mind :
)
This calculates a matrix for rotation.
eg cylinder{0,y,.1 lookat(y,<-0.5, 0.23, 0.342>) }
eg cylinder{0,y,.1 translate <0,0.5,.1> axis_rotate(x,45)}
#macro point(from, to)
#local axis = vcross(from,to);
#local axis = vnormalize(axis);
#local ang = acos(vdot(to,from)/vlength(to)/vlength(from));
axis_rotate(axis, ang)
#end
#macro axis_rotate(axis, ang)
#local cosx = cos(ang);
#local sinx = sin(ang);
matrix<
axis.x * axis.x + cosx * (1.0 - axis.x * axis.x),
axis.x * axis.y * (1.0 - cosx) + axis.z * sinx,
axis.x * axis.z * (1.0 - cosx) - axis.y * sinx,
axis.x * axis.y * (1.0 - cosx) - axis.z * sinx,
axis.y * axis.y + cosx * (1.0 - axis.y * axis.y),
axis.y * axis.z * (1.0 - cosx) + axis.x * sinx,
axis.x * axis.z * (1.0 - cosx) + axis.y * sinx,
axis.y * axis.z * (1.0 - cosx) - axis.x * sinx,
axis.z * axis.z + cosx * (1.0 - axis.z * axis.z),
0,0,0
>
#end
Hope these are of some use
Pabs
Post a reply to this message
|
|
|
|
Pabs <pab### [at] hotmailcom> wrote:
: The first rotates an object such that if it oriented in the <from>
: direction vector then after the rotation it will be oriented in the <to>
: direction vector
Sounds a lot like VanSickle's Reorient macro.
: The second rotates an object around an axis <axis> by the angle <ang>
Sounds a lot like his AxisRotate macro.
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
|
|
|
David Fontaine <dav### [at] faricynet> wrote:
: I needlessly wrote redundant macros for these long before Pabs! :-) It is good
: experience though.
That's certainly true. When you write the macro yourself you have to
understand how the math works and you will probably learn something. It's
never wasted time (at least not for yourself).
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
|