mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Fix llEuler2Rot's sign.
LL's algorithm for llEuler2Rot involves calculating a rotation matrix from the Eulers, then transforming the rotation matrix to quaternion. This generates sign discrepancies with our direct quaternion calculation algorithm. Fixed by making only the necessary calculations to find the correct sign. Unfortunately, they are still heavy (notably, six more trig functions).
This commit is contained in:
parent
390de46bdb
commit
80cbaf8fd5
1 changed files with 23 additions and 4 deletions
|
@ -1071,10 +1071,29 @@ def llEuler2Rot(v):
|
|||
c2 = math.cos(v[2]*0.5)
|
||||
s2 = math.sin(v[2]*0.5)
|
||||
|
||||
return Quaternion(F32((s0 * c1 * c2 + c0 * s1 * s2,
|
||||
c0 * s1 * c2 - s0 * c1 * s2,
|
||||
c0 * c1 * s2 + s0 * s1 * c2,
|
||||
c0 * c1 * c2 - s0 * s1 * s2)))
|
||||
r = F32((s0 * c1 * c2 + c0 * s1 * s2,
|
||||
c0 * s1 * c2 - s0 * c1 * s2,
|
||||
c0 * c1 * s2 + s0 * s1 * c2,
|
||||
c0 * c1 * c2 - s0 * s1 * s2))
|
||||
|
||||
# Fix the sign
|
||||
c0 = math.cos(v[0])
|
||||
s0 = math.sin(v[0])
|
||||
c1 = math.cos(v[1])
|
||||
s1 = math.sin(v[1])
|
||||
c2 = math.cos(v[2])
|
||||
s2 = math.sin(v[2])
|
||||
d1 = c1*c2
|
||||
d2 = c0*c2 - s0*s1*s2
|
||||
d3 = c0*c1
|
||||
if d1 + d2 + d3 > 0:
|
||||
return Quaternion(-f for f in r) if r[3] < 0 else Quaternion(r)
|
||||
i = 0
|
||||
if d2 > d1:
|
||||
i = 1
|
||||
if d1 < d3 > d2:
|
||||
i = 2
|
||||
return Quaternion(-f for f in r) if r[i] < 0 else Quaternion(r)
|
||||
|
||||
def llFabs(f):
|
||||
assert isfloat(f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue