2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-05-02 05:06:18 +08:00
|
|
|
*
|
|
|
|
* 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 <osgUtil/Optimizer>
|
|
|
|
#include <osgDB/ReadFile>
|
2007-01-05 22:56:37 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2003-05-02 05:06:18 +08:00
|
|
|
|
|
|
|
#include <osg/Material>
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/BlendFunc>
|
|
|
|
#include <osg/Depth>
|
|
|
|
#include <osg/Projection>
|
|
|
|
#include <osg/AutoTransform>
|
|
|
|
#include <osg/Geometry>
|
|
|
|
|
|
|
|
#include <osgText/Text>
|
|
|
|
|
2007-01-05 22:56:37 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2005-11-10 01:06:12 +08:00
|
|
|
osg::Node* createLabel(const osg::Vec3& pos, float size, const std::string& label, osgText::Text::AxisAlignment axisAlignment)
|
2003-05-02 05:06:18 +08:00
|
|
|
{
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
|
|
|
|
|
|
|
std::string timesFont("fonts/arial.ttf");
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
geode->addDrawable( text );
|
|
|
|
|
|
|
|
text->setFont(timesFont);
|
|
|
|
text->setPosition(pos);
|
|
|
|
text->setCharacterSize(size);
|
2005-11-10 01:06:12 +08:00
|
|
|
text->setAxisAlignment(axisAlignment);
|
2003-05-02 05:06:18 +08:00
|
|
|
text->setAlignment(osgText::Text::CENTER_CENTER);
|
|
|
|
text->setText(label);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return geode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
osg::Node* createLabel3(const osg::Vec3& pos, float size, const std::string& label)
|
|
|
|
{
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
|
|
|
|
|
|
|
std::string timesFont("fonts/arial.ttf");
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
geode->addDrawable( text );
|
|
|
|
|
|
|
|
text->setFont(timesFont);
|
|
|
|
text->setPosition(pos);
|
|
|
|
text->setFontResolution(40,40);
|
|
|
|
text->setCharacterSize(size);
|
|
|
|
text->setAlignment(osgText::Text::CENTER_CENTER);
|
|
|
|
text->setAutoRotateToScreen(true);
|
2003-06-24 23:39:59 +08:00
|
|
|
text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT);
|
2003-05-02 05:06:18 +08:00
|
|
|
text->setText(label);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return geode;
|
|
|
|
}
|
|
|
|
|
2005-11-10 01:06:12 +08:00
|
|
|
osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps, osg::AutoTransform::AutoRotateMode autoRotateMode, osgText::Text::AxisAlignment axisAlignment, const std::string& str)
|
2003-05-02 05:06:18 +08:00
|
|
|
{
|
|
|
|
osg::Group* group = new osg::Group;
|
|
|
|
|
|
|
|
osg::Vec3 dv = e-s;
|
|
|
|
dv /= float(numReps-1);
|
|
|
|
|
|
|
|
osg::Vec3 pos = s;
|
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
bool useAuto = true;
|
2003-05-02 05:06:18 +08:00
|
|
|
if (useAuto)
|
|
|
|
{
|
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array;
|
|
|
|
|
|
|
|
for(int i=0;i<numReps;++i)
|
|
|
|
{
|
|
|
|
osg::AutoTransform* at = new osg::AutoTransform;
|
|
|
|
at->setPosition(pos);
|
2004-08-06 16:22:58 +08:00
|
|
|
at->setAutoRotateMode(autoRotateMode);
|
2005-11-10 01:06:12 +08:00
|
|
|
at->addChild(createLabel(osg::Vec3(0.0f,0.0f,0.0f),dv.length()*0.2f,str, axisAlignment));
|
2003-05-02 05:06:18 +08:00
|
|
|
vertices->push_back(pos);
|
|
|
|
pos += dv;
|
|
|
|
|
|
|
|
|
|
|
|
group->addChild(at);
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array;
|
|
|
|
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
|
|
|
|
|
|
|
osg::Geometry* geom = new osg::Geometry;
|
|
|
|
geom->setVertexArray(vertices);
|
|
|
|
geom->setColorArray(colors);
|
|
|
|
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size()));
|
|
|
|
|
|
|
|
osg::Geode* geode = new osg::Geode;
|
|
|
|
geode->addDrawable(geom);
|
|
|
|
|
|
|
|
group->addChild(geode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array;
|
|
|
|
|
|
|
|
for(int i=0;i<numReps;++i)
|
|
|
|
{
|
2004-08-06 16:22:58 +08:00
|
|
|
group->addChild(createLabel3(osg::Vec3(pos),dv.length()*0.5f,str));
|
2003-05-02 05:06:18 +08:00
|
|
|
vertices->push_back(pos);
|
|
|
|
pos += dv;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array;
|
|
|
|
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
|
|
|
|
|
|
|
osg::Geometry* geom = new osg::Geometry;
|
|
|
|
geom->setVertexArray(vertices);
|
|
|
|
geom->setColorArray(colors);
|
|
|
|
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size()));
|
|
|
|
|
|
|
|
osg::Geode* geode = new osg::Geode;
|
|
|
|
geode->addDrawable(geom);
|
|
|
|
|
|
|
|
group->addChild(geode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node* createScene()
|
|
|
|
{
|
|
|
|
osg::Group* root = new osg::Group;
|
|
|
|
|
2004-08-06 16:22:58 +08:00
|
|
|
// int numReps = 3333;
|
|
|
|
int numReps = 10;
|
2005-11-10 01:06:12 +08:00
|
|
|
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(1000.0,0.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_CAMERA,osgText::Text::XY_PLANE, "ROTATE_TO_CAMERA"));
|
|
|
|
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1000.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_SCREEN,osgText::Text::XY_PLANE, "ROTATE_TO_SCREEN"));
|
|
|
|
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1000.0),numReps,osg::AutoTransform::NO_ROTATION,osgText::Text::XZ_PLANE, "NO_ROTATION"));
|
2003-05-02 05:06:18 +08:00
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
2007-01-05 23:52:33 +08:00
|
|
|
int main(int, char**)
|
2003-05-02 05:06:18 +08:00
|
|
|
{
|
|
|
|
// construct the viewer.
|
2007-01-05 22:56:37 +08:00
|
|
|
osgViewer::Viewer viewer;
|
2003-05-02 05:06:18 +08:00
|
|
|
|
|
|
|
// set the scene to render
|
|
|
|
viewer.setSceneData(createScene());
|
|
|
|
|
2007-01-05 23:52:33 +08:00
|
|
|
// run the viewers frame loop
|
2007-01-05 22:56:37 +08:00
|
|
|
return viewer.run();
|
2003-05-02 05:06:18 +08:00
|
|
|
}
|