danmaku2ass/test/test-3drot.py

80 lines
2.3 KiB
Python
Raw Permalink Normal View History

2014-04-29 21:08:22 +08:00
#!/usr/bin/env python3
import logging
import math
import sys
try:
import importlib.machinery
danmaku2ass = importlib.machinery.SourceFileLoader('danmaku2ass', '../danmaku2ass.py').load_module('danmaku2ass')
except (AttributeError, ImportError):
import imp
danmaku2ass = imp.load_source('danmaku2ass', '../danmaku2ass..py')
extcode = 0
2017-07-04 00:58:45 +08:00
2014-04-29 21:08:22 +08:00
def main():
logging.basicConfig(level=logging.INFO)
2014-06-08 20:46:24 +08:00
for Y in (120, 360):
for X in (160, 480):
for rotY in range(0, 361):
for rotZ in range(0, 361):
trX, trY, outX, outY, outZ, scaleX, scaleY = danmaku2ass.ConvertFlashRotation(rotY, rotZ, X=X, Y=Y, width=640, height=480)
logging.info('(%3d, %3d), %4d, %4d => %4d, %4d, %4d, %4d%%' % (X, Y, rotY, rotZ, outX, outY, outZ, scaleX))
CompareMatrix(rotY, rotZ, outX, outY, outZ)
2014-04-29 21:08:22 +08:00
2017-07-04 00:58:45 +08:00
2014-04-29 21:08:22 +08:00
def CompareMatrix(rotY, rotZ, outX, outY, outZ):
2014-06-08 20:48:43 +08:00
def ApproxEqual(a, b, e=0.015):
2014-04-29 21:08:22 +08:00
assert e >= 0
2017-07-04 00:58:45 +08:00
a_b = a - b
2014-04-29 21:08:22 +08:00
if -e < a_b < e:
return 0
else:
return a_b
2017-07-04 00:58:45 +08:00
2014-04-29 21:08:22 +08:00
def FormatError(i, j, l, r):
global extcode
if ApproxEqual(l, r) != 0:
extcode = 1
logging.error('l[%s][%s]=%9.6f r[%s][%s]=%9.6f' % (i, j, l, i, j, r))
2017-07-04 00:58:45 +08:00
2014-04-29 21:08:22 +08:00
def sind(x):
2017-07-04 00:58:45 +08:00
return math.sin(x * math.pi / 180.0)
2014-04-29 21:08:22 +08:00
def cosd(x):
2017-07-04 00:58:45 +08:00
return math.cos(x * math.pi / 180.0)
2014-04-29 21:08:22 +08:00
2017-07-04 00:58:45 +08:00
l = cosd(rotY) * cosd(rotZ)
r = -sind(outX) * sind(outY) * sind(outZ) + cosd(outY) * cosd(outZ)
2014-04-29 21:08:22 +08:00
FormatError(0, 0, l, r)
2017-07-04 00:58:45 +08:00
l = cosd(rotY) * sind(rotZ)
r = -cosd(outX) * sind(outZ)
2014-04-29 21:08:22 +08:00
FormatError(0, 1, l, r)
l = sind(rotY)
2017-07-04 00:58:45 +08:00
r = -sind(outX) * cosd(outY) * sind(outZ) - sind(outY) * cosd(outZ)
2014-04-29 21:08:22 +08:00
FormatError(0, 2, l, r)
l = -sind(rotZ)
2017-07-04 00:58:45 +08:00
r = sind(outX) * sind(outY) * cosd(outZ) + cosd(outY) * sind(outZ)
2014-04-29 21:08:22 +08:00
FormatError(1, 0, l, r)
l = cosd(rotZ)
2017-07-04 00:58:45 +08:00
r = cosd(outX) * cosd(outZ)
2014-04-29 21:08:22 +08:00
FormatError(1, 1, l, r)
l = 0
2017-07-04 00:58:45 +08:00
r = sind(outX) * cosd(outY) * cosd(outZ) - sind(outY) * sind(outZ)
2014-04-29 21:08:22 +08:00
FormatError(1, 2, l, r)
2017-07-04 00:58:45 +08:00
l = -sind(rotY) * cosd(rotZ)
r = cosd(outX) * sind(outY)
2014-04-29 21:08:22 +08:00
FormatError(2, 0, l, r)
2017-07-04 00:58:45 +08:00
l = -sind(rotY) * sind(rotZ)
2014-04-29 21:08:22 +08:00
r = -sind(outX)
FormatError(2, 1, l, r)
l = cosd(rotY)
2017-07-04 00:58:45 +08:00
r = cosd(outX) * cosd(outY)
2014-04-29 21:08:22 +08:00
FormatError(2, 2, l, r)
if __name__ == '__main__':
main()
sys.exit(extcode)