LCOV - code coverage report
Current view: top level - src/utils/gui/div - GUIBasePersonHelper.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 37 60 61.7 %
Date: 2024-05-02 15:31:40 Functions: 2 5 40.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4             : // This program and the accompanying materials are made available under the
       5             : // terms of the Eclipse Public License 2.0 which is available at
       6             : // https://www.eclipse.org/legal/epl-2.0/
       7             : // This Source Code may also be made available under the following Secondary
       8             : // Licenses when the conditions for such availability set forth in the Eclipse
       9             : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10             : // or later which is available at
      11             : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12             : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13             : /****************************************************************************/
      14             : /// @file    GUIBasePersonHelper.cpp
      15             : /// @author  Pablo Alvarez Lopez
      16             : /// @date    Feb 2018
      17             : ///
      18             : // Functions used in GUIPerson and GNEPerson
      19             : /****************************************************************************/
      20             : #include <config.h>
      21             : 
      22             : #include <microsim/transportables/MSPModel_Striping.h>
      23             : #include <utils/gui/globjects/GLIncludes.h>
      24             : #include <utils/gui/images/GUITexturesHelper.h>
      25             : 
      26             : #include "GLHelper.h"
      27             : #include "GUIBasePersonHelper.h"
      28             : 
      29             : // ===========================================================================
      30             : // method definitions
      31             : // ===========================================================================
      32             : 
      33             : void
      34      877429 : GUIBasePersonHelper::drawAction_drawAsTriangle(const double angle, const double length, const double width) {
      35             :     // draw triangle pointing forward
      36      877429 :     glRotated(RAD2DEG(angle), 0, 0, 1);
      37      877429 :     glScaled(length, width, 1);
      38      877429 :     glBegin(GL_TRIANGLES);
      39      877429 :     glVertex2d(0., 0.);
      40      877429 :     glVertex2d(-1, -0.5);
      41      877429 :     glVertex2d(-1, 0.5);
      42      877429 :     glEnd();
      43             :     // draw a smaller triangle to indicate facing
      44      877429 :     GLHelper::setColor(GLHelper::getColor().changedBrightness(-64));
      45      877429 :     glTranslated(0, 0, .045);
      46      877429 :     glBegin(GL_TRIANGLES);
      47      877429 :     glVertex2d(0., 0.);
      48      877429 :     glVertex2d(-0.5, -0.25);
      49      877429 :     glVertex2d(-0.5, 0.25);
      50      877429 :     glEnd();
      51      877429 :     glTranslated(0, 0, -.045);
      52      877429 : }
      53             : 
      54             : 
      55             : void
      56           0 : GUIBasePersonHelper::drawAction_drawAsCircle(const double angle, const double length, const double width, double detail) {
      57           0 :     glRotated(RAD2DEG(angle), 0, 0, 1);
      58             :     const double maxDim = MAX2(length, width);
      59           0 :     const int steps = MIN2(MAX2(8, int(detail / 10)), 64);
      60           0 :     glScaled(maxDim, maxDim, 1);
      61           0 :     glTranslated(-0.8, 0, 0);
      62           0 :     GLHelper::drawFilledCircle(0.8, steps);
      63           0 : }
      64             : 
      65             : 
      66             : void
      67           0 : GUIBasePersonHelper::drawAction_drawAsCenteredCircle(const double length, const double width, double detail) {
      68             :     const double maxDim = MAX2(length, width);
      69           0 :     const int steps = MIN2(MAX2(8, int(detail / 10)), 64);
      70           0 :     glScaled(maxDim, maxDim, 1);
      71           0 :     GLHelper::drawFilledCircle(0.8, steps);
      72           0 : }
      73             : 
      74             : 
      75             : void
      76       53326 : GUIBasePersonHelper::drawAction_drawAsPoly(const double angle, const double length, const double width) {
      77             :     // draw pedestrian shape
      78       53326 :     glRotated(RAD2DEG(angle), 0, 0, 1);
      79       53326 :     glScaled(length, width, 1);
      80       53326 :     RGBColor lighter = GLHelper::getColor().changedBrightness(51);
      81       53326 :     glTranslated(0, 0, .045);
      82             :     // front is at the nose
      83       53326 :     glTranslated(-0.5, 0, 0);
      84             :     // head
      85       53326 :     glScaled(1, 0.5, 1.);
      86       53326 :     GLHelper::drawFilledCircle(0.5);
      87             :     // nose
      88       53326 :     glBegin(GL_TRIANGLES);
      89       53326 :     glVertex2d(0.0, -0.2);
      90       53326 :     glVertex2d(0.0, 0.2);
      91       53326 :     glVertex2d(0.6, 0.0);
      92       53326 :     glEnd();
      93       53326 :     glTranslated(0, 0, -.045);
      94             :     // body
      95       53326 :     glScaled(0.9, 2.0, 1);
      96       53326 :     glTranslated(0, 0, .04);
      97       53326 :     GLHelper::setColor(lighter);
      98       53326 :     GLHelper::drawFilledCircle(0.5);
      99       53326 :     glTranslated(0, 0, -.04);
     100       53326 : }
     101             : 
     102             : 
     103             : void
     104           0 : GUIBasePersonHelper::drawAction_drawAsImage(const double angle, const double length, const double width, const std::string& file,
     105             :         const SUMOVehicleShape guiShape, const double exaggeration) {
     106             :     // first check if filename isn't empty
     107           0 :     if (file != "") {
     108           0 :         if (guiShape == SUMOVehicleShape::PEDESTRIAN) {
     109           0 :             glRotated(RAD2DEG(angle + M_PI / 2.), 0, 0, 1);
     110             :         }
     111           0 :         int textureID = GUITexturesHelper::getTextureID(file);
     112           0 :         if (textureID > 0) {
     113           0 :             const double halfLength = length / 2.0 * exaggeration;
     114           0 :             const double halfWidth = width / 2.0 * exaggeration;
     115           0 :             GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
     116             :         }
     117             :     } else {
     118             :         // fallback if no image is defined
     119           0 :         drawAction_drawAsPoly(angle, length, width);
     120             :     }
     121           0 : }
     122             : 
     123             : 
     124             : /****************************************************************************/

Generated by: LCOV version 1.14