| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
#include <OpenSG/OSGGLUT.h> |
|---|
| 8 |
#include <OpenSG/OSGConfig.h> |
|---|
| 9 |
#include <OpenSG/OSGSimpleGeometry.h> |
|---|
| 10 |
#include <OpenSG/OSGGLUTWindow.h> |
|---|
| 11 |
#include <OpenSG/OSGSimpleSceneManager.h> |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
#include <OpenSG/OSGBaseFunctions.h> |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
#include <OpenSG/OSGTransform.h> |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
OSG_USING_NAMESPACE |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
TransformPtr trans; |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
SimpleSceneManager *mgr; |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
int setupGLUT( int *argc, char *argv[] ); |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
void display( void ) |
|---|
| 37 |
{ |
|---|
| 38 |
|
|---|
| 39 |
Matrix m; |
|---|
| 40 |
Real32 t = glutGet(GLUT_ELAPSED_TIME ); |
|---|
| 41 |
|
|---|
| 42 |
m.setTransform(Vec3f( osgSin(t / 1000.f), |
|---|
| 43 |
osgCos(t / 1000.f), |
|---|
| 44 |
osgSin(t / 1000.f)), |
|---|
| 45 |
Quaternion( Vec3f(0,1,0), |
|---|
| 46 |
t / 1000.f)); |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
trans->setMatrix(m); |
|---|
| 51 |
|
|---|
| 52 |
commitChanges(); |
|---|
| 53 |
|
|---|
| 54 |
mgr->redraw(); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
int main(int argc, char **argv) |
|---|
| 59 |
{ |
|---|
| 60 |
|
|---|
| 61 |
osgInit(argc,argv); |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
int winid = setupGLUT(&argc, argv); |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
GLUTWindowPtr gwin= GLUTWindow::create(); |
|---|
| 68 |
gwin->setId(winid); |
|---|
| 69 |
gwin->init(); |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
NodePtr torus = makeTorus( .5, 2, 16, 32 ); |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
NodePtr scene = Node::create(); |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
trans = Transform::create(); |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
scene->setCore(trans); |
|---|
| 87 |
|
|---|
| 88 |
scene->addChild(torus); |
|---|
| 89 |
|
|---|
| 90 |
commitChanges(); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
mgr = new SimpleSceneManager; |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
mgr->setWindow(gwin ); |
|---|
| 97 |
mgr->setRoot (scene); |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
mgr->showAll(); |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
glutMainLoop(); |
|---|
| 104 |
|
|---|
| 105 |
return 0; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
void reshape(int w, int h) |
|---|
| 114 |
{ |
|---|
| 115 |
mgr->resize(w, h); |
|---|
| 116 |
glutPostRedisplay(); |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
void mouse(int button, int state, int x, int y) |
|---|
| 121 |
{ |
|---|
| 122 |
if (state) |
|---|
| 123 |
mgr->mouseButtonRelease(button, x, y); |
|---|
| 124 |
else |
|---|
| 125 |
mgr->mouseButtonPress(button, x, y); |
|---|
| 126 |
|
|---|
| 127 |
glutPostRedisplay(); |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
void motion(int x, int y) |
|---|
| 132 |
{ |
|---|
| 133 |
mgr->mouseMove(x, y); |
|---|
| 134 |
glutPostRedisplay(); |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
void keyboard(unsigned char k, int x, int y) |
|---|
| 139 |
{ |
|---|
| 140 |
switch(k) |
|---|
| 141 |
{ |
|---|
| 142 |
case 27: |
|---|
| 143 |
{ |
|---|
| 144 |
OSG::osgExit(); |
|---|
| 145 |
exit(0); |
|---|
| 146 |
} |
|---|
| 147 |
break; |
|---|
| 148 |
|
|---|
| 149 |
case 's': |
|---|
| 150 |
{ |
|---|
| 151 |
mgr->setStatistics(!mgr->getStatistics()); |
|---|
| 152 |
} |
|---|
| 153 |
break; |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
int setupGLUT(int *argc, char *argv[]) |
|---|
| 159 |
{ |
|---|
| 160 |
glutInit(argc, argv); |
|---|
| 161 |
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); |
|---|
| 162 |
|
|---|
| 163 |
int winid = glutCreateWindow("OpenSG"); |
|---|
| 164 |
|
|---|
| 165 |
glutReshapeFunc(reshape); |
|---|
| 166 |
glutDisplayFunc(display); |
|---|
| 167 |
glutMouseFunc(mouse); |
|---|
| 168 |
glutMotionFunc(motion); |
|---|
| 169 |
glutKeyboardFunc(keyboard); |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
glutIdleFunc(display); |
|---|
| 173 |
|
|---|
| 174 |
return winid; |
|---|
| 175 |
} |
|---|