Răsfoiți Sursa

Add ability to specify left/right bottom/top limits to orthographic projection matrix

Daniele Bartolini 12 ani în urmă
părinte
comite
5baa62f3a1

+ 7 - 7
engine/core/math/Matrix4x4.cpp

@@ -607,23 +607,23 @@ void Matrix4x4::build_projection_perspective_lh(float fovy, float aspect, float
 }
 
 //-----------------------------------------------------------------------------
-void Matrix4x4::build_projection_ortho_rh(float width, float height, float near, float far)
+void Matrix4x4::build_projection_ortho_rh(float left, float right, float bottom, float top, float near, float far)
 {
-	m[0] = (float)2.0 / width;
+	m[0] = 2.0 / (right - left);
 	m[1] = 0.0;
 	m[2] = 0.0;
 	m[3] = 0.0;
 	m[4] = 0.0;
-	m[5] = (float)2.0 / height;
+	m[5] = 2.0 / (top - bottom);
 	m[6] = 0.0;
 	m[7] = 0.0;
 	m[8] = 0.0;
 	m[9] = 0.0;
-	m[10] = (float)2 / (near - far);
+	m[10] = -2.0 / (far - near);
 	m[11] = 0.0;
-	m[12] = 0.0;
-	m[13] = 0.0;
-	m[14] = (far + near) / (near - far);
+	m[12] = -((right + left) / (right - left));
+	m[13] = -((top + bottom) / (top - bottom));
+	m[14] = -((far + near) / (far - near));
 	m[15] = 1.0;
 }
 

+ 1 - 1
engine/core/math/Matrix4x4.h

@@ -127,7 +127,7 @@ public:
 	void				build_projection_perspective_lh(float fovy, float aspect, float near, float far);
 
 	/// Builds an orthographic projection matrix suited to Right-Handed coordinate systems	
-	void				build_projection_ortho_rh(float width, float height, float near, float far);
+	void				build_projection_ortho_rh(float left, float right, float bottom, float top, float near, float far);
 
 	/// Builds an orthographic projection matrix suited to Left-Handed coordinate systems		
 	void				build_projection_ortho_lh(float width, float height, float near, float far);	

+ 0 - 85
engine/lua/LuaMatrix4x4.cpp

@@ -178,86 +178,6 @@ CE_EXPORT int matrix4x4_build_rotation(lua_State* L)
 	return 0;
 }
 
-//-----------------------------------------------------------------------------
-CE_EXPORT int matrix4x4_build_projection_perspective_rh(lua_State* L)
-{
-	LuaStack stack(L);
-
-	Matrix4x4& a = stack.get_matrix4x4(1);
-	float fovy = stack.get_float(2);
-	float aspect = stack.get_float(3);
-	float near = stack.get_float(4);
-	float far = stack.get_float(5);
-
-	a.build_projection_perspective_rh(fovy, aspect, near, far);
-
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int matrix4x4_build_projection_perspective_lh(lua_State* L)
-{
-	LuaStack stack(L);
-
-	Matrix4x4& a = stack.get_matrix4x4(1);
-	float fovy = stack.get_float(2);
-	float aspect = stack.get_float(3);
-	float near = stack.get_float(4);
-	float far = stack.get_float(5);
-
-	a.build_projection_perspective_lh(fovy, aspect, near, far);
-
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int matrix4x4_build_projection_ortho_rh(lua_State* L)
-{
-	LuaStack stack(L);
-
-	Matrix4x4& a = stack.get_matrix4x4(1);
-	float width = stack.get_float(2);
-	float height = stack.get_float(3);
-	float near = stack.get_float(4);
-	float far = stack.get_float(5);
-
-	a.build_projection_ortho_rh(width, height, near, far);
-
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int matrix4x4_build_projection_ortho_lh(lua_State* L)
-{
-	LuaStack stack(L);
-
-	Matrix4x4& a = stack.get_matrix4x4(1);
-	float width = stack.get_float(2);
-	float height = stack.get_float(3);
-	float near = stack.get_float(4);
-	float far = stack.get_float(5);
-
-	a.build_projection_ortho_lh(width, height, near, far);
-
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int matrix4x4_build_projection_ortho_2d_rh(lua_State* L)
-{
-	LuaStack stack(L);
-
-	Matrix4x4& a = stack.get_matrix4x4(1);
-	float width = stack.get_float(2);
-	float height = stack.get_float(3);
-	float near = stack.get_float(4);
-	float far = stack.get_float(5);
-
-	a.build_projection_ortho_2d_rh(width, height, near, far);
-
-	return 0;
-}
-
 //-----------------------------------------------------------------------------
 CE_EXPORT int matrix4x4_build_look_at_rh(lua_State* L)
 {
@@ -519,11 +439,6 @@ void load_matrix4x4(LuaEnvironment& env)
 	env.load_module_function("Matrix4x4", "build_rotation_y", 				matrix4x4_build_rotation_y);
 	env.load_module_function("Matrix4x4", "build_rotation_z", 				matrix4x4_build_rotation_z);
 	env.load_module_function("Matrix4x4", "build_rotation", 				matrix4x4_build_rotation);
-	env.load_module_function("Matrix4x4", "build_projection_perspective_rh", matrix4x4_build_projection_perspective_rh);
-	env.load_module_function("Matrix4x4", "build_projection_perspective_lh", matrix4x4_build_projection_perspective_lh);
-	env.load_module_function("Matrix4x4", "build_projection_ortho_rh", 		matrix4x4_build_projection_ortho_rh);
-	env.load_module_function("Matrix4x4", "build_projection_ortho_lh", 		matrix4x4_build_projection_ortho_lh);
-	env.load_module_function("Matrix4x4", "build_projection_ortho_2d_rh", 	matrix4x4_build_projection_ortho_2d_rh);
 	env.load_module_function("Matrix4x4", "build_look_at_rh", 				matrix4x4_build_look_at_rh);
 	env.load_module_function("Matrix4x4", "build_look_at_lh", 				matrix4x4_build_look_at_rh);
 	env.load_module_function("Matrix4x4", "build_viewpoint_billboard", 		matrix4x4_build_viewpoint_billboard);