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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Functions used in GUIPerson and GNEPerson
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
27 
28 #include "GLHelper.h"
29 #include "GUIBasePersonHelper.h"
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
35 void
36 GUIBasePersonHelper::drawAction_drawAsTriangle(const double angle, const double lenght, const double width) {
37  // draw triangle pointing forward
38  glRotated(RAD2DEG(angle + M_PI / 2.), 0, 0, 1);
39  glScaled(lenght, width, 1);
40  glBegin(GL_TRIANGLES);
41  glVertex2d(0., 0.);
42  glVertex2d(1, -0.5);
43  glVertex2d(1, 0.5);
44  glEnd();
45  // draw a smaller triangle to indicate facing
46  GLHelper::setColor(GLHelper::getColor().changedBrightness(-64));
47  glTranslated(0, 0, .045);
48  glBegin(GL_TRIANGLES);
49  glVertex2d(0., 0.);
50  glVertex2d(0.5, -0.25);
51  glVertex2d(0.5, 0.25);
52  glEnd();
53  glTranslated(0, 0, -.045);
54 }
55 
56 
57 void
58 GUIBasePersonHelper::drawAction_drawAsCircle(const double lenght, const double width) {
59  glScaled(lenght, width, 1);
61 }
62 
63 
64 void
65 GUIBasePersonHelper::drawAction_drawAsPoly(const double angle, const double lenght, const double width) {
66  // draw pedestrian shape
67  glRotated(GeomHelper::naviDegree(angle) - 180, 0, 0, -1);
68  glScaled(lenght, width, 1);
70  glTranslated(0, 0, .045);
71  // head
72  glScaled(1, 0.5, 1.);
74  // nose
75  glBegin(GL_TRIANGLES);
76  glVertex2d(0.0, -0.2);
77  glVertex2d(0.0, 0.2);
78  glVertex2d(-0.6, 0.0);
79  glEnd();
80  glTranslated(0, 0, -.045);
81  // body
82  glScaled(0.9, 2.0, 1);
83  glTranslated(0, 0, .04);
84  GLHelper::setColor(lighter);
86  glTranslated(0, 0, -.04);
87 }
88 
89 
90 void
91 GUIBasePersonHelper::drawAction_drawAsImage(const double angle, const double lenght, const double width, const std::string& file,
92  const SUMOVehicleShape guiShape, const double exaggeration) {
93  // first check if filename isn't empty
94  if (file != "") {
95  if (guiShape == SVS_PEDESTRIAN) {
96  glRotated(RAD2DEG(angle + M_PI / 2.), 0, 0, 1);
97  }
98  int textureID = GUITexturesHelper::getTextureID(file);
99  if (textureID > 0) {
100  const double halfLength = lenght / 2.0 * exaggeration;
101  const double halfWidth = width / 2.0 * exaggeration;
102  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
103  }
104  } else {
105  // fallback if no image is defined
106  drawAction_drawAsPoly(angle, lenght, width);
107  }
108 }
109 
110 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:154
static void drawAction_drawAsImage(const double angle, const double lenght, const double width, const std::string &file, const SUMOVehicleShape guiShape, const double exaggeration)
static void drawAction_drawAsTriangle(const double angle, const double lenght, const double width)
static void drawAction_drawAsPoly(const double angle, const double lenght, const double width)
#define RAD2DEG(x)
Definition: GeomHelper.h:39
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
static void drawAction_drawAsCircle(const double lenght, const double width)
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:194
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
static int getTextureID(const std::string &filename, const bool mirrorX=false)
return texture id for the given filename (initialize on first use)
render as a pedestrian
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
#define M_PI
Definition: odrSpiral.cpp:40
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:622