generateDirPlaneValues.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Script to precalculate dir and plane values, as this keeps them in sync
  2. # However, this means no dynamic adjustments of the FOV,
  3. # as this is determined by the ratio between dir and plane vectors
  4. # currently resulting in an FOV of 2*atan(0.66/1.0)=66°
  5. from math import cos, sin, pi, pow
  6. functionsToCreateTableOf = ["dirX", "dirY", "planeX", "planeY"]
  7. dirX = -1.0
  8. dirY = 0.0
  9. planeX = 0.0
  10. planeY = 0.66
  11. def doubleToFP16(x):
  12. return round(x * pow(2,16))
  13. # Original code quickly converted to python
  14. #rotate to the right
  15. def moveRight(rotSpeed, function):
  16. global dirX
  17. global dirY
  18. global planeX
  19. global planeY
  20. #both camera direction and camera plane must be rotated
  21. oldDirX = dirX
  22. dirX = dirX * cos(-rotSpeed) - dirY * sin(-rotSpeed)
  23. dirY = oldDirX * sin(-rotSpeed) + dirY * cos(-rotSpeed)
  24. oldPlaneX = planeX
  25. planeX = planeX * cos(-rotSpeed) - planeY * sin(-rotSpeed)
  26. planeY = oldPlaneX * sin(-rotSpeed) + planeY * cos(-rotSpeed)
  27. #print("dx:{:.5f} dy:{:.5f} px:{:.5f} py:{:.5f}".format(dirX, dirY, planeX, planeY) )
  28. if function == "dirX":
  29. print(str(doubleToFP16(dirX)) + ", ", end='')
  30. elif function == "dirY":
  31. print(str(doubleToFP16(dirY)) + ", ", end='')
  32. elif function == "planeX":
  33. print(str(doubleToFP16(planeX)) + ", ", end='')
  34. elif function == "planeY":
  35. print(str(doubleToFP16(planeY)) + ", ", end='')
  36. # pi/180 means 360 even steps -> one per degree (so use 360 as looplength)
  37. rotSpeed = pi/720
  38. loopLength = 1440
  39. # Create lookup table for each function
  40. for function in functionsToCreateTableOf:
  41. # reset to make sure
  42. dirX = -1.0
  43. dirY = 0.0
  44. planeX = 0.0
  45. planeY = 0.66
  46. print("word LUT"+function + "[" + str(loopLength) + "] = {")
  47. for i in range(loopLength):
  48. moveRight(rotSpeed, function)
  49. if (i+1) % 12 == 0:
  50. print()
  51. print("};")
  52. print("\n\n")