void basic_spaceship::draw(Wt::WPainter& painter) const { simple_rigid_body::draw(painter); /* Wt::WRectF rc( -m_half_width, -m_half_width, m_half_width * 2, m_half_width * 2 ); */ painter.save(); painter.translate(m_body->GetPosition().x, m_body->GetPosition().y); painter.rotate(m_body->GetAngle() * 360.0 / (2 * b2_pi)); // painter.drawRect(rc); thruster_config< WorldDimensionality::dim2D > const& t_cfg = *m_t_cfg; double const ThrusterSize = m_half_width * 0.3; std::array< Wt::WPointF, 3 > points = { Wt::WPointF(0, 0), Wt::WPointF(-ThrusterSize / 2, -ThrusterSize), Wt::WPointF(ThrusterSize / 2, -ThrusterSize) }; Wt::WPen pen(Wt::GlobalColor::black); for(size_t i = 0; i < m_t_cfg->num_thrusters(); ++i) { painter.save(); auto const& tpos = m_half_width * t_cfg[i].pos; painter.translate(tpos[0], tpos[1]); double dir_x = t_cfg[i].dir[0]; double dir_y = t_cfg[i].dir[1]; double theta = boost::math::copysign(std::acos(dir_y), dir_x); painter.rotate(360.0 * -theta / (2 * boost::math::double_constants::pi)); double temperature = m_t_system[i].t.temperature(); Wt::WColor color((int)(temperature * 255), 0, 0); pen.setColor(color); painter.setPen(pen); Wt::WBrush br(color); painter.setBrush(br); painter.drawPolygon(&points[0], points.size()); painter.restore(); } // double const IndicatorSize = m_half_width * 0.35; auto const IndicatorPos = b2Vec2(0.f, 1.4f * m_half_width); m_front_sensor->draw(painter, IndicatorPos); m_rear_sensor->draw(painter, IndicatorPos); m_left_sensor->draw(painter, IndicatorPos); m_right_sensor->draw(painter, IndicatorPos); painter.restore(); }
void elevator_system_drawer::draw_elevator(Wt::WPainter& painter, Wt::WRectF const& rc) { const auto floor_height = get_floor_height(SizeFormat::Pixels); const auto elevator_height = get_elevator_height(SizeFormat::Pixels); painter.save(); Wt::WRectF rc_elevator( rc.left(), rc.bottom() - get_current_floor() * floor_height - elevator_height, rc.width(), elevator_height ); if(m_stage == AnimationStage::Moving) { auto travelled = m_stage_step * ElevatorSpeed * m_pix_multiplier; travelled = std::min(travelled, floor_height); auto sign = m_sys.m_state.direction == Direction::Up ? 1.0 : -1.0; rc_elevator = Wt::WRectF( rc_elevator.left(), rc_elevator.top() - sign * travelled, rc_elevator.width(), rc_elevator.height() ); } double exit_door_openness = 0.0; switch(m_stage) { case AnimationStage::ExitDoorsOpening: exit_door_openness = m_stage_step * DoorSpeed * m_pix_multiplier / elevator_height; exit_door_openness = std::min(exit_door_openness, 1.0); break; case AnimationStage::ExitDoorsClosing: exit_door_openness = 1.0 - m_stage_step * DoorSpeed * m_pix_multiplier / elevator_height; exit_door_openness = std::max(exit_door_openness, 0.0); break; case AnimationStage::GettingOff: exit_door_openness = 1.0; break; } double entry_door_openness = 0.0; switch(m_stage) { case AnimationStage::EntryDoorsOpening: entry_door_openness = m_stage_step * DoorSpeed * m_pix_multiplier / elevator_height; entry_door_openness = std::min(entry_door_openness, 1.0); break; case AnimationStage::EntryDoorsClosing: entry_door_openness = 1.0 - m_stage_step * DoorSpeed * m_pix_multiplier / elevator_height; entry_door_openness = std::max(entry_door_openness, 0.0); break; case AnimationStage::GettingOn: entry_door_openness = 1.0; break; } painter.drawLine(rc_elevator.topLeft(), rc_elevator.topRight()); painter.drawLine(rc_elevator.bottomLeft(), rc_elevator.bottomRight()); painter.drawLine( rc_elevator.left(), rc_elevator.top(), rc_elevator.left(), rc_elevator.top() + (1.0 - entry_door_openness) * elevator_height ); painter.drawLine( rc_elevator.right(), rc_elevator.top(), rc_elevator.right(), rc_elevator.top() + (1.0 - exit_door_openness) * elevator_height ); if(m_sys.is_moving(m_sys.m_state.direction)) { painter.save(); painter.translate(rc_elevator.left(), rc_elevator.top()); if(m_sys.m_state.direction == elevator_system::Direction::Down) { painter.translate(0.0, rc_elevator.height() * 0.5); painter.scale(1.0, -1.0); } painter.scale(rc_elevator.width(), rc_elevator.height()); std::array< Wt::WPointF, 3 > points{ { { 0.5, 0.1 }, { 0.2, 0.4 }, { 0.8, 0.4 }, } }; painter.setPen(Wt::WPen(Wt::green)); painter.setBrush(Wt::WBrush(Wt::green)); painter.drawPolygon(&points[0], 3); painter.restore(); } Wt::WFont font = painter.font(); //font.setFamily(Wt::WFont::Default); font.setSize(20); painter.setFont(font); painter.drawText( Wt::WRectF(rc_elevator.left(), rc_elevator.center().y(), rc_elevator.width(), rc_elevator.height() * 0.5), Wt::AlignCenter | Wt::AlignMiddle, std::to_string(get_current_occupancy()) ); painter.restore(); }