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