Refactor camera orthographic attribute to projection enum.

PiperOrigin-RevId: 847069028
Change-Id: I7f686fe654e9b56519cab8bd2f37c9cc40091d3f
This commit is contained in:
Yuval Tassa
2025-12-20 03:27:42 -08:00
committed by Copybara-Service
parent 44c8ef890d
commit b8a4ac5d48
20 changed files with 102 additions and 44 deletions
+2 -2
View File
@@ -522,7 +522,7 @@ void mjv_cameraFrustum(float zver[2], float zhor[2], float zclip[2], const mjMod
if (cid < 0 || cid >= m->ncam) {
mjERROR("fixed camera id is outside valid range");
}
orthographic = m->cam_orthographic[cid];
orthographic = m->cam_projection[cid] == mjPROJ_ORTHOGRAPHIC;
fovy = m->cam_fovy[cid];
// if positive sensorsize, get sensorsize and intrinsic
@@ -2763,7 +2763,7 @@ void mjv_updateCamera(const mjModel* m, const mjData* d, mjvCamera* cam, mjvScen
mjERROR("fixed camera id is outside valid range");
}
ipd = m->cam_ipd[cid];
orthographic = m->cam_orthographic[cid];
orthographic = m->cam_projection[cid] == mjPROJ_ORTHOGRAPHIC;
break;
default:
+1 -1
View File
@@ -2864,7 +2864,7 @@ void mjCModel::CopyTree(mjModel* m) {
m->cam_targetbodyid[cid] = pc->targetbodyid;
mjuu_copyvec(m->cam_pos+3*cid, pc->pos, 3);
mjuu_copyvec(m->cam_quat+4*cid, pc->quat, 4);
m->cam_orthographic[cid] = pc->orthographic;
m->cam_projection[cid] = pc->proj;
m->cam_fovy[cid] = (mjtNum)pc->fovy;
m->cam_ipd[cid] = (mjtNum)pc->ipd;
mjuu_copyvec(m->cam_resolution+2*cid, pc->resolution, 2);
+2
View File
@@ -27,6 +27,7 @@
// keyword maps (defined in implementation files)
extern const int joint_sz;
extern const int bodysleep_sz;
extern const int projection_sz;
extern const int camlight_sz;
extern const int lighttype_sz;
extern const int integrator_sz;
@@ -53,6 +54,7 @@ extern const mjMap TFAuto_map[];
extern const mjMap joint_map[];
extern const mjMap bodysleep_map[];
extern const mjMap geom_map[];
extern const mjMap projection_map[];
extern const mjMap camlight_map[];
extern const mjMap lighttype_map[];
extern const mjMap integrator_map[];
+11 -4
View File
@@ -171,7 +171,7 @@ std::vector<const char*> MJCF[nMJCF] = {
"hfield", "mesh", "fitscale", "rgba", "fluidshape", "fluidcoef", "user"},
{"site", "?", "type", "group", "pos", "quat", "material",
"size", "fromto", "axisangle", "xyaxes", "zaxis", "euler", "rgba", "user"},
{"camera", "?", "orthographic", "fovy", "ipd", "resolution", "pos", "quat",
{"camera", "?", "projection", "fovy", "ipd", "resolution", "pos", "quat",
"axisangle", "xyaxes", "zaxis", "euler", "mode", "focal", "focalpixel",
"principal", "principalpixel", "sensorsize", "user"},
{"light", "?", "pos", "dir", "bulbradius", "intensity", "range",
@@ -285,7 +285,7 @@ std::vector<const char*> MJCF[nMJCF] = {
{"attach", "*", "model", "body", "prefix"},
{"site", "*", "name", "class", "type", "group", "pos", "quat",
"material", "size", "fromto", "axisangle", "xyaxes", "zaxis", "euler", "rgba", "user"},
{"camera", "*", "name", "class", "orthographic", "fovy", "ipd", "resolution", "pos",
{"camera", "*", "name", "class", "projection", "fovy", "ipd", "resolution", "pos",
"quat", "axisangle", "xyaxes", "zaxis", "euler", "mode", "target",
"focal", "focalpixel", "principal", "principalpixel", "sensorsize", "user"},
{"light", "*", "name", "class", "directional", "type", "castshadow", "active",
@@ -590,6 +590,13 @@ const mjMap geom_map[mjNGEOMTYPES] = {
};
// projection type
const int projection_sz = 2;
const mjMap projection_map[projection_sz] = {
{"perspective", mjPROJ_PERSPECTIVE},
{"orthographic", mjPROJ_ORTHOGRAPHIC}
};
// camlight type
const int camlight_sz = 5;
const mjMap camlight_map[camlight_sz] = {
@@ -1926,8 +1933,8 @@ void mjXReader::OneCamera(XMLElement* elem, mjsCamera* camera) {
ReadAlternative(elem, camera->alt);
ReadAttr(elem, "ipd", 1, &camera->ipd, text);
if (MapValue(elem, "orthographic", &n, bool_map, 2)) {
camera->orthographic = (n == 1);
if (MapValue(elem, "projection", &n, projection_map, 2)) {
camera->proj = (mjtProjection)n;
}
bool has_principal = ReadAttr(elem, "principalpixel", 2, camera->principal_pixel, text) ||
+1 -1
View File
@@ -573,7 +573,7 @@ void mjXWriter::OneCamera(XMLElement* elem, const mjCCamera* camera, mjCDef* def
WriteAttr(elem, "ipd", 1, &camera->ipd, &def->Camera().ipd);
WriteAttrKey(elem, "mode", camlight_map, camlight_sz, camera->mode, def->Camera().mode);
WriteAttr(elem, "resolution", 2, camera->resolution, def->Camera().resolution);
WriteAttrKey(elem, "orthographic", bool_map, 2, camera->orthographic, def->Camera().orthographic);
WriteAttrKey(elem, "projection", projection_map, projection_sz, camera->proj, def->Camera().proj);
// camera intrinsics if specified
if (camera->sensor_size[0] > 0 && camera->sensor_size[1] > 0) {