Addsy

shape.cpp

Apr 13th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include "shape.hpp"
  2.  
  3. Shape::Shape(const Vector2D& location) :
  4.     location_(location)
  5. {
  6.  
  7. }
  8.  
  9. void Shape::scale(float s)
  10. {
  11.     for(Vector2D& vert : vertices_) {
  12.         vert.i *= s;
  13.         vert.j *= s;
  14.     }
  15. }
  16.  
  17. void Shape::render(prg::Canvas& canvas) const
  18. {
  19.     std::vector<Vector2D>::const_iterator Shapet_iter =
  20.         vertices_.begin();
  21.     std::vector<Vector2D>::const_iterator end_iter =
  22.         vertices_.begin() + (vertices_.size()-1);
  23.  
  24.     for(
  25.         std::vector<Vector2D>::const_iterator iter = Shapet_iter,
  26.             next = Shapet_iter+1;
  27.         iter != end_iter;
  28.         ++iter,
  29.         ++next
  30.     )
  31.     {
  32.         canvas.drawLine(
  33.             location_.i + iter->i,//P1
  34.             location_.j + iter->j,
  35.             location_.i + next->i,//P2
  36.             location_.j + next->j,
  37.             prg::Colour::MAGENTA
  38.         );
  39.     }
  40.  
  41.     canvas.drawLine(
  42.             location_.i + end_iter->i,//P1
  43.             location_.j + end_iter->j,
  44.             location_.i + Shapet_iter->i,//P2
  45.             location_.j + Shapet_iter->j,
  46.             prg::Colour::MAGENTA
  47.         );
  48.  
  49. }
  50.  
  51. void Shape::update()
  52. {
  53.     //TO BE COMPLETED LATER
  54.     rotate_vectors(
  55.         vertices_.data(),
  56.         vertices_.size(),
  57.         rotation_angle_
  58.     );
  59. }
Advertisement
Add Comment
Please, Sign In to add comment