#!/usr/bin/env python3 """Checks the relative frame used by Sable's OBB collision. Sable gives a ship block OBB the SubLevel pose q_ship and gives the custom player OBB q_entity. For an upright player relative to the logical deck, q_entity must be q_ship, so inverse(q_ship) * q_entity is identity. """ import math def qx(deg): a = math.radians(deg) / 2.0 return (math.cos(a), math.sin(a), 0.0, 0.0) # w,x,y,z 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): p=(0.0,*v) r=mul(mul(q,p),conj(q)) return r[1:] def close(a,b,eps=1e-9): return all(abs(x-y)