Changeset 334
- Timestamp:
- 10/21/06 07:49:49 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Source/System/NodeCores/Drawables/Geometry/Util/OSGSimpleGeometry.cpp
r218 r334 66 66 // The Simple Geometry creation functions 67 67 68 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 69 makePlane creates a plane in the x/y plane. It spans the [-\a xsize /2,\a 70 xsize /2]x [-\a ysize /2,\a ysize/2] area and is subdivided into \a hor * 68 /*! Creates a plane in the x/y plane. It spans the [-\a xsize /2,\a 69 xsize /2] x [-\a ysize /2,\a ysize/2] area and is subdivided into \a hor * 71 70 \a vert quads. 72 */ 73 71 72 \param[in] xsize Length of plane edge in x direction. 73 \param[in] ysize Length of plane edge in y direction. 74 \param[in] hor Number of quads in x direction. 75 \param[in] vert Number of quads in y direction. 76 \return NodePtr to a newly created Node with a Geometry core. 77 78 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 79 */ 74 80 NodePtr makePlane(Real32 xsize, Real32 ysize, UInt16 hor, UInt16 vert) 75 81 { 76 82 GeometryPtr pGeo = makePlaneGeo(xsize, ysize, hor, vert); 77 83 78 84 if(pGeo == NullFC) 79 85 { 80 86 return NullFC; 81 87 } 82 88 83 89 NodePtr node = Node::create(); 84 90 … … 88 94 } 89 95 90 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 91 Create the Geometry Core for used by OSG::makePlane. 92 */ 93 94 GeometryPtr makePlaneGeo(Real32 xsize, Real32 ysize, 96 /*! Create the Geometry core used by OSG::makePlane. 97 98 \param[in] xsize Length of plane edge in x direction. 99 \param[in] ysize Length of plane edge in y direction. 100 \param[in] hor Number of quads in x direction. 101 \param[in] vert Number of quads in y direction. 102 \return GeometryPtr to a newly created Geometry core. 103 104 \sa OSG::makePlane 105 106 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 107 */ 108 GeometryPtr makePlaneGeo(Real32 xsize, Real32 ysize, 95 109 UInt16 hor, UInt16 vert) 96 110 { … … 101 115 return NullFC; 102 116 } 103 117 104 118 GeoPnt3fPropertyPtr pnts = GeoPnt3fProperty ::create(); 105 119 GeoVec3fPropertyPtr norms = GeoVec3fProperty ::create(); 106 120 GeoVec2fPropertyPtr tex = GeoVec2fProperty ::create(); 107 GeoUInt32PropertyPtr index = GeoUInt32Property::create(); 108 GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 109 GeoUInt8PropertyPtr types = GeoUInt8Property ::create(); 110 121 GeoUInt32PropertyPtr index = GeoUInt32Property::create(); 122 GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 123 GeoUInt8PropertyPtr types = GeoUInt8Property ::create(); 124 111 125 UInt16 x,y; 112 126 Real32 xstep,ystep; … … 120 134 GeoVec2fProperty::StoredFieldType *tx = tex ->editFieldPtr(); 121 135 122 123 136 for(y = 0; y <= vert; y++) 124 137 { … … 132 145 133 146 // create the faces 134 147 135 148 GeoUInt32Property::StoredFieldType *i = index->editFieldPtr(); 136 149 GeoUInt32Property::StoredFieldType *l = lens ->editFieldPtr(); … … 141 154 t->push_back(GL_TRIANGLE_STRIP); 142 155 l->push_back(2 * (hor + 1)); 143 156 144 157 for(x = 0; x <= hor; x++) 145 158 { … … 149 162 } 150 163 151 152 164 // create the geometry 153 165 154 166 GeometryPtr geo = Geometry::create(); 155 167 … … 161 173 geo->setTypes(types); 162 174 geo->setLengths(lens); 163 175 164 176 return geo; 165 177 } 166 178 167 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry168 makeCone creates a cone. It's center sits in the origin of the x/z plane.169 It's radius is \a radius and the base is subdivided into \a sides parts.179 /*! Creates a cone. It's center is in the origin and the bottom is parallel to 180 the x/y plane. 181 It's radius is \a botradius and the base is subdivided into \a sides parts. 170 182 171 183 Each part of the cone (bottom cap, sides) can be enabled or disabled. 172 184 185 \param[in] height Height of the cone. 186 \param[in] botradius Radius if the bottom. 187 \param[in] sides Number of sides the base is subdivided into. 188 \param[in] doSide If true side faces are created. 189 \param[in] doBttom If true bottom faces are created. 190 \return NodePtr to a newly created Node with a Geometry core. 191 192 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 173 193 */ 174 175 NodePtr makeCone(Real32 height, 176 Real32 botradius, 177 UInt16 sides, 178 bool doSide, 194 NodePtr makeCone(Real32 height, 195 Real32 botradius, 196 UInt16 sides, 197 bool doSide, 179 198 bool doBottom) 180 199 { 181 return makeConicalFrustum(height, 182 0, 183 botradius, 184 sides, 185 doSide, 186 false, 200 return makeConicalFrustum(height, 201 0, 202 botradius, 203 sides, 204 doSide, 205 false, 187 206 doBottom); 188 207 } 189 208 190 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 191 Create the Geometry Core for used by OSG::makeCone. 209 /*! Create the Geometry Core used by OSG::makeCone. 210 211 \param[in] height Height of the cone. 212 \param[in] botradius Radius if the bottom. 213 \param[in] sides Number of sides the base is subdivided into. 214 \param[in] doSide If true side faces are created. 215 \param[in] doBttom If true bottom faces are created. 216 \return GeometryPtr to a newly created Geometry core. 217 218 \sa OSG::makeCone 219 220 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 192 221 */ 193 194 GeometryPtr makeConeGeo(Real32 height, 195 Real32 botradius, 196 UInt16 sides, 197 bool doSide, 222 GeometryPtr makeConeGeo(Real32 height, 223 Real32 botradius, 224 UInt16 sides, 225 bool doSide, 198 226 bool doBottom) 199 227 { 200 return makeConicalFrustumGeo(height, 201 0, 202 botradius, 203 sides, 204 doSide, 205 false, 228 return makeConicalFrustumGeo(height, 229 0, 230 botradius, 231 sides, 232 doSide, 233 false, 206 234 doBottom); 207 235 } 208 236 209 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 210 makeCylinder creates a cylinder. It's center sits in the origin of the 211 x/z plane. It's radius is \a radius and the base is subdivided into \a 212 sides parts. 237 /*! Creates a cylinder. It's center is in the origin with top and bottom 238 parallel to the x/y plane. It's radius is \a radius and the base is 239 subdivided into \a sides parts. 213 240 214 241 Each part of the cylinder (top cap, bottom cap, sides) can be enabled or 215 242 disabled. 216 243 244 \param[in] height Height of the cylinder. 245 \param[in] radius Radius of the cylinder. 246 \param[in] sides Number of sides the base is subdivided into. 247 \param[in] doSide If true, side faces are created. 248 \param[in] doTop If true, top cap faces are created. 249 \param[in] doBttom If true, bottom cap faces are created. 250 \return NodePtr to a newly created Node with a Geometry core. 251 252 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 217 253 */ 218 219 NodePtr makeCylinder(Real32 height, 254 NodePtr makeCylinder(Real32 height, 220 255 Real32 radius, 221 UInt16 sides, 222 bool doSide, 223 bool doTop, 256 UInt16 sides, 257 bool doSide, 258 bool doTop, 224 259 bool doBottom) 225 260 { 226 return makeConicalFrustum(height, 227 radius, 228 radius, 229 sides, 230 doSide, 231 doTop, 261 return makeConicalFrustum(height, 262 radius, 263 radius, 264 sides, 265 doSide, 266 doTop, 232 267 doBottom); 233 268 } 234 269 235 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 236 Create the Geometry Core for used by OSG::makeCylinder. 270 /*! Create the Geometry Core used by OSG::makeCylinder. 271 272 \param[in] height Height of the cylinder. 273 \param[in] radius Radius of the cylinder. 274 \param[in] sides Number of sides the base is subdivided into. 275 \param[in] doSide If true, side faces are created. 276 \param[in] doTop If true, top cap faces are created. 277 \param[in] doBttom If true, bottom cap faces are created. 278 \return GeometryPtr to a newly created Geometry core. 279 280 \sa OSG::makeCylinder 281 282 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 237 283 */ 238 239 GeometryPtr makeCylinderGeo(Real32 height, 284 GeometryPtr makeCylinderGeo(Real32 height, 240 285 Real32 radius, 241 UInt16 sides, 242 bool doSide, 243 bool doTop, 286 UInt16 sides, 287 bool doSide, 288 bool doTop, 244 289 bool doBottom) 245 290 { 246 return makeConicalFrustumGeo(height, 247 radius, 248 radius, 249 sides, 250 doSide, 251 doTop, 291 return makeConicalFrustumGeo(height, 292 radius, 293 radius, 294 sides, 295 doSide, 296 doTop, 252 297 doBottom); 253 298 } 254 299 255 300 256 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 257 makeConicalFrustum creates a conical frustum. It's center sits in the 258 origin of the x/z plane. It's height is \a height and the base is 259 subdivided into \a sides parts. The top radius is \a topradius, the bottom 260 radius \a botradius. 301 /*! Creates a conical frustum. It's center is in the origin with top and bottom 302 parallel to the x/y plane. The height is \a height and the base is 303 subdivided into \a sides parts. The top radius is \a topradius, while the 304 bottom radius is \a botradius. 261 305 262 306 Each part of the frustum (top cap, bottom cap, sides) can be enabled or 263 disabled. Caps forradius 0 are automatically disabled. 264 265 */ 266 267 NodePtr makeConicalFrustum(Real32 height, 268 Real32 topradius, 269 Real32 botradius, 270 UInt16 sides, 271 bool doSide, 272 bool doTop, 307 disabled. Caps for radii 0 are automatically disabled. 308 309 \param[in] height Height of the conical frustum. 310 \param[in] topradius Radius at the top of the conical frustum. 311 \param[in] botradius Radius at the bottom of the conical frustum. 312 \param[in] sides Number of sides the base is subdivided into. 313 \param[in] doSide If true, side faces are created. 314 \param[in] doTop If true, top cap faces are created. 315 \param[in] doBttom If true, bottom cap faces are created. 316 \return NodePtr to a newly created Node with a Geometry core. 317 318 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 319 */ 320 NodePtr makeConicalFrustum(Real32 height, 321 Real32 topradius, 322 Real32 botradius, 323 UInt16 sides, 324 bool doSide, 325 bool doTop, 273 326 bool doBottom) 274 327 { 275 GeometryPtr pGeo = makeConicalFrustumGeo(height, 276 topradius, 328 GeometryPtr pGeo = makeConicalFrustumGeo(height, 329 topradius, 277 330 botradius, 278 sides, 279 doSide, 280 doTop, 331 sides, 332 doSide, 333 doTop, 281 334 doBottom); 282 335 … … 285 338 return NullFC; 286 339 } 287 340 288 341 NodePtr node = Node::create(); 289 342 … … 293 346 } 294 347 295 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 296 Create the Geometry Core for used by OSG::makeConicalFrustum. 297 */ 298 299 GeometryPtr makeConicalFrustumGeo(Real32 height, 300 Real32 topradius, 301 Real32 botradius, 302 UInt16 sides, 303 bool doSide, 304 bool doTop, 348 /*! Create the Geometry Core used by OSG::makeConicalFrustum. 349 350 \param[in] height Height of the conical frustum. 351 \param[in] topradius Radius at the top of the conical frustum. 352 \param[in] botradius Radius at the bottom of the conical frustum. 353 \param[in] sides Number of sides the base is subdivided into. 354 \param[in] doSide If true, side faces are created. 355 \param[in] doTop If true, top cap faces are created. 356 \param[in] doBttom If true, bottom cap faces are created. 357 \return GeometryPtr to a newly created Geometry core. 358 359 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 360 */ 361 GeometryPtr makeConicalFrustumGeo(Real32 height, 362 Real32 topradius, 363 Real32 botradius, 364 UInt16 sides, 365 bool doSide, 366 bool doTop, 305 367 bool doBottom) 306 368 { 307 369 if(height <= 0 || topradius < 0 || botradius < 0 || sides < 3) 308 370 { 309 SWARNING << "makeConicalFrustum: illegal parameters height=" << height 310 << ", topradius=" << topradius 311 << ", botradius=" << botradius 312 << ", sides=" << sides 371 SWARNING << "makeConicalFrustum: illegal parameters height=" << height 372 << ", topradius=" << topradius 373 << ", botradius=" << botradius 374 << ", sides=" << sides 313 375 << std::endl; 314 376 return NullFC; 315 377 } 316 378 317 379 GeoPnt3fPropertyPtr pnts = GeoPnt3fProperty ::create(); 318 380 GeoVec3fPropertyPtr norms = GeoVec3fProperty ::create(); 319 381 GeoVec2fPropertyPtr tex = GeoVec2fProperty ::create(); 320 GeoUInt32PropertyPtr index = GeoUInt32Property::create(); 321 GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 322 GeoUInt8PropertyPtr types = GeoUInt8Property ::create(); 323 382 GeoUInt32PropertyPtr index = GeoUInt32Property::create(); 383 GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 384 GeoUInt8PropertyPtr types = GeoUInt8Property ::create(); 385 324 386 Int16 j; 325 387 Real32 delta = 2.f * Pi / sides; … … 327 389 Real32 incl = (botradius - topradius) / height; 328 390 Real32 nlen = 1.f / osgSqrt(1 + incl * incl); 329 391 330 392 // vertices 331 393 … … 335 397 336 398 // faces 337 399 338 400 GeoUInt32Property::StoredFieldType *i = index->editFieldPtr(); 339 401 GeoUInt32Property::StoredFieldType *l = lens ->editFieldPtr(); 340 402 GeoUInt8Property::StoredFieldType *t = types->editFieldPtr(); 341 403 342 //343 344 404 if(doSide) 345 405 { 346 406 UInt32 baseindex = p->size(); 347 407 348 408 for(j = 0; j <= sides; j++) 349 409 { 350 410 beta = j * delta; 351 411 x = osgSin(beta); 352 z = -osgCos(beta); 412 z = -osgCos(beta); 353 413 354 414 p->push_back(Pnt3f(x * topradius, height/2, z * topradius)); … … 356 416 tx->push_back(Vec2f(1.f - j / (Real32) sides, 1)); 357 417 } 358 418 359 419 for(j = 0; j <= sides; j++) 360 420 { 361 421 beta = j * delta; 362 422 x = osgSin(beta); 363 z = -osgCos(beta); 423 z = -osgCos(beta); 364 424 365 425 p->push_back(Pnt3f(x * botradius, -height/2, z * botradius)); … … 371 431 l->push_back(2 * (sides + 1)); 372 432 373 for(j = 0; j <= sides; j++) 433 for(j = 0; j <= sides; j++) 374 434 { 375 435 i->push_back(baseindex + sides + 1 + j); … … 377 437 } 378 438 } 379 439 380 440 if(doTop && topradius > 0) 381 441 { 382 442 UInt32 baseindex = p->size(); 383 443 384 444 // need to duplicate the points fornow, as we don't have multi-index geo yet 385 445 386 446 for(j = sides - 1; j >= 0; j--) 387 447 { 388 448 beta = j * delta; 389 449 x = topradius * osgSin(beta); 390 z = -topradius * osgCos(beta); 450 z = -topradius * osgCos(beta); 391 451 392 452 p->push_back(Pnt3f(x, height/2, z)); … … 398 458 l->push_back(sides); 399 459 400 for(j = 0; j < sides; j++) 460 for(j = 0; j < sides; j++) 401 461 { 402 462 i->push_back(baseindex + j); 403 463 } 404 464 } 405 465 406 466 if(doBottom && botradius > 0 ) 407 467 { 408 468 UInt32 baseindex = p->size(); 409 469 410 470 // need to duplicate the points fornow, as we don't have multi-index geo yet 411 471 412 472 for(j = sides - 1; j >= 0; j--) 413 473 { 414 474 beta = j * delta; 415 475 x = botradius * osgSin(beta); 416 z = -botradius * osgCos(beta); 476 z = -botradius * osgCos(beta); 417 477 418 478 p->push_back(Pnt3f(x, -height/2, z)); … … 424 484 l->push_back(sides); 425 485 426 for(j = 0; j < sides; j++) 486 for(j = 0; j < sides; j++) 427 487 { 428 488 i->push_back(baseindex + sides - 1 - j); 429 489 } 430 490 } 431 491 432 492 // create the geometry 433 493 434 494 GeometryPtr geo = Geometry::create(); 435 495 … … 445 505 } 446 506 447 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 448 makeTorus creates a torus in the x/y plane. Sides are the number of 449 subdivisions forthe inner radius, rings forthe outer. 450 451 */ 452 453 NodePtr makeTorus(Real32 innerRadius, Real32 outerRadius, UInt16 sides, 507 /*! Creates a torus in the x/y plane. The number of subdivisions for 508 the inner radius is \a sides, for the outer radius it is \a rings. 509 510 \param[in] innerRadius Inner radius of the torus. 511 \param[in] outerRadius Outer radius of the torus. 512 \param[in] sides Number of subdivisions along the inner radius. 513 \param[in] rings Number of subdivisions along the outer radius. 514 \return NodePtr to a newly created Node with a Geometry core. 515 516 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 517 */ 518 NodePtr makeTorus(Real32 innerRadius, Real32 outerRadius, UInt16 sides, 454 519 UInt16 rings) 455 520 { 456 521 GeometryPtr pGeo = makeTorusGeo(innerRadius, outerRadius, sides, rings); 457 522 458 523 if(pGeo == NullFC) 459 524 { 460 525 return NullFC; 461 526 } 462 527 463 528 NodePtr node = Node::create(); 464 529 … … 468 533 } 469 534 470 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 471 Create the Geometry Core for used by OSG::makeTorus. 472 */ 473 474 GeometryPtr makeTorusGeo(Real32 innerRadius, Real32 outerRadius, UInt16 sides, 535 /*! Create the Geometry Core used by OSG::makeTorus. 536 537 \param[in] innerRadius Inner radius of the torus. 538 \param[in] outerRadius Outer radius of the torus. 539 \param[in] sides Number of subdivisions along the inner radius. 540 \param[in] rings Number of subdivisions along the outer radius. 541 \return GeometryPtr to a newly created Geometry core. 542 543 \sa OSG::makeTorus 544 545 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 546 */ 547 GeometryPtr makeTorusGeo(Real32 innerRadius, Real32 outerRadius, UInt16 sides, 475 548 UInt16 rings) 476 549 { 477 550 if(innerRadius <= 0 || outerRadius <= 0 || sides < 3 || rings < 3) 478 551 { 479 SWARNING << "makeTorus: illegal parameters innerRadius=" << innerRadius 480 << ", outerRadius=" << outerRadius 481 << ", sides=" << sides 482 << ", rings=" << rings 552 SWARNING << "makeTorus: illegal parameters innerRadius=" << innerRadius 553 << ", outerRadius=" << outerRadius 554 << ", sides=" << sides 555 << ", rings=" << rings 483 556 << std::endl; 484 557 return NullFC; 485 558 } 486 559 487 560 GeoPnt3fPropertyPtr pnts = GeoPnt3fProperty ::create(); 488 561 GeoVec3fPropertyPtr norms = GeoVec3fProperty ::create(); 489 562 GeoVec2fPropertyPtr tex = GeoVec2fProperty ::create(); 490 GeoUInt32PropertyPtr index = GeoUInt32Property::create(); 491 GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 492 GeoUInt8PropertyPtr types = GeoUInt8Property ::create(); 493 563 GeoUInt32PropertyPtr index = GeoUInt32Property::create(); 564 GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 565 GeoUInt8PropertyPtr types = GeoUInt8Property ::create(); 566 494 567 UInt16 a, b; 495 568 Real32 theta, phi; … … 506 579 sideDelta = 2.f * Pi / sides; 507 580 508 for(a = 0, theta = 0.0; a <= rings; a++, theta += ringDelta) 581 for(a = 0, theta = 0.0; a <= rings; a++, theta += ringDelta) 509 582 { 510 583 cosTheta = osgCos(theta); 511 584 sinTheta = osgSin(theta); 512 585 513 for(b = 0, phi = 0; b <= sides; b++, phi += sideDelta) 586 for(b = 0, phi = 0; b <= sides; b++, phi += sideDelta) 514 587 { 515 588 GLfloat cosPhi, sinPhi, dist; … … 519 592 dist = outerRadius + innerRadius * cosPhi; 520 593 521 n->push_back(Vec3f(cosTheta * cosPhi, 522 -sinTheta * cosPhi, 594 n->push_back(Vec3f(cosTheta * cosPhi, 595 -sinTheta * cosPhi, 523 596 sinPhi)); 524 p->push_back(Pnt3f(cosTheta * dist, 525 -sinTheta * dist, 597 p->push_back(Pnt3f(cosTheta * dist, 598 -sinTheta * dist, 526 599 innerRadius * sinPhi)); 527 600 tx->push_back(Vec2f(- a / (Real32) rings, b / (Real32)sides)); 528 601 } 529 } 602 } 530 603 531 604 // create the faces 532 605 533 606 GeoUInt32Property::StoredFieldType *i = index->editFieldPtr(); 534 607 GeoUInt32Property::StoredFieldType *l = lens ->editFieldPtr(); 535 608 GeoUInt8Property::StoredFieldType *t = types->editFieldPtr(); 536 609 537 for(a = 0; a < sides; a++) 610 for(a = 0; a < sides; a++) 538 611 { 539 612 t->push_back(GL_TRIANGLE_STRIP); 540 613 l->push_back((rings + 1) * 2); 541 614 542 615 for(b = 0; b <= rings; b++) 543 616 { … … 548 621 549 622 // create the geometry 550 623 551 624 GeometryPtr geo = Geometry::create(); 552 625 … … 558 631 geo->setTypes(types); 559 632 geo->setLengths(lens); 560 633 561 634 return geo; 562 635 } … … 564 637 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV) 565 638 566 Real32 setVecLen(Vec3f &vec, Real32 length) 639 /*! Scale the vector \a vec to the given \a length. If \a vec is degenerate, 640 i.e. has length 0 it is not changed. 641 642 \param[in,out] vec The vector to scale. 643 \param[in] length Length to scale \a vec to. 644 \return The \a length argument. 645 */ 646 Real32 setVecLen(Vec3f &vec, Real32 length) 567 647 { 568 648 Real32 len = vec.length(); 569 if(len == 0.0) 649 if(len == 0.0) 570 650 { 571 651 len = 1; 572 } 573 else 652 } 653 else 574 654 { 575 655 len = length / len; 576 656 } 577 657 vec *= len; 578 658 579 659 return length; 580 660 } … … 584 664 const Real32 TwoPi = 6.283185307179586; 585 665 const Real32 HalfPi = 1.570796326794897; 586 666 587 667 Real32 phi = osgATan2(-n[2], n[0]) - HalfPi; 588 668 … … 590 670 phi += TwoPi; 591 671 phi /= TwoPi; 592 672 593 673 return phi; 594 674 } … … 617 697 } 618 698 619 void subdivideTriangle( UInt32 i1, 620 UInt32 i2, 699 void subdivideTriangle( UInt32 i1, 700 UInt32 i2, 621 701 UInt32 i3, 622 Int32 depth, 702 Int32 depth, 623 703 GeoPnt3fProperty::StoredFieldType *p, 624 704 GeoVec3fProperty::StoredFieldType *n, … … 626 706 GeoUInt32Property::StoredFieldType *i, 627 707 GeoUInt32Property::StoredFieldType *tci, 628 UInt32& z, Real32 radius ) 629 { 630 if (depth == 0) 708 UInt32& z, Real32 radius ) 709 { 710 if (depth == 0) 631 711 { 632 712 i->push_back(i1); … … 636 716 i->push_back(i3); 637 717 tci->push_back(i3); 638 639 return; 718 719 return; 640 720 } 641 721 … … 648 728 v23 = v2 + (v3 - v2) * .5f; 649 729 v31 = v3 + (v1 - v3) * .5f; 650 730 651 731 v12 /= 2.0f; 652 732 v23 /= 2.0f; 653 733 v31 /= 2.0f; 654 734 655 735 UInt32 i12 = z++, i23 = z++, i31 = z++; 656 736 … … 658 738 addPoint(v23,i23,radius,p,n,tx); 659 739 addPoint(v31,i31,radius,p,n,tx); 660 740 661 741 subdivideTriangle( i1, i12, i31, depth - 1, p,n,tx,i,tci, z, radius); 662 742 subdivideTriangle( i2, i23, i12, depth - 1, p,n,tx,i,tci, z, radius); … … 667 747 #endif // exclude from doc 668 748 669 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 670 makeSphere creates a sphere centered in the origin. It is created by 749 /*! Creates a sphere centered in the origin. It is created by 671 750 recursive subdivision of an icosahedron, with \a depth giving the number 672 751 of subdivisions and \a radius being the radius. 673 752 674 */ 675 753 \param[in] depth Number of recursive subdivisions to perform. 754 \param[in] radius Radius of sphere. 755 \return NodePtr to a newly created Node with a Geometry core. 756 757 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 758 */ 676 759 NodePtr makeSphere(UInt16 depth, Real32 radius) 677 { 760 { 678 761 GeometryPtr pGeo = makeSphereGeo(depth, radius); 679 762 … … 686 769 687 770 node->setCore(pGeo); 688 771 689 772 return node; 690 773 } 691 774 692 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 693 Create the Geometry Core for used by OSG::makeSphere. 694 */ 695 775 /*! Create the Geometry Core for used by OSG::makeSphere. 776 777 \param[in] depth Number of recursive subdivisions to perform. 778 \param[in] radius Radius of sphere. 779 \return GeometryPtr to a newly created Geometry core. 780 781 \sa OSG::makeSphere 782 783 \ingroup GrpSystemDrawablesGeometrySimpleGeometry 784 */ 696 785 GeometryPtr makeSphereGeo(UInt16 depth, Real32 radius) 697 786 { … … 703 792 GeoVec3fPropertyPtr norms = GeoVec3fProperty ::create(); 704 793 GeoVec2fPropertyPtr tex = GeoVec2fProperty ::create(); 705 GeoUInt32PropertyPtr index = GeoUInt32Property::create(); 706 GeoUInt32PropertyPtr tcindex = GeoUInt32Property::create(); 707 GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 708 GeoUInt8PropertyPtr types = GeoUInt8Property ::create(); 794 GeoUInt32PropertyPtr index = GeoUInt32Property::create(); 795 GeoUInt32PropertyPtr tcindex = GeoUInt32Property::create(); 796 GeoUInt32PropertyPtr lens = GeoUInt32Property::create(); 797 GeoUInt8PropertyPtr types = GeoUInt8Property ::create(); 709 798 710 799 UInt32 j,z; 711 800 712 801 static Vec3f v[12] = { Vec3f(-X, 0., Z), 713 802 Vec3f( X, 0., Z), … … 730 819 for (j=0; j<12; j++) 731 820 mat.mult(v[j]); 732 821 733 822 Int32 tr[20][3] = { {1,4,0}, {4,9,0}, {4,5,9}, {8,5,4}, {1,8,4}, 734 823 {1,10,8}, {10,3,8}, {8,3,5}, {3,2,5}, {3,7,2}, 735 824 {3,10,7}, {10,6,7}, {6,11,7}, {6,0,11}, {6,1,0}, 736 {10,1,6}, {11,0,9}, {2,11,9}, {5,2,9}, {11,2,7} }; 737 825 {10,1,6}, {11,0,9}, {2,11,9}, {5,2,9}, {11,2,7} }; 826 738 827 GeoPnt3fProperty::StoredFieldType *p = pnts ->editFieldPtr(); 739 828 GeoVec3fProperty::StoredFieldType *n = norms->editFieldPtr(); … … 751 840 i->reserve (estimatedSize); 752 841 tci->reserve (estimatedSize); 753 754 // add the initial points to the fields 755 for (j=0; j<12; j++) 842 843 // add the initial points to the fields 844 for (j=0; j<12; j++) 756 845 { 757 846 Vec3f pnt = v[j]; 758 847 Vec3f norm = v[j]; 759 848 760 849 setVecLen(pnt, radius); 761 850 norm.normalize(); 762 851 763 852 p->push_back(pnt.addToZero()); 764 853 n->push_back(norm); … … 774 863 tx->push_back(texCoord); 775 864 } 776 865 777 866 // subdivide the triangles 778 867 z=12; 779 for(j=0; j<20; j++) 780 { 781 subdivideTriangle(tr[j][0], tr[j][1], tr[j][2], 868 for(j=0; j<20; j++) 869 { 870 subdivideTriangle(tr[j][0], tr[j][1], tr[j][2], 782 871 depth, p, n, tx, i, tci, z, radius); 783 872 } … … 785 874 types->push_back(GL_TRIANGLES); 786 875 lens->push_back(i->size()); 787 876 788 877 // create the geometry 789 878 GeometryPtr geo = Geometry::create(); 790 879 791 792 880 geo->setMaterial(getDefaultMaterial()); 793 881 geo->setPositions(pnts); … … 823 911 { 824 912 Real32 theta = ti.getTexCoords(i).y(); 825 826 if( !(q[0][0] <= -Eps || 827 q[1][0] <= -Eps || 913 914 if( !(q[0][0] <= -Eps || 915 q[1][0] <= -Eps || 828 916 q[2][0] <= -Eps ) ) 829 917 { … … 832 920 if(osgAbs(osgAbs(norm[1]) - 1) <= Eps) 833 921 texCoord[0] = 0.5; 834 922 835 923 tex->push_back(texCoord); 836 924 837 925 tcindex->setValue( tex->size() - 1, ti.getTexCoordsIndex(i)); 838 926 } … … 843 931 if (osgAbs(osgAbs(norm[1]) - 1) <= Eps) 844 932 texCoord[0] = 0.5; 845 933 846 934 tex->push_back(texCoord); 847 935 848 936 index->setValue( tex->size() - 1, ti.getTexCoordsIndex(i)); 849 937 } … … 852 940 } 853 941 } 854 942 855 943 endEditCP(geo); 856 944 #endif … … 859 947 } 860 948 861 /*! \ingroup GrpSystemDrawablesGeometrySimpleGeometry 862 makeLatLongSphere creates a sphere in the origin and divided in latitude 863 and longitude. \a radius is the radius of the sphere, \a latres and \a 864 longres are the number of subdivisions along the latitudes and longitudes. 865 866 */ 867 949 /*! Creates a sphere centered in the origin and divided in latitude 950 and longitude. \a radius is the radius of the sphere, \a latres and 951 \a longres are the number of subdivisions along the latitudes and longitudes. 952 953 \param[in] latres Number of subdivisions along latitudes. 954 \param[in] longres Number of subdivisions along longitudes. 955 \param[in] radius Radius of sphere. 956 \return NodePtr to a newly created Node with a Geometry core. 957
