h-raylib-5.5.2.0: Raylib bindings for Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Raylib.Util.Math

Description

Bindings to raymath

These were rewritten in Haskell instead of binding to C. All the functions are pure. This may not be an exact one-to-one mapping to the C code; some of the functions and high-level structures have been changed to be more idiomatic Haskell.

Synopsis

Utility constants

Float math

clamp Source #

Arguments

:: Float

Lower bound

-> Float

Upper bound

-> Float

Value to clamp

-> Float 

Clamp float to range (WARNING: this does not use the same argument order as raymath)

lerp Source #

Arguments

:: Float

Starting value

-> Float

Ending value

-> Float

Lerp amount

-> Float 

Calculate linear interpolation between two floats

normalize Source #

Arguments

:: Float

Starting value of range

-> Float

Ending value of range

-> Float

Value to normalize

-> Float 

Normalize input value within input range

remap Source #

Arguments

:: Float

Input range start

-> Float

Input range end

-> Float

Output range start

-> Float

Output range end

-> Float

Input value

-> Float 

Remap input value within input range to output range

wrap Source #

Arguments

:: Float

Min value

-> Float

Max value

-> Float

Input value

-> Float 

Wrap input value from min to max

floatEquals :: Float -> Float -> Bool Source #

Check if two floats are close to equal

Vector math

class Vector a where Source #

Minimal complete definition

asList, fromList, foldlV, foldrV, mapV, zipWithV, zipWithV3, constant

Methods

asList :: a -> [Float] Source #

List representation of a vector

fromList :: [Float] -> a Source #

Vector representation of a list

foldlV :: (b -> Float -> b) -> b -> a -> b Source #

Left fold over a vector

foldrV :: (Float -> b -> b) -> b -> a -> b Source #

Right fold over a vector

mapV :: (Float -> Float) -> a -> a Source #

Map over a vector

zipWithV :: (Float -> Float -> Float) -> a -> a -> a Source #

Equivalent of zipWith over a vector

zipWithV3 :: (Float -> Float -> Float -> Float) -> a -> a -> a -> a Source #

Equivalent of zipWith3 over a vector

(|+|) :: a -> a -> a Source #

Vector-vector addition

(|-|) :: a -> a -> a Source #

Vector-vector subtraction

(|+) :: a -> Float -> a Source #

Vector-scalar addition

(|-) :: a -> Float -> a Source #

Vector-scalar subtraction

(|*|) :: a -> a -> a Source #

Vector-vector multiplication

(|/|) :: a -> a -> a Source #

Vector-vector division

(|*) :: a -> Float -> a Source #

Vector-scalar multiplication

(|/) :: a -> Float -> a Source #

Vector-scalar division

(|.|) :: a -> a -> Float Source #

Vector-vector dot product

zero :: a Source #

Zero vector

one :: a Source #

One vector

constant :: Float -> a Source #

Scalar to vector (all elements are set to the scalar)

vectorSum :: Foldable t => t a -> a Source #

Sum of all vectors in a structure

additiveInverse :: a -> a Source #

Vector additive inverse

multiplicativeInverse :: a -> a Source #

Vector multiplicative inverse

magnitudeSqr :: a -> Float Source #

Squared magnitude of a vector

magnitude :: a -> Float Source #

Vector magnitude

vectorDistanceSqr :: a -> a -> Float Source #

Squared distance between two vectors

vectorDistance :: a -> a -> Float Source #

Distance between two vectors

vectorNormalize :: a -> a Source #

Normalize vector (same direction, magnitude 1)

vectorLerp :: a -> a -> Float -> a Source #

Lerp between two vectors

vectorMoveTowards Source #

Arguments

:: a

Vector to move

-> a

Target vector

-> Float

Max distance to move by

-> a 

Move vector towards target

vectorClamp Source #

Arguments

:: a

Vector to clamp

-> a

Lower bound

-> a

Upper bound

-> a 

Clamp vector to range

vectorClampValue Source #

Arguments

:: a

Vector to clamp

-> Float

Lower bound

-> Float

Upper bound

-> a 

Clamp the magnitude of a vector to a range

vectorMin :: a -> a -> a Source #

Min value for each pair of components

vectorMax :: a -> a -> a Source #

Max value for each pair of components

Instances

Instances details
Vector Vector2 Source # 
Instance details

Defined in Raylib.Util.Math

Methods

asList :: Vector2 -> [Float] Source #

fromList :: [Float] -> Vector2 Source #

foldlV :: (b -> Float -> b) -> b -> Vector2 -> b Source #

foldrV :: (Float -> b -> b) -> b -> Vector2 -> b Source #

mapV :: (Float -> Float) -> Vector2 -> Vector2 Source #

zipWithV :: (Float -> Float -> Float) -> Vector2 -> Vector2 -> Vector2 Source #

zipWithV3 :: (Float -> Float -> Float -> Float) -> Vector2 -> Vector2 -> Vector2 -> Vector2 Source #

(|+|) :: Vector2 -> Vector2 -> Vector2 Source #

(|-|) :: Vector2 -> Vector2 -> Vector2 Source #

(|+) :: Vector2 -> Float -> Vector2 Source #

(|-) :: Vector2 -> Float -> Vector2 Source #

(|*|) :: Vector2 -> Vector2 -> Vector2 Source #

(|/|) :: Vector2 -> Vector2 -> Vector2 Source #

(|*) :: Vector2 -> Float -> Vector2 Source #

(|/) :: Vector2 -> Float -> Vector2 Source #

(|.|) :: Vector2 -> Vector2 -> Float Source #

zero :: Vector2 Source #

one :: Vector2 Source #

constant :: Float -> Vector2 Source #

vectorSum :: Foldable t => t Vector2 -> Vector2 Source #

additiveInverse :: Vector2 -> Vector2 Source #

multiplicativeInverse :: Vector2 -> Vector2 Source #

magnitudeSqr :: Vector2 -> Float Source #

magnitude :: Vector2 -> Float Source #

vectorDistanceSqr :: Vector2 -> Vector2 -> Float Source #

vectorDistance :: Vector2 -> Vector2 -> Float Source #

vectorNormalize :: Vector2 -> Vector2 Source #

vectorLerp :: Vector2 -> Vector2 -> Float -> Vector2 Source #

vectorMoveTowards :: Vector2 -> Vector2 -> Float -> Vector2 Source #

vectorClamp :: Vector2 -> Vector2 -> Vector2 -> Vector2 Source #

vectorClampValue :: Vector2 -> Float -> Float -> Vector2 Source #

vectorMin :: Vector2 -> Vector2 -> Vector2 Source #

vectorMax :: Vector2 -> Vector2 -> Vector2 Source #

Vector Vector3 Source # 
Instance details

Defined in Raylib.Util.Math

Methods

asList :: Vector3 -> [Float] Source #

fromList :: [Float] -> Vector3 Source #

foldlV :: (b -> Float -> b) -> b -> Vector3 -> b Source #

foldrV :: (Float -> b -> b) -> b -> Vector3 -> b Source #

mapV :: (Float -> Float) -> Vector3 -> Vector3 Source #

zipWithV :: (Float -> Float -> Float) -> Vector3 -> Vector3 -> Vector3 Source #

zipWithV3 :: (Float -> Float -> Float -> Float) -> Vector3 -> Vector3 -> Vector3 -> Vector3 Source #

(|+|) :: Vector3 -> Vector3 -> Vector3 Source #

(|-|) :: Vector3 -> Vector3 -> Vector3 Source #

(|+) :: Vector3 -> Float -> Vector3 Source #

(|-) :: Vector3 -> Float -> Vector3 Source #

(|*|) :: Vector3 -> Vector3 -> Vector3 Source #

(|/|) :: Vector3 -> Vector3 -> Vector3 Source #

(|*) :: Vector3 -> Float -> Vector3 Source #

(|/) :: Vector3 -> Float -> Vector3 Source #

(|.|) :: Vector3 -> Vector3 -> Float Source #

zero :: Vector3 Source #

one :: Vector3 Source #

constant :: Float -> Vector3 Source #

vectorSum :: Foldable t => t Vector3 -> Vector3 Source #

additiveInverse :: Vector3 -> Vector3 Source #

multiplicativeInverse :: Vector3 -> Vector3 Source #

magnitudeSqr :: Vector3 -> Float Source #

magnitude :: Vector3 -> Float Source #

vectorDistanceSqr :: Vector3 -> Vector3 -> Float Source #

vectorDistance :: Vector3 -> Vector3 -> Float Source #

vectorNormalize :: Vector3 -> Vector3 Source #

vectorLerp :: Vector3 -> Vector3 -> Float -> Vector3 Source #

vectorMoveTowards :: Vector3 -> Vector3 -> Float -> Vector3 Source #

vectorClamp :: Vector3 -> Vector3 -> Vector3 -> Vector3 Source #

vectorClampValue :: Vector3 -> Float -> Float -> Vector3 Source #

vectorMin :: Vector3 -> Vector3 -> Vector3 Source #

vectorMax :: Vector3 -> Vector3 -> Vector3 Source #

Vector Vector4 Source # 
Instance details

Defined in Raylib.Util.Math

Methods

asList :: Vector4 -> [Float] Source #

fromList :: [Float] -> Vector4 Source #

foldlV :: (b -> Float -> b) -> b -> Vector4 -> b Source #

foldrV :: (Float -> b -> b) -> b -> Vector4 -> b Source #

mapV :: (Float -> Float) -> Vector4 -> Vector4 Source #

zipWithV :: (Float -> Float -> Float) -> Vector4 -> Vector4 -> Vector4 Source #

zipWithV3 :: (Float -> Float -> Float -> Float) -> Vector4 -> Vector4 -> Vector4 -> Vector4 Source #

(|+|) :: Vector4 -> Vector4 -> Vector4 Source #

(|-|) :: Vector4 -> Vector4 -> Vector4 Source #

(|+) :: Vector4 -> Float -> Vector4 Source #

(|-) :: Vector4 -> Float -> Vector4 Source #

(|*|) :: Vector4 -> Vector4 -> Vector4 Source #

(|/|) :: Vector4 -> Vector4 -> Vector4 Source #

(|*) :: Vector4 -> Float -> Vector4 Source #

(|/) :: Vector4 -> Float -> Vector4 Source #

(|.|) :: Vector4 -> Vector4 -> Float Source #

zero :: Vector4 Source #

one :: Vector4 Source #

constant :: Float -> Vector4 Source #

vectorSum :: Foldable t => t Vector4 -> Vector4 Source #

additiveInverse :: Vector4 -> Vector4 Source #

multiplicativeInverse :: Vector4 -> Vector4 Source #

magnitudeSqr :: Vector4 -> Float Source #

magnitude :: Vector4 -> Float Source #

vectorDistanceSqr :: Vector4 -> Vector4 -> Float Source #

vectorDistance :: Vector4 -> Vector4 -> Float Source #

vectorNormalize :: Vector4 -> Vector4 Source #

vectorLerp :: Vector4 -> Vector4 -> Float -> Vector4 Source #

vectorMoveTowards :: Vector4 -> Vector4 -> Float -> Vector4 Source #

vectorClamp :: Vector4 -> Vector4 -> Vector4 -> Vector4 Source #

vectorClampValue :: Vector4 -> Float -> Float -> Vector4 Source #

vectorMin :: Vector4 -> Vector4 -> Vector4 Source #

vectorMax :: Vector4 -> Vector4 -> Vector4 Source #

Vector2 math

vector2Angle :: Vector2 -> Vector2 -> Float Source #

Angle between two 2D vectors

vector2LineAngle :: Vector2 -> Vector2 -> Float Source #

Angle created by the line between two 2D vectors (parameters must be normalized)

vector2Transform :: Vector2 -> Matrix -> Vector2 Source #

Transform a 2D vector by the given matrix

vector2Reflect Source #

Arguments

:: Vector2

Input vector

-> Vector2

Normal vector

-> Vector2 

Reflect 2D vector to normal

vector2Rotate :: Vector2 -> Float -> Vector2 Source #

Rotate 2D vector by angle

vector2Refract Source #

Arguments

:: Vector2

Normalized direction of the incoming ray

-> Vector2

Normalized normal vector of the interface of two optical media

-> Float

Ratio of the refractive index of the medium from where the ray comes to the refractive index of the medium on the other side of the surface

-> Vector2 

Compute the direction of a refracted ray

Vector3 math

vector3CrossProduct :: Vector3 -> Vector3 -> Vector3 Source #

3D vector cross-product

vector3Perpendicular :: Vector3 -> Vector3 Source #

Perpendicular to given 3D vector

vector3Angle :: Vector3 -> Vector3 -> Float Source #

Angle between two 3D vectors

vector3OrthoNormalize :: Vector3 -> Vector3 -> (Vector3, Vector3) Source #

Orthonormalize provided vectors. Makes vectors normalized and orthogonal to each other. Gram-Schmidt function implementation.

vector3Transform :: Vector3 -> Matrix -> Vector3 Source #

Transform a 3D vector by a matrix

vector3RotateByQuaternion :: Vector3 -> Quaternion -> Vector3 Source #

Transform a 3D vector by quaternion rotation

vector3RotateByAxisAngle Source #

Arguments

:: Vector3

Vector to rotate

-> Vector3

Axis to rotate around

-> Float

Angle to rotate by

-> Vector3 

Rotate a 3D vector around an axis

vector3CubicHermite Source #

Arguments

:: Vector3

Vector 1

-> Vector3

Tangent for vector 1

-> Vector3

Vector 2

-> Vector3

Tangent for vector 2

-> Float

Interpolation amount

-> Vector3 

Cubic hermite interpolation between two vectors and their tangents as described in the GLTF 2.0 specification

vector3Reflect Source #

Arguments

:: Vector3

Input vector

-> Vector3

Normal vector

-> Vector3 

Reflect 3D vector to normal

vector3Barycenter Source #

Arguments

:: Vector3

Input point

-> (Vector3, Vector3, Vector3)

Triangle vertices

-> Vector3 

Compute barycenter coordinates (u, v, w) for a point with respect to a triangle. NOTE: Assumes the point is on the plane of the triangle.

vector3Unproject Source #

Arguments

:: Vector3

Vector to unproject

-> Matrix

Projection matrix

-> Matrix

View matrix

-> Vector3 

Project a Vector3 from screen space into object space

vector3Refract Source #

Arguments

:: Vector3

Normalized direction of the incoming ray

-> Vector3

Normalized normal vector of the interface of two optical media

-> Float

Ratio of the refractive index of the medium from where the ray comes to the refractive index of the medium on the other side of the surface

-> Vector3 

Compute the direction of a refracted ray

Matrix math

matrixToList :: Matrix -> [Float] Source #

Utility function

matrixFromList :: [Float] -> Matrix Source #

Utility function

matrixConstant :: Float -> Matrix Source #

Scalar to matrix (all elements are set to the scalar)

matrixDeterminant :: Matrix -> Float Source #

Compute matrix determinant

matrixTrace :: Matrix -> Float Source #

Trace of a matrix (sum of the values along the diagonal)

matrixTranspose :: Matrix -> Matrix Source #

Transpose a matrix

matrixInvert :: Matrix -> Matrix Source #

Invert a matrix

matrixIdentity :: Matrix Source #

Identity matrix

matrixAdd :: Matrix -> Matrix -> Matrix Source #

Add two matrices

matrixSubtract :: Matrix -> Matrix -> Matrix Source #

Subtract two matrices

matrixMultiply :: Matrix -> Matrix -> Matrix Source #

Multiply two matrices (order matters!)

matrixTranslate Source #

Arguments

:: Float

x translation

-> Float

y translation

-> Float

z translation

-> Matrix 

Translation matrix

matrixRotate Source #

Arguments

:: Vector3

Axis to rotate around

-> Float

Angle to rotate by

-> Matrix 

Axis-angle rotation matrix (angle should be in radians)

matrixRotateX :: Float -> Matrix Source #

x-rotation matrix (angle should be in radians)

matrixRotateY :: Float -> Matrix Source #

y-rotation matrix (angle should be in radians)

matrixRotateZ :: Float -> Matrix Source #

z-rotation matrix (angle should be in radians)

matrixRotateXYZ :: Vector3 -> Matrix Source #

Euler angle xyz rotation matrix (angles should be in radians)

matrixRotateZYX :: Vector3 -> Matrix Source #

Euler angle zyx rotation matrix (angles should be in radians)

matrixScale :: Vector3 -> Matrix Source #

Scaling matrix

matrixFrustum Source #

Arguments

:: Float

Left edge distance

-> Float

Right edge distance

-> Float

Bottom edge distance

-> Float

Top edge distance

-> Float

Near clipping plane distance

-> Float

Far clipping plane distance

-> Matrix 

Frustum projection matrix

matrixPerspective Source #

Arguments

:: Float

y-fov angle (should be in radians)

-> Float

Aspect ratio

-> Float

Near clipping plane distance

-> Float

Far clipping plane distance

-> Matrix 

Perspective projection matrix

matrixOrtho Source #

Arguments

:: Float

Left edge distance

-> Float

Right edge distance

-> Float

Bottom edge distance

-> Float

Top edge distance

-> Float

Near clipping plane distance

-> Float

Far clipping plane distance

-> Matrix 

Orthographic projection matrix

matrixLookAt Source #

Arguments

:: Vector3

Camera position

-> Vector3

Camera target

-> Vector3

World up vector

-> Matrix 

Camera look-at matrix (view matrix)

matrixDecompose :: Matrix -> (Vector3, Quaternion, Vector3) Source #

Decompose a transformation matrix into its rotational, translational and scaling components

Quaternion math

quaternionIdentity :: Quaternion Source #

Identity quaternion

quaternionInvert :: Quaternion -> Quaternion Source #

Invert a quaternion

quaternionMultiply :: Quaternion -> Quaternion -> Quaternion Source #

Multiply two quaternions

quaternionNormalize :: Quaternion -> Quaternion Source #

Normalize a quaternion (alias for vectorNormalize)

quaternionLerp Source #

Arguments

:: Quaternion

Lerp start value

-> Quaternion

Lerp end value

-> Float

Lerp amount

-> Quaternion 

Lerp between two quaternions (alias for quaternionLerp)

quaternionNLerp Source #

Arguments

:: Quaternion

Lerp start value

-> Quaternion

Lerp end value

-> Float

Lerp amount

-> Quaternion 

Slerp-optimized interpolation between two quaternions

quaternionSLerp Source #

Arguments

:: Quaternion

Lerp start value

-> Quaternion

Lerp end value

-> Float

Lerp amount

-> Quaternion 

Spherical linear interpolation between two quaternions

quaternionCubicHermiteSpline Source #

Arguments

:: Quaternion

Quaternion 1

-> Quaternion

Out tangent 1

-> Quaternion

Quaternion 2

-> Quaternion

In tangent 2

-> Float

Interpolation amount

-> Quaternion 

Quaternion cubic spline interpolation using the Cubic Hermite Spline algorithm as described in the GLTF 2.0 specification

quaternionFromVector3ToVector3 :: Vector3 -> Vector3 -> Quaternion Source #

Quaternion based on the rotation between two vectors

quaternionFromMatrix :: Matrix -> Quaternion Source #

Create a quaternion from a rotation matrix

quaternionToMatrix :: Quaternion -> Matrix Source #

Create a rotation matrix from a quaternion

quaternionFromAxisAngle Source #

Arguments

:: Vector3

Rotation axis

-> Float

Angle in radians

-> Quaternion 

Create a quaternion for an angle and axis

quaternionToAxisAngle :: Quaternion -> (Vector3, Float) Source #

Convert a quaternion to axis-angle representation

quaternionFromEuler Source #

Arguments

:: Float

Pitch

-> Float

Yaw

-> Float

Roll

-> Quaternion 

Create a quaternion from Euler angles (ZYX rotation order, angles should be in radians)

quaternionToEuler :: Quaternion -> Vector3 Source #

Convert a quaternion to Euler angle representation (Vector3 roll pitch yaw, all angles in radians)

quaternionTransform :: Quaternion -> Matrix -> Quaternion Source #

Transform a quaternion given a transformation matrix