diff --git a/examples/osgtext3D/CMakeLists.txt b/examples/osgtext3D/CMakeLists.txt index 8c68b00c7..27c014f22 100644 --- a/examples/osgtext3D/CMakeLists.txt +++ b/examples/osgtext3D/CMakeLists.txt @@ -2,10 +2,12 @@ SET(TARGET_H GlyphGeometry.h + TextNode.h ) SET(TARGET_SRC GlyphGeometry.cpp + TextNode.cpp osgtext3D_orig.cpp osgtext3D_test.cpp osgtext3D.cpp diff --git a/examples/osgtext3D/GlyphGeometry.cpp b/examples/osgtext3D/GlyphGeometry.cpp index 3829a1d7d..516f581b9 100644 --- a/examples/osgtext3D/GlyphGeometry.cpp +++ b/examples/osgtext3D/GlyphGeometry.cpp @@ -520,7 +520,7 @@ struct CollectTriangleIndicesFunctor }; -osg::Geometry* computeGlyphGeometry(osgText::Font3D::Glyph3D* glyph, float bevelThickness, float shellThickness) +osg::Geometry* computeGlyphGeometry(osgText::Glyph3D* glyph, float bevelThickness, float shellThickness) { osg::Vec3Array* orig_vertices = glyph->getRawVertexArray(); osg::Geometry::PrimitiveSetList& orig_primitives = glyph->getRawFacePrimitiveSetList(); diff --git a/examples/osgtext3D/GlyphGeometry.h b/examples/osgtext3D/GlyphGeometry.h index 6f619956d..e45168d8e 100644 --- a/examples/osgtext3D/GlyphGeometry.h +++ b/examples/osgtext3D/GlyphGeometry.h @@ -42,7 +42,7 @@ class BevelProfile Vertices _vertices; }; -extern osg::Geometry* computeGlyphGeometry(osgText::Font3D::Glyph3D* glyph, float bevelThickness, float shellThickness); +extern osg::Geometry* computeGlyphGeometry(osgText::Glyph3D* glyph, float bevelThickness, float shellThickness); extern osg::Geometry* computeTextGeometry(osg::Geometry* glyphGeometry, BevelProfile& profile, float width); diff --git a/examples/osgtext3D/TextNode.cpp b/examples/osgtext3D/TextNode.cpp new file mode 100644 index 000000000..4a716afe6 --- /dev/null +++ b/examples/osgtext3D/TextNode.cpp @@ -0,0 +1,289 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include "TextNode.h" +#include + +using namespace osgText; + +///////////////////////////////////////////////////////////////////////////////////////// +// +// Bevel +// +Bevel::Bevel() +{ + _thickness = 0.1f; + flatBevel(); +} + +Bevel::Bevel(const Bevel& bevel, const osg::CopyOp&): + _thickness(bevel._thickness), + _vertices(bevel._vertices) +{ +} + +void Bevel::flatBevel(float width) +{ + _vertices.clear(); + + if (width>0.5f) width = 0.5f; + + _vertices.push_back(osg::Vec2(0.0f,0.0f)); + + _vertices.push_back(osg::Vec2(width,1.0f)); + + if (width<0.5f) _vertices.push_back(osg::Vec2(1-width,1.0f)); + + _vertices.push_back(osg::Vec2(1.0f,0.0f)); +} + +void Bevel::roundedBevel(float width, unsigned int numSteps) +{ + _vertices.clear(); + + if (width>0.5f) width = 0.5f; + + unsigned int i = 0; + for(; i<=numSteps; ++i) + { + float angle = float(osg::PI)*0.5f*(float(i)/float(numSteps)); + _vertices.push_back( osg::Vec2((1.0f-cosf(angle))*width, sinf(angle)) ); + } + + // start the second half one into the curve if the width is half way across + i = width<0.5f ? 0 : 1; + for(; i<=numSteps; ++i) + { + float angle = float(osg::PI)*0.5f*(float(numSteps-i)/float(numSteps)); + _vertices.push_back( osg::Vec2(1.0-(1.0f-cosf(angle))*width, sin(angle)) ); + } +} + +void Bevel::roundedBevel2(float width, unsigned int numSteps) +{ + _vertices.clear(); + + if (width>0.5f) width = 0.5f; + + float h = 0.1f; + float r = 1.0f-h; + + _vertices.push_back(osg::Vec2(0.0,0.0)); + + unsigned int i = 0; + for(; i<=numSteps; ++i) + { + float angle = float(osg::PI)*0.5f*(float(i)/float(numSteps)); + _vertices.push_back( osg::Vec2((1.0f-cosf(angle))*width, h + sinf(angle)*r) ); + } + + // start the second half one into the curve if the width is half way across + i = width<0.5f ? 0 : 1; + for(; i<=numSteps; ++i) + { + float angle = float(osg::PI)*0.5f*(float(numSteps-i)/float(numSteps)); + _vertices.push_back( osg::Vec2(1.0-(1.0f-cosf(angle))*width, h + sin(angle)*r) ); + } + + _vertices.push_back(osg::Vec2(1.0,0.0)); + +} + +void Bevel::print(std::ostream& fout) +{ + OSG_NOTICE<<"print bevel"<(copyop(style._bevel.get()))), + _widthRatio(style._widthRatio), + _thicknessRatio(style._thicknessRatio), + _outlineRatio(style._outlineRatio), + _sampleDensity(style._sampleDensity) +{ +} + +/// default Layout implementation used if no other is specified on TextNode +osg::ref_ptr