simvx.core.math.matrices¶
Pure NumPy matrix utilities — replaces GLM dependency.
All matrices use NumPy’s native row-major layout. When sending to GLSL:
Matrices must be transposed (GLSL expects column-major)
This is handled at GPU boundary points only
This eliminates the entire class of row-major vs column-major bugs.
Module Contents¶
Functions¶
Convert a quaternion to a 4x4 rotation matrix. |
|
Create 4x4 identity matrix. |
|
Create perspective projection matrix. |
|
Create view matrix using look-at vectors. |
|
Create translation matrix. |
|
Create rotation matrix using axis-angle representation. |
|
Create scale matrix. |
|
Create orthographic projection matrix. |
Data¶
API¶
- simvx.core.math.matrices.__all__¶
[‘identity’, ‘perspective’, ‘look_at’, ‘translate’, ‘rotate’, ‘scale’, ‘orthographic’, ‘quat_to_mat4…
- simvx.core.math.matrices.quat_to_mat4(q, dtype: numpy.dtype = np.float32) numpy.ndarray¶
Convert a quaternion to a 4x4 rotation matrix.
Args: q: Quaternion — any object with .w, .x, .y, .z attributes (e.g. glm.quat) or a 4-element array [w, x, y, z]. dtype: NumPy data type (default float32)
Returns: 4x4 rotation matrix as numpy array
- simvx.core.math.matrices.identity(dtype: numpy.dtype = np.float32) numpy.ndarray¶
Create 4x4 identity matrix.
Args: dtype: NumPy data type (default float32)
Returns: 4x4 identity matrix as numpy array
- simvx.core.math.matrices.perspective(fov: float, aspect: float, near: float, far: float, dtype: numpy.dtype = np.float32) numpy.ndarray¶
Create perspective projection matrix.
Args: fov: Field of view in radians aspect: Aspect ratio (width / height) near: Near clipping plane far: Far clipping plane dtype: NumPy data type (default float32)
Returns: 4x4 perspective projection matrix
Note: Does NOT include Y-flip for Vulkan. Caller must do: proj[1, 1] *= -1 # Flip Y-axis for Vulkan
- simvx.core.math.matrices.look_at(eye: numpy.ndarray | tuple[float, float, float], center: numpy.ndarray | tuple[float, float, float], up: numpy.ndarray | tuple[float, float, float], dtype: numpy.dtype = np.float32) numpy.ndarray¶
Create view matrix using look-at vectors.
Args: eye: Camera position center: Point to look at up: Up vector (should be normalized) dtype: NumPy data type (default float32)
Returns: 4x4 view matrix
- simvx.core.math.matrices.translate(t: numpy.ndarray | tuple[float, float, float], dtype: numpy.dtype = np.float32) numpy.ndarray¶
Create translation matrix.
Args: t: Translation vector (x, y, z) dtype: NumPy data type (default float32)
Returns: 4x4 translation matrix
- simvx.core.math.matrices.rotate(axis: numpy.ndarray | tuple[float, float, float], angle: float, dtype: numpy.dtype = np.float32) numpy.ndarray¶
Create rotation matrix using axis-angle representation.
Args: axis: Rotation axis (should be normalized) angle: Rotation angle in radians dtype: NumPy data type (default float32)
Returns: 4x4 rotation matrix
Uses Rodrigues’ rotation formula.
- simvx.core.math.matrices.scale(s: numpy.ndarray | tuple[float, float, float] | float, dtype: numpy.dtype = np.float32) numpy.ndarray¶
Create scale matrix.
Args: s: Scale factors (x, y, z) or uniform scale factor dtype: NumPy data type (default float32)
Returns: 4x4 scale matrix
- simvx.core.math.matrices.orthographic(left: float, right: float, bottom: float, top: float, near: float, far: float, dtype: numpy.dtype = np.float32) numpy.ndarray¶
Create orthographic projection matrix.
Args: left: Left plane right: Right plane bottom: Bottom plane top: Top plane near: Near plane far: Far plane dtype: NumPy data type (default float32)
Returns: 4x4 orthographic projection matrix
Note: For Vulkan, you may need to flip Y: proj[1, 1] *= -1