Text3D character/glyph size fixed

This commit is contained in:
konstantin.matveyev 2017-08-15 22:11:15 +03:00
parent 7e0a20b4ba
commit b0ef9b0c42
4 changed files with 43 additions and 9 deletions

View File

@ -238,10 +238,22 @@ int main(int argc, char** argv)
geode->addDrawable( osg::createTexturedQuadGeometry(osg::Vec3(0.0f,characterSize*thickness,0.0f),osg::Vec3(characterSize,0.0,0.0),osg::Vec3(0.0f,0.0,characterSize), 0.0, 0.0, 1.0, 1.0) );
}
if (arguments.read("--add-axes"))
group->addChild(osgDB::readNodeFile("axes.osgt"));
std::string mode;
if (arguments.read("--character-size-mode", mode))
{
if (mode == "screen_coords")
{
text3D->setCharacterSizeMode(osgText::TextBase::SCREEN_COORDS);
text3D->setCharacterSize(1080/4);
}
}
viewer.addEventHandler(new Text3DAttributeHandler(text3D));
}
viewer.setSceneData(group);
#endif

View File

@ -325,12 +325,12 @@ protected:
osg::Vec4 _textBBColor;
KerningType _kerningType;
unsigned int _lineCount;
bool _glyphNormalized;
osg::Vec3 _offset;
osg::Vec3 _normal;
osg::BoundingBox _textBB;
mutable osg::Matrix _matrix;
Primitives _decorationPrimitives;

View File

@ -21,12 +21,14 @@ namespace osgText
Text3D::Text3D():
_renderMode(PER_GLYPH)
{
_glyphNormalized = true;
}
Text3D::Text3D(const Text3D & text3D, const osg::CopyOp & copyop):
osgText::TextBase(text3D, copyop),
_renderMode(text3D._renderMode)
{
_glyphNormalized = text3D._glyphNormalized;
computeGlyphRepresentation();
}

View File

@ -47,7 +47,8 @@ TextBase::TextBase():
_textBBMargin(0.0f),
_textBBColor(0.0, 0.0, 0.0, 0.5),
_kerningType(KERNING_DEFAULT),
_lineCount(0)
_lineCount(0),
_glyphNormalized(false)
{
setStateSet(Font::getDefaultFont()->getStateSet());
setUseDisplayList(false);
@ -78,7 +79,8 @@ TextBase::TextBase(const TextBase& textBase,const osg::CopyOp& copyop):
_textBBMargin(textBase._textBBMargin),
_textBBColor(textBase._textBBColor),
_kerningType(textBase._kerningType),
_lineCount(textBase._lineCount)
_lineCount(textBase._lineCount),
_glyphNormalized(textBase._glyphNormalized)
{
initArraysAndBuffers();
}
@ -537,6 +539,12 @@ bool TextBase::computeMatrix(osg::Matrix& matrix, osg::State* state) const
if (pixelSizeHori == 0.0f)
pixelSizeHori= 1.0f;
if (_glyphNormalized)
{
osg::Vec3 scaleVec(_characterHeight/getCharacterAspectRatio(), _characterHeight, _characterHeight);
matrix.postMultScale(scaleVec);
}
if (_characterSizeMode==SCREEN_COORDS)
{
float scale_font_vert=_characterHeight/pixelSizeVert;
@ -544,12 +552,12 @@ bool TextBase::computeMatrix(osg::Matrix& matrix, osg::State* state) const
if (P10<0)
scale_font_vert=-scale_font_vert;
matrix.postMultScale(osg::Vec3f(scale_font_hori, scale_font_vert,1.0f));
matrix.postMultScale(osg::Vec3f(scale_font_hori, scale_font_vert, scale_font_hori));
}
else if (pixelSizeVert>getFontHeight())
{
float scale_font = getFontHeight()/pixelSizeVert;
matrix.postMultScale(osg::Vec3f(scale_font, scale_font,1.0f));
matrix.postMultScale(osg::Vec3f(scale_font, scale_font, scale_font));
}
}
@ -560,17 +568,29 @@ bool TextBase::computeMatrix(osg::Matrix& matrix, osg::State* state) const
}
matrix.postMultTranslate(_position);
}
else if (!_rotation.zeroRotation())
{
matrix.makeRotate(_rotation);
matrix.preMultTranslate(-_offset);
matrix.makeTranslate(-_offset);
if (_glyphNormalized)
{
osg::Vec3 scaleVec(_characterHeight/getCharacterAspectRatio(), _characterHeight, _characterHeight);
matrix.postMultScale(scaleVec);
}
matrix.postMultRotate(_rotation);
matrix.postMultTranslate(_position);
// OSG_NOTICE<<"New Need to rotate "<<matrix<<std::endl;
}
else
{
matrix.makeTranslate(_position-_offset);
matrix.makeTranslate(-_offset);
if (_glyphNormalized)
{
osg::Vec3 scaleVec(_characterHeight/getCharacterAspectRatio(), _characterHeight, _characterHeight);
matrix.postMultScale(scaleVec);
}
matrix.postMultTranslate(_position);
}
if (_matrix!=matrix)