BaseFrustumVisual.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17#ifndef GZ_RENDERING_BASEFRUSTUMVISUAL_HH_
18#define GZ_RENDERING_BASEFRUSTUMVISUAL_HH_
19
20#include <array>
21
25#include "gz/rendering/Scene.hh"
26
27namespace gz
28{
29 namespace rendering
30 {
31 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
33 template <class T>
35 public virtual FrustumVisual,
36 public virtual T
37 {
38 // Documentation inherited
39 protected: BaseFrustumVisual();
40
41 // Documentation inherited
42 public: virtual ~BaseFrustumVisual();
43
44 // Documentation inherited
45 public: virtual void PreRender() override;
46
47 // Documentation inherited
48 public: virtual void Destroy() override;
49
50 // Documentation inherited
51 public: virtual void Update() override;
52
53 // Documentation inherited
54 public: virtual void Init() override;
55
56 // Documentation inherited
57 public: virtual double NearClipPlane() const override;
58
59 // Documentation inherited
60 public: virtual void SetNearClipPlane(double _near) override;
61
62 // Documentation inherited
63 public: virtual double FarClipPlane() const override;
64
65 // Documentation inherited
66 public: virtual void SetFarClipPlane(double _far) override;
67
68 // Documentation inherited
69 public: virtual math::Angle HFOV() const override;
70
71 // Documentation inherited
72 public: virtual void SetHFOV(const math::Angle &_hfov) override;
73
74 // Documentation inherited
75 public: virtual double AspectRatio() const override;
76
77 // Documentation inherited
78 public: virtual void SetAspectRatio(double _aspectRatio) override;
79
80 // Documentation inherited
81 public: virtual gz::math::Planed Plane(
82 const FrustumVisualPlane _plane) const override;
83
85 public: virtual void CreateMaterials();
86
88 protected: double nearClip = 0.0;
89
91 protected: double farClip = 1.0;
92
94 protected: gz::math::Angle hfov = gz::math::Angle(0.78539);
95
97 protected: double aspectRatio = 1.0;
98
101
104 };
105
107 // BaseFrustumVisual
109 template <class T>
113
115 template <class T>
119
121 template <class T>
123 {
124 T::PreRender();
125 }
126
128 template <class T>
130 {
131 T::Destroy();
132 }
133
135 template <class T>
137 {
138 // no op
139 }
140
142 template <class T>
144 {
145 T::Init();
146 this->CreateMaterials();
147 }
148
150 template <class T>
152 {
153 this->nearClip = _near;
154 }
155
157 template <class T>
159 {
160 return this->nearClip;
161 }
162
164 template <class T>
166 {
167 this->farClip = _far;
168 }
169
171 template <class T>
173 {
174 return this->farClip;
175 }
176
178 template <class T>
180 const gz::math::Angle &_hfov)
181 {
182 this->hfov = _hfov;
183 }
184
186 template <class T>
188 {
189 return this->hfov;
190 }
191
193 template <class T>
195 double _aspectRatio)
196 {
197 this->aspectRatio = _aspectRatio;
198 }
199
201 template <class T>
203 {
204 return this->aspectRatio;
205 }
206
208 template <class T>
210 const FrustumVisualPlane _plane) const
211 {
212 return this->planes[_plane];
213 }
214
216 template <class T>
218 {
219 MaterialPtr mtl;
220
221 if (!this->Scene()->MaterialRegistered("Frustum/BlueRay"))
222 {
223 mtl = this->Scene()->CreateMaterial("Frustum/BlueRay");
224 mtl->SetAmbient(0.0, 0.0, 1.0);
225 mtl->SetDiffuse(0.0, 0.0, 1.0);
226 mtl->SetEmissive(0.0, 0.0, 1.0);
227 mtl->SetSpecular(0.0, 0.0, 1.0);
228 mtl->SetTransparency(0.0);
229 mtl->SetCastShadows(false);
230 mtl->SetReceiveShadows(false);
231 mtl->SetLightingEnabled(false);
232 mtl->SetMetalness(0.1f);
233 mtl->SetReflectivity(0.2);
234 }
235 }
236 }
237 }
238}
239#endif