pseudo rotation with ofNode

This commit is contained in:
jrkb 2023-04-17 17:07:36 +02:00
parent cd4d7f2224
commit c9f89f5853

View file

@ -876,9 +876,13 @@ class Font {
std::vector <int32_t> & indices, std::vector <int32_t> & indices,
const bool vFlip = false, const bool vFlip = false,
const float fontSize_px = 42){ const float fontSize_px = 42){
float x = position.x; float advanceX = 0;
float y = position.y; float advanceY = 0;
float originalX = x;
float degree = ofMap(sin(ofGetElapsedTimef()), -1, 1, 0, 90);
ofNode node;
node.rotateDeg(degree, glm::vec3(0, 0, 1));
node.move(position);
FT_UInt previous = 0; FT_UInt previous = 0;
for(const GlyphIdentity & glyphIdentity : variationText){ for(const GlyphIdentity & glyphIdentity : variationText){
@ -892,11 +896,14 @@ class Font {
continue; continue;
} }
if(charcode == '\n'){ if(charcode == '\n' || charcode == 'n'){
x = originalX; advanceX = 0;
y -= (float)face->height / (float)face->units_per_EM * worldSize; advanceY += ((float)face->height * fontSize_px) / (float)face->units_per_EM * worldSize;
if(!vFlip){
advanceY *= -1;
}
if(hinting){ if(hinting){
y = std::round(y); advanceY = std::round(advanceY);
} }
continue; continue;
} }
@ -909,7 +916,7 @@ class Font {
FT_Vector kerning; FT_Vector kerning;
FT_Error error = FT_Get_Kerning(face, previous, glyph.index, kerningMode, &kerning); FT_Error error = FT_Get_Kerning(face, previous, glyph.index, kerningMode, &kerning);
if(!error){ if(!error){
x += (float)kerning.x / emSize * worldSize; advanceX += ((float)kerning.x * fontSize_px) / emSize * worldSize;
} }
} }
@ -922,31 +929,35 @@ class Font {
float u1 = (float)(glyph.bearingX + glyph.width + d) / emSize; float u1 = (float)(glyph.bearingX + glyph.width + d) / emSize;
float v1 = (float)(glyph.bearingY + d) / emSize; float v1 = (float)(glyph.bearingY + d) / emSize;
float x0 = advanceX + u0 * worldSize * letterFontSize_px;
float x0 = x + u0 * worldSize * letterFontSize_px; float y0 = v0 * worldSize * letterFontSize_px;
float y0 = y + v0 * worldSize * letterFontSize_px; float x1 = advanceX + u1 * worldSize * letterFontSize_px;
float x1 = x + u1 * worldSize * letterFontSize_px; float y1 = v1 * worldSize * letterFontSize_px;
float y1 = y + v1 * worldSize * letterFontSize_px;
if(vFlip){ if(vFlip){
float _v = v0; float _v = v0;
v0 = v1; v0 = v1;
v1 = _v; v1 = _v;
y0 = y - v0 * worldSize * letterFontSize_px; y0 = -v0 * worldSize * letterFontSize_px;
y1 = y - v1 * worldSize * letterFontSize_px; y1 = -v1 * worldSize * letterFontSize_px;
} }
glm::vec4 p0 = node.getGlobalTransformMatrix() * glm::vec4(x0, y0 + advanceY, 0, 1);
glm::vec4 p1 = node.getGlobalTransformMatrix() * glm::vec4(x1, y0 + advanceY, 0, 1);
glm::vec4 p2 = node.getGlobalTransformMatrix() * glm::vec4(x1, y1 + advanceY, 0, 1);
glm::vec4 p3 = node.getGlobalTransformMatrix() * glm::vec4(x0, y1 + advanceY, 0, 1);
int32_t base = static_cast <int32_t>(vertices.size()); int32_t base = static_cast <int32_t>(vertices.size());
vertices.push_back(BufferVertex{x0, y0, u0, v0, glyph.bufferIndex}); vertices.push_back(BufferVertex{p0.x, p0.y, u0, v0, glyph.bufferIndex});
vertices.push_back(BufferVertex{x1, y0, u1, v0, glyph.bufferIndex}); vertices.push_back(BufferVertex{p1.x, p1.y, u1, v0, glyph.bufferIndex});
vertices.push_back(BufferVertex{x1, y1, u1, v1, glyph.bufferIndex}); vertices.push_back(BufferVertex{p2.x, p2.y, u1, v1, glyph.bufferIndex});
vertices.push_back(BufferVertex{x0, y1, u0, v1, glyph.bufferIndex}); vertices.push_back(BufferVertex{p3.x, p3.y, u0, v1, glyph.bufferIndex});
indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base}); indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base});
} }
x += ((float)glyph.advance * letterFontSize_px) / emSize * worldSize; advanceX += ((float)glyph.advance * letterFontSize_px) / emSize * worldSize;
previous = glyph.index; previous = glyph.index;
} }
} }
@ -970,9 +981,8 @@ class Font {
}; };
BoundingBox measure(float x, float y, const std::string & text){ BoundingBox measure(float x, float y, const std::string & text){
BoundingBox bb; //BoundingBox bb;
cerr << "ofxGPUFont::Font::BoundingBox not implemented" << endl; cerr << "ofxGPUFont::Font::BoundingBox not implemented" << endl;
cout << "ofxGPUFont::Font::BoundingBox not implemented" << endl;
//bb.minX = +std::numeric_limits <float>::infinity(); //bb.minX = +std::numeric_limits <float>::infinity();
//bb.minY = +std::numeric_limits <float>::infinity(); //bb.minY = +std::numeric_limits <float>::infinity();
//bb.maxX = -std::numeric_limits <float>::infinity(); //bb.maxX = -std::numeric_limits <float>::infinity();
@ -1036,7 +1046,8 @@ class Font {
//previous = glyph.index; //previous = glyph.index;
//} //}
return bb; //return bb;
return BoundingBox();
} }
private: private: