BARE2D
Vertex.cpp
Go to the documentation of this file.
1 #include "Vertex.hpp"
2 
3 namespace BARE2D {
4  Glyph::Glyph(glm::vec4& destRect, glm::vec4& uvRect, GLuint& Texture, float& Depth, Colour& colour) : texture(Texture), depth(Depth) {
5  topLeft.colour = colour;
6  topLeft.setPosition(destRect.x, destRect.y + destRect.w, depth);
7  topLeft.setUV(uvRect.x, uvRect.y + uvRect.w);
8 
9  bottomLeft.colour = colour;
10  bottomLeft.setPosition(destRect.x, destRect.y, depth);
11  bottomLeft.setUV(uvRect.x, uvRect.y);
12 
13  bottomRight.colour = colour;
14  bottomRight.setPosition(destRect.x + destRect.z, destRect.y, depth);
15  bottomRight.setUV(uvRect.x + uvRect.z, uvRect.y);
16 
17  topRight.colour = colour;
18  topRight.setPosition(destRect.x + destRect.z, destRect.y + destRect.w, depth);
19  topRight.setUV(uvRect.x + uvRect.z, uvRect.y + uvRect.w);
20  }
21 
22  Glyph::Glyph(glm::vec4& destRect, glm::vec4& uvRect, GLuint& Texture, float& Depth, Colour& colour, float& angle) : texture(Texture), depth(Depth) {
23  glm::vec2 centrePoint = glm::vec2(destRect.z, destRect.w) * glm::vec2(0.5f);
24 
25  // Get points centered at origin
26  glm::vec2 tl(-centrePoint.x, centrePoint.y);
27  glm::vec2 bl(-centrePoint.x, -centrePoint.y);
28  glm::vec2 br(centrePoint.x, -centrePoint.y);
29  glm::vec2 tr(centrePoint.x, centrePoint.y);
30 
31  // Rotate the points
32  tl = rotatePoint(tl, angle) + centrePoint;
33  bl = rotatePoint(bl, angle) + centrePoint;
34  br = rotatePoint(br, angle) + centrePoint;
35  tr = rotatePoint(tr, angle) + centrePoint;
36 
37  topLeft.colour = colour;
38  topLeft.setPosition(destRect.x + tl.x, destRect.y + tl.y, depth);
39  topLeft.setUV(uvRect.x, uvRect.y + uvRect.w);
40 
41  bottomLeft.colour = colour;
42  bottomLeft.setPosition(destRect.x + bl.x, destRect.y + bl.y, depth);
43  bottomLeft.setUV(uvRect.x, uvRect.y);
44 
45  bottomRight.colour = colour;
46  bottomRight.setPosition(destRect.x + br.x, destRect.y + br.y, depth);
47  bottomRight.setUV(uvRect.x + uvRect.z, uvRect.y);
48 
49  topRight.colour = colour;
50  topRight.setPosition(destRect.x + tr.x, destRect.y + tr.y, depth);
51  topRight.setUV(uvRect.x + uvRect.z, uvRect.y + uvRect.w);
52  }
53 
54  Glyph::Glyph(glm::vec4& destRect, glm::vec4& uvRect, GLuint& Texture, float& Depth, Colour& colour, float& angle, glm::vec2& COR) : texture(Texture), depth(Depth) {
55  glm::vec2 centrePoint = glm::vec2(destRect.z, destRect.w) * COR;
56  glm::vec2 invCentrePoint = glm::vec2(destRect.z, destRect.w) * (1.0f - COR);
57 
58  // Get points centered at origin
59  glm::vec2 tl(-invCentrePoint.x, centrePoint.y);
60  glm::vec2 bl(-invCentrePoint.x, -invCentrePoint.y);
61  glm::vec2 br(centrePoint.x, -invCentrePoint.y);
62  glm::vec2 tr(centrePoint.x, centrePoint.y);
63 
64  // Rotate the points
65  tl = rotatePoint(tl, angle) + centrePoint;
66  bl = rotatePoint(bl, angle) + centrePoint;
67  br = rotatePoint(br, angle) + centrePoint;
68  tr = rotatePoint(tr, angle) + centrePoint;
69 
70  topLeft.colour = colour;
71  topLeft.setPosition(destRect.x + tl.x, destRect.y + tl.y, depth);
72  topLeft.setUV(uvRect.x, uvRect.y + uvRect.w);
73 
74  bottomLeft.colour = colour;
75  bottomLeft.setPosition(destRect.x + bl.x, destRect.y + bl.y, depth);
76  bottomLeft.setUV(uvRect.x, uvRect.y);
77 
78  bottomRight.colour = colour;
79  bottomRight.setPosition(destRect.x + br.x, destRect.y + br.y, depth);
80  bottomRight.setUV(uvRect.x + uvRect.z, uvRect.y);
81 
82  topRight.colour = colour;
83  topRight.setPosition(destRect.x + tr.x, destRect.y + tr.y, depth);
84  topRight.setUV(uvRect.x + uvRect.z, uvRect.y + uvRect.w);
85  }
86 
87  glm::vec2 Glyph::rotatePoint(const glm::vec2& pos, float& angle) {
88  glm::vec2 newv;
89  newv.x = pos.x * cos(angle) - pos.y * sin(angle);
90  newv.y = pos.y * cos(angle) + pos.x * sin(angle);
91  return newv;
92  }
93 
94 
95 }
BARE2D
Definition: App.cpp:13
BARE2D::Glyph::depth
float depth
Definition: Vertex.hpp:97
BARE2D::Texture
The texture struct holds very basic stuff - the filepath, width, height, and ID,.
Definition: Texture.hpp:13
BARE2D::Glyph::topRight
Vertex topRight
Definition: Vertex.hpp:100
BARE2D::Glyph::bottomRight
Vertex bottomRight
Definition: Vertex.hpp:100
Vertex.hpp
BARE2D::Glyph::bottomLeft
Vertex bottomLeft
Definition: Vertex.hpp:100
BARE2D::Vertex::setUV
void setUV(float u, float v)
Sets the UV coords/dimensions.
Definition: Vertex.hpp:77
BARE2D::Glyph::rotatePoint
glm::vec2 rotatePoint(const glm::vec2 &pos, float &angle)
Definition: Vertex.cpp:87
BARE2D::Glyph::topLeft
Vertex topLeft
Definition: Vertex.hpp:100
BARE2D::Vertex::colour
Colour colour
Definition: Vertex.hpp:42
BARE2D::Glyph::Glyph
Glyph(glm::vec4 &destRect, glm::vec4 &uvRect, GLuint &Texture, float &Depth, Colour &colour)
Definition: Vertex.cpp:4
BARE2D::Vertex::setPosition
void setPosition(float x, float y, float z)
Literally just sets the position. Convenient.
Definition: Vertex.hpp:52
BARE2D::Colour
An RGBA 8-bit colour value.
Definition: Vertex.hpp:20