Browse Source

fix static text in y-up (or other non-default) coordinate system

David Rose 12 years ago
parent
commit
abf29fa3fe
2 changed files with 32 additions and 4 deletions
  1. 29 3
      panda/src/text/staticTextFont.cxx
  2. 3 1
      panda/src/text/staticTextFont.h

+ 29 - 3
panda/src/text/staticTextFont.cxx

@@ -34,17 +34,43 @@ TypeHandle StaticTextFont::_type_handle;
 //  Description: The constructor expects the root node to a model
 //  Description: The constructor expects the root node to a model
 //               generated via egg-mkfont, which consists of a set of
 //               generated via egg-mkfont, which consists of a set of
 //               models, one per each character in the font.
 //               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::
-StaticTextFont(PandaNode *font_def) {
+StaticTextFont(PandaNode *font_def, CoordinateSystem cs) {
   nassertv(font_def != (PandaNode *)NULL);
   nassertv(font_def != (PandaNode *)NULL);
   _font = font_def;
   _font = font_def;
+  _cs = cs;
   _glyphs.clear();
   _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
   // If there is no explicit quality level or filter settings on the
   // textures in the static font, set the appropriate defaults for
   // textures in the static font, set the appropriate defaults for
   // text.
   // text.
-  NodePath np(font_def);
   TextureCollection tc = np.find_all_textures();
   TextureCollection tc = np.find_all_textures();
   int num_textures = tc.get_num_textures();
   int num_textures = tc.get_num_textures();
   for (int i = 0; i < num_textures; ++i) {
   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();
   _is_valid = !_glyphs.empty();
   
   
   // Check for an explicit space width.
   // Check for an explicit space width.

+ 3 - 1
panda/src/text/staticTextFont.h

@@ -18,6 +18,7 @@
 #include "pandabase.h"
 #include "pandabase.h"
 
 
 #include "config_text.h"
 #include "config_text.h"
+#include "coordinateSystem.h"
 #include "textFont.h"
 #include "textFont.h"
 #include "textGlyph.h"
 #include "textGlyph.h"
 #include "pandaNode.h"
 #include "pandaNode.h"
@@ -39,7 +40,7 @@ class GeomPoint;
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDA_TEXT StaticTextFont : public TextFont {
 class EXPCL_PANDA_TEXT StaticTextFont : public TextFont {
 PUBLISHED:
 PUBLISHED:
-  StaticTextFont(PandaNode *font_def);
+  StaticTextFont(PandaNode *font_def, CoordinateSystem cs = CS_default);
 
 
   virtual PT(TextFont) make_copy() const;
   virtual PT(TextFont) make_copy() const;
 
 
@@ -59,6 +60,7 @@ private:
   Glyphs _glyphs;
   Glyphs _glyphs;
   PN_stdfloat _font_height;
   PN_stdfloat _font_height;
   PT(PandaNode) _font;
   PT(PandaNode) _font;
+  CoordinateSystem _cs;
 
 
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {