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