Remove dependency on Window, Physics, and Renderer classes.
PiperOrigin-RevId: 825137441 Change-Id: I099a518ca9618698401d0330a6ef08278168f88e
This commit is contained in:
committed by
Copybara-Service
parent
4620b9f23a
commit
80eb511620
@@ -13,45 +13,39 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "experimental/toolbox/interaction.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "experimental/toolbox/physics.h"
|
||||
#include "experimental/toolbox/renderer.h"
|
||||
#include "experimental/toolbox/window.h"
|
||||
#include <mujoco/mujoco.h>
|
||||
|
||||
namespace mujoco::toolbox {
|
||||
|
||||
PickResult Pick(float x, float y, Window* window, Renderer* renderer,
|
||||
Physics* physics, const mjvOption& vis_options) {
|
||||
const float w = static_cast<float>(window->GetWidth());
|
||||
const float h = static_cast<float>(window->GetHeight());
|
||||
const float aspect_ratio = w / h;
|
||||
|
||||
PickResult Pick(const mjModel* m, const mjData* d, const mjvCamera* camera,
|
||||
float x, float y, float aspect_ratio, const mjvScene* scene,
|
||||
const mjvOption* vis_options) {
|
||||
PickResult result;
|
||||
result.body =
|
||||
mjv_select(physics->GetModel(), physics->GetData(), &vis_options,
|
||||
aspect_ratio, x, 1.0f - y, &renderer->GetScene(), result.point,
|
||||
&result.geom, &result.flex, &result.skin);
|
||||
mjv_select(m, d, vis_options, aspect_ratio, x, 1.0f - y, scene,
|
||||
result.point, &result.geom, &result.flex, &result.skin);
|
||||
return result;
|
||||
}
|
||||
|
||||
int SetCamera(const mjModel& model, mjvCamera& camera, int request_idx) {
|
||||
int SetCamera(const mjModel* m, mjvCamera* camera, int request_idx) {
|
||||
// 0 = free, 1 = tracking, 2+ = fixed
|
||||
int camera_idx = std::clamp(request_idx, 0, std::max(model.ncam + 1, 0));
|
||||
int camera_idx = std::clamp(request_idx, 0, std::max(m->ncam + 1, 0));
|
||||
if (camera_idx == 0) {
|
||||
camera.type = mjCAMERA_FREE;
|
||||
camera->type = mjCAMERA_FREE;
|
||||
} else if (camera_idx == 1) {
|
||||
if (camera.trackbodyid >= 0) {
|
||||
camera.type = mjCAMERA_TRACKING;
|
||||
camera.fixedcamid = -1;
|
||||
if (camera->trackbodyid >= 0) {
|
||||
camera->type = mjCAMERA_TRACKING;
|
||||
camera->fixedcamid = -1;
|
||||
} else {
|
||||
camera.type = mjCAMERA_FREE;
|
||||
camera->type = mjCAMERA_FREE;
|
||||
camera_idx = 0;
|
||||
}
|
||||
} else {
|
||||
camera.type = mjCAMERA_FIXED;
|
||||
camera.fixedcamid = camera_idx - 2;
|
||||
camera->type = mjCAMERA_FIXED;
|
||||
camera->fixedcamid = camera_idx - 2;
|
||||
}
|
||||
|
||||
return camera_idx;
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
#ifndef MUJOCO_SRC_EXPERIMENTAL_TOOLBOX_INTERACTION_H_
|
||||
#define MUJOCO_SRC_EXPERIMENTAL_TOOLBOX_INTERACTION_H_
|
||||
|
||||
#include "experimental/toolbox/physics.h"
|
||||
#include "experimental/toolbox/renderer.h"
|
||||
#include "experimental/toolbox/window.h"
|
||||
#include <mujoco/mujoco.h>
|
||||
|
||||
namespace mujoco::toolbox {
|
||||
@@ -32,8 +29,9 @@ struct PickResult {
|
||||
};
|
||||
|
||||
// Returns information about the object (if any) under the mouse cursor.
|
||||
PickResult Pick(float x, float y, Window* window, Renderer* renderer,
|
||||
Physics* physics, const mjvOption& vis_options);
|
||||
PickResult Pick(const mjModel* m, const mjData* d, const mjvCamera* camera,
|
||||
float x, float y, float aspect_ratio, const mjvScene* scene,
|
||||
const mjvOption* vis_options);
|
||||
|
||||
// Updates the camera according to the requested index using this convention:
|
||||
//
|
||||
@@ -45,7 +43,7 @@ PickResult Pick(float x, float y, Window* window, Renderer* renderer,
|
||||
// convention. Note the returned index may differ from the request if the
|
||||
// request was invalid (index was out of range or tracking camera was not
|
||||
// available).
|
||||
int SetCamera(const mjModel& model, mjvCamera& camera, int request_idx);
|
||||
int SetCamera(const mjModel* model, mjvCamera* camera, int request_idx);
|
||||
|
||||
} // namespace mujoco::toolbox
|
||||
|
||||
|
||||
@@ -68,10 +68,15 @@ class Window {
|
||||
// Sets the title of the window.
|
||||
void SetTitle(std::string_view title);
|
||||
|
||||
// Returns the current size of the window.
|
||||
// Returns information related to the current size of the window.
|
||||
int GetWidth() const { return width_; }
|
||||
int GetHeight() const { return height_; }
|
||||
float GetScale() const { return scale_; }
|
||||
float GetAspectRatio() const {
|
||||
return height_ > 0
|
||||
? static_cast<float>(width_) / static_cast<float>(height_)
|
||||
: 1.0f;
|
||||
}
|
||||
|
||||
// Returns the path to a file that was dropped on the window. Once called,
|
||||
// the value will be cleared until the next time a file is dropped.
|
||||
|
||||
Reference in New Issue
Block a user