Przeglądaj źródła

world: fix wrong z-axis values

Daniele Bartolini 4 lat temu
rodzic
commit
623956a988
2 zmienionych plików z 7 dodań i 1 usunięć
  1. 1 0
      docs/changelog.rst
  2. 6 1
      src/world/world.cpp

+ 1 - 0
docs/changelog.rst

@@ -29,6 +29,7 @@ Changelog
 
 * Added ``Math.obb_intersects_frustum()``
 * Removed ``DebugLine.add_unit()``
+* Fixed ``World.camera_screen_to_world()`` returning incorrect z-axis values on Windows/D3D.
 
 0.42.0
 ------

+ 6 - 1
src/world/world.cpp

@@ -436,10 +436,15 @@ Vector3 World::camera_screen_to_world(CameraInstance camera, const Vector3& pos)
 	Matrix4x4 mvp = world_inv * projection;
 	invert(mvp);
 
+	const bgfx::Caps* caps = bgfx::getCaps();
+
 	Vector4 ndc;
 	ndc.x = (2.0f * (pos.x - 0.0f)) / _camera[camera.i].view_width - 1.0f;
 	ndc.y = (2.0f * (_camera[camera.i].view_height - pos.y)) / _camera[camera.i].view_height - 1.0f;
-	ndc.z = (2.0f * pos.z) - 1.0f;
+	ndc.z = caps->homogeneousDepth
+		? (2.0f * pos.z) - 1.0f
+		: pos.z
+		;
 	ndc.w = 1.0f;
 
 	Vector4 tmp = ndc * mvp;