Implementation:Google deepmind Mujoco Engine Vis Interact
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, Visualization, User Interaction |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Implements interactive visualization functions for MuJoCo, including coordinate space transformations, camera control, object selection via ray casting, and user perturbation force application.
Description
This file provides the interactive visualization layer that bridges user input with the physics simulation. It includes room-to-model and model-to-room coordinate transformations (mjv_room2model, mjv_model2room) that account for scene scaling and transformation, camera movement functions (mjv_moveCamera) for orbit, pan, and zoom, object selection via ray casting (mjv_select) that identifies bodies, geoms, and other objects under the mouse cursor, and perturbation force/torque application (mjv_applyPerturbPose, mjv_applyPerturbForce). The camera control supports both free and tracking modes with configurable sensitivity. The perturbation system allows interactive dragging and rotation of bodies during simulation.
Usage
These functions are called by GUI applications (such as the MuJoCo simulate viewer) in response to mouse and keyboard input to manipulate the camera, select objects, and apply perturbation forces to the simulation.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/engine/engine_vis_interact.c
- Lines: 1-977
Key Functions
// Coordinate transformations
void mjv_room2model(mjtNum* modelpos, mjtNum* modelquat,
const mjtNum* roompos, const mjtNum* roomquat,
const mjvScene* scn);
void mjv_model2room(mjtNum* roompos, mjtNum* roomquat,
const mjtNum* modelpos, const mjtNum* modelquat,
const mjvScene* scn);
// Camera control
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvCamera* cam);
// Object selection
int mjv_select(const mjModel* m, const mjData* d, const mjvOption* vopt,
mjtNum aspectratio, mjtNum relx, mjtNum rely,
const mjvScene* scn, mjtNum selpnt[3], int geomid[1],
int skinid[1]);
// Perturbation
void mjv_applyPerturbPose(const mjModel* m, mjData* d,
const mjvPerturb* pert, int flg_paused);
void mjv_applyPerturbForce(const mjModel* m, mjData* d,
const mjvPerturb* pert);
Import
#include "engine/engine_vis_interact.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | const mjModel* | Yes | Model containing geometry and physics parameters |
| d | mjData* | Yes | Simulation data with current state |
| scn | const mjvScene* | Yes | Scene with current transform and scale |
| action | int | Yes | Camera action type (orbit, pan, zoom) |
| reldx, reldy | mjtNum | Yes | Relative mouse displacement |
| pert | const mjvPerturb* | Yes | Perturbation specification (body, force, torque) |
Outputs
| Name | Type | Description |
|---|---|---|
| modelpos, modelquat | mjtNum* | Transformed position and orientation in model space |
| cam | mjvCamera* | Updated camera state after movement |
| selpnt | mjtNum[3] | 3D selection point on selected object |
| return value | int | Selected body ID, or -1 if no selection |