1. OpenSourceRoboticsFoundation
  2. Untitled project
  3. gazebo

Commits

John Hsu  committed 58f459b

dynamically change horizontal field of view on cameras.

  • Participants
  • Parent commits 7cd3fab
  • Branches camera_change_hfov

Comments (0)

Files changed (1)

File gazebo/rendering/Camera.cc

View file
 void Camera::SetHFOV(math::Angle _angle)
 {
   this->sdf->GetElement("horizontal_fov")->Set(_angle.Radian());
+
+  if (this->camera)
+  {
+    double ratio = static_cast<double>(this->imageWidth) /
+                   static_cast<double>(this->imageHeight);
+    double hfov = this->GetHFOV().Radian();
+    double vfov = 2.0 * atan(tan(hfov / 2.0) / ratio);
+    this->camera->setAspectRatio(ratio);
+    this->camera->setFOVy(Ogre::Radian(vfov));
+  }
 }
 
 //////////////////////////////////////////////////