init.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. local ffi = require("ffi")
  2. local lib_path = os.getenv("LD_LIBRARY_PATH")
  3. lib = ffi.load(lib_path .. "/libcrown.so", true)
  4. require("vec3")
  5. require("mat4")
  6. require("quat")
  7. require("math_utils")
  8. -- require("camera")
  9. require("script")
  10. --------------------------------------------------------------
  11. --------------------------------------------------------------
  12. --------------------------------------------------------------
  13. print("-- Testing Vec3 --\n")
  14. local pos = Vec3.vec3(1.0, 1.0, 1.0)
  15. pos = Vec3.add(pos, Vec3.vec3(1.0, 2.0, 3.0)
  16. )
  17. print(pos.x)
  18. print(pos.y)
  19. print(pos.z)
  20. Vec3.negate(pos)
  21. print(pos.x)
  22. print(pos.y)
  23. print(pos.z)
  24. --------------------------------------------------------------
  25. --------------------------------------------------------------
  26. --------------------------------------------------------------
  27. print("-- Testing Mat4 --\n")
  28. local m = Mat4.mat4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)
  29. local t = Mat4.mat4(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0)
  30. local trans = Vec3.vec3(1.0, 1.0, 0.0)
  31. local scale = Vec3.vec3(10.0, 10.0, 10.0)
  32. Mat4.print(m)
  33. print("\n")
  34. print("-- Mat4.add --\n")
  35. m = Mat4.add(m, t)
  36. Mat4.print(m)
  37. print("\n")
  38. print("-- Mat4.subtract --\n")
  39. m = Mat4.subtract(m, t)
  40. Mat4.print(m)
  41. print("\n")
  42. print(".. Mat4.set_translation-- \n")
  43. Mat4.set_translation(m, trans)
  44. Mat4.print(m)
  45. print("\n")
  46. print(".. Mat4.get_translation-- \n")
  47. local tr = Mat4.get_translation(m)
  48. print(tr.x)
  49. print(tr.y)
  50. print(tr.z)
  51. print(".. Mat4.set_scale-- \n")
  52. Mat4.set_scale(m, scale)
  53. Mat4.print(m)
  54. print("\n")
  55. print(".. Mat4.get_scale-- \n")
  56. local sc = Mat4.get_scale(m)
  57. print(sc.x)
  58. print(sc.y)
  59. print(sc.z)
  60. --------------------------------------------------------------
  61. --------------------------------------------------------------
  62. --------------------------------------------------------------
  63. print("-- Testing MathUtils --\n")
  64. print("sin of 0 is " .. Math.sin(0.0))
  65. -- --------------------------------------------------------------
  66. -- --------------------------------------------------------------
  67. -- --------------------------------------------------------------
  68. -- print("-- Testing Camera --\n")
  69. -- local cam = Camera.camera(pos, 90.0, 1.6)
  70. -- print("@move forward by 1 meter")
  71. -- print("x:" .. Camera.position(cam).x)
  72. -- print("y:" .. Camera.position(cam).y)
  73. -- print("z:" .. Camera.position(cam).z)
  74. -- for i=1,10 do
  75. -- Camera.move_forward(cam, 1.0);
  76. -- print("@move forward by 1 meter\n")
  77. -- print("x:" .. Camera.position(cam).x)
  78. -- print("y:" .. Camera.position(cam).y)
  79. -- print("z:" .. Camera.position(cam).z)
  80. -- end
  81. -- local vm = Camera.view_matrix(cam)
  82. -- local pm = Camera.projection_matrix(cam)
  83. -- print("@printing view matrix\n")
  84. -- print(Mat4.print(vm))
  85. -- print("@printing projection matrix\n")
  86. -- print(Mat4.print(pm))
  87. --------------------------------------------------------------
  88. --------------------------------------------------------------
  89. --------------------------------------------------------------
  90. print("-- Testing Script --\n")
  91. print(Script.vec3_used())
  92. print(Script.mat4_used())
  93. print(Script.quat_used())