transform origins
This commit is contained in:
parent
e357a7f4a2
commit
53f3b92e70
2 changed files with 134 additions and 15 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include "ofColor.h"
|
#include "ofColor.h"
|
||||||
#include "ofEvents.h"
|
#include "ofEvents.h"
|
||||||
#include "ofGraphics.h"
|
#include "ofGraphics.h"
|
||||||
|
#include "ofRectangle.h"
|
||||||
#include "ofUtils.h"
|
#include "ofUtils.h"
|
||||||
|
|
||||||
namespace ofxVariableLab {
|
namespace ofxVariableLab {
|
||||||
|
@ -179,8 +180,7 @@ void GPUFontAtlasLayerCombo::draw(){
|
||||||
int currentProgram;
|
int currentProgram;
|
||||||
glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram);
|
glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram);
|
||||||
|
|
||||||
float cx = FLT_MAX;
|
float superLineHeight = 0;
|
||||||
float cy = FLT_MAX;
|
|
||||||
if(font){
|
if(font){
|
||||||
fontShaderProgram = fontShader->program;
|
fontShaderProgram = fontShader->program;
|
||||||
glUseProgram(fontShaderProgram);
|
glUseProgram(fontShaderProgram);
|
||||||
|
@ -210,25 +210,135 @@ void GPUFontAtlasLayerCombo::draw(){
|
||||||
std::vector <ofxGPUFont::Font::BufferVertex> vertices;
|
std::vector <ofxGPUFont::Font::BufferVertex> vertices;
|
||||||
std::vector <int32_t> indices;
|
std::vector <int32_t> indices;
|
||||||
|
|
||||||
for(const auto & layer : layers){
|
|
||||||
ofNode node;
|
|
||||||
node.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
|
||||||
node.move(glm::vec3(layer->getProps().x,
|
|
||||||
layer->getProps().y,
|
|
||||||
0));
|
|
||||||
font->collectVerticesAndIndices(node,
|
|
||||||
layer->getVariationText(),
|
|
||||||
vertices, indices,
|
|
||||||
layer->getColor(),
|
|
||||||
true,
|
|
||||||
layer->getProps().fontSize_px);
|
|
||||||
}
|
|
||||||
vertices.resize(totalCharacters * 4);
|
vertices.resize(totalCharacters * 4);
|
||||||
indices.resize(totalCharacters * 6);
|
indices.resize(totalCharacters * 6);
|
||||||
|
|
||||||
|
std::vector <ofVboMesh> outerBoundingBoxes;
|
||||||
|
for(const auto & layer : layers){
|
||||||
|
float lineHeight = font->getLineHeight(layer->getProps().fontSize_px);
|
||||||
|
float ascender = font->getAscender(layer->getProps().fontSize_px);
|
||||||
|
superLineHeight = lineHeight;
|
||||||
|
ofxGPUFont::Font::BoundingBox bb;
|
||||||
|
std::vector <ofxGPUFont::Font::BoundingBox> bbs;
|
||||||
|
float advanceY = 0;
|
||||||
|
font->collectBoundingBoxes(layer->getVariationText(),
|
||||||
|
bb, bbs, advanceY,
|
||||||
|
true, layer->getProps().fontSize_px);
|
||||||
|
ofNode momNode;
|
||||||
|
ofNode node;
|
||||||
|
node.setParent(momNode);
|
||||||
|
glm::vec4 transformOrigin;
|
||||||
|
switch(layer->getProps().transformOrigin){
|
||||||
|
default:
|
||||||
|
case Layer::TransformOrigin::TOP_LEFT: {
|
||||||
|
node.move(glm::vec3(0,
|
||||||
|
ascender,
|
||||||
|
0));
|
||||||
|
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
||||||
|
transformOrigin = glm::vec4(layer->getProps().x,
|
||||||
|
layer->getProps().y - ascender,
|
||||||
|
0, 1);
|
||||||
|
momNode.move(transformOrigin);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Layer::TransformOrigin::TOP_RIGHT: {
|
||||||
|
float moveX = bb.p1.x - bb.p0.x;
|
||||||
|
node.move(glm::vec3(-moveX,
|
||||||
|
ascender,
|
||||||
|
0));
|
||||||
|
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
||||||
|
transformOrigin = glm::vec4(layer->getProps().x + moveX,
|
||||||
|
layer->getProps().y - ascender,
|
||||||
|
0, 1);
|
||||||
|
momNode.move(transformOrigin);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Layer::TransformOrigin::CENTER: {
|
||||||
|
float moveX = (bb.p2.x - bb.p0.x) * 0.5 + bb.p0.x;
|
||||||
|
float moveY = (bb.p2.y - bb.p0.y) * 0.5 - bb.p2.y;
|
||||||
|
node.move(glm::vec3(-moveX,
|
||||||
|
moveY,
|
||||||
|
0));
|
||||||
|
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
||||||
|
transformOrigin = glm::vec4(layer->getProps().x + moveX,
|
||||||
|
layer->getProps().y - moveY,
|
||||||
|
0, 1);
|
||||||
|
momNode.move(transformOrigin);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Layer::TransformOrigin::BOTTOM_LEFT: {
|
||||||
|
float moveY = ascender - advanceY;
|
||||||
|
node.move(glm::vec3(0,
|
||||||
|
moveY,
|
||||||
|
0));
|
||||||
|
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
||||||
|
transformOrigin = glm::vec4(layer->getProps().x,
|
||||||
|
layer->getProps().y - moveY,
|
||||||
|
0, 1);
|
||||||
|
momNode.move(transformOrigin);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Layer::TransformOrigin::BOTTOM_RIGHT: {
|
||||||
|
float moveY = ascender - (advanceY);
|
||||||
|
float moveX = (bb.p2.x - bb.p0.x);
|
||||||
|
node.move(glm::vec3(-moveX,
|
||||||
|
moveY,
|
||||||
|
0));
|
||||||
|
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
||||||
|
transformOrigin = glm::vec4(layer->getProps().x + moveX,
|
||||||
|
layer->getProps().y - moveY,
|
||||||
|
0, 1);
|
||||||
|
momNode.move(transformOrigin);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
bb.multiply(node.getGlobalTransformMatrix());
|
||||||
|
ofVboMesh mesh;
|
||||||
|
mesh.addVertices({bb.p0, bb.p1, bb.p2, bb.p3,
|
||||||
|
glm::vec4(layer->getProps().x, layer->getProps().y, 0, 1),
|
||||||
|
transformOrigin
|
||||||
|
});
|
||||||
|
mesh.addColors({
|
||||||
|
ofColor::red,
|
||||||
|
ofColor::red,
|
||||||
|
ofColor::red,
|
||||||
|
ofColor::red,
|
||||||
|
ofColor::white,
|
||||||
|
ofColor::green,
|
||||||
|
});
|
||||||
|
outerBoundingBoxes.push_back(mesh);
|
||||||
|
|
||||||
|
font->collectVerticesAndIndices(node,
|
||||||
|
bbs,
|
||||||
|
vertices,
|
||||||
|
indices,
|
||||||
|
layer->getColor(),
|
||||||
|
layer->getProps().fontSize_px);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
font->draw(vertices, indices);
|
font->draw(vertices, indices);
|
||||||
|
|
||||||
glUseProgram(currentProgram);
|
glUseProgram(currentProgram);
|
||||||
|
ofPushStyle();
|
||||||
|
ofSetColor(ofColor::white);
|
||||||
|
for(const auto & b : outerBoundingBoxes){
|
||||||
|
int i = 0;
|
||||||
|
for(const auto & v : b.getVertices()){
|
||||||
|
ofSetColor(b.getColors()[i]);
|
||||||
|
ofDrawCircle(v, 4);
|
||||||
|
ofDrawBitmapString(ofToString(i), 0, 0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
b.drawVertices();
|
||||||
|
}
|
||||||
|
ofFill();
|
||||||
|
ofPopStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
@ -236,6 +346,7 @@ void GPUFontAtlasLayerCombo::draw(){
|
||||||
ofDrawBitmapStringHighlight(
|
ofDrawBitmapStringHighlight(
|
||||||
"fps: " + ofToString(ofGetFrameRate()) + "\n"
|
"fps: " + ofToString(ofGetFrameRate()) + "\n"
|
||||||
+ "font: " + this->identifier.fontPath + "\n"
|
+ "font: " + this->identifier.fontPath + "\n"
|
||||||
|
+ "lineHEight: " + ofToString(superLineHeight) + "\n"
|
||||||
, 20, 20);
|
, 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,13 @@ struct LayerSettings {
|
||||||
|
|
||||||
class Layer {
|
class Layer {
|
||||||
public:
|
public:
|
||||||
|
enum TransformOrigin : int {
|
||||||
|
TOP_LEFT = 0,
|
||||||
|
TOP_RIGHT,
|
||||||
|
CENTER,
|
||||||
|
BOTTOM_LEFT,
|
||||||
|
BOTTOM_RIGHT
|
||||||
|
};
|
||||||
struct Props {
|
struct Props {
|
||||||
float x = 200;
|
float x = 200;
|
||||||
float y = 200;
|
float y = 200;
|
||||||
|
@ -29,6 +36,7 @@ class Layer {
|
||||||
bool mirror_y = false;
|
bool mirror_y = false;
|
||||||
float mirror_y_distance = 0;
|
float mirror_y_distance = 0;
|
||||||
float letterDelay = 0;
|
float letterDelay = 0;
|
||||||
|
int transformOrigin = TransformOrigin::TOP_LEFT;
|
||||||
std::vector <ofxVariableLab::FontVariation> fontVariations;
|
std::vector <ofxVariableLab::FontVariation> fontVariations;
|
||||||
string text = "abc";
|
string text = "abc";
|
||||||
string fontPath = "data/celines-fonts/Version-2-var.ttf";
|
string fontPath = "data/celines-fonts/Version-2-var.ttf";
|
||||||
|
|
Loading…
Reference in a new issue