Prechádzať zdrojové kódy

init.lua implemented

mikymod 12 rokov pred
rodič
commit
c95ed883de
2 zmenil súbory, kde vykonal 98 pridanie a 0 odobranie
  1. 14 0
      game/lua/init.lua
  2. 84 0
      src/binds/QuatBind.cpp

+ 14 - 0
game/lua/init.lua

@@ -0,0 +1,14 @@
+require("vec3")
+require("quat")
+
+local ffi = require("ffi")
+
+local lib_path = os.getenv("LD_LIBRARY_PATH")
+
+lib = ffi.load(lib_path .. "libcrown.so", true)
+
+local v = lib.vec3(1.0, 1.0, 1.0)
+local q = lib.quat(10.0, v)
+
+print(q.w)
+print(q.v.x)

+ 84 - 0
src/binds/QuatBind.cpp

@@ -0,0 +1,84 @@
+#include "Quat.h"
+
+namespace crown
+{
+
+/// Lightweight bind for Quat
+
+extern "C"
+{
+	Quat*		quat(float angle, const Vec3* v);
+
+	void		quat_negate(Quat* self);
+
+	void		quat_load_identity(Quat* self);
+
+	float		quat_length(Quat* self);	
+
+	void		quat_conjugate(Quat* self);
+
+	Quat*		quat_inverse(Quat* self);			
+
+	Quat*		quat_cross(Quat* self, const Quat* b);
+
+	Quat*		quat_multiply(Quat* self, const float& k);
+
+	Quat*		quat_power(Quat* self, float exp);
+
+	// Mat4		quat_to_mat4(Quat* self);
+}
+
+Quat* quat(float angle, const Vec3* v)
+{
+	return new Quat(angle, *v);
+}
+
+void quat_negate(Quat* self)
+{
+	self->negate();
+}
+
+void quat_load_identity(Quat* self)
+{
+	self->load_identity();
+}
+
+float quat_length(Quat* self)
+{
+	return self->length();
+}
+
+void quat_conjugate(Quat* self)
+{
+	self->conjugate();
+}
+
+Quat* quat_inverse(Quat* self)
+{
+	Quat tmp = self->get_inverse();
+
+	return new Quat(tmp.w, tmp.v);
+}
+
+Quat* quat_cross(Quat* self, const Quat* b)
+{
+	*self = *self * (*b);
+
+	return self;
+}
+
+Quat* quat_multiply(Quat* self, const float& k)
+{
+	*self = *self * k;
+
+	return self;
+}
+
+Quat* quat_power(Quat* self, float exp)
+{
+	self->power(exp);
+
+	return self;
+}
+
+} //namespace crown