فهرست منبع

Merge branch 'master' of github.com:taylor001/crown

Daniele Bartolini 10 سال پیش
والد
کامیت
2336bf3b4e
2فایلهای تغییر یافته به همراه11 افزوده شده و 0 حذف شده
  1. 3 0
      docs/lua_api.txt
  2. 8 0
      src/lua/lua_math.cpp

+ 3 - 0
docs/lua_api.txt

@@ -255,6 +255,9 @@ Matrix4x4
 	**identity** ()
 		Returns the identity matrix.
 
+	**transform** (m, v) : Vector3
+		Transforms the vector *v* by the matrix *m* and returns the result.
+
 	**to_string** (a)
 		Returns a string representing the matrix.
 

+ 8 - 0
src/lua/lua_math.cpp

@@ -571,6 +571,13 @@ static int matrix4x4_identity(lua_State* L)
 	return 1;
 }
 
+static int matrix4x4_transform(lua_State* L)
+{
+	LuaStack stack(L);
+	stack.push_vector3(stack.get_vector3(2) * stack.get_matrix4x4(1));
+	return 1;
+}
+
 static int matrix4x4_to_string(lua_State* L)
 {
 	LuaStack stack(L);
@@ -966,6 +973,7 @@ void load_math(LuaEnvironment& env)
 	env.load_module_function("Matrix4x4", "rotation",                    matrix4x4_rotation);
 	env.load_module_function("Matrix4x4", "set_rotation",                matrix4x4_set_rotation);
 	env.load_module_function("Matrix4x4", "identity",                    matrix4x4_identity);
+	env.load_module_function("Matrix4x4", "transform",                   matrix4x4_transform);
 	env.load_module_function("Matrix4x4", "to_string",                   matrix4x4_to_string);
 
 	env.load_module_constructor("Matrix4x4", matrix4x4_ctor);