Files
SableGravity/verification/verify_local_animation.py
T

36 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Checks that limb animation uses ship-local displacement, not world X/Z."""
import math
def qx(deg):
a=math.radians(deg)/2
return (math.cos(a),math.sin(a),0.0,0.0)
def conj(q):
w,x,y,z=q; return (w,-x,-y,-z)
def mul(a,b):
aw,ax,ay,az=a; bw,bx,by,bz=b
return (aw*bw-ax*bx-ay*by-az*bz,
aw*bx+ax*bw+ay*bz-az*by,
aw*by-ax*bz+ay*bw+az*bx,
aw*bz+ax*by-ay*bx+az*bw)
def rotate(q,v):
r=mul(mul(q,(0.0,*v)),conj(q)); return r[1:]
def length_xz(v): return math.sqrt(v[0]*v[0]+v[2]*v[2])
def length_local(v): return math.sqrt(v[0]*v[0]+v[2]*v[2])
walk=(0.0,0.0,0.25)
for deg in (0,20,90,180):
world=rotate(qx(deg),walk)
recovered=rotate(conj(qx(deg)),world)
assert abs(length_local(recovered)-0.25)<1e-9
print(f"X {deg:3d}: world delta={world}, local walk distance={length_local(recovered):.3f}, vanilla world-XZ={length_xz(world):.3f}")
# At 90 degrees around X, forward walking is world-vertical: vanilla X/Z animation would be 0.
assert length_xz(rotate(qx(90),walk)) < 1e-9
print('OK: local animation still walks at 90 degrees while vanilla world-XZ would freeze')