Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Aug 31, 2024
1 parent c2b867a commit f730e27
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions selfdrive/ui/qt/onroad/dmon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "selfdrive/ui/qt/onroad/buttons.h"
#include "selfdrive/ui/qt/util.h"

// Default 3D coordinates for face keypoints
static constexpr vec3 DEFAULT_FACE_KPTS_3D[] = {
{-5.98, -51.20, 8.00}, {-17.64, -49.14, 8.00}, {-23.81, -46.40, 8.00}, {-29.98, -40.91, 8.00}, {-32.04, -37.49, 8.00},
{-34.10, -32.00, 8.00}, {-36.16, -21.03, 8.00}, {-36.16, 6.40, 8.00}, {-35.47, 10.51, 8.00}, {-32.73, 19.43, 8.00},
Expand All @@ -15,6 +16,7 @@ static constexpr vec3 DEFAULT_FACE_KPTS_3D[] = {
{18.02, -49.14, 8.00}, {6.36, -51.20, 8.00}, {-5.98, -51.20, 8.00},
};

// Colors used for drawing based on monitoring state
static const QColor DMON_ENGAGED_COLOR = QColor::fromRgbF(0.1, 0.945, 0.26);
static const QColor DMON_DISENGAGED_COLOR = QColor::fromRgbF(0.545, 0.545, 0.545);

Expand Down Expand Up @@ -47,6 +49,7 @@ void DriverMonitorRenderer::updateState(const UIState &s) {
auto [sin_y, sin_x, sin_z] = driver_pose_sins;
auto [cos_y, cos_x, cos_z] = driver_pose_coss;

// Rotation matrix for transforming face keypoints based on driver's head orientation
const mat3 r_xyz = {{
cos_x * cos_z, cos_x * sin_z, -sin_x,
-sin_y * sin_x * cos_z - cos_y * sin_z, -sin_y * sin_x * sin_z + cos_y * cos_z, -sin_y * cos_x,
Expand Down Expand Up @@ -92,8 +95,11 @@ void DriverMonitorRenderer::draw(QPainter &painter, const QRect &surface_rect) {
float delta_x = -driver_pose_sins[1] * arc_l / 2;
float delta_y = -driver_pose_sins[0] * arc_l / 2;

// Draw horizontal tracking arc
painter.setPen(QPen(arc_color, arc_t_default + arc_t_extend * fmin(1.0, driver_pose_diff[1] * 5.0), Qt::SolidLine, Qt::RoundCap));
painter.drawArc(QRectF(std::fmin(x + delta_x, x), y - arc_l / 2, fabs(delta_x), arc_l), (driver_pose_sins[1] > 0 ? 90 : -90) * 16, 180 * 16);

// Draw vertical tracking arc
painter.setPen(QPen(arc_color, arc_t_default + arc_t_extend * fmin(1.0, driver_pose_diff[0] * 5.0), Qt::SolidLine, Qt::RoundCap));
painter.drawArc(QRectF(x - arc_l / 2, std::fmin(y + delta_y, y), arc_l, fabs(delta_y)), (driver_pose_sins[0] > 0 ? 0 : 180) * 16, 180 * 16);

Expand Down

0 comments on commit f730e27

Please sign in to comment.