Path: blob/main/src/utils/gui/div/GUIBasePersonHelper.cpp
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GUIBasePersonHelper.cpp14/// @author Pablo Alvarez Lopez15/// @date Feb 201816///17// Functions used in GUIPerson and GNEPerson18/****************************************************************************/19#include <config.h>2021#include <microsim/transportables/MSPModel_Striping.h>22#include <utils/gui/globjects/GLIncludes.h>23#include <utils/gui/images/GUITexturesHelper.h>2425#include "GLHelper.h"26#include "GUIBasePersonHelper.h"2728// ===========================================================================29// method definitions30// ===========================================================================3132void33GUIBasePersonHelper::drawAction_drawAsTriangle(const double angle, const double length, const double width) {34// draw triangle pointing forward35glRotated(RAD2DEG(angle), 0, 0, 1);36glScaled(length, width, 1);37glBegin(GL_TRIANGLES);38glVertex2d(0., 0.);39glVertex2d(-1, -0.5);40glVertex2d(-1, 0.5);41glEnd();42// draw a smaller triangle to indicate facing43GLHelper::setColor(GLHelper::getColor().changedBrightness(-64));44glTranslated(0, 0, .045);45glBegin(GL_TRIANGLES);46glVertex2d(0., 0.);47glVertex2d(-0.5, -0.25);48glVertex2d(-0.5, 0.25);49glEnd();50glTranslated(0, 0, -.045);51}525354void55GUIBasePersonHelper::drawAction_drawAsCircle(const double angle, const double length, const double width, double detail) {56glRotated(RAD2DEG(angle), 0, 0, 1);57const double maxDim = MAX2(length, width);58const int steps = MIN2(MAX2(8, int(detail / 10)), 64);59glScaled(maxDim, maxDim, 1);60glTranslated(-0.8, 0, 0);61GLHelper::drawFilledCircle(0.8, steps);62}636465void66GUIBasePersonHelper::drawAction_drawAsCenteredCircle(const double length, const double width, double detail) {67const double maxDim = MAX2(length, width);68const int steps = MIN2(MAX2(8, int(detail / 10)), 64);69glScaled(maxDim, maxDim, 1);70GLHelper::drawFilledCircle(0.8, steps);71}727374void75GUIBasePersonHelper::drawAction_drawAsPoly(const double angle, const double length, const double width) {76// draw pedestrian shape77glRotated(RAD2DEG(angle), 0, 0, 1);78glScaled(length, width, 1);79RGBColor lighter = GLHelper::getColor().changedBrightness(51);80glTranslated(0, 0, .045);81// front is at the nose82glTranslated(-0.5, 0, 0);83// head84glScaled(1, 0.5, 1.);85GLHelper::drawFilledCircle(0.5);86// nose87glBegin(GL_TRIANGLES);88glVertex2d(0.0, -0.2);89glVertex2d(0.0, 0.2);90glVertex2d(0.6, 0.0);91glEnd();92glTranslated(0, 0, -.045);93// body94glScaled(0.9, 2.0, 1);95glTranslated(0, 0, .04);96GLHelper::setColor(lighter);97GLHelper::drawFilledCircle(0.5);98glTranslated(0, 0, -.04);99}100101102void103GUIBasePersonHelper::drawAction_drawAsImage(const double angle, const double length, const double width, const std::string& file,104const SUMOVehicleShape guiShape, const double exaggeration) {105// first check if filename isn't empty106if (file != "") {107if (guiShape == SUMOVehicleShape::PEDESTRIAN) {108glRotated(RAD2DEG(angle + M_PI / 2.), 0, 0, 1);109}110int textureID = GUITexturesHelper::getTextureID(file);111if (textureID > 0) {112const double halfLength = length / 2.0 * exaggeration;113const double halfWidth = width / 2.0 * exaggeration;114GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);115}116} else {117// fallback if no image is defined118drawAction_drawAsPoly(angle, length, width);119}120}121122123/****************************************************************************/124125126