Documentation ¶
Overview ¶
Package Projection provides a 4×4 matrix for 3D projective transformations.
Index ¶
- Variables
- func AspectRatio(p XYZW) Float.X
- func Determinant(p XYZW) Float.X
- func FarPlaneHalfExtents(p XYZW) Vector2.XY
- func FarZ(p XYZW) Float.X
- func FieldOfView(p XYZW) Angle.Degrees
- func Fovy[X Float.Any](hfov Angle.Degrees, aspect X) Angle.Degrees
- func IsOrthogonal(p XYZW) bool
- func LevelOfDetailMultiplier(p XYZW) Float.X
- func NearZ(p XYZW) Float.X
- func PixelsPerMeter(p XYZW, pixel_width int) int
- func Transform(v Vector4.XYZW, p XYZW) Vector4.XYZW
- func ViewportHalfExtents(p XYZW) Vector2.XY
- type ClippingPlane
- type XYZW
- func DepthCorrection(fliy bool) XYZW
- func FitAABB(aabb AABB.PositionSize) XYZW
- func FlippedY(p XYZW) XYZW
- func Frustum[X Float.Any](left, right, bottom, top, z_near, z_far X) XYZW
- func FrustumAspectRatio[X Float.Any](size, aspect X, offset Vector2.XY, z_near, z_far X, flip_fov bool) XYZW
- func HeadMountedDisplay[X Float.Any, I Int.Any](eye I, ...) XYZW
- func HeadMountedDisplayPerspective(fovy Angle.Degrees, aspect, z_near, z_far Float.X, flip_fov bool, eye int, ...) XYZW
- func IntoRect2(rect Rect2.PositionSize) XYZW
- func Inverse(proj XYZW) XYZW
- func JitterOffseted(p XYZW, jitter Vector2.XY) XYZW
- func Mul(a, b XYZW) XYZW
- func New() XYZW
- func Orthogonal[X Float.Any](left, right, bottom, top, z_near, z_far X) XYZW
- func OrthogonalAspectRatio[X Float.Any](size, aspect, z_near, z_far X, flip_fov bool) XYZW
- func Perspective[X Float.Any](fovy Angle.Degrees, aspect, z_near, z_far X, flip_fov bool) XYZW
- func PerspectiveAdjustedNearZ(p XYZW, new_near_z Float.X) XYZW
Constants ¶
This section is empty.
Variables ¶
var ( // Identity projection with no transformation defined. When applied to other data // structures, no transformation is performed. Identity = XYZW{ X: Vector4.XYZW{X: 1, Y: 0, Z: 0, W: 0}, Y: Vector4.XYZW{X: 0, Y: 1, Z: 0, W: 0}, Z: Vector4.XYZW{X: 0, Y: 0, Z: 1, W: 0}, W: Vector4.XYZW{X: 0, Y: 0, Z: 0, W: 1}, } // Zero projection with all values initialized to 0. When applied to other data // structures, they will be zeroed. Zero = XYZW{} )
Functions ¶
func AspectRatio ¶
AspectRatio returns the X:Y aspect ratio of this Projection's viewport.
func Determinant ¶
Determinant returns a scalar value that is the signed factor by which areas are scaled by this matrix. If the sign is negative, the matrix flips the orientation of the area.
The determinant can be used to calculate the invertibility of a matrix or solve linear systems of equations involving the matrix, among other applications.
func FarPlaneHalfExtents ¶
FarPlaneHalfExtents returns the dimensions of the far clipping plane of the projection, divided by two.
func FieldOfView ¶
FieldOfView returns the horizontal field of view of the projection (in degrees).
func Fovy ¶
Fovy returns the vertical field of view of the projection (in degrees) associated with the given horizontal field of view (in degrees) and aspect ratio.
func IsOrthogonal ¶
IsOrthogonal returns true if this Projection performs an orthogonal projection.
func LevelOfDetailMultiplier ¶
LevelOfDetailMultiplier returns the factor by which the visible level of detail is scaled by this Projection.
func PixelsPerMeter ¶
PixelsPerMeter returns the number of pixels with the given pixel width displayed per meter, after this Projection is applied.
func Transform ¶
Transform transforms (multiplies) the [Vector4.XYZW] by the given projection's transformation matrix.
func ViewportHalfExtents ¶
ViewportHalfExtents returns the dimensions of the viewport plane that this Projection projects positions onto, divided by two.
Types ¶
type ClippingPlane ¶
type ClippingPlane int
const ( PlaneNear ClippingPlane = iota PlaneFar PlaneLeft PlaneTop PlaneRight PlaneBottom )
type XYZW ¶
type XYZW = struct { X Vector4.XYZW // The projection matrix's X vector (column 0). Equivalent to array index 0. Y Vector4.XYZW // The projection matrix's Y vector (column 1). Equivalent to array index 1. Z Vector4.XYZW // The projection matrix's Z vector (column 2). Equivalent to array index 2. W Vector4.XYZW // The projection matrix's W vector (column 3). Equivalent to array index 3. }
XYZW is a 4×4 matrix used for 3D projective transformations. It can represent transformations such as translation, rotation, scaling, shearing, and perspective division. It consists of four Vector4 columns.
For purely linear transformations (translation, rotation, and scale), it is recommended to use Transform3D, as it is more performant and requires less memory.
func DepthCorrection ¶
DepthCorrection creates a new Projection that projects positions from a depth range of -1 to 1 to one that ranges from 0 to 1, and flips the projected positions vertically, according to fliy.
func FitAABB ¶
func FitAABB(aabb AABB.PositionSize) XYZW
FitAABB creates a new Projection that scales a given projection to fit around a given AABB in projection space.
func FlippedY ¶
FlippedY returns a copy of this Projection with the signs of the values of the Y column flipped.
func Frustum ¶
Frustum creates a new Projection that projects positions in a frustum with the given clipping planes.
func FrustumAspectRatio ¶
func FrustumAspectRatio[X Float.Any](size, aspect X, offset Vector2.XY, z_near, z_far X, flip_fov bool) XYZW
FrustumAspectRatio creates a new Projection that projects positions in a frustum with the given size, X:Y aspect ratio, offset, and clipping planes.
flip_fov determines whether the projection's field of view is flipped over its diagonal.
func HeadMountedDisplay ¶
func HeadMountedDisplay[X Float.Any, I Int.Any](eye I, aspect, intraocular_dist, display_width, display_to_lens, oversample, z_near, z_far Float.X) XYZW
HeadMountedDisplay creates a new Projection for projecting positions onto a head-mounted display with the given X:Y aspect ratio, distance between eyes, display width, distance to lens, oversampling factor, and depth clipping planes.
eye creates the projection for the left eye when set to 1, or the right eye when set to 2.
func HeadMountedDisplayPerspective ¶
func HeadMountedDisplayPerspective(fovy Angle.Degrees, aspect, z_near, z_far Float.X, flip_fov bool, eye int, intraocular_dist, convergence_dist Float.X) XYZW
HeadMountedDisplayPerspective creates a new Projection that projects positions using a perspective projection with the given Y-axis field of view (in degrees), X:Y aspect ratio, and clipping distances. The projection is adjusted for a head-mounted display with the given distance between eyes and distance to a point that can be focused on.
eye creates the projection for the left eye when set to 1, or the right eye when set to 2.
flip_fov determines whether the projection's field of view is flipped over its diagonal
func IntoRect2 ¶
func IntoRect2(rect Rect2.PositionSize) XYZW
IntoRect2 creates a new Projection that projects positions into the given Rect2.
func Inverse ¶
Inverse returns a Projection that performs the inverse of this Projection's projective transformation.
func JitterOffseted ¶
JitterOffseted returns a Projection with the X and Y values from the given Vector2 added to the first and second values of the final column respectively.
func Orthogonal ¶
Orthogonal creates a new Projection that projects positions using an orthogonal projection with the given clipping planes.
func OrthogonalAspectRatio ¶
OrthogonalAspectRatio creates a new Projection that projects positions using an orthogonal projection with the given size, X:Y aspect ratio, and clipping planes.
flip_fov determines whether the projection's field of view is flipped over its diagonal.
func Perspective ¶
Perspective creates a new Projection that projects positions using a perspective projection with the given Y-axis field of view (in degrees), X:Y aspect ratio, and clipping planes.
flip_fov determines whether the projection's field of view is flipped over its diagonal.