void GUIPerson::drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const { glPushName(getGlID()); glPushMatrix(); glTranslated(0, 0, getType() - .1); // don't draw on top of other cars if (hasActiveAddVisualisation(parent, VO_SHOW_WALKINGAREA_PATH)) { drawAction_drawWalkingareaPath(s); } if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) { if (getCurrentStageType() == MOVING_WITHOUT_VEHICLE) { setColor(s); RGBColor current = GLHelper::getColor(); RGBColor darker = current.changedBrightness(-51); GLHelper::setColor(darker); MSPersonStage_Walking* stage = dynamic_cast<MSPersonStage_Walking*>(getCurrentStage()); assert(stage != 0); const SUMOReal exaggeration = s.personSize.getExaggeration(s); const ConstMSEdgeVector& edges = stage->getRoute(); for (ConstMSEdgeVector::const_iterator it = edges.begin(); it != edges.end(); ++it) { GUILane* lane = static_cast<GUILane*>((*it)->getLanes()[0]); GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration); } } } glPopMatrix(); glPopName(); }
void GUIVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& s, bool asImage) const { RGBColor current = GLHelper::getColor(); RGBColor darker = current.changedBrightness(-51); const double exaggeration = s.vehicleSize.getExaggeration(s, this); const double totalLength = getVType().getLength(); double upscaleLength = exaggeration; if (exaggeration > 1 && totalLength > 5) { // reduce the length/width ratio because this is not usefull at high zoom upscaleLength = MAX2(1.0, upscaleLength * (5 + sqrt(totalLength - 5)) / totalLength); } const double locomotiveLength = getVehicleType().getParameter().locomotiveLength * upscaleLength; if (exaggeration == 0) { return; } const double defaultLength = getVehicleType().getParameter().carriageLength * upscaleLength; const double carriageGap = getVehicleType().getParameter().carriageGap * upscaleLength; const double length = totalLength * upscaleLength; const double halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration; glPopMatrix(); // undo initial translation and rotation const double xCornerCut = 0.3 * exaggeration; const double yCornerCut = 0.4 * exaggeration; // round to closest integer const int numCarriages = MAX2(1, 1 + (int)((length - locomotiveLength) / (defaultLength + carriageGap) + 0.5)); assert(numCarriages > 0); double carriageLengthWithGap = length / numCarriages; double carriageLength = carriageLengthWithGap - carriageGap; double firstCarriageLength = carriageLength; if (defaultLength != locomotiveLength && numCarriages > 1) { firstCarriageLength = locomotiveLength; carriageLengthWithGap = (length - locomotiveLength) / (numCarriages - 1); carriageLength = carriageLengthWithGap - carriageGap; } const int firstPassengerCarriage = defaultLength == locomotiveLength || numCarriages == 1 ? 0 : 1; const int totalSeats = getVType().getPersonCapacity() + getVType().getContainerCapacity(); const int seatsPerCarriage = (int)ceil(totalSeats / (numCarriages - firstPassengerCarriage)); // lane on which the carriage front is situated MSLane* lane = myLane; int routeIndex = getRoutePosition(); // lane on which the carriage back is situated MSLane* backLane = myLane; int backRouteIndex = routeIndex; // offsets of front and back double carriageOffset = myState.pos(); double carriageBackOffset = myState.pos() - firstCarriageLength; // handle seats int requiredSeats = getNumPassengers() + getNumContainers(); if (requiredSeats > 0) { mySeatPositions.clear(); } Position front, back; double angle = 0.; // draw individual carriages double curCLength = firstCarriageLength; //std::cout << SIMTIME << " veh=" << getID() << " curCLength=" << curCLength << " loc=" << locomotiveLength << " car=" << carriageLength << " tlen=" << totalLength << " len=" << length << "\n"; for (int i = 0; i < numCarriages; ++i) { if (i > 0) { curCLength = carriageLength; } while (carriageOffset < 0) { MSLane* prev = getPreviousLane(lane, routeIndex); if (prev != lane) { carriageOffset += prev->getLength(); } else { // no lane available for drawing. carriageOffset = 0; } lane = prev; } while (carriageBackOffset < 0) { MSLane* prev = getPreviousLane(backLane, backRouteIndex); if (prev != backLane) { carriageBackOffset += prev->getLength(); } else { // no lane available for drawing. carriageBackOffset = 0; } backLane = prev; } front = lane->geometryPositionAtOffset(carriageOffset); back = backLane->geometryPositionAtOffset(carriageBackOffset); if (front == back) { // no place for drawing available continue; } const double drawnCarriageLength = front.distanceTo2D(back); angle = atan2((front.x() - back.x()), (back.y() - front.y())) * (double) 180.0 / (double) M_PI; if (i >= firstPassengerCarriage) { computeSeats(front, back, seatsPerCarriage, exaggeration, requiredSeats); } glPushMatrix(); glTranslated(front.x(), front.y(), getType()); glRotated(angle, 0, 0, 1); if (!asImage || !GUIBaseVehicleHelper::drawAction_drawVehicleAsImage(s, getVType().getImgFile(), this, getVType().getWidth(), curCLength)) { switch (getVType().getGuiShape()) { case SVS_TRUCK_SEMITRAILER: case SVS_TRUCK_1TRAILER: if (i == 0) { GUIBaseVehicleHelper::drawAction_drawVehicleAsPoly(s, getVType().getGuiShape(), getVType().getWidth() * exaggeration, curCLength, i); } else { GLHelper::setColor(current); GLHelper::drawBoxLine(Position(0, 0), 180, curCLength, halfWidth); } break; default: { if (i == 0) { GLHelper::setColor(darker); } else { GLHelper::setColor(current); } // generic rail carriage glBegin(GL_TRIANGLE_FAN); glVertex2d(-halfWidth + xCornerCut, 0); glVertex2d(-halfWidth, yCornerCut); glVertex2d(-halfWidth, drawnCarriageLength - yCornerCut); glVertex2d(-halfWidth + xCornerCut, drawnCarriageLength); glVertex2d(halfWidth - xCornerCut, drawnCarriageLength); glVertex2d(halfWidth, drawnCarriageLength - yCornerCut); glVertex2d(halfWidth, yCornerCut); glVertex2d(halfWidth - xCornerCut, 0); glEnd(); } } } glPopMatrix(); carriageOffset -= (curCLength + carriageGap); carriageBackOffset -= carriageLengthWithGap; } if (getVType().getGuiShape() == SVS_RAIL_CAR) { glPushMatrix(); glTranslated(front.x(), front.y(), getType()); glRotated(angle, 0, 0, 1); drawAction_drawVehicleBlinker(curCLength); drawAction_drawVehicleBrakeLight(curCLength); glPopMatrix(); } // restore matrix glPushMatrix(); front = getPosition(); glTranslated(front.x(), front.y(), getType()); const double degAngle = RAD2DEG(getAngle() + M_PI / 2.); glRotated(degAngle, 0, 0, 1); glScaled(exaggeration, upscaleLength, 1); if (mySeatPositions.size() == 0) { mySeatPositions.push_back(back); } }