Eclipse SUMO - Simulation of Urban MObility
GUIBasePersonHelper.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 /****************************************************************************/
18 // Functions used in GUIPerson and GNEPerson
19 /****************************************************************************/
20 #include <config.h>
21 
25 
26 #include "GLHelper.h"
27 #include "GUIBasePersonHelper.h"
28 
29 // ===========================================================================
30 // method definitions
31 // ===========================================================================
32 
33 void
34 GUIBasePersonHelper::drawAction_drawAsTriangle(const double angle, const double length, const double width) {
35  // draw triangle pointing forward
36  glRotated(RAD2DEG(angle), 0, 0, 1);
37  glScaled(length, width, 1);
38  glBegin(GL_TRIANGLES);
39  glVertex2d(0., 0.);
40  glVertex2d(-1, -0.5);
41  glVertex2d(-1, 0.5);
42  glEnd();
43  // draw a smaller triangle to indicate facing
44  GLHelper::setColor(GLHelper::getColor().changedBrightness(-64));
45  glTranslated(0, 0, .045);
46  glBegin(GL_TRIANGLES);
47  glVertex2d(0., 0.);
48  glVertex2d(-0.5, -0.25);
49  glVertex2d(-0.5, 0.25);
50  glEnd();
51  glTranslated(0, 0, -.045);
52 }
53 
54 
55 void
56 GUIBasePersonHelper::drawAction_drawAsCircle(const double length, const double width, double detail) {
57  const double maxDim = MAX2(length, width);
58  const int steps = MIN2(MAX2(8, int(detail / 10)), 64);
59  glScaled(maxDim, maxDim, 1);
60  GLHelper::drawFilledCircle(0.8, steps);
61 }
62 
63 
64 void
65 GUIBasePersonHelper::drawAction_drawAsPoly(const double angle, const double length, const double width) {
66  // draw pedestrian shape
67  glRotated(RAD2DEG(angle), 0, 0, 1);
68  glScaled(length, width, 1);
70  glTranslated(0, 0, .045);
71  // front is at the nose
72  glTranslated(-0.5, 0, 0);
73  // head
74  glScaled(1, 0.5, 1.);
76  // nose
77  glBegin(GL_TRIANGLES);
78  glVertex2d(0.0, -0.2);
79  glVertex2d(0.0, 0.2);
80  glVertex2d(0.6, 0.0);
81  glEnd();
82  glTranslated(0, 0, -.045);
83  // body
84  glScaled(0.9, 2.0, 1);
85  glTranslated(0, 0, .04);
86  GLHelper::setColor(lighter);
88  glTranslated(0, 0, -.04);
89 }
90 
91 
92 void
93 GUIBasePersonHelper::drawAction_drawAsImage(const double angle, const double length, const double width, const std::string& file,
94  const SUMOVehicleShape guiShape, const double exaggeration) {
95  // first check if filename isn't empty
96  if (file != "") {
97  if (guiShape == SUMOVehicleShape::PEDESTRIAN) {
98  glRotated(RAD2DEG(angle + M_PI / 2.), 0, 0, 1);
99  }
100  int textureID = GUITexturesHelper::getTextureID(file);
101  if (textureID > 0) {
102  const double halfLength = length / 2.0 * exaggeration;
103  const double halfWidth = width / 2.0 * exaggeration;
104  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
105  }
106  } else {
107  // fallback if no image is defined
108  drawAction_drawAsPoly(angle, length, width);
109  }
110 }
111 
112 
113 /****************************************************************************/
#define RAD2DEG(x)
Definition: GeomHelper.h:36
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
@ PEDESTRIAN
render as a pedestrian
T MIN2(T a, T b)
Definition: StdDefs.h:74
T MAX2(T a, T b)
Definition: StdDefs.h:80
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:431
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:513
static void drawAction_drawAsPoly(const double angle, const double length, const double width)
static void drawAction_drawAsImage(const double angle, const double length, const double width, const std::string &file, const SUMOVehicleShape guiShape, const double exaggeration)
static void drawAction_drawAsCircle(const double length, const double width, double detail)
static void drawAction_drawAsTriangle(const double angle, const double length, const double width)
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
static int getTextureID(const std::string &filename, const bool mirrorX=false)
return texture id for the given filename (initialize on first use)
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:197
#define M_PI
Definition: odrSpiral.cpp:40