| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
#include <OpenSG/OSGGLUT.h> |
|---|
| 11 |
#include <OpenSG/OSGConfig.h> |
|---|
| 12 |
#include <OpenSG/OSGSimpleGeometry.h> |
|---|
| 13 |
#include <OpenSG/OSGGLUTWindow.h> |
|---|
| 14 |
#include <OpenSG/OSGSimpleSceneManager.h> |
|---|
| 15 |
#include <OpenSG/OSGAction.h> |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
#include <OpenSG/OSGSceneFileHandler.h> |
|---|
| 21 |
#include <boost/bind.hpp> |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
OSG_USING_NAMESPACE |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
SimpleSceneManager *mgr; |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
int setupGLUT( int *argc, char *argv[] ); |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
#include <OpenSG/OSGSimpleAttachments.h> |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
class NamedNodeFinder |
|---|
| 42 |
{ |
|---|
| 43 |
public: |
|---|
| 44 |
|
|---|
| 45 |
NamedNodeFinder(void) : _name(), _found() {} |
|---|
| 46 |
|
|---|
| 47 |
NodePtr operator() (NodePtr root, std::string name) |
|---|
| 48 |
{ |
|---|
| 49 |
_name=&name; |
|---|
| 50 |
_found=NullFC; |
|---|
| 51 |
|
|---|
| 52 |
TraverseEnterFunctor enter = |
|---|
| 53 |
boost::bind(&NamedNodeFinder::check, this, _1); |
|---|
| 54 |
traverse(root, enter); |
|---|
| 55 |
|
|---|
| 56 |
return _found; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
static NodePtr find(NodePtr root, std::string name) |
|---|
| 60 |
{ |
|---|
| 61 |
NamedNodeFinder f; |
|---|
| 62 |
|
|---|
| 63 |
return f(root,name); |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
private: |
|---|
| 67 |
|
|---|
| 68 |
Action::ResultE check(NodePtr node) |
|---|
| 69 |
{ |
|---|
| 70 |
if(getName(node) && *_name == getName(node)) |
|---|
| 71 |
{ |
|---|
| 72 |
_found = node; |
|---|
| 73 |
return Action::Quit; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
return Action::Continue; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
NodePtr _found; |
|---|
| 80 |
std::string *_name; |
|---|
| 81 |
}; |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
int main(int argc, char **argv) |
|---|
| 85 |
{ |
|---|
| 86 |
|
|---|
| 87 |
osgInit(argc,argv); |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
int winid = setupGLUT(&argc, argv); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
GLUTWindowPtr gwin= GLUTWindow::create(); |
|---|
| 94 |
gwin->setId(winid); |
|---|
| 95 |
gwin->init(); |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
NodePtr scene; |
|---|
| 100 |
|
|---|
| 101 |
if(argc < 2) |
|---|
| 102 |
{ |
|---|
| 103 |
FWARNING(("No file given!\n")); |
|---|
| 104 |
FWARNING(("Supported file formats:\n")); |
|---|
| 105 |
|
|---|
| 106 |
std::list<const char*> suffixes; |
|---|
| 107 |
SceneFileHandler::the()->getSuffixList(suffixes); |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
for(std::list<const char*>::iterator it = suffixes.begin(); |
|---|
| 111 |
it != suffixes.end(); |
|---|
| 112 |
++it) |
|---|
| 113 |
{ |
|---|
| 114 |
FWARNING(("%s\n", *it)); |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
scene = makeTorus(.5, 2, 16, 16); |
|---|
| 118 |
} |
|---|
| 119 |
else |
|---|
| 120 |
{ |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
scene = SceneFileHandler::the()->read(argv[1]); |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
NodePtr found; |
|---|
| 129 |
|
|---|
| 130 |
NamedNodeFinder f; |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
found = f(scene, "Scene"); |
|---|
| 135 |
if(found == NullFC) |
|---|
| 136 |
{ |
|---|
| 137 |
SLOG << "Found no object named Scene." << endLog; |
|---|
| 138 |
} |
|---|
| 139 |
else |
|---|
| 140 |
{ |
|---|
| 141 |
SLOG << "Found object " << found << " named Scene. How did that happen?" |
|---|
| 142 |
<< endLog; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
found = NamedNodeFinder::find(scene, "TF_DETAIL"); |
|---|
| 148 |
if(found == NullFC) |
|---|
| 149 |
{ |
|---|
| 150 |
SLOG << "Found no object named TF_DETAIL (did you load the tie?)." |
|---|
| 151 |
<< endLog; |
|---|
| 152 |
} |
|---|
| 153 |
else |
|---|
| 154 |
{ |
|---|
| 155 |
SLOG << "Found object " << found << " named TF_DETAIL." << endLog; |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
commitChanges(); |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
mgr = new SimpleSceneManager; |
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
mgr->setWindow(gwin ); |
|---|
| 165 |
mgr->setRoot (scene); |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
mgr->showAll(); |
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
glutMainLoop(); |
|---|
| 172 |
|
|---|
| 173 |
return 0; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
void display(void) |
|---|
| 182 |
{ |
|---|
| 183 |
mgr->idle(); |
|---|
| 184 |
mgr->redraw(); |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
void reshape(int w, int h) |
|---|
| 189 |
{ |
|---|
| 190 |
mgr->resize(w, h); |
|---|
| 191 |
glutPostRedisplay(); |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
void mouse(int button, int state, int x, int y) |
|---|
| 196 |
{ |
|---|
| 197 |
|
|---|
| 198 |
if (state) |
|---|
| 199 |
mgr->mouseButtonRelease(button, x, y); |
|---|
| 200 |
else |
|---|
| 201 |
mgr->mouseButtonPress(button, x, y); |
|---|
| 202 |
|
|---|
| 203 |
glutPostRedisplay(); |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
void motion(int x, int y) |
|---|
| 208 |
{ |
|---|
| 209 |
|
|---|
| 210 |
mgr->mouseMove(x, y); |
|---|
| 211 |
glutPostRedisplay(); |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
void keyboard(unsigned char k, int , int ) |
|---|
| 216 |
{ |
|---|
| 217 |
switch(k) |
|---|
| 218 |
{ |
|---|
| 219 |
case 27: |
|---|
| 220 |
{ |
|---|
| 221 |
OSG::osgExit(); |
|---|
| 222 |
exit(0); |
|---|
| 223 |
} |
|---|
| 224 |
break; |
|---|
| 225 |
|
|---|
| 226 |
case 'f': |
|---|
| 227 |
{ |
|---|
| 228 |
mgr->setNavigationMode(Navigator::FLY); |
|---|
| 229 |
} |
|---|
| 230 |
break; |
|---|
| 231 |
|
|---|
| 232 |
case 't': |
|---|
| 233 |
{ |
|---|
| 234 |
mgr->setNavigationMode(Navigator::TRACKBALL); |
|---|
| 235 |
} |
|---|
| 236 |
break; |
|---|
| 237 |
|
|---|
| 238 |
case 's': |
|---|
| 239 |
{ |
|---|
| 240 |
mgr->setStatistics(!mgr->getStatistics()); |
|---|
| 241 |
} |
|---|
| 242 |
} |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
int setupGLUT(int *argc, char *argv[]) |
|---|
| 247 |
{ |
|---|
| 248 |
glutInit(argc, argv); |
|---|
| 249 |
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); |
|---|
| 250 |
|
|---|
| 251 |
int winid = glutCreateWindow("OpenSG"); |
|---|
| 252 |
|
|---|
| 253 |
glutReshapeFunc(reshape); |
|---|
| 254 |
glutDisplayFunc(display); |
|---|
| 255 |
glutIdleFunc(display); |
|---|
| 256 |
glutMouseFunc(mouse); |
|---|
| 257 |
glutMotionFunc(motion); |
|---|
| 258 |
glutKeyboardFunc(keyboard); |
|---|
| 259 |
|
|---|
| 260 |
return winid; |
|---|
| 261 |
} |
|---|