From abf29fa3fe45055e7f052fbc62d31de57313b517 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 10 Apr 2013 21:33:01 +0000 Subject: [PATCH] fix static text in y-up (or other non-default) coordinate system --- panda/src/text/staticTextFont.cxx | 32 ++++++++++++++++++++++++++++--- panda/src/text/staticTextFont.h | 4 +++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/panda/src/text/staticTextFont.cxx b/panda/src/text/staticTextFont.cxx index 9431ffd4f7..650c540e11 100644 --- a/panda/src/text/staticTextFont.cxx +++ b/panda/src/text/staticTextFont.cxx @@ -34,17 +34,43 @@ TypeHandle StaticTextFont::_type_handle; // Description: The constructor expects the root node to a model // generated via egg-mkfont, which consists of a set of // models, one per each character in the font. +// +// If a CoordinateSystem value is specified, it informs +// the font of the coordinate system in which this model +// was generated. "up" in this coordinate system will +// be the direction of the top of the letters. //////////////////////////////////////////////////////////////////// StaticTextFont:: -StaticTextFont(PandaNode *font_def) { +StaticTextFont(PandaNode *font_def, CoordinateSystem cs) { nassertv(font_def != (PandaNode *)NULL); _font = font_def; + _cs = cs; _glyphs.clear(); + if (_cs == CS_default) { + _cs = get_default_coordinate_system(); + } + + NodePath np(font_def); + if (_cs != CS_zup_right) { + // We have to convert the entire font to CS_zup_right before we + // can use it, because the text subsystem assumes the glyphs are + // stored in CS_zup_right. + NodePath temp_root("root"); + NodePath temp_child = temp_root.attach_new_node("child"); + np = np.copy_to(temp_child); + LMatrix4 mat = LMatrix4::convert_mat(_cs, CS_zup_right); + temp_child.set_mat(mat); + temp_root.clear_model_nodes(); + temp_root.flatten_light(); + np = temp_root.get_child(0).get_child(0); + _font = np.node(); + _cs = CS_zup_right; + } + // If there is no explicit quality level or filter settings on the // textures in the static font, set the appropriate defaults for // text. - NodePath np(font_def); TextureCollection tc = np.find_all_textures(); int num_textures = tc.get_num_textures(); for (int i = 0; i < num_textures; ++i) { @@ -68,7 +94,7 @@ StaticTextFont(PandaNode *font_def) { } } - find_characters(font_def, RenderState::make_empty()); + find_characters(_font, RenderState::make_empty()); _is_valid = !_glyphs.empty(); // Check for an explicit space width. diff --git a/panda/src/text/staticTextFont.h b/panda/src/text/staticTextFont.h index fb7d7609d2..92c626c0d1 100644 --- a/panda/src/text/staticTextFont.h +++ b/panda/src/text/staticTextFont.h @@ -18,6 +18,7 @@ #include "pandabase.h" #include "config_text.h" +#include "coordinateSystem.h" #include "textFont.h" #include "textGlyph.h" #include "pandaNode.h" @@ -39,7 +40,7 @@ class GeomPoint; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA_TEXT StaticTextFont : public TextFont { PUBLISHED: - StaticTextFont(PandaNode *font_def); + StaticTextFont(PandaNode *font_def, CoordinateSystem cs = CS_default); virtual PT(TextFont) make_copy() const; @@ -59,6 +60,7 @@ private: Glyphs _glyphs; PN_stdfloat _font_height; PT(PandaNode) _font; + CoordinateSystem _cs; public: static TypeHandle get_class_type() {