Skip to content

Commit b42f155

Browse files
committed
add doc
1 parent bfb15b3 commit b42f155

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

crates/bevy_render/src/camera/camera.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ impl Default for DepthCalculation {
122122

123123
impl Camera {
124124
/// Given a position in world space, use the camera to compute the screen space coordinates.
125+
///
126+
/// To get the coordinates in Normalized Device Coordinates, you should use
127+
/// [`world_to_ndc`](Self::world_to_ndc).
125128
pub fn world_to_screen(
126129
&self,
127130
windows: &Windows,
@@ -138,14 +141,17 @@ impl Camera {
138141
}
139142

140143
// Once in NDC space, we can discard the z element and rescale x/y to fit the screen
141-
let screen_space_coords = (ndc_space_coords.truncate() + Vec2::ONE) / 2.0 * window_size;
142-
Some(screen_space_coords)
144+
Some((ndc_space_coords.truncate() + Vec2::ONE) / 2.0 * window_size)
143145
} else {
144146
None
145147
}
146148
}
147149

148-
/// Given a position in world space, use the camera to compute the normalized device coordinates.
150+
/// Given a position in world space, use the camera to compute the Normalized Device Coordinates.
151+
///
152+
/// Values returned will be between -1.0 and 1.0 when the position is in screen space.
153+
/// To get the coordinates in the render target dimensions, you should use
154+
/// [`world_to_screen`](Self::world_to_screen).
149155
pub fn world_to_ndc(
150156
&self,
151157
camera_transform: &GlobalTransform,

0 commit comments

Comments
 (0)