|
|
Margus Ramst wrote:
> ... 8< Snip ...
> #macro v_parallel(V1i,V2i)
> #local V1=vnormalize(V1i+<0,0,0>);
> #local V2=vnormalize(V2i+<0,0,0>);
> #local Vt=(vlength(V1+V2)-1);
> #if(Vt=1|Vt=-1) Vt
> #else 0
> #end
> #end
> ...
> #macro v_reorient(V,RefA,RefB)
> (#if((v_parallel(RefA,RefB))=0)
> vaxis_rotate(
> V,
> vcross(vnormalize(RefA),vnormalize(RefB)),
> degrees(atan2(vlength(vcross(vnormalize(RefA),vnormalize(RefB))),
> vdot(vnormalize(RefA),vnormalize(RefB)))))
> #else
> ((v_parallel(RefA,RefB))*V)
> #end)
> #end
> ...
I like the way you're finding if the two vectors are parallel in the first
macro and how the result is used to make a decision, and later to scale
the "incoming" vector if the other two are parallel.
BUT: From what I can see you're calculating the same things several times.
Wouldn't it be better to store calculated values in variables and use them
up again when needed ?
(Or is there too much overhead for POV to make these new variables ?)
Below are my suggestions of how the same thing could be done with only
one macro. (At least they seem to work the same way :)
Regards,
Tor Olav
--
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html
// First using your parallel-method:
#macro vReorient(vI,vRefA,vRefB)
#local vA=vnormalize(vRefA+<0,0,0>);
#local vB=vnormalize(vRefB+<0,0,0>);
#local vC=vcross(vA,vB);
#local vD=vdot(vA,vB);
#local SS=vlength(vA+vB)-1;
(SS=-1|SS=1?SS*vI:vaxis_rotate(vI,vC,degrees(atan2(vlength(vC),vD))))
#end
// Then with information about parallelism from vdot:
#macro vReorient2(vI,vRefA,vRefB)
#local vA=vnormalize(vRefA+<0,0,0>);
#local vB=vnormalize(vRefB+<0,0,0>);
#local vC=vcross(vA,vB);
#local vD=vdot(vA,vB);
(abs(vD)=1?vD*vI:vaxis_rotate(vI,vC,degrees(atan2(vlength(vC),vD))))
#end
Post a reply to this message
|
|