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