| [6941] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| [1697] | 19 | #include <osg/Geode> |
|---|
| 20 | #include <osg/Geometry> |
|---|
| 21 | #include <osg/Material> |
|---|
| 22 | #include <osg/Vec3> |
|---|
| 23 | #include <osg/MatrixTransform> |
|---|
| 24 | #include <osg/Texture2D> |
|---|
| 25 | #include <osg/PolygonStipple> |
|---|
| 26 | #include <osg/TriangleFunctor> |
|---|
| [3994] | 27 | #include <osg/io_utils> |
|---|
| [1697] | 28 | |
|---|
| 29 | #include <osgDB/ReadFile> |
|---|
| 30 | #include <osgDB/WriteFile> |
|---|
| 31 | |
|---|
| 32 | #include <osgGA/TrackballManipulator> |
|---|
| 33 | |
|---|
| [5927] | 34 | #include <osgViewer/Viewer> |
|---|
| [1697] | 35 | |
|---|
| 36 | #include <osg/Math> |
|---|
| 37 | |
|---|
| [5927] | 38 | #include <iostream> |
|---|
| [1697] | 39 | |
|---|
| [11763] | 40 | |
|---|
| 41 | |
|---|
| [7648] | 42 | |
|---|
| [11763] | 43 | |
|---|
| [7648] | 44 | |
|---|
| [11763] | 45 | |
|---|
| [7648] | 46 | |
|---|
| [1697] | 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| [7648] | 51 | |
|---|
| 52 | |
|---|
| [1697] | 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | struct NormalPrint |
|---|
| 61 | { |
|---|
| [2315] | 62 | void operator() (const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec3& v3, bool) const |
|---|
| [1697] | 63 | { |
|---|
| 64 | osg::Vec3 normal = (v2-v1)^(v3-v2); |
|---|
| 65 | normal.normalize(); |
|---|
| 66 | std::cout << "\t("<<v1<<") ("<<v2<<") ("<<v3<<") "<<") normal ("<<normal<<")"<<std::endl; |
|---|
| 67 | } |
|---|
| 68 | }; |
|---|
| 69 | |
|---|
| [7648] | 70 | |
|---|
| [1697] | 71 | void printTriangles(const std::string& name, osg::Drawable& drawable) |
|---|
| 72 | { |
|---|
| 73 | std::cout<<name<<std::endl; |
|---|
| 74 | |
|---|
| 75 | osg::TriangleFunctor<NormalPrint> tf; |
|---|
| 76 | drawable.accept(tf); |
|---|
| 77 | |
|---|
| 78 | std::cout<<std::endl; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | osg::Node* createScene() |
|---|
| 83 | { |
|---|
| 84 | |
|---|
| 85 | osg::Geode* geode = new osg::Geode(); |
|---|
| 86 | |
|---|
| [11763] | 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| [1697] | 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | { |
|---|
| [7648] | 94 | |
|---|
| [1697] | 95 | osg::Geometry* pointsGeom = new osg::Geometry(); |
|---|
| 96 | |
|---|
| 97 | |
|---|
| [7648] | 98 | |
|---|
| [1697] | 99 | |
|---|
| [7648] | 100 | |
|---|
| [1697] | 101 | |
|---|
| 102 | osg::Vec3Array* vertices = new osg::Vec3Array; |
|---|
| 103 | vertices->push_back(osg::Vec3(-1.02168, -2.15188e-09, 0.885735)); |
|---|
| 104 | vertices->push_back(osg::Vec3(-0.976368, -2.15188e-09, 0.832179)); |
|---|
| 105 | vertices->push_back(osg::Vec3(-0.873376, 9.18133e-09, 0.832179)); |
|---|
| 106 | vertices->push_back(osg::Vec3(-0.836299, -2.15188e-09, 0.885735)); |
|---|
| 107 | vertices->push_back(osg::Vec3(-0.790982, 9.18133e-09, 0.959889)); |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | pointsGeom->setVertexArray(vertices); |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| [7648] | 115 | |
|---|
| [1697] | 116 | |
|---|
| 117 | osg::Vec4Array* colors = new osg::Vec4Array; |
|---|
| 118 | |
|---|
| 119 | colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); |
|---|
| 120 | |
|---|
| [7648] | 121 | |
|---|
| [1697] | 122 | |
|---|
| 123 | pointsGeom->setColorArray(colors); |
|---|
| 124 | pointsGeom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | osg::Vec3Array* normals = new osg::Vec3Array; |
|---|
| 129 | normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); |
|---|
| 130 | pointsGeom->setNormalArray(normals); |
|---|
| 131 | pointsGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| [7648] | 134 | |
|---|
| 135 | |
|---|
| [1697] | 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | pointsGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS,0,vertices->size())); |
|---|
| 140 | |
|---|
| 141 | |
|---|
| [7648] | 142 | |
|---|
| [1697] | 143 | geode->addDrawable(pointsGeom); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | { |
|---|
| [7648] | 148 | |
|---|
| [1697] | 149 | osg::Geometry* linesGeom = new osg::Geometry(); |
|---|
| 150 | |
|---|
| [7648] | 151 | |
|---|
| [1697] | 152 | |
|---|
| 153 | |
|---|
| 154 | osg::Vec3Array* vertices = new osg::Vec3Array(8); |
|---|
| 155 | (*vertices)[0].set(-1.13704, -2.15188e-09, 0.40373); |
|---|
| 156 | (*vertices)[1].set(-0.856897, -2.15188e-09, 0.531441); |
|---|
| 157 | (*vertices)[2].set(-0.889855, -2.15188e-09, 0.444927); |
|---|
| 158 | (*vertices)[3].set(-0.568518, -2.15188e-09, 0.40373); |
|---|
| 159 | (*vertices)[4].set(-1.00933, -2.15188e-09, 0.370773); |
|---|
| 160 | (*vertices)[5].set(-0.716827, -2.15188e-09, 0.292498); |
|---|
| 161 | (*vertices)[6].set(-1.07936, 9.18133e-09, 0.317217); |
|---|
| 162 | (*vertices)[7].set(-0.700348, 9.18133e-09, 0.362533); |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | linesGeom->setVertexArray(vertices); |
|---|
| 167 | |
|---|
| [7648] | 168 | |
|---|
| [1697] | 169 | osg::Vec4Array* colors = new osg::Vec4Array; |
|---|
| 170 | colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); |
|---|
| 171 | linesGeom->setColorArray(colors); |
|---|
| 172 | linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | osg::Vec3Array* normals = new osg::Vec3Array; |
|---|
| 177 | normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); |
|---|
| 178 | linesGeom->setNormalArray(normals); |
|---|
| 179 | linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,8)); |
|---|
| 185 | |
|---|
| 186 | |
|---|
| [7648] | 187 | |
|---|
| [1697] | 188 | geode->addDrawable(linesGeom); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | { |
|---|
| [7648] | 193 | |
|---|
| [1697] | 194 | osg::Geometry* linesGeom = new osg::Geometry(); |
|---|
| 195 | |
|---|
| [7648] | 196 | |
|---|
| [1697] | 197 | |
|---|
| 198 | |
|---|
| 199 | osg::Vec3Array* vertices = new osg::Vec3Array(5); |
|---|
| 200 | osg::Vec3Array::iterator vitr = vertices->begin(); |
|---|
| 201 | (vitr++)->set(-0.0741545, -2.15188e-09, 0.416089); |
|---|
| 202 | (vitr++)->set(0.234823, -2.15188e-09, 0.259541); |
|---|
| 203 | (vitr++)->set(0.164788, -2.15188e-09, 0.366653); |
|---|
| 204 | (vitr++)->set(-0.0288379, -2.15188e-09, 0.333695); |
|---|
| 205 | (vitr++)->set(-0.0453167, -2.15188e-09, 0.280139); |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | linesGeom->setVertexArray(vertices); |
|---|
| 209 | |
|---|
| [7648] | 210 | |
|---|
| [1697] | 211 | osg::Vec4Array* colors = new osg::Vec4Array; |
|---|
| 212 | colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); |
|---|
| 213 | linesGeom->setColorArray(colors); |
|---|
| 214 | linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | osg::Vec3Array* normals = new osg::Vec3Array; |
|---|
| 219 | normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); |
|---|
| 220 | linesGeom->setNormalArray(normals); |
|---|
| 221 | linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,5)); |
|---|
| 227 | |
|---|
| 228 | |
|---|
| [7648] | 229 | |
|---|
| [1697] | 230 | geode->addDrawable(linesGeom); |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | { |
|---|
| [7648] | 235 | |
|---|
| [1697] | 236 | osg::Geometry* linesGeom = new osg::Geometry(); |
|---|
| 237 | |
|---|
| [7648] | 238 | |
|---|
| [1697] | 239 | |
|---|
| 240 | osg::Vec3 myCoords[] = |
|---|
| 241 | { |
|---|
| 242 | osg::Vec3(0.741546, -2.15188e-09, 0.453167), |
|---|
| 243 | osg::Vec3(0.840418, -2.15188e-09, 0.304858), |
|---|
| 244 | osg::Vec3(1.12468, -2.15188e-09, 0.300738), |
|---|
| 245 | osg::Vec3(1.03816, 9.18133e-09, 0.453167), |
|---|
| 246 | osg::Vec3(0.968129, -2.15188e-09, 0.337815), |
|---|
| 247 | osg::Vec3(0.869256, -2.15188e-09, 0.531441) |
|---|
| 248 | }; |
|---|
| 249 | |
|---|
| 250 | int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); |
|---|
| 251 | |
|---|
| 252 | osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | linesGeom->setVertexArray(vertices); |
|---|
| 256 | |
|---|
| [7648] | 257 | |
|---|
| [1697] | 258 | osg::Vec4Array* colors = new osg::Vec4Array; |
|---|
| 259 | colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); |
|---|
| 260 | linesGeom->setColorArray(colors); |
|---|
| 261 | linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | osg::Vec3Array* normals = new osg::Vec3Array; |
|---|
| 266 | normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); |
|---|
| 267 | linesGeom->setNormalArray(normals); |
|---|
| 268 | linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,numCoords)); |
|---|
| 274 | |
|---|
| 275 | |
|---|
| [7648] | 276 | |
|---|
| [1697] | 277 | geode->addDrawable(linesGeom); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | osg::ref_ptr<osg::Vec4Array> shared_colors = new osg::Vec4Array; |
|---|
| 291 | shared_colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | osg::ref_ptr<osg::Vec3Array> shared_normals = new osg::Vec3Array; |
|---|
| 295 | shared_normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| [11763] | 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| [1697] | 303 | |
|---|
| [11763] | 304 | |
|---|
| [1697] | 305 | |
|---|
| 306 | |
|---|
| 307 | { |
|---|
| [7648] | 308 | |
|---|
| [1697] | 309 | osg::Geometry* polyGeom = new osg::Geometry(); |
|---|
| 310 | |
|---|
| [11763] | 311 | |
|---|
| [7648] | 312 | |
|---|
| [11763] | 313 | |
|---|
| [1697] | 314 | |
|---|
| [5928] | 315 | |
|---|
| [1697] | 316 | |
|---|
| 317 | osg::Vec3 myCoords[] = |
|---|
| 318 | { |
|---|
| 319 | osg::Vec3(-1.0464, 0.0f, -0.193626), |
|---|
| 320 | osg::Vec3(-1.0258, 0.0f, -0.26778), |
|---|
| 321 | osg::Vec3(-0.807461, 0.0f, -0.181267), |
|---|
| 322 | osg::Vec3(-0.766264, 0.0f, -0.0576758), |
|---|
| 323 | osg::Vec3(-0.980488, 0.0f, -0.094753) |
|---|
| 324 | }; |
|---|
| 325 | |
|---|
| 326 | int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); |
|---|
| 327 | |
|---|
| 328 | osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | polyGeom->setVertexArray(vertices); |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | polyGeom->setColorArray(shared_colors.get()); |
|---|
| 335 | polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | polyGeom->setNormalArray(shared_normals.get()); |
|---|
| 340 | polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,numCoords)); |
|---|
| 346 | |
|---|
| 347 | printTriangles("Polygon",*polyGeom); |
|---|
| 348 | |
|---|
| [7648] | 349 | |
|---|
| [1697] | 350 | geode->addDrawable(polyGeom); |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | { |
|---|
| [7648] | 356 | |
|---|
| [1697] | 357 | osg::Geometry* polyGeom = new osg::Geometry(); |
|---|
| 358 | |
|---|
| [7648] | 359 | |
|---|
| [1697] | 360 | osg::Vec3 myCoords[] = |
|---|
| 361 | { |
|---|
| 362 | osg::Vec3(0.0247182, 0.0f, -0.156548), |
|---|
| 363 | osg::Vec3(0.0247182, 0.0f, -0.00823939), |
|---|
| 364 | osg::Vec3(-0.160668, 0.0f, -0.0453167), |
|---|
| 365 | osg::Vec3(-0.222464, 0.0f, -0.13183), |
|---|
| 366 | |
|---|
| 367 | osg::Vec3(0.238942, 0.0f, -0.251302), |
|---|
| 368 | osg::Vec3(0.333696, 0.0f, 0.0329576), |
|---|
| 369 | osg::Vec3(0.164788, 0.0f, -0.0453167), |
|---|
| 370 | osg::Vec3(0.13595, 0.0f, -0.255421) |
|---|
| 371 | }; |
|---|
| 372 | |
|---|
| 373 | int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); |
|---|
| 374 | |
|---|
| 375 | osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | polyGeom->setVertexArray(vertices); |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | polyGeom->setColorArray(shared_colors.get()); |
|---|
| 382 | polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | polyGeom->setNormalArray(shared_normals.get()); |
|---|
| 387 | polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,numCoords)); |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | printTriangles("Quads",*polyGeom); |
|---|
| 396 | |
|---|
| [7648] | 397 | |
|---|
| [1697] | 398 | geode->addDrawable(polyGeom); |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | { |
|---|
| [7648] | 403 | |
|---|
| [1697] | 404 | osg::Geometry* polyGeom = new osg::Geometry(); |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | osg::Vec3 myCoords[] = |
|---|
| 408 | { |
|---|
| 409 | osg::Vec3(0.733306, -2.15188e-09, -0.0741545), |
|---|
| 410 | osg::Vec3(0.758024, -2.15188e-09, -0.205985), |
|---|
| 411 | |
|---|
| 412 | osg::Vec3(0.885735, -2.15188e-09, -0.0576757), |
|---|
| 413 | osg::Vec3(0.885735, -2.15188e-09, -0.214224), |
|---|
| 414 | |
|---|
| 415 | osg::Vec3(0.964009, 9.18133e-09, -0.0370773), |
|---|
| 416 | osg::Vec3(1.0464, 9.18133e-09, -0.173027), |
|---|
| 417 | |
|---|
| 418 | osg::Vec3(1.11232, -2.15188e-09, 0.0123591), |
|---|
| 419 | osg::Vec3(1.12468, 9.18133e-09, -0.164788), |
|---|
| 420 | }; |
|---|
| 421 | |
|---|
| 422 | int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); |
|---|
| 423 | |
|---|
| 424 | osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | polyGeom->setVertexArray(vertices); |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | polyGeom->setColorArray(shared_colors.get()); |
|---|
| 431 | polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | |
|---|
| 435 | polyGeom->setNormalArray(shared_normals.get()); |
|---|
| 436 | polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,numCoords)); |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | printTriangles("Quads strip",*polyGeom); |
|---|
| 445 | |
|---|
| [7648] | 446 | |
|---|
| [1697] | 447 | geode->addDrawable(polyGeom); |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | { |
|---|
| [7648] | 452 | |
|---|
| [1697] | 453 | osg::Geometry* polyGeom = new osg::Geometry(); |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | osg::Vec3 myCoords[] = |
|---|
| 457 | { |
|---|
| 458 | |
|---|
| [7648] | 459 | |
|---|
| [1697] | 460 | osg::Vec3(-1.12056, -2.15188e-09, -0.840418), |
|---|
| 461 | osg::Vec3(-0.95165, -2.15188e-09, -0.840418), |
|---|
| 462 | osg::Vec3(-1.11644, 9.18133e-09, -0.716827), |
|---|
| 463 | |
|---|
| [7648] | 464 | |
|---|
| [1697] | 465 | osg::Vec3(-0.840418, 9.18133e-09, -0.778623), |
|---|
| 466 | osg::Vec3(-0.622074, 9.18133e-09, -0.613835), |
|---|
| 467 | osg::Vec3(-1.067, 9.18133e-09, -0.609715), |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | |
|---|
| 472 | |
|---|
| 473 | osg::Vec3(-0.160668, -2.15188e-09, -0.531441), |
|---|
| 474 | osg::Vec3(-0.160668, -2.15188e-09, -0.749785), |
|---|
| 475 | osg::Vec3(0.0617955, 9.18133e-09, -0.531441), |
|---|
| 476 | osg::Vec3(0.168908, -2.15188e-09, -0.753905), |
|---|
| 477 | osg::Vec3(0.238942, -2.15188e-09, -0.531441), |
|---|
| 478 | osg::Vec3(0.280139, -2.15188e-09, -0.823939), |
|---|
| 479 | |
|---|
| 480 | |
|---|
| [7648] | 481 | |
|---|
| [1697] | 482 | osg::Vec3(0.844538, 9.18133e-09, -0.712708), |
|---|
| 483 | osg::Vec3(1.0258, 9.18133e-09, -0.799221), |
|---|
| 484 | osg::Vec3(1.03816, -2.15188e-09, -0.692109), |
|---|
| 485 | osg::Vec3(0.988727, 9.18133e-09, -0.568518), |
|---|
| 486 | osg::Vec3(0.840418, -2.15188e-09, -0.506723), |
|---|
| 487 | |
|---|
| 488 | }; |
|---|
| 489 | |
|---|
| 490 | int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); |
|---|
| 491 | |
|---|
| 492 | osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords); |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | polyGeom->setVertexArray(vertices); |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | polyGeom->setColorArray(shared_colors.get()); |
|---|
| 499 | polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | polyGeom->setNormalArray(shared_normals.get()); |
|---|
| 504 | polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,6)); |
|---|
| 510 | polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,6,6)); |
|---|
| 511 | polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,12,5)); |
|---|
| 512 | |
|---|
| [4805] | 513 | |
|---|
| 514 | osg::StateSet* stateSet = new osg::StateSet(); |
|---|
| 515 | polyGeom->setStateSet(stateSet); |
|---|
| [10741] | 516 | |
|---|
| 517 | #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) |
|---|
| [4805] | 518 | osg::PolygonStipple* polygonStipple = new osg::PolygonStipple; |
|---|
| 519 | stateSet->setAttributeAndModes(polygonStipple,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| [10741] | 520 | #endif |
|---|
| [1697] | 521 | |
|---|
| 522 | printTriangles("Triangles/Strip/Fan",*polyGeom); |
|---|
| 523 | |
|---|
| [7648] | 524 | |
|---|
| [1697] | 525 | geode->addDrawable(polyGeom); |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | return geode; |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | |
|---|
| [11763] | 532 | |
|---|
| [1697] | 533 | class MyTransformCallback : public osg::NodeCallback |
|---|
| 534 | { |
|---|
| 535 | |
|---|
| 536 | public: |
|---|
| 537 | |
|---|
| 538 | MyTransformCallback(float angularVelocity) |
|---|
| 539 | { |
|---|
| 540 | _angular_velocity = angularVelocity; |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | virtual void operator() (osg::Node* node, osg::NodeVisitor* nv) |
|---|
| 544 | { |
|---|
| 545 | osg::MatrixTransform* transform = dynamic_cast<osg::MatrixTransform*>(node); |
|---|
| 546 | if (nv && transform && nv->getFrameStamp()) |
|---|
| 547 | { |
|---|
| [6051] | 548 | double time = nv->getFrameStamp()->getSimulationTime(); |
|---|
| [1697] | 549 | transform->setMatrix(osg::Matrix::translate(0.0f,1.0f+cosf(time*_angular_velocity),0.0f)); |
|---|
| 550 | } |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | traverse(node,nv); |
|---|
| 554 | |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | protected: |
|---|
| 558 | |
|---|
| 559 | float _angular_velocity; |
|---|
| 560 | |
|---|
| 561 | }; |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | osg::Node* createBackground() |
|---|
| 565 | { |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | osg::Image* image = osgDB::readImageFile("Images/primitives.gif"); |
|---|
| 569 | if (!image) return NULL; |
|---|
| 570 | |
|---|
| 571 | |
|---|
| [7648] | 572 | |
|---|
| [1697] | 573 | osg::Geometry* polyGeom = new osg::Geometry(); |
|---|
| 574 | |
|---|
| [7648] | 575 | |
|---|
| [1697] | 576 | osg::Vec3 myCoords[] = |
|---|
| 577 | { |
|---|
| 578 | osg::Vec3(-1.22908f,0.0f,1.0f), |
|---|
| 579 | osg::Vec3(-1.22908f,0.0f,-1.0f), |
|---|
| 580 | osg::Vec3(1.22908f,0.0f,-1.0f), |
|---|
| 581 | osg::Vec3(1.22908f,0.0f,1.0f) |
|---|
| 582 | }; |
|---|
| 583 | |
|---|
| 584 | int numCoords = sizeof(myCoords)/sizeof(osg::Vec3); |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | polyGeom->setVertexArray(new osg::Vec3Array(numCoords,myCoords)); |
|---|
| 588 | |
|---|
| 589 | osg::Vec4Array* colors = new osg::Vec4Array; |
|---|
| 590 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
|---|
| 591 | polyGeom->setColorArray(colors); |
|---|
| 592 | polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | osg::Vec3Array* normals = new osg::Vec3Array; |
|---|
| 597 | normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); |
|---|
| 598 | polyGeom->setNormalArray(normals); |
|---|
| 599 | polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 600 | |
|---|
| 601 | osg::Vec2 myTexCoords[] = |
|---|
| 602 | { |
|---|
| 603 | osg::Vec2(0,1), |
|---|
| 604 | osg::Vec2(0,0), |
|---|
| 605 | osg::Vec2(1,0), |
|---|
| 606 | osg::Vec2(1,1) |
|---|
| 607 | }; |
|---|
| 608 | |
|---|
| [2890] | 609 | int numTexCoords = sizeof(myTexCoords)/sizeof(osg::Vec2); |
|---|
| [1697] | 610 | |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | polyGeom->setTexCoordArray(0,new osg::Vec2Array(numTexCoords,myTexCoords)); |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | unsigned short myIndices[] = |
|---|
| 617 | { |
|---|
| 618 | 0, |
|---|
| 619 | 1, |
|---|
| [10741] | 620 | 3, |
|---|
| 621 | 2 |
|---|
| [1697] | 622 | }; |
|---|
| 623 | |
|---|
| 624 | int numIndices = sizeof(myIndices)/sizeof(unsigned short); |
|---|
| 625 | |
|---|
| [7648] | 626 | |
|---|
| 627 | |
|---|
| 628 | |
|---|
| [1697] | 629 | |
|---|
| [10741] | 630 | polyGeom->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP,numIndices,myIndices)); |
|---|
| [1697] | 631 | |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | osg::Texture2D* texture = new osg::Texture2D; |
|---|
| 638 | texture->setImage(image); |
|---|
| 639 | |
|---|
| 640 | stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); |
|---|
| 641 | |
|---|
| 642 | polyGeom->setStateSet(stateset); |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | osg::Geode* geode = new osg::Geode(); |
|---|
| 647 | |
|---|
| [7648] | 648 | |
|---|
| [1697] | 649 | geode->addDrawable(polyGeom); |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | |
|---|
| [7648] | 653 | |
|---|
| [1697] | 654 | |
|---|
| 655 | osg::MatrixTransform* transform = new osg::MatrixTransform(); |
|---|
| 656 | transform->setUpdateCallback(new MyTransformCallback(1.0f)); |
|---|
| 657 | transform->addChild(geode); |
|---|
| 658 | |
|---|
| 659 | return transform; |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| [5927] | 662 | int main(int, char **) |
|---|
| [1697] | 663 | { |
|---|
| 664 | |
|---|
| 665 | osg::Group* root = new osg::Group; |
|---|
| 666 | root->addChild( createScene() ); |
|---|
| 667 | root->addChild( createBackground() ); |
|---|
| 668 | |
|---|
| [12529] | 669 | |
|---|
| [1697] | 670 | |
|---|
| [5927] | 671 | osgViewer::Viewer viewer; |
|---|
| [1697] | 672 | |
|---|
| 673 | |
|---|
| 674 | viewer.setSceneData( root ); |
|---|
| 675 | |
|---|
| [5927] | 676 | return viewer.run(); |
|---|
| [1697] | 677 | } |
|---|