Implementation:Google deepmind Mujoco Render Util
| Knowledge Sources | |
|---|---|
| Domains | Mathematics, Graphics, 3D Rendering, Linear Algebra |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Rendering utility library providing vector math, matrix operations, OpenGL transformation helpers, and geometric computations used by MuJoCo's 3D renderer.
Description
This file implements low-level mathematical and OpenGL utility functions used by the rendering pipeline. It provides 3D vector operations (cross product, normalization, dot product, orthogonal vector computation), 4x4 matrix multiplication and row extraction, triangle normal computation, and OpenGL fixed-function pipeline helpers for view transformations (lookAt, perspective, reflection) and model transforms (translate/rotate/scale). It also includes a rectangle hit-testing function for viewport selection.
Usage
Called internally by the 3D renderer (render_gl3.c) and other rendering modules to set up view and projection matrices, compute surface normals, and perform coordinate transformations. The functions bridge mathematical operations with OpenGL state commands.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/render/render_util.c
- Lines: 1-287
Key Functions
// Triangle normal computation
void mjr_makeNormal(float* normal, const float* p1, const float* p2, const float* p3);
// Vector utilities
void mjr_setf4(float* vec, float f0, float f1, float f2, float f3);
void mjr_setf3(float* vec, float f0, float f1, float f2);
void mjr_crossVec(float* a, const float* b, const float* c);
void mjr_normalizeVec(float* v);
void mjr_orthoVec(float* res, const float* v);
float mjr_dotVec(const float* a, const float* b);
// Matrix operations (4x4, column-major)
void mjr_mulMat44(float* res, const float* A, const float* B);
void mjr_getrow4(float* res, const float* A, int r);
void mjr_multiply4(float* res, const float* mat, const float* vec);
// OpenGL transformation helpers
void mjr_lookAt(const float* eye, const float* forward, const float* up);
void mjr_perspective(float fovy, float aspect, float znear, float zfar);
void mjr_reflect(const float* pos, const float* mat);
void mjr_transform(const float* translate, const float* rotate, float scale);
// Viewport hit testing
int mjr_findRect(int x, int y, int nrect, const mjrRect* rect);
Import
#include "render/render_util.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| p1, p2, p3 | const float* | Yes (for makeNormal) | Triangle vertex positions (3-element float arrays) |
| A, B | const float* | Yes (for mulMat44) | 4x4 column-major matrices |
| eye, forward, up | const float* | Yes (for lookAt) | Camera position, forward direction, and up vector |
| fovy, aspect, znear, zfar | float | Yes (for perspective) | Perspective projection parameters |
| x, y | int | Yes (for findRect) | Point coordinates for rectangle hit testing |
| rect | const mjrRect* | Yes (for findRect) | Array of rectangles to test against |
Outputs
| Name | Type | Description |
|---|---|---|
| normal | float* | Computed triangle normal vector (3 elements) |
| res | float* | Result vector or matrix from math operations |
| return value (findRect) | int | Index of the rectangle containing the point, or -1 |
| (OpenGL state) | - | Modified OpenGL modelview/projection matrices (via lookAt, perspective, transform) |