Glyph::Glyph(const glm::vec4& destRect, const glm::vec4& uvRect, GLuint Texture, float Depth, const ColorRGBA8& color, float angle) : texture(Texture), depth(Depth) { glm::vec2 halfDims(destRect.z / 2.0f, destRect.w / 2.0f); // Get points centered at origin glm::vec2 tl(-halfDims.x, halfDims.y); glm::vec2 bl(-halfDims.x, -halfDims.y); glm::vec2 br(halfDims.x, -halfDims.y); glm::vec2 tr(halfDims.x, halfDims.y); // Rotate the points tl = rotatePoint(tl, angle) + halfDims; bl = rotatePoint(bl, angle) + halfDims; br = rotatePoint(br, angle) + halfDims; tr = rotatePoint(tr, angle) + halfDims; topLeft.color = color; topLeft.setPosition(destRect.x + tl.x, destRect.y + tl.y); topLeft.setUV(uvRect.x, uvRect.y + uvRect.w); bottomLeft.color = color; bottomLeft.setPosition(destRect.x + bl.x, destRect.y + bl.y); bottomLeft.setUV(uvRect.x, uvRect.y); bottomRight.color = color; bottomRight.setPosition(destRect.x + br.x, destRect.y + br.y); bottomRight.setUV(uvRect.x + uvRect.z, uvRect.y); topRight.color = color; topRight.setPosition(destRect.x + tr.x, destRect.y + tr.y); topRight.setUV(uvRect.x + uvRect.z, uvRect.y + uvRect.w); }
Glyph::Glyph(OShader *shader, const maths::vec2 &position, const maths::vec2 &dimensions, const maths::vec4 &uvRect, GLuint texture, unsigned int color, float zOrder, float angle) :textureID(texture), a_zOrder(zOrder), currentShader(shader) { maths::vec2 halfDims(dimensions.x * 0.5f, dimensions.y * 0.5f); // Get points centered at origin maths::vec2 tl(-halfDims.x, halfDims.y); maths::vec2 bl(-halfDims.x, -halfDims.y); maths::vec2 br(halfDims.x, -halfDims.y); maths::vec2 tr(halfDims.x, halfDims.y); // Rotate the points tl = rotatePoint(tl, angle) + halfDims; bl = rotatePoint(bl, angle) + halfDims; br = rotatePoint(br, angle) + halfDims; tr = rotatePoint(tr, angle) + halfDims; topLeft.setColor(color); topLeft.setPosition(position.x + tl.x, position.y + tl.y); topLeft.setUV(uvRect.x, uvRect.y + uvRect.w); bottomLeft.setColor(color); bottomLeft.setPosition(position.x + bl.x, position.y + bl.y); bottomLeft.setUV(uvRect.x, uvRect.y); bottomRight.setColor(color); bottomRight.setPosition(position.x + br.x, position.y + br.y); bottomRight.setUV(uvRect.x + uvRect.z, uvRect.y); topRight.setColor(color); topRight.setPosition(position.x + tr.x, position.y + tr.y); topRight.setUV(uvRect.x + uvRect.z, uvRect.y + uvRect.w); }
void DebugRenderer::drawBox(const glm::vec4& destRect, const Color& color, float angle){ int i = _verts.size(); _verts.resize(_verts.size() + 4); glm::vec2 halfDims(destRect.z / 2.0f, destRect.w / 2.0f); //Get points centered at origin glm::vec2 TL(-halfDims.x, halfDims.y); glm::vec2 BL(-halfDims.x, -halfDims.y); glm::vec2 BR(halfDims.x, -halfDims.y); glm::vec2 TR(halfDims.x, halfDims.y); glm::vec2 positionOffset(destRect.x, destRect.y); //Rotate the points _verts[i].position = rotatePoint(TL, angle) + halfDims + positionOffset; _verts[i + 1].position = rotatePoint(BL, angle) + halfDims + positionOffset; _verts[i + 2].position = rotatePoint(BR, angle) + halfDims + positionOffset; _verts[i + 3].position = rotatePoint(TR, angle) + halfDims + positionOffset; for (int j = i; j < i + 4; j++){ _verts[j].color = color; } _indices.reserve(_indices.size() + 8); //Line 1 _indices.push_back(i); _indices.push_back(i + 1); //Line 2 _indices.push_back(i + 1); _indices.push_back(i + 2); //Line 3 _indices.push_back(i + 2); _indices.push_back(i + 3); //Line 4 _indices.push_back(i + 3); _indices.push_back(i); }
void Adina::DebugRenderer::drawBox(const glm::vec4& destRect, const ColorRGBA8& color, float angle) { int i = m_verts.size(); m_verts.resize(m_verts.size() + 4); glm::vec2 halfDims(destRect.z / 2.0f, destRect.w / 2.0f); // Get points centered at origin glm::vec2 tl(-halfDims.x, halfDims.y); glm::vec2 bl(-halfDims.x, -halfDims.y); glm::vec2 br(halfDims.x, -halfDims.y); glm::vec2 tr(halfDims.x, halfDims.y); glm::vec2 positionOffset(destRect.x, destRect.y); // Rotate the points m_verts[i].position = rotatePoint(tl, angle) + halfDims + positionOffset; m_verts[i + 1].position = rotatePoint(bl, angle) + halfDims + positionOffset; m_verts[i + 2].position = rotatePoint(br, angle) + halfDims + positionOffset; m_verts[i + 3].position = rotatePoint(tr, angle) + halfDims + positionOffset; for (int j = i; j < i + 4; j++) { m_verts[j].color = color; } m_indices.reserve(m_indices.size() + 8); m_indices.push_back(i); m_indices.push_back(i + 1); m_indices.push_back(i + 1); m_indices.push_back(i + 2); m_indices.push_back(i + 2); m_indices.push_back(i + 3); m_indices.push_back(i + 3); m_indices.push_back(i); }
void DebugRenderer::drawTriangle(const glm::vec4& destRect, const Color& color, float angle){ int i = _verts.size(); _verts.resize(_verts.size() + 3); glm::vec2 halfDims(destRect.z / 2.0f, destRect.w / 2.0f); glm::vec2 Top(0, halfDims.y); glm::vec2 BL(-halfDims.x, -halfDims.y); glm::vec2 BR(halfDims.x, -halfDims.y); glm::vec2 positionOffset(destRect.x, destRect.y); _verts[i].position = rotatePoint(Top, angle) + halfDims + positionOffset; _verts[i + 1].position = rotatePoint(BL, angle) + halfDims + positionOffset; _verts[i + 2].position = rotatePoint(BR, angle) + halfDims + positionOffset; for (int j = i; j < i + 3; j++){ _verts[j].color = color; } _indices.reserve(_indices.size() + 6); //First line _indices.push_back(i); _indices.push_back(i + 1); //Second line _indices.push_back(i + 1); _indices.push_back(i + 2); //Third line _indices.push_back(i + 2); _indices.push_back(i); }