init.lua 3.3 KB

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