Add orthographic cameras.

Orthographic cameras are specified by setting the `orthographic` attribute of the `<camera>` element. The `fovy` attribute is still used to specify the field-of-view, but its semantic is different for orthographic cameras. For orthographic cameras, the field-of-view is expressed in units of length, rather than degrees.

Other related changes:

* Fix bug in the ordering of `cam_xxx` elements in `mjModel`.
* Make camera visualization translucent only when the frustum is visualized.
* Added a button to `simulate` to toggle between perspective and orthographic free cameras.

https://youtu.be/ZXBTEIDWHhs

PiperOrigin-RevId: 642293435
Change-Id: Id090a421ad88ab404b5b27ddbbd6bfc81ad49bc5
This commit is contained in:
Yuval Tassa
2024-06-11 09:21:39 -07:00
committed by Copybara-Service
parent 171b0d6e06
commit 07fc95ca9a
23 changed files with 490 additions and 235 deletions
+30
View File
@@ -1249,6 +1249,36 @@ TEST_F(XMLReaderTest, InvalidSkinGroup) {
EXPECT_THAT(
error.data(),
HasSubstr("skin group must be between 0 and 5\nElement 'skin', line 7"));
}
TEST_F(XMLReaderTest, Orthographic) {
static constexpr char xml[] = R"(
<mujoco>
<visual>
<global orthographic="true" fovy="5"/>
<map znear="0.01"/>
</visual>
<default>
<camera orthographic="true"/>
</default>
<worldbody>
<camera name="fovy=1" pos=".5 .5 2" orthographic="true" fovy="1"/>
<camera name="fovy=2" pos="0 0 2" fovy="2"/>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(model, NotNull()) << error.data();
EXPECT_EQ(model->vis.global.orthographic, 1);
EXPECT_EQ(model->cam_orthographic[0], 1);
EXPECT_EQ(model->cam_orthographic[1], 1);
EXPECT_EQ(model->cam_fovy[0], 1);
EXPECT_EQ(model->cam_fovy[1], 2);
mj_deleteModel(model);
}