|
|
I think did something similar in my spline_tools include...
http://news.povray.org/povray.binaries.scene-files/thread/%3C44e2e8f3@news.povray.org%3E/?ttop=240477&toff=50
The spline is passed as a global #declare to avoid certain
bugs that happen when repeatedly passing splines to macros...
VSpline_Trans_Path() in other respects behaves exactly like
Spline_Trans() except it works on a vector in relation to the
origin. You could get the relative up and right vectors for
two positions along your spline by feeding your absolute
up and right into the macro then comparing the returned
vectors.
The only real restriction is that the up vector needs to
be mostly perpendicular to your spline (like Spline_Trans)
// transforms a vector by a matrix
#macro VMatrix_Trans(vec, A, B, C, D)
#local fn = function { transform {
matrix < A.x, A.y, A.z,
B.x, B.y, B.z,
C.x, C.y, C.z,
D.x, D.y, D.z>
} }
#local result = (fn(vec.x, vec.y, vec.z));
(result)
#end
// transforms a vector along Path_Spline
#macro VSpline_Trans_Path (Vect, Time, Sky, Foresight, Banking)
#ifndef (Path_Spline)
#error "VSpline_Trans_Path requires Path_Spline to be #declared!\n"
#end
#local Location = <0,0,0>+Path_Spline(Time);
#local LocationNext = <0,0,0>+Path_Spline(Time+Foresight);
#local LocationPrev = <0,0,0>+Path_Spline(Time-Foresight);
#local Forward = vnormalize(LocationNext-Location);
#local Right = VPerp_To_Plane(Sky,Forward);
#local Up = VPerp_To_Plane(Forward,Right);
#local BankingRotation =
degrees(atan2(
VRotation(
VProject_Plane((LocationNext-Location),Sky),
VProject_Plane((Location-LocationPrev),Sky),
Up
)*Banking
,1
));
#local result = vrotate(Vect, BankingRotation*z);
#local result = VMatrix_Trans(result,Right,Up,Forward,Location);
(result)
#end
Post a reply to this message
|
|