/*! \ingroup GrpSystemDrawablesGeometryFunctions Draw the given BoxVolume using direct OpenGL calls. */ OSG_SYSTEMLIB_DLLMAPPING void OSG::drawVolume(const BoxVolume &volume) { Pnt3f min,max; volume.getBounds(min, max); glBegin(GL_LINE_LOOP); glVertex3f(min[0], min[1], min[2]); glVertex3f(max[0], min[1], min[2]); glVertex3f(max[0], max[1], min[2]); glVertex3f(min[0], max[1], min[2]); glVertex3f(min[0], min[1], min[2]); glVertex3f(min[0], min[1], max[2]); glVertex3f(max[0], min[1], max[2]); glVertex3f(max[0], max[1], max[2]); glVertex3f(min[0], max[1], max[2]); glVertex3f(min[0], min[1], max[2]); glEnd(); glBegin(GL_LINES); glVertex3f(min[0], max[1], min[2]); glVertex3f(min[0], max[1], max[2]); glVertex3f(max[0], max[1], min[2]); glVertex3f(max[0], max[1], max[2]); glVertex3f(max[0], min[1], min[2]); glVertex3f(max[0], min[1], max[2]); glEnd(); return; }
Action::ResultE draw(DrawEnv *) { BoxVolume vol; _node->getWorldVolume(vol); Pnt3f Min,Max; vol.getBounds(Min,Max); Real32 Length(1.05f * (Max-Min).maxValue()); drawPhysicsBodyCoordinateSystem(_body, Length); drawPhysicsBodyLinearVelocity(_body, Length); drawPhysicsBodyAngularVelocity(_body, Length); // self-destruct delete this; return Action::Continue; }
OSG_BASE_DLLMAPPING bool intersect(const BoxVolume &box, const FrustumVolume &frustum) { Pnt3f min, max; box.getBounds(min, max); const Plane *frust = frustum.getPlanes(); // check each point of the box to the 6 planes for(Int32 i = 0; i < 6; i++) { if(frust[i].isOutHalfSpace(min, max)) return false; } return true; }
OSG_BASE_DLLMAPPING void extend(SphereVolume &srcVol, const BoxVolume &vol) { Pnt3f min, max, min1, max1, c; Real32 r; BoxVolume vol1; vol.getBounds(min, max); if((!srcVol.isValid () && !srcVol.isEmpty()) || srcVol.isInfinite() || srcVol.isStatic () ) { return; } if(!vol.isValid()) return; if(srcVol.isEmpty()) { if(vol.isEmpty()) { return; } else { c = Pnt3f((min.x() + max.x()) * 0.5f, (min.y() + max.y()) * 0.5f, (min.z() + max.z()) * 0.5f); r = ((max - min).length()) / 2; srcVol.setValue(c, r); return; } } else if(vol.isEmpty()) { return; } srcVol.getBounds(min1, max1); vol1.setBounds(osgMin(min.x(), min1.x()), osgMin(min.y(), min1.y()), osgMin(min.z(), min1.z()), osgMax(max.x(), max1.x()), osgMax(max.y(), max1.y()), osgMax(max.z(), max1.z())); vol1.getBounds(min, max); c = Pnt3f((min.x() + max.x()) * 0.5f, (min.y() + max.y()) * 0.5f, (min.z() + max.z()) * 0.5f); r = ((max - min).length()) / 2; srcVol.setValue(c, r); return; }
OSG_BASE_DLLMAPPING void extend(CylinderVolume &srcVol, const BoxVolume &vol) { Pnt3f min, max, min1, max1, min2, max2, apos; Vec2f p; Vec3f adir; Real32 r; if((!srcVol.isValid () && !srcVol.isEmpty()) || srcVol.isInfinite() || srcVol.isStatic () ) { return; } if(!vol.isValid()) { return; } if(srcVol.isEmpty()) { if(vol.isEmpty()) { return; } else { vol.getBounds(min, max); p = Vec2f(max.x() - min.x(), max.y() - min.y()); r = (p.length()) * 0.5f; adir = Vec3f(0.f, 0.f, max.z() - min.z()); apos = Pnt3f(p.x(), p.y(), min.z()); srcVol.setValue(apos, adir, r); return; } } else if(vol.isEmpty()) { return; } srcVol.getBounds(min, max ); vol .getBounds(min1, max1); min2 = Pnt3f(osgMin(min.x(), min1.x()), osgMin(min.y(), min1.y()), osgMin(min.z(), min1.z())); max2 = Pnt3f(osgMax(max.x(), max1.x()), osgMax(max.y(), max1.y()), osgMax(max.z(), max1.z())); p = Vec2f(max2.x() - min2.x(), max2.y() - min2.y()); r = (p.length()) * 0.5f; adir = Vec3f(0.f, 0.f, max2.z() - min2.z()); apos = Pnt3f(p.x(), p.y(), min2.z()); srcVol.setValue(apos, adir, r); return; }
void selectedNodeChanged(void) { mgr->setHighlight(SelectedNode); //Update Details Panel if(SelectedNode == NULL) { NodeNameValueLabel->setText(""); NodeCoreTypeValueLabel->setText(""); NodeMinValueLabel->setText(""); NodeMaxValueLabel->setText(""); NodeCenterValueLabel->setText(""); NodeTriCountValueLabel->setText(""); NodeTravMaskValueLabel->setText(""); NodeOcclusionMaskValueLabel->setText(""); NodeActiveValueLabel->setText(""); } else { const Char8 *NodeName = getName(SelectedNode); if(NodeName == NULL) { NodeNameValueLabel->setText("Unnamed Node"); } else { NodeNameValueLabel->setText(NodeName); } NodeCoreTypeValueLabel->setText(SelectedNode->getCore()->getType().getCName()); BoxVolume DyVol; SelectedNode->getWorldVolume(DyVol); Pnt3f Min,Max,Center; DyVol.getBounds(Min,Max); DyVol.getCenter(Center); std::string TempText(""); TempText = boost::lexical_cast<std::string>(Min.x()) + ", " +boost::lexical_cast<std::string>(Min.x()) + ", " + boost::lexical_cast<std::string>(Min.x()); NodeMinValueLabel->setText(TempText); TempText = boost::lexical_cast<std::string>(Max.x()) + ", " +boost::lexical_cast<std::string>(Max.x()) + ", " + boost::lexical_cast<std::string>(Max.x()); NodeMaxValueLabel->setText(TempText); TempText = boost::lexical_cast<std::string>(Center.x()) + ", " +boost::lexical_cast<std::string>(Center.x()) + ", " + boost::lexical_cast<std::string>(Center.x()); NodeCenterValueLabel->setText(TempText); //GeometryPrimitivesCounter PrimCounter; //PrimCounter(SelectedNode); //NodeTriCountValueLabel->setText(boost::lexical_cast<std::string>(PrimCounter.getTriCount())); //NodeTravMaskValueLabel->setText(boost::lexical_cast<std::string>(SelectedNode->getTravMask())); //NodeOcclusionMaskValueLabel->setText(boost::lexical_cast<std::string>(SelectedNode->getOcclusionMask())); //NodeActiveValueLabel->setText(boost::lexical_cast<std::string>(SelectedNode->getActive())); } }
void SortLastWindow::collectDrawables(Node * const node, DrawableListT &drawables) { Material *mat = NULL; NodeCore *core = node->getCore(); if(core != NULL) { // handle material groups MaterialGroup *matGrp = dynamic_cast<MaterialGroup *>(core); if(matGrp != NULL) { mat = matGrp->getMaterial(); // ignore transparent material groups if(mat != NULL && mat->isTransparent()) return; } // handle geometries Geometry *geo = dynamic_cast<Geometry *>(core); if(geo != NULL) { mat = geo->getMaterial(); // ignore transparent materials if(mat == NULL || mat->isTransparent() == false) { DrawableInfo drawableInfo; drawableInfo.node = node; // get transformed volume node->updateVolume(); BoxVolume volume; node->getWorldVolume(volume); // get min,max volume.getBounds(drawableInfo.bMin, drawableInfo.bMax); // num of indices drawableInfo.load = 0; GeoIntegralProperty *indicesPtr = geo->getIndex(Geometry::PositionsIndex); if(indicesPtr != NULL) drawableInfo.load = indicesPtr->size(); // put to list drawables.push_back(drawableInfo); } } // handle poxy groups ProxyGroup *proxy = dynamic_cast<ProxyGroup *>(core); if(proxy != NULL) { DrawableInfo drawableInfo; drawableInfo.node = node; // get transformed volume node->updateVolume(); BoxVolume volume; node->getWorldVolume(volume); // get min,max volume.getBounds(drawableInfo.bMin, drawableInfo.bMax); // num of indices drawableInfo.load = proxy->getIndices(); // put to list drawables.push_back(drawableInfo); } } MFUnrecChildNodePtr::const_iterator nI; for( nI = node->getMFChildren()->begin(); nI != node->getMFChildren()->end(); ++nI) { collectDrawables(*nI, drawables); } }
void selectedNodeChanged(void) { _mgr->setHighlight(_SelectedNode); //Update Details Panel if(_SelectedNode == NULL) { _NodeNameValueLabel->setText(""); _NodeCoreTypeValueLabel->setText(""); _NodeMinValueLabel->setText(""); _NodeMaxValueLabel->setText(""); _NodeCenterValueLabel->setText(""); _NodeTriCountValueLabel->setText(""); _NodeTravMaskValueLabel->setText(""); } else { const Char8 *NodeName = getName(_SelectedNode); if(NodeName == NULL) { _NodeNameValueLabel->setText("Unnamed Node"); } else { _NodeNameValueLabel->setText(NodeName); } _NodeCoreTypeValueLabel->setText(_SelectedNode->getCore()->getType().getCName()); BoxVolume DyVol; _SelectedNode->getWorldVolume(DyVol); Pnt3f Min,Max,Center; DyVol.getBounds(Min,Max); DyVol.getCenter(Center); std::string TempText(""); TempText = boost::lexical_cast<std::string>(Min.x()) + ", " +boost::lexical_cast<std::string>(Min.x()) + ", " + boost::lexical_cast<std::string>(Min.x()); _NodeMinValueLabel->setText(TempText); TempText = boost::lexical_cast<std::string>(Max.x()) + ", " +boost::lexical_cast<std::string>(Max.x()) + ", " + boost::lexical_cast<std::string>(Max.x()); _NodeMaxValueLabel->setText(TempText); TempText = boost::lexical_cast<std::string>(Center.x()) + ", " +boost::lexical_cast<std::string>(Center.x()) + ", " + boost::lexical_cast<std::string>(Center.x()); _NodeCenterValueLabel->setText(TempText); _NodeTravMaskValueLabel->setText(boost::lexical_cast<std::string>(_SelectedNode->getTravMask())); //Tri Cound TriCountGraphOpRefPtr TheTriGraphOp = TriCountGraphOp::create(); TheTriGraphOp->traverse(_SelectedNode); _NodeTriCountValueLabel->setText(boost::lexical_cast<std::string>(TheTriGraphOp->getNumTri())); } }
bool Line::intersect(const BoxVolume &box, Real &enter, Real &exit ) const { Pnt3r low; Pnt3r high; box.getBounds(low, high); Real r; Real te; Real tl; Real in = 0.f; Real out = Inf; if(_dir[0] > TypeTraits<Real>::getDefaultEps()) { r = 1.f / _dir[0]; te = (low [0] - _pos[0]) * r; tl = (high[0] - _pos[0]) * r; if(tl < out) out = tl; if(te > in) in = te; } else if(_dir[0] < -TypeTraits<Real>::getDefaultEps()) { r = 1.f / _dir[0]; te = (high[0] - _pos[0]) * r; tl = (low [0] - _pos[0]) * r; if(tl < out) out = tl; if(te > in) in = te; } else if(_pos[0] < low[0] || _pos[0] > high[0]) { return false; } if(_dir[1] > TypeTraits<Real>::getDefaultEps()) { r = 1.f / _dir[1]; te = (low [1] - _pos[1]) * r; tl = (high[1] - _pos[1]) * r; if(tl < out) out = tl; if(te > in) in = te; if(in-out >= TypeTraits<Real>::getDefaultEps()) return false; } else if(_dir[1] < -TypeTraits<Real>::getDefaultEps()) { r = 1.f / _dir[1]; te = (high[1] - _pos[1]) * r; tl = (low [1] - _pos[1]) * r; if(tl < out) out = tl; if(te > in) in = te; if(in-out >= TypeTraits<Real>::getDefaultEps()) return false; } else if(_pos[1] < low[1] || _pos[1] > high[1]) { return false; } if(_dir[2] > TypeTraits<Real>::getDefaultEps()) { r = 1.f / _dir[2]; te = (low [2] - _pos[2]) * r; tl = (high[2] - _pos[2]) * r; if(tl < out) out = tl; if(te > in) in = te; } else if(_dir[2] < -TypeTraits<Real>::getDefaultEps()) { r = 1.f / _dir[2]; te = (high[2] - _pos[2]) * r; tl = (low [2] - _pos[2]) * r; if(tl < out) out = tl; if(te > in) in = te; } else if(_pos[2] < low[2] || _pos[2] > high[2]) { return false; } enter = in; exit = out; // Eps: count flat boxes as intersected // BUGFIXED, was: // return enter-exit < Eps; // This got unstable with bbox check of huge planes // and if compiled as opt lib (at least with my gcc 4.0.2). // However it worked when compiled as dbg lib. // And now something completely different... return in-out < TypeTraits<Real>::getDefaultEps(); // To get you even more confused: It also works if you leave it // as "enter-exit" but declare in/out as Real64. // Now think about it......and if it is not 42, please tell! }