Skip to content

ndc_to_world seems to have wrong output range in documentation #16809

Open
@jwir3

Description

How can Bevy's documentation be improved?

Inside of bevy_render/src/camera/camera.rs, the following documentation for ndc_to_world states:

    /// Given a position in Normalized Device Coordinates,
    /// use the camera's viewport to compute the world space position.
    ///
    /// When the position is within the viewport the values returned will be between -1.0 and 1.0 on the X and Y axes,
    /// and between 0.0 and 1.0 on the Z axis.
    /// To get the world space coordinates with the viewport position, you should use
    /// [`world_to_viewport`](Self::world_to_viewport).
    ///
    /// Returns `None` if the `camera_transform`, the `world_position`, or the projection matrix defined by [`CameraProjection`] contain `NAN`.
    ///
    /// # Panics
    ///
    /// Will panic if the projection matrix is invalid (has a determinant of 0) and `glam_assert` is enabled.

I believe this should state:

    /// When the position is within the viewport the values returned will be between `-world_max_width/2.0` and `world_max_width/2.0` on the X axis, `-world_max_height/2.0` and `world_max_height/2.0` on the Y axis, and between `0.0` and `world_max_depth` on the Z axis.
    /// where `world_max_width` is the maximum world width, `world_max_height` is the maximum world width, and `world_max_depth`
    /// is the maximum depth, in units (by default, pixels) defined by the user. 

For reference, when running the above code in my world, I can definitely get it to be outside the -1.0 to 1.0 bounds. It seems like this is an input constraint, not an output constraint, though I wanted to be sure before I posted a PR.

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-DocsAn addition or correction to our documentationD-TrivialNice and easy! A great choice to get started with BevyS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions