17 #ifndef GZ_RENDERING_BASE_BASECAMERA_HH_
18 #define GZ_RENDERING_BASE_BASECAMERA_HH_
22 #include <gz/math/Matrix3.hh>
23 #include <gz/math/Pose3.hh>
25 #include <gz/common/Event.hh>
26 #include <gz/common/Console.hh>
27 #include <gz/utils/SuppressWarning.hh>
39 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
41 class BaseDepthCamera;
52 public:
virtual unsigned int ImageWidth()
const override;
65 bool _reinterpretable =
false)
94 public:
virtual void Update()
override;
100 public:
virtual void Copy(
Image &_image)
const override;
111 &_mousePos)
override;
142 const bool _worldFrame)
override;
213 protected:
virtual void Load()
override;
219 GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
220 protected:
common::EventT<void(
const void *,
unsigned int,
unsigned int,
226 protected:
double nearClip = 0.01;
229 protected:
double farClip = 1000.0;
232 protected:
double aspect = 1.3333333;
238 protected:
unsigned int antiAliasing = 0u;
244 protected:
bool trackWorldFrame =
false;
252 protected:
double trackPGain = 1.0;
256 GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
259 protected:
bool followWorldFrame =
false;
263 protected:
double followPGain = 1.0;
301 this->SetAspectRatio(
302 static_cast<double>(_width) /
static_cast<double>(this->ImageHeight()));
317 this->SetAspectRatio(
318 static_cast<double>(this->ImageWidth()) /
static_cast<double>(_height));
326 unsigned int width = this->ImageWidth();
327 unsigned int height = this->ImageHeight();
341 bool _reinterpretable)
354 std::dynamic_pointer_cast<Camera>(this->shared_from_this());
359 if (this->followNode)
362 if (this->followWorldFrame)
365 this->followNode->WorldPosition() + this->followOffset;
367 (targetCamPos - this->WorldPosition()) * this->followPGain;
368 this->SetWorldPosition(pos);
374 this->WorldRotation());
375 targetCamPose = this->followNode->WorldPose() * targetCamPose;
378 (targetCamPose.
Pos() - this->WorldPosition()) * this->followPGain;
379 this->SetWorldPosition(pos);
389 if (this->trackWorldFrame)
391 targetPose.
Pos() += this->trackNode->WorldPosition();
395 targetPose = this->trackNode->WorldPose() * targetPose;
406 this->trackPGain, this->WorldRotation(), p.
Rot(),
true);
408 this->SetWorldRotation(q);
424 unsigned int width = this->ImageWidth();
425 unsigned int height = this->ImageHeight();
426 return Image(width, height, format);
436 if (!this->
Scene()->LegacyAutoGpuFlush())
469 return newFrameEvent.Connect(_listener);
477 unsigned int size = this->ImageMemorySize();
478 return new unsigned char *[size];
494 this->SetImageWidth(1);
495 this->SetImageHeight(1);
497 this->SetAspectRatio(0.0);
498 this->SetAntiAliasing(0u);
500 this->SetNearClipPlane(0.01);
501 this->SetFarClipPlane(1000);
509 gzerr <<
"Render window not supported for render engine: " <<
521 double ratio = this->AspectRatio();
522 double fov = this->HFOV().Radian();
525 double _near = this->NearClipPlane();
526 double _far = this->FarClipPlane();
527 double top = _near *
std::tan(0.5*vfov) / f;
528 double height = 2 * top;
529 double width = ratio * height;
530 double left = -0.5 * width;
531 double right = left + width;
532 double bottom = top - height;
534 double invw = 1.0 / (right - left);
535 double invh = 1.0 / (top - bottom);
536 double invd = 1.0 / (_far - _near);
537 double x = 2 * _near * invw;
538 double y = 2 * _near * invh;
539 double a = (right + left) * invw;
540 double b = (top + bottom) * invh;
541 double c = -(_far + _near) * invd;
542 double d = -2 * _far * _near * invd;
553 double width = this->ImageWidth();
554 double height = this->ImageHeight();
555 double left = -width * 0.5;
556 double right = -left;
557 double top = height * 0.5;
558 double bottom = -top;
559 double _near = this->NearClipPlane();
560 double _far = this->FarClipPlane();
562 double invw = 1.0 / (right - left);
563 double invh = 1.0 / (top - bottom);
564 double invd = 1.0 / (_far - _near);
566 result(0, 0) = 2.0 * invw;
567 result(0, 3) = -(right + left) * invw;
568 result(1, 1) = 2.0 * invh;
569 result(1, 3) = -(top + bottom) * invh;
570 result(2, 2) = -2.0 * invd;
571 result(2, 3) = -(_far + _near) * invd;
576 gzerr <<
"Unknown camera projection type: " << this->projectionType
587 this->projectionMatrix = _matrix;
613 this->projectionType = _type;
620 return this->projectionType;
630 double w = m(3, 0) * _pt.
X() + m(3, 1) * _pt.
Y() + m(3, 2) * _pt.
Z()
632 pos.
X() = pos.
X() / w;
633 pos.
Y() = pos.
Y() / w;
635 screenPos.
X() =
static_cast<int>(
636 ((pos.
X() / 2.0) + 0.5) * this->ImageWidth());
637 screenPos.
Y() =
static_cast<int>(
638 (1 - ((pos.
Y() / 2.0) + 0.5)) * this->ImageHeight());
654 gzerr <<
"VisualAt not implemented for the render engine" <<
std::endl;
672 if (this->aspect <= 0.0)
674 return static_cast<double>(this->ImageWidth()) /
675 static_cast<double>(this->ImageHeight());
684 this->aspect = _aspect;
691 return this->antiAliasing;
698 this->antiAliasing = _aa;
705 return this->farClip;
712 this->farClip = _far;
719 return this->nearClip;
726 this->nearClip = _near;
734 this->trackNode = _target;
735 this->trackWorldFrame = _worldFrame;
736 this->trackOffset = _offset;
743 return this->trackNode;
750 return this->trackOffset;
757 this->trackOffset = _offset;
771 return this->trackPGain;
779 this->followNode = _target;
780 this->followWorldFrame = _worldFrame;
781 this->followOffset = _offset;
788 return this->followNode;
795 return this->followOffset;
802 this->followOffset = _offset;
816 return this->followPGain;
823 gzerr <<
"SetMaterial not implemented for current render"
831 gzerr <<
"RenderTextureGLId is not supported by current render"
840 gzerr <<
"RenderTextureMetalId is not supported by current render"
848 gzerr <<
"PrepareForExternalSampling is not supported by current render"
873 renderTarget->RemoveAllRenderPasses();