Difference between revisions of "Talk:LlAngleBetween"
Jump to navigation
Jump to search
(LSO Optimized Reference Impelementation) |
m |
||
Line 20: | Line 20: | ||
//in that case we want to return zero so multiplying v2 by 2.0 will have no effect on the value returned. | //in that case we want to return zero so multiplying v2 by 2.0 will have no effect on the value returned. | ||
return v2 * 2.0; | return v2 * 2.0; | ||
}//Written by Moon Metty & Miranda Umino. | }//Written by Moon Metty & Miranda Umino. Optimizations by Strife Onizuka</lsl> | ||
-- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 09:48, 2 September 2012 (PDT) | -- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 09:48, 2 September 2012 (PDT) |
Revision as of 09:57, 2 September 2012
LSO Optimized Reference Impelementation
This version of the latest reference implementation is optimized for LSO bytecode. Execution speed should be about the same.
<lsl>float AngleBetween(rotation a, rotation b)//more complex implementation but more accurate, and reasonably fast. {
b /= a; // calculate the rotation between the two arguments as quaternion float s2 = b.s * b.s; // square of the s-element float v2 = b.x * b.x + b.y * b.y + b.z * b.z; // sum of the squares of the v-elements
//we bulk all our returns into a single return because returning requires several bytecodes. //specifically the local variables and parameters must be popped off the stack.
if (s2 < v2) // compare the s-component to the v-component v2 = llAcos(llSqrt(s2 / (s2 + v2))); // use arccos if the v-component is dominant else if (v2) // make sure the v-component is non-zero v2 = llAsin(llSqrt(v2 / (s2 + v2))); // use arcsin if the s-component is dominant
//if one or both arguments are scaled too small to be meaningful v2 is zero, or the values are the same, v2 is zero. //in that case we want to return zero so multiplying v2 by 2.0 will have no effect on the value returned. return v2 * 2.0;
}//Written by Moon Metty & Miranda Umino. Optimizations by Strife Onizuka</lsl>