diff options
author | Cheeseness <contact@jbushproductions.com> | 2019-05-28 23:14:13 +1000 |
---|---|---|
committer | Cheeseness <contact@jbushproductions.com> | 2019-05-29 02:04:50 +1000 |
commit | 6fe957de63b8ecbd51caf2e6c1bf7efc1d53221c (patch) | |
tree | 0c395e3a29d46fe050ba8cacb26081e3959dad20 /scene/3d/camera.cpp | |
parent | 254286af367e3a9726cd13db11f5fa6de9c92a74 (diff) |
Add a depth parameter to Camera::project_position()
Diffstat (limited to 'scene/3d/camera.cpp')
-rw-r--r-- | scene/3d/camera.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index e360de5b8e..29002c6701 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -391,13 +391,17 @@ Point2 Camera::unproject_position(const Vector3 &p_pos) const { return res; } -Vector3 Camera::project_position(const Point2 &p_point) const { +Vector3 Camera::project_position(const Point2 &p_point, float p_z_depth) const { if (!is_inside_tree()) { ERR_EXPLAIN("Camera is not inside scene."); ERR_FAIL_COND_V(!is_inside_tree(), Vector3()); } + if (p_z_depth == 0) { + return get_global_transform().origin; + } + Size2 viewport_size = get_viewport()->get_visible_rect().size; CameraMatrix cm; @@ -415,7 +419,7 @@ Vector3 Camera::project_position(const Point2 &p_point) const { point.y = (1.0 - (p_point.y / viewport_size.y)) * 2.0 - 1.0; point *= vp_size; - Vector3 p(point.x, point.y, -near); + Vector3 p(point.x, point.y, -p_z_depth); return get_camera_transform().xform(p); } @@ -490,7 +494,7 @@ void Camera::_bind_methods() { ClassDB::bind_method(D_METHOD("project_ray_origin", "screen_point"), &Camera::project_ray_origin); ClassDB::bind_method(D_METHOD("unproject_position", "world_point"), &Camera::unproject_position); ClassDB::bind_method(D_METHOD("is_position_behind", "world_point"), &Camera::is_position_behind); - ClassDB::bind_method(D_METHOD("project_position", "screen_point"), &Camera::project_position); + ClassDB::bind_method(D_METHOD("project_position", "screen_point", "z_depth"), &Camera::project_position, DEFVAL(0)); ClassDB::bind_method(D_METHOD("set_perspective", "fov", "z_near", "z_far"), &Camera::set_perspective); ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera::set_orthogonal); ClassDB::bind_method(D_METHOD("set_frustum", "size", "offset", "z_near", "z_far"), &Camera::set_frustum); |