Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. void SpriteBatch::draw(const glm::vec4& destRect, float rotation, const glm::vec4& uvRect, GLuint texture, float depth, const Color& color) {
  2.  
  3.     Glyph* newGlyph = new Glyph;
  4.     newGlyph->texture = texture;
  5.     newGlyph->depth = depth;
  6.  
  7.     //tl bl br tr
  8.     glm::vec2 verts[4] = { glm::vec2(-destRect.z/2,destRect.w/2), glm::vec2(-destRect.z/2,-destRect.w/2), glm::vec2(destRect.z/2,-destRect.w/2), glm::vec2(destRect.z/2,destRect.w/2) };
  9.     glm::mat2 rotationMatrix(cos(rotation*PI/180),-sin(rotation*PI/180),sin(rotation*PI/180),cos(rotation*PI/180));
  10.  
  11.     for (int i = 0; i < 4; i++)
  12.     {
  13.         verts[i] = rotationMatrix * verts[i];
  14.     }
  15.  
  16.     newGlyph->topLeft.color = color;
  17.     newGlyph->topLeft.setPosition(verts[0].x + destRect.x, verts[0].y + destRect.y);
  18.     newGlyph->topLeft.setUV(uvRect.x, uvRect.y + uvRect.w);
  19.  
  20.     newGlyph->bottomLeft.color = color;
  21.     newGlyph->bottomLeft.setPosition(verts[1].x + destRect.x, verts[1].y + destRect.y);
  22.     newGlyph->bottomLeft.setUV(uvRect.x, uvRect.y);
  23.  
  24.     newGlyph->bottomRight.color = color;
  25.     newGlyph->bottomRight.setPosition(verts[2].x + destRect.x, verts[2].y + destRect.y);
  26.     newGlyph->bottomRight.setUV(uvRect.x + uvRect.z, uvRect.y);
  27.  
  28.     newGlyph->topRight.color = color;
  29.     newGlyph->topRight.setPosition(verts[3].x + destRect.x, verts[3].y + destRect.y);
  30.     newGlyph->topRight.setUV(uvRect.x + uvRect.z, uvRect.y + uvRect.w);
  31.  
  32.     _glyphs.push_back(newGlyph);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement