@@ -133,57 +133,53 @@ namespace ROS2
133
133
const AZ::u32 stateBefore = debugDisplay.GetState ();
134
134
AZ::Transform transform = GetEntity ()->GetTransform ()->GetWorldTM ();
135
135
136
+ const float distance = m_cameraSensorConfiguration.m_farClipDistance * 0 .1f ;
137
+ const float tangent = static_cast <float >(tan (0 .5f * AZ::DegToRad (m_cameraSensorConfiguration.m_verticalFieldOfViewDeg )));
138
+
139
+ float height = distance * tangent;
140
+ float width = height * m_cameraSensorConfiguration.m_width / m_cameraSensorConfiguration.m_height ;
141
+
142
+ AZ::Vector3 farPoints[4 ];
143
+ farPoints[0 ] = AZ::Vector3 (width, height, distance);
144
+ farPoints[1 ] = AZ::Vector3 (-width, height, distance);
145
+ farPoints[2 ] = AZ::Vector3 (-width, -height, distance);
146
+ farPoints[3 ] = AZ::Vector3 (width, -height, distance);
147
+
148
+ AZ::Vector3 nearPoints[4 ];
149
+ nearPoints[0 ] = farPoints[0 ].GetNormalizedSafe () * m_cameraSensorConfiguration.m_nearClipDistance ;
150
+ nearPoints[1 ] = farPoints[1 ].GetNormalizedSafe () * m_cameraSensorConfiguration.m_nearClipDistance ;
151
+ nearPoints[2 ] = farPoints[2 ].GetNormalizedSafe () * m_cameraSensorConfiguration.m_nearClipDistance ;
152
+ nearPoints[3 ] = farPoints[3 ].GetNormalizedSafe () * m_cameraSensorConfiguration.m_nearClipDistance ;
153
+
136
154
// dimension of drawing
137
- const float arrowRise = 1 .1f ;
138
- const float arrowSize = 0 .5f ;
139
- const float frustumScale = 0 .1f ;
140
-
141
- transform.SetUniformScale (frustumScale);
142
- debugDisplay.DepthTestOff ();
143
- const float vertical = 0 .5f * AZStd::tan ((AZ::DegToRad (m_cameraSensorConfiguration.m_verticalFieldOfViewDeg * 0 .5f )));
144
- const float horizontal = m_cameraSensorConfiguration.m_height * vertical / m_cameraSensorConfiguration.m_width ;
145
-
146
- // frustum drawing
147
- const AZ::Vector3 p1 (-vertical, -horizontal, 1 .f );
148
- const AZ::Vector3 p2 (vertical, -horizontal, 1 .f );
149
- const AZ::Vector3 p3 (vertical, horizontal, 1 .f );
150
- const AZ::Vector3 p4 (-vertical, horizontal, 1 .f );
151
- const AZ::Vector3 p0 (0 , 0 , 0 );
152
- const AZ::Vector3 py (0.1 , 0 , 0 );
153
-
154
- const auto pt1 = transform.TransformPoint (p1);
155
- const auto pt2 = transform.TransformPoint (p2);
156
- const auto pt3 = transform.TransformPoint (p3);
157
- const auto pt4 = transform.TransformPoint (p4);
158
- const auto pt0 = transform.TransformPoint (p0);
159
- const auto ptz = transform.TransformPoint (AZ::Vector3::CreateAxisZ (0 .2f ));
160
- const auto pty = transform.TransformPoint (AZ::Vector3::CreateAxisY (0 .2f ));
161
- const auto ptx = transform.TransformPoint (AZ::Vector3::CreateAxisX (0 .2f ));
155
+ const float arrowRise = 0 .11f ;
156
+ const float arrowSize = 0 .05f ;
157
+
158
+ const AZ::Vector3 pt0 (0 , 0 , 0 );
159
+ const auto ptz = AZ::Vector3::CreateAxisZ (0 .2f );
160
+ const auto pty = AZ::Vector3::CreateAxisY (0 .2f );
161
+ const auto ptx = AZ::Vector3::CreateAxisX (0 .2f );
162
+
163
+ debugDisplay.PushMatrix (transform);
162
164
163
165
debugDisplay.SetColor (AZ::Color (0 .f , 1 .f , 1 .f , 1 .f ));
164
- debugDisplay.SetLineWidth (1 );
165
- debugDisplay.DrawLine (pt1, pt2);
166
- debugDisplay.DrawLine (pt2, pt3);
167
- debugDisplay.DrawLine (pt3, pt4);
168
- debugDisplay.DrawLine (pt4, pt1);
169
- debugDisplay.DrawLine (pt1, pt0);
170
- debugDisplay.DrawLine (pt2, pt0);
171
- debugDisplay.DrawLine (pt3, pt0);
172
- debugDisplay.DrawLine (pt4, pt0);
166
+ debugDisplay.DrawLine (nearPoints[0 ], farPoints[0 ]);
167
+ debugDisplay.DrawLine (nearPoints[1 ], farPoints[1 ]);
168
+ debugDisplay.DrawLine (nearPoints[2 ], farPoints[2 ]);
169
+ debugDisplay.DrawLine (nearPoints[3 ], farPoints[3 ]);
170
+ debugDisplay.DrawPolyLine (nearPoints, AZ_ARRAY_SIZE (nearPoints));
171
+ debugDisplay.DrawPolyLine (farPoints, AZ_ARRAY_SIZE (farPoints));
173
172
174
173
// up-arrow drawing
175
- const AZ::Vector3 pa1 (-arrowSize * vertical, -arrowRise * horizontal, 1 .f );
176
- const AZ::Vector3 pa2 (arrowSize * vertical, -arrowRise * horizontal, 1 .f );
177
- const AZ::Vector3 pa3 (0 , (-arrowRise - arrowSize) * horizontal, 1 .f );
178
- const auto pat1 = transform.TransformPoint (pa1);
179
- const auto pat2 = transform.TransformPoint (pa2);
180
- const auto pat3 = transform.TransformPoint (pa3);
174
+ const AZ::Vector3 pa1 (-arrowSize * height, -arrowRise * width, 1 .f );
175
+ const AZ::Vector3 pa2 (arrowSize * height, -arrowRise * width, 1 .f );
176
+ const AZ::Vector3 pa3 (0 , (-arrowRise - arrowSize) * width, 1 .f );
181
177
182
178
debugDisplay.SetColor (AZ::Color (0 .f , 0 .6f , 1 .f , 1 .f ));
183
179
debugDisplay.SetLineWidth (1 );
184
- debugDisplay.DrawLine (pat1, pat2 );
185
- debugDisplay.DrawLine (pat2, pat3 );
186
- debugDisplay.DrawLine (pat3, pat1 );
180
+ debugDisplay.DrawLine (pa1, pa2 );
181
+ debugDisplay.DrawLine (pa2, pa3 );
182
+ debugDisplay.DrawLine (pa3, pa1 );
187
183
188
184
// coordinate system drawing
189
185
debugDisplay.SetColor (AZ::Color (1 .f , 0 .f , 0 .f , 1 .f ));
@@ -198,6 +194,8 @@ namespace ROS2
198
194
debugDisplay.SetLineWidth (2 );
199
195
debugDisplay.DrawLine (ptz, pt0);
200
196
197
+ debugDisplay.PopMatrix ();
198
+
201
199
debugDisplay.SetState (stateBefore);
202
200
}
203
201
0 commit comments