QOL improvement when building an XML? Unity Style Navigation for the simulate viewer #3272
rohit-kumar-j
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
This is mostly an ease of use modification made to mujoco's simulate(I don't think this would improve simulate).
I don't like taking my keys off the keyboard... Let me rephrase that... I'd like to have an option to not use the mouse and still navigate around.
So I've make unity style keybinds to move the camera around when I build my robot.
Unity like movement:
Shift + W/A/S/D— translate along camera view axesShift + Q / E— world up / downCtrl + Alt + W/A/S/D— pitch / yaw, pivoting on the camera positionSince this deviates from the
UiEvent()pipeline (key releases don't surface throughOnKey, so continuous motion needs polling), I had to modify the main render loop a bit:A new
ApplyCameraKeys(Simulate*)helper runs once per frame inside the mutex, alongsideUiEvent. It uses one new pure-virtual onbool PlatformUIAdapter::IsKeyPressed(int key) constwith a one line glfwGetKey override inGlfwAdapterIf this is okay I could open a PR, or maybe there is a better way to do this. Either ways, I'm just sharing this to find any other takers for such a feature.
Please share your thoughts 🙌
Diff
diff --git a/simulate/glfw_adapter.cc b/simulate/glfw_adapter.cc index 6bae8822..53da6c03 100644 --- a/simulate/glfw_adapter.cc +++ b/simulate/glfw_adapter.cc @@ -231,6 +231,10 @@ bool GlfwAdapter::IsShiftKeyPressed() const { Glfw().glfwGetKey(window_, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; }
+bool GlfwAdapter::IsKeyPressed(int key) const {
+}
bool GlfwAdapter::IsMouseButtonDownEvent(int act) const {
return act == GLFW_PRESS;
}
diff --git a/simulate/glfw_adapter.h b/simulate/glfw_adapter.h
index 1490c333..e1a252c0 100644
--- a/simulate/glfw_adapter.h
+++ b/simulate/glfw_adapter.h
@@ -52,6 +52,7 @@ class GlfwAdapter : public PlatformUIAdapter {
bool IsAltKeyPressed() const override;
bool IsCtrlKeyPressed() const override;
bool IsShiftKeyPressed() const override;
bool IsKeyPressed(int key) const override;
bool IsMouseButtonDownEvent(int act) const override;
bool IsKeyDownEvent(int act) const override;
diff --git a/simulate/platform_ui_adapter.h b/simulate/platform_ui_adapter.h
index 64b0211d..0a9c9c82 100644
--- a/simulate/platform_ui_adapter.h
+++ b/simulate/platform_ui_adapter.h
@@ -64,6 +64,7 @@ class PlatformUIAdapter {
virtual bool IsAltKeyPressed() const = 0;
virtual bool IsCtrlKeyPressed() const = 0;
virtual bool IsShiftKeyPressed() const = 0;
virtual bool IsKeyPressed(int key) const = 0;
virtual bool IsMouseButtonDownEvent(int act) const = 0;
virtual bool IsKeyDownEvent(int act) const = 0;
diff --git a/simulate/simulate.cc b/simulate/simulate.cc
index 76e2b788..4c4b8f06 100644
--- a/simulate/simulate.cc
+++ b/simulate/simulate.cc
@@ -1578,6 +1578,76 @@ void UiModify(mjUI* ui, mjuiState* state, mjrContext* con) {
mjui_update(-1, -1, ui, state, con);
}
+// Continuous Unity-style flycam, polled once per frame via the platform UI
+// Shift + W/A/S/D : forward / left / back / right along camera axes
+// Shift + Q / E : world-up / world-down
+// Ctrl+Alt + W/S/A/D : pitch up/down, yaw left/right (pivot at camera position)
+void ApplyCameraKeys(mj::Simulate* sim) {
+}
// handle UI event
void UiEvent(mjuiState* state) {
mj::Simulate* sim = static_castmj::Simulate*(state->userdata);
@@ -3006,6 +3076,8 @@ void Simulate::RenderLoop() {
cond_upload_.notify_all();
}
diff --git a/simulate/simulate.h b/simulate/simulate.h
index 27727ee7..3c8a6551 100644
--- a/simulate/simulate.h
+++ b/simulate/simulate.h
@@ -255,6 +255,10 @@ class Simulate {
// rendering: need sync
int camera = 0;
// abstract visualization
mjvScene scn;
mjvCamera& cam;
Screen.Recording.2026-05-15.at.1.38.43.PM.mp4
Beta Was this translation helpful? Give feedback.
All reactions