Преглед изворни кода

Replace camera_set_orthographic_metrics() with camera_set_orthographic_size()

Daniele Bartolini пре 8 година
родитељ
комит
2085f824a0
4 измењених фајлова са 16 додато и 22 уклоњено
  1. 3 2
      docs/lua_api.rst
  2. 3 4
      src/lua/lua_api.cpp
  3. 6 10
      src/world/world.cpp
  4. 4 6
      src/world/world.h

+ 3 - 2
docs/lua_api.rst

@@ -484,8 +484,9 @@ Camera
 **camera_set_far_clip_distance** (world, unit, far)
 **camera_set_far_clip_distance** (world, unit, far)
 	Sets the far clip distance of the camera.
 	Sets the far clip distance of the camera.
 
 
-**camera_set_orthographic_metrics** (world, unit, left, right, bottom, top)
-	Sets the coordinates for orthographic clipping planes. (Orthographic projection only.)
+**camera_set_orthographic_size** (world, unit, half_size)
+	Sets the vertical *half_size* of the orthographic view volume.
+	The horizontal size is proportional to the viewport's aspect ratio.
 
 
 **camera_screen_to_world** (world, unit, pos) : Vector3
 **camera_screen_to_world** (world, unit, pos) : Vector3
 	Returns *pos* from screen-space to world-space coordinates.
 	Returns *pos* from screen-space to world-space coordinates.

+ 3 - 4
src/lua/lua_api.cpp

@@ -1442,11 +1442,10 @@ static int world_camera_set_far_clip_distance(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-static int world_camera_set_orthographic_metrics(lua_State* L)
+static int world_camera_set_orthographic_size(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
-	stack.get_world(1)->camera_set_orthographic_metrics(stack.get_unit(2), stack.get_float(3), stack.get_float(4),
-		stack.get_float(5), stack.get_float(6));
+	stack.get_world(1)->camera_set_orthographic_size(stack.get_unit(2), stack.get_float(3));
 	return 0;
 	return 0;
 }
 }
 
 
@@ -3353,7 +3352,7 @@ void load_api(LuaEnvironment& env)
 	env.add_module_function("World", "camera_set_near_clip_distance",   world_camera_set_near_clip_distance);
 	env.add_module_function("World", "camera_set_near_clip_distance",   world_camera_set_near_clip_distance);
 	env.add_module_function("World", "camera_far_clip_distance",        world_camera_far_clip_distance);
 	env.add_module_function("World", "camera_far_clip_distance",        world_camera_far_clip_distance);
 	env.add_module_function("World", "camera_set_far_clip_distance",    world_camera_set_far_clip_distance);
 	env.add_module_function("World", "camera_set_far_clip_distance",    world_camera_set_far_clip_distance);
-	env.add_module_function("World", "camera_set_orthographic_metrics", world_camera_set_orthographic_metrics);
+	env.add_module_function("World", "camera_set_orthographic_size",    world_camera_set_orthographic_size);
 	env.add_module_function("World", "camera_screen_to_world",          world_camera_screen_to_world);
 	env.add_module_function("World", "camera_screen_to_world",          world_camera_screen_to_world);
 	env.add_module_function("World", "camera_world_to_screen",          world_camera_world_to_screen);
 	env.add_module_function("World", "camera_world_to_screen",          world_camera_world_to_screen);
 	env.add_module_function("World", "update_animations",               world_update_animations);
 	env.add_module_function("World", "update_animations",               world_update_animations);

+ 6 - 10
src/world/world.cpp

@@ -257,10 +257,10 @@ Matrix4x4 World::camera_projection_matrix(UnitId unit)
 	{
 	{
 	case ProjectionType::ORTHOGRAPHIC:
 	case ProjectionType::ORTHOGRAPHIC:
 		orthographic(projection
 		orthographic(projection
-			, cam.left
-			, cam.right
-			, cam.bottom
-			, cam.top
+			, -cam.half_size * cam.aspect
+			, cam.half_size * cam.aspect
+			, -cam.half_size
+			, cam.half_size
 			, cam.near_range
 			, cam.near_range
 			, cam.far_range
 			, cam.far_range
 			);
 			);
@@ -333,14 +333,10 @@ void World::camera_set_far_clip_distance(UnitId unit, f32 far)
 	_camera[i.i].far_range = far;
 	_camera[i.i].far_range = far;
 }
 }
 
 
-void World::camera_set_orthographic_metrics(UnitId unit, f32 left, f32 right, f32 bottom, f32 top)
+void World::camera_set_orthographic_size(UnitId unit, f32 half_size)
 {
 {
 	CameraInstance i = camera_instances(unit);
 	CameraInstance i = camera_instances(unit);
-	_camera[i.i].left = left;
-	_camera[i.i].right = right;
-	_camera[i.i].bottom = bottom;
-	_camera[i.i].top = top;
-
+	_camera[i.i].half_size = half_size;
 }
 }
 
 
 void World::camera_set_viewport_metrics(UnitId unit, u16 x, u16 y, u16 width, u16 height)
 void World::camera_set_viewport_metrics(UnitId unit, u16 x, u16 y, u16 width, u16 height)

+ 4 - 6
src/world/world.h

@@ -33,10 +33,7 @@ struct World
 		f32 far_range;
 		f32 far_range;
 
 
 		// Orthographic projection only
 		// Orthographic projection only
-		f32 left;
-		f32 right;
-		f32 bottom;
-		f32 top;
+		f32 half_size;
 
 
 		u16 view_x;
 		u16 view_x;
 		u16 view_y;
 		u16 view_y;
@@ -131,8 +128,9 @@ public:
 	/// Sets the far clip distance of the camera.
 	/// Sets the far clip distance of the camera.
 	void camera_set_far_clip_distance(UnitId unit, f32 far);
 	void camera_set_far_clip_distance(UnitId unit, f32 far);
 
 
-	/// Sets the coordinates for orthographic clipping planes. (Orthographic projection only.)
-	void camera_set_orthographic_metrics(UnitId unit, f32 left, f32 right, f32 bottom, f32 top);
+	/// Sets the vertical *half_size* of the orthographic view volume.
+	/// The horizontal size is proportional to the viewport's aspect ratio.
+	void camera_set_orthographic_size(UnitId unit, f32 half_size);
 
 
 	/// Sets the coordinates for the camera viewport in pixels.
 	/// Sets the coordinates for the camera viewport in pixels.
 	void camera_set_viewport_metrics(UnitId unit, u16 x, u16 y, u16 width, u16 height);
 	void camera_set_viewport_metrics(UnitId unit, u16 x, u16 y, u16 width, u16 height);