| 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/OSGGeoProperties.h> |
|---|
| 14 |
#include <OpenSG/OSGGLUTWindow.h> |
|---|
| 15 |
#include <OpenSG/OSGSimpleSceneManager.h> |
|---|
| 16 |
#include <OpenSG/OSGBaseFunctions.h> |
|---|
| 17 |
#include <OpenSG/OSGTransform.h> |
|---|
| 18 |
#include <OpenSG/OSGGroup.h> |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
#include <OpenSG/OSGGeometry.h> |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
OSG_USING_NAMESPACE |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
TransformPtr trans; |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
GeometryPtr geo; |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
SimpleSceneManager *mgr; |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
int setupGLUT( int *argc, char *argv[] ); |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
int main(int argc, char **argv) |
|---|
| 43 |
{ |
|---|
| 44 |
|
|---|
| 45 |
osgInit(argc,argv); |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
int winid = setupGLUT(&argc, argv); |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
GLUTWindowPtr gwin= GLUTWindow::create(); |
|---|
| 52 |
gwin->setId(winid); |
|---|
| 53 |
gwin->init(); |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
GeoUInt8PropertyPtr type = GeoUInt8Property::create(); |
|---|
| 77 |
type->addValue(GL_POLYGON ); |
|---|
| 78 |
type->addValue(GL_TRIANGLES); |
|---|
| 79 |
type->addValue(GL_QUADS ); |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); |
|---|
| 88 |
lens->addValue(4); |
|---|
| 89 |
lens->addValue(6); |
|---|
| 90 |
lens->addValue(8); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
GeoPnt3fPropertyPtr pnts = OSG::GeoPnt3fProperty::create(); |
|---|
| 102 |
|
|---|
| 103 |
pnts->addValue(Pnt3f(-1, -1, -1)); |
|---|
| 104 |
pnts->addValue(Pnt3f(-1, -1, 1)); |
|---|
| 105 |
pnts->addValue(Pnt3f( 1, -1, 1)); |
|---|
| 106 |
pnts->addValue(Pnt3f( 1, -1, -1)); |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
pnts->addValue(Pnt3f( 1, 0, -1)); |
|---|
| 110 |
pnts->addValue(Pnt3f(-1, 0, -1)); |
|---|
| 111 |
pnts->addValue(Pnt3f( 0, 1, -1)); |
|---|
| 112 |
|
|---|
| 113 |
pnts->addValue(Pnt3f(-1, 0, 1)); |
|---|
| 114 |
pnts->addValue(Pnt3f( 1, 0, 1)); |
|---|
| 115 |
pnts->addValue(Pnt3f( 0, 1, 1)); |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
pnts->addValue(Pnt3f(-1, -1, 1)); |
|---|
| 119 |
pnts->addValue(Pnt3f( 1, -1, 1)); |
|---|
| 120 |
pnts->addValue(Pnt3f( 1, 0, 1)); |
|---|
| 121 |
pnts->addValue(Pnt3f(-1, 0, 1)); |
|---|
| 122 |
|
|---|
| 123 |
pnts->addValue(Pnt3f( 1, -1, -1)); |
|---|
| 124 |
pnts->addValue(Pnt3f(-1, -1, -1)); |
|---|
| 125 |
pnts->addValue(Pnt3f(-1, 0, -1)); |
|---|
| 126 |
pnts->addValue(Pnt3f( 1, 0, -1)); |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
geo=Geometry::create(); |
|---|
| 132 |
geo->setTypes (type); |
|---|
| 133 |
geo->setLengths (lens); |
|---|
| 134 |
geo->setPositions(pnts); |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
geo->setMaterial(getDefaultUnlitMaterial()); |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
NodePtr n = Node::create(); |
|---|
| 142 |
n->setCore(geo); |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
NodePtr scene = Node::create(); |
|---|
| 146 |
trans = Transform::create(); |
|---|
| 147 |
scene->setCore(trans); |
|---|
| 148 |
scene->addChild(n); |
|---|
| 149 |
|
|---|
| 150 |
commitChanges(); |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
mgr = new SimpleSceneManager; |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
mgr->setWindow(gwin ); |
|---|
| 157 |
mgr->setRoot (scene); |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
mgr->showAll(); |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
glutMainLoop(); |
|---|
| 164 |
|
|---|
| 165 |
return 0; |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
void display( void ) |
|---|
| 174 |
{ |
|---|
| 175 |
|
|---|
| 176 |
Matrix m; |
|---|
| 177 |
Real32 t = glutGet(GLUT_ELAPSED_TIME ); |
|---|
| 178 |
|
|---|
| 179 |
m.setTransform(Quaternion( Vec3f(0,1,0), |
|---|
| 180 |
t / 1000.f)); |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
trans->setMatrix(m); |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
GeoPositionsPtr pos = geo->getPositions(); |
|---|
| 206 |
|
|---|
| 207 |
for(UInt32 i = 0; i < pos->getSize(); i++) |
|---|
| 208 |
{ |
|---|
| 209 |
Pnt3f p; |
|---|
| 210 |
pos->getValue(p, i); |
|---|
| 211 |
|
|---|
| 212 |
p[0] += osgSin(t / 300) * p[1] / 100; |
|---|
| 213 |
p[1] += osgSin(t / 300) * p[2] / 100; |
|---|
| 214 |
p[2] += osgSin(t / 300) * p[0] / 100; |
|---|
| 215 |
|
|---|
| 216 |
pos->setValue(p, i); |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
commitChanges(); |
|---|
| 220 |
|
|---|
| 221 |
mgr->redraw(); |
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
void reshape(int w, int h) |
|---|
| 226 |
{ |
|---|
| 227 |
mgr->resize(w, h); |
|---|
| 228 |
glutPostRedisplay(); |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
void mouse(int button, int state, int x, int y) |
|---|
| 233 |
{ |
|---|
| 234 |
if (state) |
|---|
| 235 |
mgr->mouseButtonRelease(button, x, y); |
|---|
| 236 |
else |
|---|
| 237 |
mgr->mouseButtonPress(button, x, y); |
|---|
| 238 |
|
|---|
| 239 |
glutPostRedisplay(); |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
void motion(int x, int y) |
|---|
| 244 |
{ |
|---|
| 245 |
mgr->mouseMove(x, y); |
|---|
| 246 |
glutPostRedisplay(); |
|---|
| 247 |
} |
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
void keyboard(unsigned char k, int x, int y) |
|---|
| 251 |
{ |
|---|
| 252 |
switch(k) |
|---|
| 253 |
{ |
|---|
| 254 |
case 27: |
|---|
| 255 |
{ |
|---|
| 256 |
OSG::osgExit(); |
|---|
| 257 |
exit(0); |
|---|
| 258 |
} |
|---|
| 259 |
break; |
|---|
| 260 |
|
|---|
| 261 |
case 's': |
|---|
| 262 |
{ |
|---|
| 263 |
mgr->setStatistics(!mgr->getStatistics()); |
|---|
| 264 |
} |
|---|
| 265 |
break; |
|---|
| 266 |
} |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
int setupGLUT(int *argc, char *argv[]) |
|---|
| 271 |
{ |
|---|
| 272 |
glutInit(argc, argv); |
|---|
| 273 |
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); |
|---|
| 274 |
|
|---|
| 275 |
int winid = glutCreateWindow("OpenSG"); |
|---|
| 276 |
|
|---|
| 277 |
glutReshapeFunc(reshape); |
|---|
| 278 |
glutDisplayFunc(display); |
|---|
| 279 |
glutMouseFunc(mouse); |
|---|
| 280 |
glutMotionFunc(motion); |
|---|
| 281 |
glutKeyboardFunc(keyboard); |
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
glutIdleFunc(display); |
|---|
| 285 |
|
|---|
| 286 |
return winid; |
|---|
| 287 |
} |
|---|