Remove unneeded mjvScene argument from mjv_moveCamera.
PiperOrigin-RevId: 948204736 Change-Id: Ic9b116ce439b3153764af67c449a824aec1994dc
This commit is contained in:
committed by
Copybara-Service
parent
6c78c8664e
commit
fa36015bae
@@ -45,6 +45,7 @@ General
|
||||
negative half-integers, e.g. ``mju_round(-2.5)`` now returns -3 rather than -2.
|
||||
- Changed the default value of :ref:`sleep_tolerance<option-sleep_tolerance>` from 1e-4 to 1e-3 (1mm/sec in SI
|
||||
units).
|
||||
- Removed unneeded `mjvScene` argument from :ref:`mjv_moveCamera`.
|
||||
|
||||
Bug fixes
|
||||
^^^^^^^^^
|
||||
|
||||
@@ -3438,8 +3438,7 @@ void mjv_cameraInRoom(mjtNum headpos[3], mjtNum forward[3], mjtNum up[3],
|
||||
const mjvScene* scn);
|
||||
mjtNum mjv_frustumHeight(const mjvScene* scn);
|
||||
void mjv_alignToCamera(mjtNum res[3], const mjtNum vec[3], const mjtNum forward[3]);
|
||||
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
|
||||
const mjvScene* scn, mjvCamera* cam);
|
||||
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, mjvCamera* cam);
|
||||
void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx,
|
||||
mjtNum reldy, const mjvScene* scn, mjvPerturb* pert);
|
||||
void mjv_moveModel(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
|
||||
|
||||
@@ -757,8 +757,7 @@ MJAPI mjtNum mjv_frustumHeight(const mjvScene* scn);
|
||||
MJAPI void mjv_alignToCamera(mjtNum res[3], const mjtNum vec[3], const mjtNum forward[3]);
|
||||
|
||||
// Move camera with mouse; action is mjtMouse.
|
||||
MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
|
||||
const mjvScene* scn, mjvCamera* cam);
|
||||
MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, mjvCamera* cam);
|
||||
|
||||
// Move perturb object with mouse; action is mjtMouse.
|
||||
MJAPI void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx,
|
||||
|
||||
@@ -4728,12 +4728,6 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
||||
name='reldy',
|
||||
type=ValueType(name='mjtNum'),
|
||||
),
|
||||
FunctionParameterDecl(
|
||||
name='scn',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='mjvScene', is_const=True),
|
||||
),
|
||||
),
|
||||
FunctionParameterDecl(
|
||||
name='cam',
|
||||
type=PointerType(
|
||||
|
||||
+2
-2
@@ -89,14 +89,14 @@ void mouse_move(GLFWwindow* window, double xpos, double ypos) {
|
||||
}
|
||||
|
||||
// move camera
|
||||
mjv_moveCamera(m, action, dx/height, dy/height, &scn, &cam);
|
||||
mjv_moveCamera(m, action, dx/height, dy/height, &cam);
|
||||
}
|
||||
|
||||
|
||||
// scroll callback
|
||||
void scroll(GLFWwindow* window, double xoffset, double yoffset) {
|
||||
// emulate vertical mouse motion = 5% of window height
|
||||
mjv_moveCamera(m, mjMOUSE_ZOOM, 0, -0.05*yoffset, &scn, &cam);
|
||||
mjv_moveCamera(m, mjMOUSE_ZOOM, 0, -0.05*yoffset, &cam);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2033,7 +2033,7 @@ void UiEvent(mjuiState* state) {
|
||||
// 3D scroll
|
||||
if (state->type==mjEVENT_SCROLL && state->mouserect==3 && model) {
|
||||
// emulate vertical mouse motion = 2% of window height
|
||||
mjv_moveCamera(model, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &sim->scn, &sim->cam);
|
||||
mjv_moveCamera(model, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &sim->cam);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2092,8 +2092,7 @@ void UiEvent(mjuiState* state) {
|
||||
mjv_movePerturb(model, data, action, state->dx / r.height, -state->dy / r.height,
|
||||
&sim->scn, &sim->pert);
|
||||
} else {
|
||||
mjv_moveCamera(model, action, state->dx / r.height, -state->dy / r.height,
|
||||
&sim->scn, &sim->cam);
|
||||
mjv_moveCamera(model, action, state->dx / r.height, -state->dy / r.height, &sim->cam);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "engine/engine_util_errmem.h"
|
||||
#include "engine/engine_util_misc.h"
|
||||
#include "engine/engine_util_spatial.h"
|
||||
#include "engine/engine_vis_visualize.h"
|
||||
|
||||
// transform pose from room to model space
|
||||
void mjv_room2model(mjtNum* modelpos, mjtNum* modelquat, const mjtNum* roompos,
|
||||
@@ -247,6 +248,20 @@ mjtNum mjv_frustumHeight(const mjvScene* scn) {
|
||||
}
|
||||
|
||||
|
||||
static mjtNum cameraFrustumHeight(const mjModel* m, const mjvCamera* cam) {
|
||||
float zclip[2] = {0, 0}, zver[2] = {0, 0};
|
||||
mjv_cameraFrustum(zver, NULL, zclip, m, cam);
|
||||
if (cam->orthographic) {
|
||||
return (zver[1] + zver[0]);
|
||||
} else {
|
||||
if (zclip[0] < mjMINVAL) {
|
||||
mjERROR("mjvScene frustum_near too small");
|
||||
}
|
||||
return (zver[1] + zver[0]) / zclip[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// rotate 3D vec in horizontal plane by angle between (0,1) and (forward_x,forward_y)
|
||||
void mjv_alignToCamera(mjtNum* res, const mjtNum* vec, const mjtNum* forward) {
|
||||
mjtNum xaxis[2], yaxis[2];
|
||||
@@ -311,12 +326,12 @@ static void convert2D(mjtNum* res, int action, mjtNum dx, mjtNum dy, const mjtNu
|
||||
|
||||
|
||||
// move camera with mouse; action is mjtMouse
|
||||
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
|
||||
const mjvScene* scn, mjvCamera* cam) {
|
||||
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, mjvCamera* cam) {
|
||||
mjtNum headpos[3], forward[3], up[3], right[3];
|
||||
mjtNum vec[3], dif[3], scl;
|
||||
|
||||
// fixed camera: nothing to do
|
||||
// note: mjv_cameraFrame, which we use below, requires mjData for non-fixed camera
|
||||
if (cam->type == mjCAMERA_FIXED) {
|
||||
return;
|
||||
}
|
||||
@@ -337,12 +352,12 @@ void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
|
||||
}
|
||||
|
||||
// get camera info and align
|
||||
mjv_cameraInModel(headpos, forward, NULL, scn);
|
||||
mjv_cameraFrame(headpos, forward, NULL, NULL, NULL, cam);
|
||||
convert2D(vec, action, reldx, reldy, forward);
|
||||
|
||||
// compute scaling: rendered lookat displacement = mouse displacement
|
||||
mju_sub3(dif, cam->lookat, headpos);
|
||||
scl = mjv_frustumHeight(scn) * mju_dot3(dif, forward);
|
||||
scl = cameraFrustumHeight(m, cam) * mju_dot3(dif, forward);
|
||||
|
||||
// multiply by mystery coefficient TODO: b/346130949
|
||||
if (cam->orthographic) scl *= 0.15;
|
||||
@@ -362,7 +377,7 @@ void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
|
||||
return;
|
||||
}
|
||||
|
||||
mjv_cameraInModel(headpos, forward, up, scn);
|
||||
mjv_cameraFrame(headpos, forward, up, NULL, NULL, cam);
|
||||
mju_cross(right, forward, up);
|
||||
|
||||
// y-axis movement moves forward/backward (ie. camera dolly) on horizontal plane or up/down
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <mujoco/mjexport.h>
|
||||
#include <mujoco/mjmodel.h>
|
||||
#include <mujoco/mjvisualize.h>
|
||||
#include <mujoco/mjtype.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -47,8 +48,7 @@ MJAPI mjtNum mjv_frustumHeight(const mjvScene* scn);
|
||||
MJAPI void mjv_alignToCamera(mjtNum* res, const mjtNum* vec, const mjtNum* forward);
|
||||
|
||||
// move camera with mouse; action is mjtMouse
|
||||
MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
|
||||
const mjvScene* scn, mjvCamera* cam);
|
||||
MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, mjvCamera* cam);
|
||||
|
||||
// move perturb object with mouse; action is mjtMouse
|
||||
MJAPI void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx,
|
||||
|
||||
@@ -7150,7 +7150,7 @@ public static unsafe extern double mjv_frustumHeight(mjvScene_* scn);
|
||||
public static unsafe extern void mjv_alignToCamera(double* res, double* vec, double* forward);
|
||||
|
||||
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static unsafe extern void mjv_moveCamera(mjModel_* m, int action, double reldx, double reldy, mjvScene_* scn, mjvCamera_* cam);
|
||||
public static unsafe extern void mjv_moveCamera(mjModel_* m, int action, double reldx, double reldy, mjvCamera_* cam);
|
||||
|
||||
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static unsafe extern void mjv_movePerturb(mjModel_* m, mjData_* d, int action, double reldx, double reldy, mjvScene_* scn, mjvPerturb_* pert);
|
||||
|
||||
@@ -3801,8 +3801,8 @@ void mjv_model2room_wrapper(const val& roompos, const val& roomquat, const Numbe
|
||||
mjv_model2room(roompos_.data(), roomquat_.data(), modelpos_.data(), modelquat_.data(), scn.get());
|
||||
}
|
||||
|
||||
void mjv_moveCamera_wrapper(const MjModel& m, int action, mjtNum reldx, mjtNum reldy, const MjvScene& scn, MjvCamera& cam) {
|
||||
mjv_moveCamera(m.get(), action, reldx, reldy, scn.get(), cam.get());
|
||||
void mjv_moveCamera_wrapper(const MjModel& m, int action, mjtNum reldx, mjtNum reldy, MjvCamera& cam) {
|
||||
mjv_moveCamera(m.get(), action, reldx, reldy, cam.get());
|
||||
}
|
||||
|
||||
void mjv_moveModel_wrapper(const MjModel& m, int action, mjtNum reldx, mjtNum reldy, const NumberArray& roomup, MjvScene& scn) {
|
||||
|
||||
Reference in New Issue
Block a user