2007-06-12 22:20:16 +08:00
|
|
|
/* OpenSceneGraph example, osglauncher.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2004-11-29 09:12:25 +08:00
|
|
|
//#include <cstdio>
|
|
|
|
//#include <cstdlib>
|
2004-10-01 23:49:57 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/ShapeDrawable>
|
|
|
|
#include <osg/Material>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <osg/Geometry>
|
|
|
|
#include <osg/MatrixTransform>
|
|
|
|
#include <osg/PositionAttitudeTransform>
|
|
|
|
#include <osg/BlendFunc>
|
|
|
|
#include <osg/ClearNode>
|
|
|
|
#include <osg/Depth>
|
|
|
|
#include <osg/Projection>
|
2005-04-08 17:45:06 +08:00
|
|
|
#include <osg/io_utils>
|
2004-10-01 23:49:57 +08:00
|
|
|
|
|
|
|
#include <osgUtil/CullVisitor>
|
|
|
|
#include <osgUtil/Optimizer>
|
|
|
|
|
|
|
|
#include <osgText/Text>
|
|
|
|
|
|
|
|
#include <osgGA/TrackballManipulator>
|
|
|
|
|
2007-01-08 18:00:16 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2017-10-24 23:04:14 +08:00
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2004-10-01 23:49:57 +08:00
|
|
|
|
|
|
|
#include <osgDB/ReadFile>
|
2004-11-18 21:46:13 +08:00
|
|
|
#include <osgDB/FileUtils>
|
2008-11-07 23:08:08 +08:00
|
|
|
#include <osgDB/fstream>
|
2004-10-01 23:49:57 +08:00
|
|
|
|
|
|
|
int runApp(std::string xapp);
|
|
|
|
|
|
|
|
// class to handle events with a pick
|
|
|
|
class PickHandler : public osgGA::GUIEventHandler {
|
2015-10-22 21:42:19 +08:00
|
|
|
public:
|
2004-10-01 23:49:57 +08:00
|
|
|
|
2007-01-08 18:00:16 +08:00
|
|
|
PickHandler(osgViewer::Viewer* viewer,osgText::Text* updateText):
|
2004-10-01 23:49:57 +08:00
|
|
|
_viewer(viewer),
|
|
|
|
_updateText(updateText) {}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
~PickHandler() {}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
|
|
|
|
|
2013-05-04 03:26:27 +08:00
|
|
|
std::string pick(const osgGA::GUIEventAdapter& event);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
void highlight(const std::string& name)
|
|
|
|
{
|
|
|
|
if (_updateText.get()) _updateText->setText(name);
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
protected:
|
|
|
|
|
2007-01-08 18:00:16 +08:00
|
|
|
osgViewer::Viewer* _viewer;
|
2004-10-01 23:49:57 +08:00
|
|
|
osg::ref_ptr<osgText::Text> _updateText;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
|
|
|
|
{
|
|
|
|
switch(ea.getEventType())
|
|
|
|
{
|
|
|
|
case(osgGA::GUIEventAdapter::FRAME):
|
|
|
|
case(osgGA::GUIEventAdapter::MOVE):
|
|
|
|
{
|
2013-05-04 03:26:27 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<"MOVE "<<ea.getX()<<", "<<ea.getY()<<std::endl;
|
|
|
|
std::string picked_name = pick(ea);
|
2004-10-01 23:49:57 +08:00
|
|
|
highlight(picked_name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case(osgGA::GUIEventAdapter::PUSH):
|
|
|
|
{
|
2013-05-04 03:26:27 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<"PUSH "<<ea.getX()<<", "<<ea.getY()<<std::endl;
|
|
|
|
std::string picked_name = pick(ea);
|
2004-10-01 23:49:57 +08:00
|
|
|
if (!picked_name.empty())
|
|
|
|
{
|
|
|
|
runApp(picked_name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-04 03:26:27 +08:00
|
|
|
std::string PickHandler::pick(const osgGA::GUIEventAdapter& event)
|
2004-10-01 23:49:57 +08:00
|
|
|
{
|
2007-01-10 01:35:46 +08:00
|
|
|
osgUtil::LineSegmentIntersector::Intersections intersections;
|
2013-05-04 03:26:27 +08:00
|
|
|
if (_viewer->computeIntersections(event, intersections))
|
2004-10-01 23:49:57 +08:00
|
|
|
{
|
2007-01-10 01:35:46 +08:00
|
|
|
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
|
|
|
|
hitr != intersections.end();
|
2004-10-01 23:49:57 +08:00
|
|
|
++hitr)
|
|
|
|
{
|
2007-01-10 01:35:46 +08:00
|
|
|
osg::Node* node = hitr->nodePath.empty() ? 0 : hitr->nodePath.back();
|
|
|
|
if (node && !node->getName().empty()) return node->getName();
|
2004-10-01 23:49:57 +08:00
|
|
|
}
|
|
|
|
}
|
2007-01-10 01:35:46 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node* createHUD(osgText::Text* updateText)
|
|
|
|
{ // create the hud. derived from osgHud.cpp
|
|
|
|
// adds a set of quads, each in a separate Geode - which can be picked individually
|
|
|
|
// eg to be used as a menuing/help system!
|
|
|
|
// Can pick texts too!
|
|
|
|
osg::MatrixTransform* modelview_abs = new osg::MatrixTransform;
|
2004-10-25 04:04:00 +08:00
|
|
|
modelview_abs->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
2004-10-01 23:49:57 +08:00
|
|
|
modelview_abs->setMatrix(osg::Matrix::identity());
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
osg::Projection* projection = new osg::Projection;
|
|
|
|
projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
|
|
|
|
projection->addChild(modelview_abs);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
std::string timesFont("fonts/times.ttf");
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
// turn lighting off for the text and disable depth test to ensure its always ontop.
|
2004-11-18 04:01:51 +08:00
|
|
|
osg::Vec3 position(50.0f,510.0f,0.0f);
|
2004-10-01 23:49:57 +08:00
|
|
|
osg::Vec3 delta(0.0f,-60.0f,0.0f);
|
|
|
|
|
|
|
|
{ // this displays what has been selected
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
|
|
|
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
|
|
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
|
|
|
|
geode->setName("The text label");
|
|
|
|
geode->addDrawable( updateText );
|
|
|
|
modelview_abs->addChild(geode);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
updateText->setCharacterSize(20.0f);
|
|
|
|
updateText->setFont(timesFont);
|
|
|
|
updateText->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
|
|
|
|
updateText->setText("");
|
|
|
|
updateText->setPosition(position);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
position += delta;
|
2015-10-22 21:42:19 +08:00
|
|
|
}
|
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
return projection;
|
|
|
|
|
|
|
|
} // end create HUDf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static osg::Vec3 defaultPos( 0.0f, 0.0f, 0.0f );
|
|
|
|
static osg::Vec3 centerScope(0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
class Xample
|
|
|
|
{
|
|
|
|
std::string texture;
|
|
|
|
std::string app;
|
|
|
|
public:
|
|
|
|
Xample(std::string image, std::string prog)
|
2015-10-22 21:42:19 +08:00
|
|
|
{
|
2004-10-01 23:49:57 +08:00
|
|
|
texture = image;
|
|
|
|
app = prog;
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "New Xample!" << std::endl;
|
2004-10-01 23:49:57 +08:00
|
|
|
};
|
|
|
|
~Xample() { };
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
std::string getTexture()
|
|
|
|
{
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
std::string getApp()
|
|
|
|
{
|
|
|
|
return app;
|
|
|
|
}
|
2009-02-05 18:14:49 +08:00
|
|
|
private:
|
|
|
|
Xample() {}
|
2004-10-01 23:49:57 +08:00
|
|
|
}; // end class Xample
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::list<Xample>::iterator OP;
|
|
|
|
static std::list<Xample> Xamplelist;
|
|
|
|
|
|
|
|
|
|
|
|
void printList()
|
|
|
|
{
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "start printList()" << std::endl;
|
2004-10-01 23:49:57 +08:00
|
|
|
for (OP i = Xamplelist.begin() ; i != Xamplelist.end() ; ++i)
|
|
|
|
{
|
|
|
|
Xample& x = *i;
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "current x.texture = " << x.getTexture() << std::endl;
|
|
|
|
osg::notify(osg::INFO) << "current x.app = " << x.getApp() << std::endl;
|
2004-10-01 23:49:57 +08:00
|
|
|
}
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "end printList()" << std::endl;
|
2004-10-01 23:49:57 +08:00
|
|
|
} // end printList()
|
|
|
|
|
|
|
|
|
|
|
|
int runApp(std::string xapp)
|
|
|
|
{
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "start runApp()" << std::endl;
|
2004-10-01 23:49:57 +08:00
|
|
|
for (OP i = Xamplelist.begin() ; i != Xamplelist.end() ; ++i)
|
|
|
|
{
|
|
|
|
Xample& x = *i;
|
|
|
|
if(!xapp.compare(x.getApp()))
|
|
|
|
{
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "app found!" << std::endl;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
const char* cxapp = xapp.c_str();
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "char* = " << cxapp <<std::endl;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-12-18 21:56:30 +08:00
|
|
|
return system(cxapp);
|
2004-10-01 23:49:57 +08:00
|
|
|
}
|
|
|
|
}
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "app not found!" << std::endl;
|
2008-12-18 21:56:30 +08:00
|
|
|
return 1;
|
2004-10-01 23:49:57 +08:00
|
|
|
} // end printList()
|
|
|
|
|
|
|
|
|
2007-08-26 18:27:31 +08:00
|
|
|
void readConfFile(const char* confFile) // read confFile 1
|
2004-10-01 23:49:57 +08:00
|
|
|
{
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "Start reading confFile" << std::endl;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-11-18 21:46:13 +08:00
|
|
|
std::string fileName = osgDB::findDataFile(confFile);
|
|
|
|
if (fileName.empty())
|
|
|
|
{
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "Config file not found"<<confFile << std::endl;
|
2004-11-18 21:46:13 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
|
2008-11-07 23:08:08 +08:00
|
|
|
osgDB::ifstream in(fileName.c_str());
|
2004-10-01 23:49:57 +08:00
|
|
|
if (!in)
|
|
|
|
{
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "File " << fileName << " can not be opened!" << std::endl;
|
2004-10-01 23:49:57 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
std::string imageBuffer;
|
|
|
|
std::string appBuffer;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
while (!in.eof())
|
|
|
|
{
|
2004-11-19 16:47:14 +08:00
|
|
|
std::getline(in, imageBuffer);
|
|
|
|
std::getline(in, appBuffer);
|
2004-10-01 23:49:57 +08:00
|
|
|
if(imageBuffer == "" || appBuffer == "");
|
|
|
|
else
|
|
|
|
{
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "imageBuffer: " << imageBuffer << std::endl;
|
|
|
|
osg::notify(osg::INFO) << "appBuffer: " << appBuffer << std::endl;
|
2004-10-01 23:49:57 +08:00
|
|
|
// jeweils checken ob image vorhanden ist.
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
Xample tmp(imageBuffer, appBuffer); // create Xample objects 2
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
Xamplelist.push_back(tmp); // store objects in list 2
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
}
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
in.close();
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << "End reading confFile" << std::endl;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
printList();
|
|
|
|
} // end readConfFile
|
|
|
|
|
|
|
|
|
|
|
|
void SetObjectTextureState(osg::Geode *geodeCurrent, std::string texture)
|
|
|
|
{
|
|
|
|
// retrieve or create a StateSet
|
|
|
|
osg::StateSet* stateTexture = geodeCurrent->getOrCreateStateSet();
|
|
|
|
|
|
|
|
// load texture.jpg as an image
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::Image> imgTexture = osgDB::readRefImageFile( texture );
|
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
// if the image is successfully loaded
|
|
|
|
if (imgTexture)
|
|
|
|
{
|
|
|
|
// create a new two-dimensional texture object
|
|
|
|
osg::Texture2D* texCube = new osg::Texture2D;
|
|
|
|
|
|
|
|
// set the texture to the loaded image
|
|
|
|
texCube->setImage(imgTexture);
|
|
|
|
|
|
|
|
// set the texture to the state
|
|
|
|
stateTexture->setTextureAttributeAndModes(0,texCube,osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
// set the state of the current geode
|
|
|
|
geodeCurrent->setStateSet(stateTexture);
|
|
|
|
}
|
|
|
|
} // end SetObjectTextureState
|
|
|
|
|
|
|
|
|
|
|
|
osg::Geode* createTexturedCube(float fRadius,osg::Vec3 vPosition, std::string texture, std::string geodeName)
|
|
|
|
{
|
|
|
|
// create a cube shape
|
|
|
|
osg::Box *bCube = new osg::Box(vPosition,fRadius);
|
|
|
|
// osg::Box *bCube = new osg::Box(vPosition,fRadius);
|
|
|
|
|
|
|
|
// create a container that makes the cube drawable
|
|
|
|
osg::ShapeDrawable *sdCube = new osg::ShapeDrawable(bCube);
|
|
|
|
|
|
|
|
// create a geode object to as a container for our drawable cube object
|
|
|
|
osg::Geode* geodeCube = new osg::Geode();
|
|
|
|
geodeCube->setName( geodeName );
|
|
|
|
|
|
|
|
// set the object texture state
|
|
|
|
SetObjectTextureState(geodeCube, texture);
|
|
|
|
|
|
|
|
// add our drawable cube to the geode container
|
|
|
|
geodeCube->addDrawable(sdCube);
|
|
|
|
|
|
|
|
return(geodeCube);
|
|
|
|
} // end CreateCube
|
|
|
|
|
|
|
|
|
|
|
|
osg::PositionAttitudeTransform* getPATransformation(osg::Node* object, osg::Vec3 position, osg::Vec3 scale, osg::Vec3 pivot)
|
|
|
|
{
|
|
|
|
osg::PositionAttitudeTransform* tmpTrans = new osg::PositionAttitudeTransform();
|
|
|
|
tmpTrans->addChild( object );
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
tmpTrans->setPosition( position );
|
|
|
|
tmpTrans->setScale( scale );
|
|
|
|
tmpTrans->setPivotPoint( pivot );
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
return tmpTrans;
|
|
|
|
}
|
|
|
|
|
|
|
|
void printBoundings(osg::Node* current, std::string name)
|
|
|
|
{
|
|
|
|
const osg::BoundingSphere& currentBound = current->getBound();
|
2004-11-19 00:20:48 +08:00
|
|
|
osg::notify(osg::INFO) << name << std::endl;
|
|
|
|
osg::notify(osg::INFO) << "center = " << currentBound.center() << std::endl;
|
|
|
|
osg::notify(osg::INFO) << "radius = " << currentBound.radius() << std::endl;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
// return currentBound.radius();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
osg::Group* setupGraph() // create Geodes/Nodes from Xamplelist 3
|
|
|
|
{
|
|
|
|
osg::Group* xGroup = new osg::Group();
|
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
// positioning and sizes
|
|
|
|
float defaultRadius = 0.8f;
|
|
|
|
|
|
|
|
int itemsInLine = 4; // name says everything
|
|
|
|
float offset = 0.05f;
|
|
|
|
float bs = (defaultRadius / 4) + offset;
|
|
|
|
float xstart = (3*bs) * (-1);
|
|
|
|
float zstart = xstart * (-1);
|
|
|
|
float xnext = xstart;
|
|
|
|
float znext = zstart;
|
|
|
|
float xjump = (2*bs);
|
|
|
|
float zjump = xjump;
|
|
|
|
osg::Vec3 vScale( 0.5f, 0.5f, 0.5f );
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::Vec3 vPivot( 0.0f, 0.0f, 0.0f );
|
2004-10-01 23:49:57 +08:00
|
|
|
|
2004-11-18 04:01:51 +08:00
|
|
|
// run through Xampleliste
|
2004-10-01 23:49:57 +08:00
|
|
|
int z = 1;
|
|
|
|
for (OP i = Xamplelist.begin() ; i != Xamplelist.end() ; ++i, ++z)
|
|
|
|
{
|
|
|
|
Xample& x = *i;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
osg::Node* tmpCube = createTexturedCube(defaultRadius, defaultPos, x.getTexture(), x.getApp());
|
|
|
|
printBoundings(tmpCube, x.getApp());
|
|
|
|
osg::Vec3 vPosition( xnext, 0.0f, znext );
|
|
|
|
osg::PositionAttitudeTransform* transX = getPATransformation(tmpCube, vPosition, vScale, vPivot);
|
|
|
|
xGroup->addChild( transX );
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-11-18 04:01:51 +08:00
|
|
|
// line feed
|
2004-10-01 23:49:57 +08:00
|
|
|
if(z < itemsInLine)
|
|
|
|
xnext += xjump;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xnext = xstart;
|
|
|
|
znext -= zjump;
|
2004-11-18 04:01:51 +08:00
|
|
|
z = 0;
|
2004-10-01 23:49:57 +08:00
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
} // end run through list
|
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
return xGroup;
|
|
|
|
} // end setupGraph
|
|
|
|
|
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
2004-11-14 05:42:45 +08:00
|
|
|
if (argc<=1)
|
2004-10-01 23:49:57 +08:00
|
|
|
{
|
2004-11-18 21:46:13 +08:00
|
|
|
readConfFile("osg.conf"); // read ConfigFile 1
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
readConfFile(argv[1]); // read ConfigFile 1
|
2004-10-01 23:49:57 +08:00
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
// construct the viewer.
|
2007-01-08 18:00:16 +08:00
|
|
|
osgViewer::Viewer viewer;
|
2004-10-01 23:49:57 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osgText::Text> updateText = new osgText::Text;
|
2007-06-22 00:14:54 +08:00
|
|
|
updateText->setDataVariance(osg::Object::DYNAMIC);
|
2004-10-01 23:49:57 +08:00
|
|
|
|
|
|
|
// add the handler for doing the picking
|
2007-01-08 18:00:16 +08:00
|
|
|
viewer.addEventHandler(new PickHandler(&viewer,updateText.get()));
|
2004-10-01 23:49:57 +08:00
|
|
|
|
2017-10-24 23:04:14 +08:00
|
|
|
// add the stats handler
|
|
|
|
viewer.addEventHandler(new osgViewer::StatsHandler);
|
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
osg::Group* root = new osg::Group();
|
|
|
|
|
|
|
|
root->addChild( setupGraph() );
|
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
// add the HUD subgraph.
|
2004-10-01 23:49:57 +08:00
|
|
|
root->addChild(createHUD(updateText.get()));
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
// add model to viewer.
|
|
|
|
viewer.setSceneData( root );
|
|
|
|
|
|
|
|
osg::Matrix lookAt;
|
|
|
|
lookAt.makeLookAt(osg::Vec3(0.0f, -4.0f, 0.0f), centerScope, osg::Vec3(0.0f, 0.0f, 1.0f));
|
|
|
|
|
2007-01-08 18:00:16 +08:00
|
|
|
viewer.getCamera()->setViewMatrix(lookAt);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2007-01-08 18:00:16 +08:00
|
|
|
viewer.realize();
|
|
|
|
|
2004-10-01 23:49:57 +08:00
|
|
|
while( !viewer.done() )
|
|
|
|
{
|
|
|
|
// fire off the cull and draw traversals of the scene.
|
2015-10-22 21:42:19 +08:00
|
|
|
viewer.frame();
|
2004-10-01 23:49:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} // end main
|