Skip to content

Commit fa36015

Browse files
haroonqcopybara-github
authored andcommitted
Remove unneeded mjvScene argument from mjv_moveCamera.
PiperOrigin-RevId: 948204736 Change-Id: Ic9b116ce439b3153764af67c449a824aec1994dc
1 parent 6c78c86 commit fa36015

10 files changed

Lines changed: 32 additions & 25 deletions

File tree

‎doc/changelog.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ General
4545
negative half-integers, e.g. ``mju_round(-2.5)`` now returns -3 rather than -2.
4646
- Changed the default value of :ref:`sleep_tolerance<option-sleep_tolerance>` from 1e-4 to 1e-3 (1mm/sec in SI
4747
units).
48+
- Removed unneeded `mjvScene` argument from :ref:`mjv_moveCamera`.
4849

4950
Bug fixes
5051
^^^^^^^^^

‎doc/includes/references.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,8 +3438,7 @@ void mjv_cameraInRoom(mjtNum headpos[3], mjtNum forward[3], mjtNum up[3],
34383438
const mjvScene* scn);
34393439
mjtNum mjv_frustumHeight(const mjvScene* scn);
34403440
void mjv_alignToCamera(mjtNum res[3], const mjtNum vec[3], const mjtNum forward[3]);
3441-
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
3442-
const mjvScene* scn, mjvCamera* cam);
3441+
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, mjvCamera* cam);
34433442
void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx,
34443443
mjtNum reldy, const mjvScene* scn, mjvPerturb* pert);
34453444
void mjv_moveModel(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,

‎include/mujoco/mujoco.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,7 @@ MJAPI mjtNum mjv_frustumHeight(const mjvScene* scn);
757757
MJAPI void mjv_alignToCamera(mjtNum res[3], const mjtNum vec[3], const mjtNum forward[3]);
758758

759759
// Move camera with mouse; action is mjtMouse.
760-
MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
761-
const mjvScene* scn, mjvCamera* cam);
760+
MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, mjvCamera* cam);
762761

763762
// Move perturb object with mouse; action is mjtMouse.
764763
MJAPI void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx,

‎python/mujoco/introspect/functions.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4728,12 +4728,6 @@
47284728
name='reldy',
47294729
type=ValueType(name='mjtNum'),
47304730
),
4731-
FunctionParameterDecl(
4732-
name='scn',
4733-
type=PointerType(
4734-
inner_type=ValueType(name='mjvScene', is_const=True),
4735-
),
4736-
),
47374731
FunctionParameterDecl(
47384732
name='cam',
47394733
type=PointerType(

‎sample/basic.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ void mouse_move(GLFWwindow* window, double xpos, double ypos) {
8989
}
9090

9191
// move camera
92-
mjv_moveCamera(m, action, dx/height, dy/height, &scn, &cam);
92+
mjv_moveCamera(m, action, dx/height, dy/height, &cam);
9393
}
9494

9595

9696
// scroll callback
9797
void scroll(GLFWwindow* window, double xoffset, double yoffset) {
9898
// emulate vertical mouse motion = 5% of window height
99-
mjv_moveCamera(m, mjMOUSE_ZOOM, 0, -0.05*yoffset, &scn, &cam);
99+
mjv_moveCamera(m, mjMOUSE_ZOOM, 0, -0.05*yoffset, &cam);
100100
}
101101

102102

‎simulate/simulate.cc‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ void UiEvent(mjuiState* state) {
20332033
// 3D scroll
20342034
if (state->type==mjEVENT_SCROLL && state->mouserect==3 && model) {
20352035
// emulate vertical mouse motion = 2% of window height
2036-
mjv_moveCamera(model, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &sim->scn, &sim->cam);
2036+
mjv_moveCamera(model, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &sim->cam);
20372037
return;
20382038
}
20392039

@@ -2092,8 +2092,7 @@ void UiEvent(mjuiState* state) {
20922092
mjv_movePerturb(model, data, action, state->dx / r.height, -state->dy / r.height,
20932093
&sim->scn, &sim->pert);
20942094
} else {
2095-
mjv_moveCamera(model, action, state->dx / r.height, -state->dy / r.height,
2096-
&sim->scn, &sim->cam);
2095+
mjv_moveCamera(model, action, state->dx / r.height, -state->dy / r.height, &sim->cam);
20972096
}
20982097
return;
20992098
}

‎src/engine/engine_vis_interact.c‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "engine/engine_util_errmem.h"
2929
#include "engine/engine_util_misc.h"
3030
#include "engine/engine_util_spatial.h"
31+
#include "engine/engine_vis_visualize.h"
3132

3233
// transform pose from room to model space
3334
void mjv_room2model(mjtNum* modelpos, mjtNum* modelquat, const mjtNum* roompos,
@@ -247,6 +248,20 @@ mjtNum mjv_frustumHeight(const mjvScene* scn) {
247248
}
248249

249250

251+
static mjtNum cameraFrustumHeight(const mjModel* m, const mjvCamera* cam) {
252+
float zclip[2] = {0, 0}, zver[2] = {0, 0};
253+
mjv_cameraFrustum(zver, NULL, zclip, m, cam);
254+
if (cam->orthographic) {
255+
return (zver[1] + zver[0]);
256+
} else {
257+
if (zclip[0] < mjMINVAL) {
258+
mjERROR("mjvScene frustum_near too small");
259+
}
260+
return (zver[1] + zver[0]) / zclip[0];
261+
}
262+
}
263+
264+
250265
// rotate 3D vec in horizontal plane by angle between (0,1) and (forward_x,forward_y)
251266
void mjv_alignToCamera(mjtNum* res, const mjtNum* vec, const mjtNum* forward) {
252267
mjtNum xaxis[2], yaxis[2];
@@ -311,12 +326,12 @@ static void convert2D(mjtNum* res, int action, mjtNum dx, mjtNum dy, const mjtNu
311326

312327

313328
// move camera with mouse; action is mjtMouse
314-
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
315-
const mjvScene* scn, mjvCamera* cam) {
329+
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, mjvCamera* cam) {
316330
mjtNum headpos[3], forward[3], up[3], right[3];
317331
mjtNum vec[3], dif[3], scl;
318332

319333
// fixed camera: nothing to do
334+
// note: mjv_cameraFrame, which we use below, requires mjData for non-fixed camera
320335
if (cam->type == mjCAMERA_FIXED) {
321336
return;
322337
}
@@ -337,12 +352,12 @@ void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
337352
}
338353

339354
// get camera info and align
340-
mjv_cameraInModel(headpos, forward, NULL, scn);
355+
mjv_cameraFrame(headpos, forward, NULL, NULL, NULL, cam);
341356
convert2D(vec, action, reldx, reldy, forward);
342357

343358
// compute scaling: rendered lookat displacement = mouse displacement
344359
mju_sub3(dif, cam->lookat, headpos);
345-
scl = mjv_frustumHeight(scn) * mju_dot3(dif, forward);
360+
scl = cameraFrustumHeight(m, cam) * mju_dot3(dif, forward);
346361

347362
// multiply by mystery coefficient TODO: b/346130949
348363
if (cam->orthographic) scl *= 0.15;
@@ -362,7 +377,7 @@ void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
362377
return;
363378
}
364379

365-
mjv_cameraInModel(headpos, forward, up, scn);
380+
mjv_cameraFrame(headpos, forward, up, NULL, NULL, cam);
366381
mju_cross(right, forward, up);
367382

368383
// y-axis movement moves forward/backward (ie. camera dolly) on horizontal plane or up/down

‎src/engine/engine_vis_interact.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <mujoco/mjexport.h>
2020
#include <mujoco/mjmodel.h>
2121
#include <mujoco/mjvisualize.h>
22+
#include <mujoco/mjtype.h>
2223

2324
#ifdef __cplusplus
2425
extern "C" {
@@ -47,8 +48,7 @@ MJAPI mjtNum mjv_frustumHeight(const mjvScene* scn);
4748
MJAPI void mjv_alignToCamera(mjtNum* res, const mjtNum* vec, const mjtNum* forward);
4849

4950
// move camera with mouse; action is mjtMouse
50-
MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
51-
const mjvScene* scn, mjvCamera* cam);
51+
MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, mjvCamera* cam);
5252

5353
// move perturb object with mouse; action is mjtMouse
5454
MJAPI void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx,

‎unity/Runtime/Bindings/MjBindings.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7150,7 +7150,7 @@ public unsafe struct mjuiItemEdit_ {}
71507150
public static unsafe extern void mjv_alignToCamera(double* res, double* vec, double* forward);
71517151

71527152
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
7153-
public static unsafe extern void mjv_moveCamera(mjModel_* m, int action, double reldx, double reldy, mjvScene_* scn, mjvCamera_* cam);
7153+
public static unsafe extern void mjv_moveCamera(mjModel_* m, int action, double reldx, double reldy, mjvCamera_* cam);
71547154

71557155
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
71567156
public static unsafe extern void mjv_movePerturb(mjModel_* m, mjData_* d, int action, double reldx, double reldy, mjvScene_* scn, mjvPerturb_* pert);

‎wasm/codegen/generated/bindings.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,8 +3801,8 @@ void mjv_model2room_wrapper(const val& roompos, const val& roomquat, const Numbe
38013801
mjv_model2room(roompos_.data(), roomquat_.data(), modelpos_.data(), modelquat_.data(), scn.get());
38023802
}
38033803

3804-
void mjv_moveCamera_wrapper(const MjModel& m, int action, mjtNum reldx, mjtNum reldy, const MjvScene& scn, MjvCamera& cam) {
3805-
mjv_moveCamera(m.get(), action, reldx, reldy, scn.get(), cam.get());
3804+
void mjv_moveCamera_wrapper(const MjModel& m, int action, mjtNum reldx, mjtNum reldy, MjvCamera& cam) {
3805+
mjv_moveCamera(m.get(), action, reldx, reldy, cam.get());
38063806
}
38073807

38083808
void mjv_moveModel_wrapper(const MjModel& m, int action, mjtNum reldx, mjtNum reldy, const NumberArray& roomup, MjvScene& scn) {

0 commit comments

Comments
 (0)
⌂ 换网址