فهرست منبع

Add x, y, z and set_x, set_y, set_z to Mat*

Daniele Bartolini 12 سال پیش
والد
کامیت
d0505669c8
5فایلهای تغییر یافته به همراه218 افزوده شده و 10 حذف شده
  1. 42 0
      engine/core/math/Mat3.cpp
  2. 19 1
      engine/core/math/Mat3.h
  3. 43 1
      engine/core/math/Mat4.cpp
  4. 20 2
      engine/core/math/Mat4.h
  5. 94 6
      engine/lua/Mat4Binds.cpp

+ 42 - 0
engine/core/math/Mat3.cpp

@@ -483,6 +483,48 @@ void Mat3::load_identity()
 	m[1] = m[2] = m[3] = m[5] = m[6] = m[7] = 0.0;
 	m[1] = m[2] = m[3] = m[5] = m[6] = m[7] = 0.0;
 }
 }
 
 
+//-----------------------------------------------------------------------------
+Vec3 Mat3::x() const
+{
+	return Vec3(m[0], m[1], m[2]);
+}
+
+//-----------------------------------------------------------------------------
+Vec3 Mat3::y() const
+{
+	return Vec3(m[3], m[4], m[5]);
+}
+
+//-----------------------------------------------------------------------------
+Vec3 Mat3::z() const
+{
+	return Vec3(m[6], m[7], m[8]);
+}
+
+//-----------------------------------------------------------------------------
+void Mat3::set_x(const Vec3& x)
+{
+	m[0] = x.x;
+	m[1] = x.y;
+	m[2] = x.z;
+}
+
+//-----------------------------------------------------------------------------
+void Mat3::set_y(const Vec3& y)
+{
+	m[3] = y.x;
+	m[4] = y.y;
+	m[5] = y.z;
+}
+
+//-----------------------------------------------------------------------------
+void Mat3::set_z(const Vec3& z)
+{
+	m[6] = z.x;
+	m[7] = z.y;
+	m[8] = z.z;
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 Vec3 Mat3::get_scale() const
 Vec3 Mat3::get_scale() const
 {
 {

+ 19 - 1
engine/core/math/Mat3.h

@@ -120,6 +120,24 @@ public:
 	/// Builds the identity matrix
 	/// Builds the identity matrix
 	void				load_identity();							
 	void				load_identity();							
 
 
+	/// Returns a Vec3 containing the matrix's x base vector.
+	Vec3				x() const;
+
+	/// Returns a Vec3 containing the matrix's y base vector.
+	Vec3				y() const;
+
+	/// Returns a Vec3 containing the matrix's z base vector.
+	Vec3				z() const;
+
+	/// Sets the matrix's x base vector.
+	void				set_x(const Vec3& x);
+
+	/// Sets the matrix's y base vector.
+	void				set_y(const Vec3& y);
+
+	/// Sets the matrix's z base vector.
+	void				set_z(const Vec3& z);
+
 	/// Returns a Vec3 containing the matrix's scale portion
 	/// Returns a Vec3 containing the matrix's scale portion
 	Vec3				get_scale() const;	
 	Vec3				get_scale() const;	
 
 
@@ -130,7 +148,7 @@ public:
 	float*				to_float_ptr();				
 	float*				to_float_ptr();				
 
 
 	/// Returns the pointer to the matrix's data				
 	/// Returns the pointer to the matrix's data				
-	const float*			to_float_ptr() const;
+	const float*		to_float_ptr() const;
 
 
 	/// Returns a 4x4 matrix according to the matrix's rotation portion						
 	/// Returns a 4x4 matrix according to the matrix's rotation portion						
 	Mat4				to_mat4() const;
 	Mat4				to_mat4() const;

+ 43 - 1
engine/core/math/Mat4.cpp

@@ -908,7 +908,49 @@ void Mat4::load_identity()
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-Vec3 Mat4::get_translation() const
+Vec3 Mat4::x() const
+{
+	return Vec3(m[0], m[1], m[2]);
+}
+
+//-----------------------------------------------------------------------------
+Vec3 Mat4::y() const
+{
+	return Vec3(m[4], m[5], m[6]);
+}
+
+//-----------------------------------------------------------------------------
+Vec3 Mat4::z() const
+{
+	return Vec3(m[8], m[9], m[10]);
+}
+
+//-----------------------------------------------------------------------------
+void Mat4::set_x(const Vec3& x)
+{
+	m[0] = x.x;
+	m[1] = x.y;
+	m[2] = x.z;
+}
+
+//-----------------------------------------------------------------------------
+void Mat4::set_y(const Vec3& y)
+{
+	m[4] = y.x;
+	m[5] = y.y;
+	m[6] = y.z;
+}
+
+//-----------------------------------------------------------------------------
+void Mat4::set_z(const Vec3& z)
+{
+	m[8] = z.x;
+	m[9] = z.y;
+	m[10] = z.z;
+}
+
+//-----------------------------------------------------------------------------
+Vec3 Mat4::translation() const
 {
 {
 	Vec3 tmp;
 	Vec3 tmp;
 
 

+ 20 - 2
engine/core/math/Mat4.h

@@ -150,8 +150,26 @@ public:
 	/// Builds the identity matrix
 	/// Builds the identity matrix
 	void				load_identity();							
 	void				load_identity();							
 
 
+	/// Returns a Vec3 containing the matrix's x base vector.
+	Vec3				x() const;
+
+	/// Returns a Vec3 containing the matrix's y base vector.
+	Vec3				y() const;
+
+	/// Returns a Vec3 containing the matrix's z base vector.
+	Vec3				z() const;
+
+	/// Sets the matrix's x base vector.
+	void				set_x(const Vec3& x);
+
+	/// Sets the matrix's y base vector.
+	void				set_y(const Vec3& y);
+
+	/// Sets the matrix's z base vector.
+	void				set_z(const Vec3& z);
+
 	/// Returns a Vec3 containing the matrix's translation portion
 	/// Returns a Vec3 containing the matrix's translation portion
-	Vec3				get_translation() const;	
+	Vec3				translation() const;	
 
 
 	/// Fills the matrix's translation portion values contained in @a trans				
 	/// Fills the matrix's translation portion values contained in @a trans				
 	void				set_translation(const Vec3& trans);			
 	void				set_translation(const Vec3& trans);			
@@ -166,7 +184,7 @@ public:
 	float*				to_float_ptr();
 	float*				to_float_ptr();
 
 
 	/// Returns the pointer to the matrix's data								
 	/// Returns the pointer to the matrix's data								
-	const float*			to_float_ptr() const;
+	const float*		to_float_ptr() const;
 
 
 	/// Returns a 3x3 matrix according to the matrix's rotation portion						
 	/// Returns a 3x3 matrix according to the matrix's rotation portion						
 	Mat3				to_mat3() const;
 	Mat3				to_mat3() const;

+ 94 - 6
engine/lua/Mat4Binds.cpp

@@ -386,14 +386,98 @@ CE_EXPORT int32_t mat4_load_identity(lua_State* L)
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-CE_EXPORT int32_t mat4_get_translation(lua_State* L)
+CE_EXPORT int32_t mat4_x(lua_State* L)
+{	
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	Vec3* x = next_vec3();
+	*x = a->x();
+
+	stack.push_vec3(x);
+
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int32_t mat4_y(lua_State* L)
+{	
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	Vec3* y = next_vec3();
+	*y = a->y();
+
+	stack.push_vec3(y);
+
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int32_t mat4_z(lua_State* L)
+{	
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	Vec3* z = next_vec3();
+	*z = a->z();
+
+	stack.push_vec3(z);
+
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int32_t mat4_set_x(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Vec3* x = stack.get_vec3(2);
+
+	a->set_x(*x);
+
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int32_t mat4_set_y(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Vec3* y = stack.get_vec3(2);
+
+	a->set_y(*y);
+
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int32_t mat4_set_z(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Vec3* z = stack.get_vec3(2);
+
+	a->set_z(*z);
+
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int32_t mat4_translation(lua_State* L)
 {	
 {	
 	LuaStack stack(L);
 	LuaStack stack(L);
 
 
 	Mat4* a = stack.get_mat4(1);
 	Mat4* a = stack.get_mat4(1);
 
 
 	Vec3* translation = next_vec3();
 	Vec3* translation = next_vec3();
-	*translation = a->get_translation();
+	*translation = a->translation();
 
 
 	stack.push_vec3(translation);
 	stack.push_vec3(translation);
 
 
@@ -482,13 +566,17 @@ void load_mat4(LuaEnvironment& env)
 	env.load_module_function("Mat4", "determinant", 					mat4_determinant);
 	env.load_module_function("Mat4", "determinant", 					mat4_determinant);
 	env.load_module_function("Mat4", "invert", 							mat4_invert);
 	env.load_module_function("Mat4", "invert", 							mat4_invert);
 	env.load_module_function("Mat4", "load_identity", 					mat4_load_identity);
 	env.load_module_function("Mat4", "load_identity", 					mat4_load_identity);
-	env.load_module_function("Mat4", "get_translation", 				mat4_get_translation);
+	env.load_module_function("Mat4", "x",								mat4_x);
+	env.load_module_function("Mat4", "y",								mat4_y);
+	env.load_module_function("Mat4", "z",								mat4_z);
+	env.load_module_function("Mat4", "set_x",							mat4_set_x);
+	env.load_module_function("Mat4", "set_y",							mat4_set_y);
+	env.load_module_function("Mat4", "set_z",							mat4_set_z);
+	env.load_module_function("Mat4", "translation", 					mat4_translation);
 	env.load_module_function("Mat4", "set_translation", 				mat4_set_translation);
 	env.load_module_function("Mat4", "set_translation", 				mat4_set_translation);
 	env.load_module_function("Mat4", "get_scale", 						mat4_get_scale);
 	env.load_module_function("Mat4", "get_scale", 						mat4_get_scale);
 	env.load_module_function("Mat4", "set_scale", 						mat4_set_scale);
 	env.load_module_function("Mat4", "set_scale", 						mat4_set_scale);
 	env.load_module_function("Mat4", "print", 							mat4_print);
 	env.load_module_function("Mat4", "print", 							mat4_print);
-
 }
 }
 
 
-
-} //namespace crown
+} //namespace crown