virtual void keyPressed(const KeyEventUnrecPtr e) { if(e->getKey() == KeyEvent::KEY_Q && e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND) { TutorialWindow->closeWindow(); } switch(e->getKey()) { case KeyEvent::KEY_SPACE: TheAnimationGroup->pause(!TheAnimationGroup->isPaused()); break; case KeyEvent::KEY_ENTER: TheAnimationGroup->attachUpdateProducer(TutorialWindow->editEventProducer()); TheAnimationGroup->start(); break; case KeyEvent::KEY_MINUS: TheAnimationGroup->setScale(osgMax(TheAnimationGroup->getScale()-0.1f, 0.0f)); break; case KeyEvent::KEY_PLUS: case KeyEvent::KEY_EQUALS: TheAnimationGroup->setScale(osgMax(TheAnimationGroup->getScale()+0.1f, 0.0f)); break; } }
void UIViewport::updateViewComponentSize(void) { Pnt2f InsetsTopLeft, InsetsBottomRight; getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); Vec2f Size(getCorrectedViewSize()); if(getViewComponent()->getScrollableTracksViewportHeight()) { Size[1] = (InsetsBottomRight - InsetsTopLeft).y(); } if(getViewComponent()->getScrollableHeightMinTracksViewport()) { Size[1] = osgMax(Size[1],(InsetsBottomRight - InsetsTopLeft).y()); } if(getViewComponent()->getScrollableTracksViewportWidth()) { Size[0] = (InsetsBottomRight - InsetsTopLeft).x(); } if(getViewComponent()->getScrollableWidthMinTracksViewport()) { Size[0] = osgMax(Size[0],(InsetsBottomRight - InsetsTopLeft).x()); } getViewComponent()->setSize(Size); }
// The SimpleSceneManager to manage simple applications void keyPressed(KeyEventDetails* const details, AnimationGroup* const TheAnimationGroup, WindowEventProducer* const TutorialWindow) { if(details->getKey() == KeyEventDetails::KEY_Q && details->getModifiers() & KeyEventDetails::KEY_MODIFIER_COMMAND) { TutorialWindow->closeWindow(); } switch(details->getKey()) { case KeyEventDetails::KEY_SPACE: TheAnimationGroup->pause(!TheAnimationGroup->isPaused()); break; case KeyEventDetails::KEY_ENTER: TheAnimationGroup->attachUpdateProducer(TutorialWindow); TheAnimationGroup->start(); break; case KeyEventDetails::KEY_MINUS: TheAnimationGroup->setScale(osgMax(TheAnimationGroup->getScale()-0.1f, 0.0f)); break; case KeyEventDetails::KEY_PLUS: case KeyEventDetails::KEY_EQUALS: TheAnimationGroup->setScale(osgMax(TheAnimationGroup->getScale()+0.1f, 0.0f)); break; } }
Vec3f calcMinGeometryBounds(GeometryUnrecPtr geo) { if(geo == NULL || geo->getPositions() == NULL || geo->getPositions()->size() == 0) { return Vec3f(); } GeoVectorProperty* Positions(geo->getPositions()); Pnt3f Min(Positions->getValue<Pnt3f>(0)), Max(Positions->getValue<Pnt3f>(0)); for(UInt32 i(1) ; i<Positions->size(); ++i) { Min[0] = osgMin(Min[0], Positions->getValue<Pnt3f>(i)[0]); Min[1] = osgMin(Min[1], Positions->getValue<Pnt3f>(i)[1]); Min[2] = osgMin(Min[2], Positions->getValue<Pnt3f>(i)[2]); Max[0] = osgMax(Max[0], Positions->getValue<Pnt3f>(i)[0]); Max[1] = osgMax(Max[1], Positions->getValue<Pnt3f>(i)[1]); Max[2] = osgMax(Max[2], Positions->getValue<Pnt3f>(i)[2]); } return Max-Min; }
/*! Computes the \a minPnt and \a maxPnt of an axis aligned bounding box containing this volume. */ void FrustumVolume::getBounds(Pnt3f &minPnt, Pnt3f &maxPnt ) const { Pnt3f corners[8]; this->getCorners(corners[0], corners[1], corners[2], corners[3], corners[4], corners[5], corners[6], corners[7] ); minPnt[0] = TypeTraits<Pnt3f::ValueType>::getMax(); minPnt[1] = TypeTraits<Pnt3f::ValueType>::getMax(); minPnt[2] = TypeTraits<Pnt3f::ValueType>::getMax(); maxPnt[0] = TypeTraits<Pnt3f::ValueType>::getMin(); maxPnt[1] = TypeTraits<Pnt3f::ValueType>::getMin(); maxPnt[2] = TypeTraits<Pnt3f::ValueType>::getMin(); for(UInt32 i = 0; i < 8; ++i) { minPnt[0] = osgMin(minPnt[0], corners[i][0]); minPnt[1] = osgMin(minPnt[1], corners[i][1]); minPnt[2] = osgMin(minPnt[2], corners[i][2]); maxPnt[0] = osgMax(maxPnt[0], corners[i][0]); maxPnt[1] = osgMax(maxPnt[1], corners[i][1]); maxPnt[2] = osgMax(maxPnt[2], corners[i][2]); } }
OSG_BASE_DLLMAPPING void extend(SphereVolume &srcVol, const CylinderVolume &vol) { Pnt3f min, max, min1, max1, min2, max2, c; 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); vol.getCenter(c); r = (min - c).length(); srcVol.setValue(c, 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())); c = Pnt3f((min2.x() + max2.x()) * 0.5f, (min2.y() + max2.y()) * 0.5f, (min2.z() + max2.z()) * 0.5f); r = ((max2 - min2).length()) * 0.5f; srcVol.setValue(c, r); return; }
Vec2f Button::getContentRequestedSize(void) const { Vec2f Result(0.0f,0.0f); UIDrawObjectCanvasRefPtr DrawnDrawObject = getDrawnDrawObject(); if(getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_LEFT_OF_TEXT || getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT) { if(getFont() != NULL) { Pnt2f TextTopLeft(0.0f,0.0f), TextBottomRight(0.0f,0.0f); getFont()->getBounds(getText(), TextTopLeft, TextBottomRight); Result[0] += (TextBottomRight - TextTopLeft).x(); Result[1] = osgMax(Result[1],(TextBottomRight - TextTopLeft).y()); } if(DrawnDrawObject != NULL) { Pnt2f DrawObjectTopLeft, DrawObjectBottomRight; DrawnDrawObject->getDrawObjectBounds(DrawObjectTopLeft, DrawObjectBottomRight); Result[0] += (DrawObjectBottomRight - DrawObjectTopLeft).x(); Result[1] = osgMax(Result[1],(DrawObjectBottomRight - DrawObjectTopLeft).y()); } if(getFont() != NULL && DrawnDrawObject != NULL) { Result[0] += getDrawObjectToTextPadding(); } } else if(getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_ABOVE_TEXT || getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_BELOW_TEXT) { if(getFont() != NULL) { Pnt2f TextTopLeft(0.0f,0.0f), TextBottomRight(0.0f,0.0f); getFont()->getBounds(getText(), TextTopLeft, TextBottomRight); Result[1] += (TextBottomRight - TextTopLeft).y(); Result[0] = osgMax(Result[0],(TextBottomRight - TextTopLeft).x()); } if(DrawnDrawObject != NULL) { Pnt2f DrawObjectTopLeft, DrawObjectBottomRight; DrawnDrawObject->getDrawObjectBounds(DrawObjectTopLeft, DrawObjectBottomRight); Result[1] += (DrawObjectBottomRight - DrawObjectTopLeft).y(); Result[0] = osgMax(Result[0],(DrawObjectBottomRight - DrawObjectTopLeft).x()); } if(getFont() != NULL && DrawnDrawObject != NULL) { Result[1] += getDrawObjectToTextPadding(); } } return Result + Vec2f(2.0,2.0); }
OSG_BASE_DLLMAPPING void extend(CylinderVolume &srcVol, const CylinderVolume &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 { srcVol = vol; 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 SpaceNavigatorSSM::showAll(void) { if(_root == NullFC) return; _root->updateVolume(); Vec3f min,max; _root->getVolume().getBounds( min, max ); Vec3f d = max - min; if(d.length() < Eps) // Nothing loaded? Use a unity box { min.setValues(-1.f,-1.f,-1.f); max.setValues( 1.f, 1.f, 1.f); d = max - min; } SpaceNavigatorOSGClient::Instance()->setTranslationFactorToSceneSize(_root); bool zUpAxis = SpaceNavigatorOSGClient::Instance()->getZUpAxis(); Real32 dist; if(zUpAxis) dist = osgMax(d[0],d[2]) / (2 * osgtan(_camera->getFov() / 2.f)); else dist = osgMax(d[0],d[1]) / (2 * osgtan(_camera->getFov() / 2.f)); // get the correct up axis Vec3f up = getNavigator()->getUp(); Pnt3f at; if(zUpAxis) at = Pnt3f((min[0] + max[0]) * .5f,(min[2] + max[2]) * .5f,(min[1] + max[1]) * .5f); else at = Pnt3f((min[0] + max[0]) * .5f,(min[1] + max[1]) * .5f,(min[2] + max[2]) * .5f); Pnt3f from=at; if(zUpAxis) from[1]+=(dist+fabs(max[1]-min[1])*0.5f); else from[2]+=(dist+fabs(max[2]-min[2])*0.5f); _navigator.set(from,at,up); // set the camera to go from 1% of the object to twice its size Real32 diag = osgMax(osgMax(d[0], d[1]), d[2]); beginEditCP(_camera); _camera->setNear (diag / 100.f); _camera->setFar (10 * diag); endEditCP(_camera); }
void GrabForeground::draw(DrawEnv *, Viewport *port) { if(getActive() == false) return; Image *i = getImage(); if(i == NULL) // No image, no grab. return; Int32 w = osgMax(2, port->getPixelWidth ()); Int32 h = osgMax(2, port->getPixelHeight()); // If image is smaller than 2x2, resize it to vp size // the 2x2 is because you can't create 0x0 images // If autoResize then update img size if vp changed if( (i->getWidth() <= 1 || i->getHeight() <= 1) || (getAutoResize() && (w != i->getWidth() || h != i->getHeight())) ) { i->set(i->getPixelFormat(), w, h); } bool storeChanged = false; if ( !getAutoResize() ) { w = osgMin(Int32(i->getWidth ()), port->getPixelWidth()); h = osgMin(Int32(i->getHeight()), port->getPixelHeight()); if(Int32(i->getWidth()) != port->getPixelWidth()) { glPixelStorei(GL_PACK_ROW_LENGTH, i->getWidth()); storeChanged = true; } } glReadPixels(port->getPixelLeft(), port->getPixelBottom(), w, h, i->getPixelFormat(), i->getDataType(), i->editData()); if(storeChanged) glPixelStorei(GL_PACK_ROW_LENGTH, 0); }
OSG_BASE_DLLMAPPING void extend(BoxVolume &srcVol, const CylinderVolume &vol) { Pnt3f min, max; 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); srcVol.setBounds(min, max); return; } } else if(vol.isEmpty()) { return; } vol.getBounds(min, max); srcVol.setBounds(osgMin(min.x(), srcVol.getMin().x()), osgMin(min.y(), srcVol.getMin().y()), osgMin(min.z(), srcVol.getMin().z()), osgMax(max.x(), srcVol.getMax().x()), osgMax(max.y(), srcVol.getMax().y()), osgMax(max.z(), srcVol.getMax().z())); if(vol.isInfinite()) srcVol.setInfinite(true); return; }
Vec2f BorderLayout::layoutSize(const MFUnrecChildComponentPtr* Components, const Component* ParentComponent, SizeType TheSizeType) const { Vec2f Result(0.0,0.0); Vec2f WestSize(0.0,0.0), EastSize(0.0,0.0), NorthSize(0.0,0.0), SouthSize(0.0,0.0), CenterSize(0.0,0.0); for(UInt32 i(0) ; i<Components->size() ; ++i) { switch(dynamic_cast<BorderLayoutConstraints*>((*Components)[i]->getConstraints())->getRegion()) { case BorderLayoutConstraints::BORDER_WEST: WestSize = getComponentSize((*Components)[i],TheSizeType); break; case BorderLayoutConstraints::BORDER_EAST: EastSize = getComponentSize((*Components)[i],TheSizeType); break; case BorderLayoutConstraints::BORDER_NORTH: NorthSize = getComponentSize((*Components)[i],TheSizeType); break; case BorderLayoutConstraints::BORDER_SOUTH: SouthSize = getComponentSize((*Components)[i],TheSizeType); break; case BorderLayoutConstraints::BORDER_CENTER: CenterSize = getComponentSize((*Components)[i],TheSizeType); break; } } switch(TheSizeType) { case MAX_SIZE: Result[0] = osgMin(osgMin(EastSize.x() + CenterSize.x() + WestSize.x(),NorthSize.x()),SouthSize.x()); Result[1] = osgMin(osgMin(EastSize.y(), CenterSize.y()), WestSize.y()) + NorthSize.y() + SouthSize.y(); break; case MIN_SIZE: case PREFERRED_SIZE: case REQUESTED_SIZE: default: Result[0] = osgMax(osgMax(EastSize.x() + CenterSize.x() + WestSize.x(),NorthSize.x()),SouthSize.x()); Result[1] = osgMax(osgMax(EastSize.y(), CenterSize.y()), WestSize.y()) + NorthSize.y() + SouthSize.y(); break; } return Result; }
void FixedHeightLayoutManager::calculatePreferredSize(void) { if(getParentTextDomArea()->getWrapStyleWord()) { Pnt2f topLeft,bottomRight; getParentTextDomArea()->getClipBounds(topLeft,bottomRight); if(topLeft.x() == 0 && topLeft.y() == 0) { _preferredWidth = getParentTextDomArea()->getPreferredSize().x(); } else { _preferredWidth = bottomRight.x()-topLeft.x(); } _preferredHeight = linesToElements.size() * heightOfLine; } else { if(getParentTextDomArea()->getDocumentModel()) { ElementRefPtr defaultRoot=getParentTextDomArea()->getDocumentModel()->getDefaultRootElement(); PlainDocumentBranchElementRefPtr rootElement = dynamic_pointer_cast<PlainDocumentBranchElement>(defaultRoot); _preferredWidth = osgMax(getParentTextDomArea()->getSize().x(),calculateWidthOfLongestLine(rootElement)); _preferredHeight = rootElement->getElementCount() * heightOfLine; } else { _preferredWidth = getParentTextDomArea()->getSize().x(); _preferredHeight = getParentTextDomArea()->getSize().y(); } } }
void AbstractWindow::updateContainerLayout(void) { if(getParentContainer() != NULL) { Inherited::updateContainerLayout(); } else if(getSize() != getPreferredSize()) { Vec2f Size(osgMax(osgMin(getPreferredSize().x(), getMaxSize().x()), getMinSize().x()), osgMax(osgMin(getPreferredSize().y(), getMaxSize().y()), getMinSize().y())); if(getSize() != Size) { setSize(Size); } } }
virtual void keyPressed(const KeyEventUnrecPtr e) { if(e->getKey()== KeyEvent::KEY_1) // Use the Point Drawer { ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer); } if(e->getKey()== KeyEvent::KEY_2)//Use the Line Drawer for 2 { ParticleNodeCore->setDrawer(ExampleLineParticleSystemDrawer); } if(e->getKey()== KeyEvent::KEY_3)// increase velocity conservation { ExampleConserveVelocityAffector->setConserve(osgMax(0.0f,ExampleConserveVelocityAffector->getConserve() - 0.03f)); } if(e->getKey()== KeyEvent::KEY_4) // decrease velocity conservation { ExampleConserveVelocityAffector->setConserve(osgMin(1.0f,ExampleConserveVelocityAffector->getConserve() + 0.03f)); } if(e->getKey() == KeyEvent::KEY_Q && e->getModifiers() & KeyEvent::KEY_MODIFIER_CONTROL) { TutorialWindow->closeWindow(); } }
void NumberSet::collapseIntersectingRanges(void) { if(_List.size() < 2) { //No collapsing possible return; } RangeListTypeItor ListItor,NextListItor; ListItor = _List.begin(); NextListItor = ++_List.begin(); while (NextListItor != _List.end()) { if(ListItor->getMax() >= NextListItor->getMin()-1) { NextListItor->setMin(osgMin(ListItor->getMin(), NextListItor->getMin())); NextListItor->setMax(osgMax(ListItor->getMax(), NextListItor->getMax())); _List.erase(ListItor); } else if(ListItor->isEmpty()) { _List.erase(ListItor); } ListItor = NextListItor; ++NextListItor; } }
UInt32 ParticleBSPTree::doBuild(std::vector<Int32>::iterator begin, std::vector<Int32>::iterator end, UInt32 nodeindex, GeoVectorProperty *pos) { // reached a leaf? if(begin + 1 == end) { _tree[nodeindex].setValue(*begin); return nodeindex + 1; } // find the bounding volume of the group BoxVolume b; Pnt3f p; b.setEmpty(); for(std::vector<Int32>::iterator i = begin; i != end; ++i) { pos->getValue(p,*i); b.extendBy(p); } // find the axis with the longest extension Vec3f d = b.getMax() - b.getMin(); UInt8 axis = ParticleBSPNode::X; Real32 maxval = d[0]; if(d[1] > maxval) { axis = ParticleBSPNode::Y; maxval = d[1]; } if(d[2] > maxval) { axis = ParticleBSPNode::Z; maxval = d[2]; } // sort in that axis ParticleCompare comp(pos, axis); std::sort(begin,end,comp); // find median value std::vector<Int32>::iterator mid = begin + (end - begin) / 2; Pnt3f p2; pos->getValue(p ,*mid); pos->getValue(p2,(*mid)-1); _tree[nodeindex].setSplit(axis, (p[axis] + p2[axis]) / 2.f); return osgMax( doBuild(begin, mid, nodeindex * 2 , pos), doBuild( mid, end, nodeindex * 2 + 1, pos) ); }
void Log::doLog(const Char8 * format, ...) { va_list args; va_start( args, format ); #if defined(OSG_HAS_VSNPRINTF) && !defined(__sgi) int count; if(_buffer == NULL) { _bufferSize = 8; _buffer = new Char8[_bufferSize]; } // on windows it returns -1 if the output // was truncated due to the buffer size limit. // on irix this returns always buffer_size-1 ???? count = vsnprintf(_buffer, _bufferSize, format, args); while(count >= _bufferSize || count == -1) { _bufferSize = osgMax(_bufferSize * 2, count + 1); if(_buffer != NULL) delete [] _buffer; _buffer = new Char8[_bufferSize]; va_start(args, format); count = vsnprintf(_buffer, _bufferSize, format, args); } #else if(_bufferSize < 8192) { _bufferSize = 8192; if(_buffer != NULL) delete [] _buffer; _buffer = new Char8[_bufferSize]; } vsprintf(_buffer, format, args); #endif // *this << buffer; // *this << std::flush; // Work around VC71. Patch by Chad Austin. std::ostream& os = *this; os << _buffer; os << std::flush; va_end(args); }
OSG_BASE_DLLMAPPING void extend(BoxVolume &srcVol, const BoxVolume &vol) { if( (!srcVol.isValid () && !srcVol.isEmpty()) || srcVol.isInfinite() || srcVol.isStatic () ) { return; } if(!vol.isValid()) return; if(srcVol.isEmpty()) { if(vol.isEmpty()) { return; } else { srcVol = vol; return; } } else if(vol.isEmpty()) { return; } srcVol.setBounds(osgMin(vol.getMin().x(), srcVol.getMin().x()), osgMin(vol.getMin().y(), srcVol.getMin().y()), osgMin(vol.getMin().z(), srcVol.getMin().z()), osgMax(vol.getMax().x(), srcVol.getMax().x()), osgMax(vol.getMax().y(), srcVol.getMax().y()), osgMax(vol.getMax().z(), srcVol.getMax().z())); if(vol.isInfinite()) srcVol.setInfinite(true); return; }
void showAll(PerspectiveCameraRefPtr TheCamera, NodeRefPtr Scene, Vec3f Up) { //Make sure the volume is up to date for the Scene Scene->updateVolume(); //Get the Minimum and Maximum bounds of the volume Vec3f min,max; Scene->getVolume().getBounds( min, max ); Vec3f d = max - min; if(d.length() < Eps) //The volume is 0 { //Default to a 1x1x1 box volume min.setValues(-0.5f,-0.5f,-0.5f); max.setValues( 0.5f, 0.5f, 0.5f); d = max - min; } Real32 dist = osgMax(d[0],d[1]) / (2 * osgTan(TheCamera->getFov() / 2.f)); Pnt3f at((min[0] + max[0]) * .5f,(min[1] + max[1]) * .5f,(min[2] + max[2]) * .5f); Pnt3f from=at; from[2]+=(dist+fabs(max[2]-min[2])*0.5f); //If the Camera Beacon is a node with a transfrom core if(TheCamera->getBeacon() != NULL && TheCamera->getBeacon()->getCore() != NULL && TheCamera->getBeacon()->getCore()->getType().isDerivedFrom(Transform::getClassType())) { Matrix m; if(!MatrixLookAt(m, from, at, Up)) { dynamic_cast<Transform*>(TheCamera->getBeacon()->getCore())->setMatrix(m); } } //Set the camera to go from 1% of the object to 10 times its size Real32 diag = osgMax(osgMax(d[0], d[1]), d[2]); TheCamera->setNear (diag / 100.f); TheCamera->setFar (10 * diag); }
////////////////////////////////////////////////////////////////////////// //! build a ship ////////////////////////////////////////////////////////////////////////// PhysicsBodyRefPtr buildShip(Vec3f Dimensions, Pnt3f Position) { Real32 Radius(osgMax(Dimensions.x(), Dimensions.y())/2.0f); Real32 Length(Dimensions.z() - 2.0f*Radius); Matrix m; //create OpenSG mesh GeometryRefPtr box; NodeRefPtr boxNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1); box = dynamic_cast<Geometry*>(boxNode->getCore()); SimpleMaterialRefPtr box_mat = SimpleMaterial::create(); box_mat->setAmbient(Color3f(0.0,0.0,0.0)); box_mat->setDiffuse(Color3f(1.0,1.0 ,0.0)); box->setMaterial(box_mat); TransformRefPtr boxTrans; NodeRefPtr boxTransNode = makeCoredNode<Transform>(&boxTrans); m.setIdentity(); m.setTranslate(Position - Vec3f(0.0f,0.0f,0.5f*Dimensions.z())); boxTrans->setMatrix(m); for(UInt32 i(0) ; i<box->getPositions()->size() ; ++i) { box->getPositions()->setValue<Pnt3f>(box->getPositions()->getValue<Pnt3f>(i) + Vec3f(0.0,0.0,Dimensions.z()/2.0f),i); } //create ODE data PhysicsBodyRefPtr CapsuleBody = PhysicsBody::create(physicsWorld); CapsuleBody->setPosition(Vec3f(Position - Vec3f(0.0f,0.0f,0.5f*Dimensions.z()))); CapsuleBody->setLinearDamping(0.01); CapsuleBody->setMaxAngularSpeed(0.0); CapsuleBody->setCapsuleMass(1.0,3,Radius, Length); PhysicsCapsuleGeomRefPtr CapsuleGeom = PhysicsCapsuleGeom::create(); CapsuleGeom->setBody(CapsuleBody); CapsuleGeom->setOffsetPosition(Vec3f(0.0f,0.0f,0.5f*Dimensions.z())); CapsuleGeom->setSpace(hashSpace); CapsuleGeom->setRadius(Radius); CapsuleGeom->setLength(Length); //add attachments boxNode->addAttachment(CapsuleGeom); boxTransNode->addAttachment(CapsuleBody); boxTransNode->addChild(boxNode); //add to SceneGraph spaceGroupNode->addChild(boxTransNode); commitChanges(); return CapsuleBody; }
void TabPanel::calculateMaxTabBorderLengths(Real32& Left, Real32& Right, Real32& Top, Real32& Bottom) const { std::vector<Border*> Borders; Borders.push_back(getTabBorder()); Borders.push_back(getTabActiveBorder()); Borders.push_back(getTabDisabledBorder()); Borders.push_back(getTabRolloverBorder()); Borders.push_back(getTabFocusedBorder()); Left = Right = Top = Bottom = 0.0f; Real32 BorderLeft, BorderRight, BorderTop, BorderBottom; for(UInt32 i(0) ; i<Borders.size() ; ++i) { if(Borders[i] != NULL) { Borders[i]->getInsets(BorderLeft, BorderRight, BorderTop, BorderBottom); Left = osgMax(Left, BorderLeft); Right = osgMax(Right, BorderRight); Top = osgMax(Top, BorderTop); Bottom = osgMax(Bottom, BorderBottom); } } switch(getTabPlacement()) { case PLACEMENT_SOUTH: Top = 0.0f; break; case PLACEMENT_EAST: Left = 0.0f; break; case PLACEMENT_NORTH: Bottom = 0.0f; break; case PLACEMENT_WEST: Right = 0.0f; break; } }
////////////////////////////////////////////////////////////////////////// //! build a character ////////////////////////////////////////////////////////////////////////// PhysicsBodyRefPtr buildCharacter(Vec3f Dimensions, Pnt3f Position, Node* const spaceGroupNode, PhysicsWorld* const physicsWorld, PhysicsHashSpace* const physicsSpace ) { Real32 Radius(osgMax(Dimensions.x(), Dimensions.y())/2.0f); Real32 Length(Dimensions.z() - 2.0f*Radius); Matrix m; //create OpenSG mesh GeometryRefPtr box; //NodeRefPtr characterNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1); NodeRefPtr characterNode = SceneFileHandler::the()->read("Data/Jack.osb"); if(characterNode == NULL) { characterNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1); } box = dynamic_cast<Geometry*>(characterNode->getCore()); TransformRefPtr boxTrans; NodeRefPtr boxTransNode = makeCoredNode<Transform>(&boxTrans); m.setIdentity(); m.setTranslate(Position); boxTrans->setMatrix(m); //create ODE data PhysicsBodyRefPtr boxBody = PhysicsBody::create(physicsWorld); boxBody->setPosition(Vec3f(Position)); //boxBody->setLinearDamping(0.001); //boxBody->setAngularDamping(0.001); boxBody->setMaxAngularSpeed(0.0); boxBody->setCapsuleMass(1.0,3,Radius, Length); PhysicsCapsuleGeomRefPtr CapsuleGeom = PhysicsCapsuleGeom::create(); CapsuleGeom->setBody(boxBody); CapsuleGeom->setSpace(physicsSpace); CapsuleGeom->setRadius(Radius); CapsuleGeom->setLength(Length); //add attachments characterNode->addAttachment(CapsuleGeom); boxTransNode->addAttachment(boxBody); boxTransNode->addChild(characterNode); //add to SceneGraph spaceGroupNode->addChild(boxTransNode); commitChanges(); return boxBody; }
QSize QMFieldView::sizeHint(void) const { QMFieldView *pThis = const_cast<QMFieldView *>(this); QFieldValueLabelBase *pLabel; QSize labelSize( 0, 0); QSize retSize (10, 10); bool bReleaseLabel = false; if(_usedLabels.size() != 0) { pLabel = (*_usedLabels.begin()).second.getLabel(); } else { pLabel = QFieldLabelFactory::the().createLabel(pThis, 0); bReleaseLabel = true; } labelSize = pLabel->sizeHint(); retSize.setHeight( osgMin<UInt32>(5, getFieldPtr()->getSize()) * labelSize.height()); retSize.setWidth( osgMax(retSize.width(), labelSize.width() + _pScrollbar->width())); retSize.setWidth (osgMax(retSize.width(), 10*fontMetrics().width("W"))); retSize.setHeight(osgMax(retSize.height(), fontMetrics().height() )); if(bReleaseLabel) delete pLabel; return retSize; }
Int32 getQuadtreeLeafNodeCount(Int32 iSamplesX, Int32 iSamplesY, Int32 iTileSize) { const Int32 iLeafNodeCountX = getNextPowerOf2(getCeil(Real32(iSamplesX) / Real32(iTileSize))); const Int32 iLeafNodeCountY = getNextPowerOf2(getCeil(Real32(iSamplesY) / Real32(iTileSize))); // todo: output a warning, if leafNodeCountX and leafNodeCountY are to // much apart.. this wastes a lot of memory right now.. return osgMax(iLeafNodeCountX, iLeafNodeCountY); }
void TexturedQuadUIDrawObject::getBounds(Pnt2f& TopLeft, Pnt2f& BottomRight) const { TopLeft.setValues( osgMin(osgMin(osgMin(getPoint1().x(), getPoint2().x()),getPoint3().x()),getPoint4().x()), osgMin(osgMin(osgMin(getPoint1().y(), getPoint2().y()),getPoint3().y()),getPoint4().y())); BottomRight.setValues( osgMax(osgMax(osgMax(getPoint1().x(), getPoint2().x()),getPoint3().x()),getPoint4().x()), osgMax(osgMax(osgMax(getPoint1().y(), getPoint2().y()),getPoint3().y()),getPoint4().y())); }
Real32 BlendedKeyframeAnimator::getLength(void) const { if(getMFKeyframeSequences()->size() > 0 && checkSequencesValidity()) { Real32 MaxLength(0.0f); for(UInt32 i(0) ; i< getMFKeyframeSequences()->size() ; ++i) { MaxLength = osgMax(MaxLength, getKeyframeSequences(i)->getKeys().back()); } return MaxLength; } else { return 0.0f; } }
//String Linear Interpolation //This String interpolation will create a string that is length //Max(From.size(),To.size()), it then interpolates all of the characters at once //using their ASCII values to interpolate on std::string lerpAll( const std::string& From, const std::string& To, const Real32& t) { std::string Result(From); Result.resize(osgMax(From.size(),To.size()), ' '); //Loop through each character for(UInt32 i(0) ; i<Result.size() ; ++i) { if(i<To.size()) { Result[i] +=( (To[i] - Result[i]) * t ); } else { Result[i] +=( (' ' - Result[i]) * t ); } } return Result; }
void CSMSceneParameter::reset(void) { fprintf(stderr, "CSMSceneParameter::reset\n"); if(_sfSceneRef.getValue() != NULL) { Vec3f vVolMin; Vec3f vVolMax; _sfSceneRef.getValue()->editVolume(true).getBounds(vVolMin, vVolMax); std::cerr << "Volume: from " << vVolMin << " to " << vVolMax << std::endl; editSFSceneDiag()->setValue(vVolMax - vVolMin); editSFSceneCenter()->setValue( Pnt3f((vVolMin[0] + vVolMax[0]) * .5, (vVolMin[1] + vVolMax[1]) * .5, (vVolMin[2] + vVolMax[2]) * .5)); Real32 rDist = osgMax(_sfSceneDiag.getValue()[0], _sfSceneDiag.getValue()[1]) * _sfDistScale.getValue(); editSFInitViewPos()->setValue( Pnt3f(_sfSceneCenter.getValue()[0], _sfSceneCenter.getValue()[1], _sfSceneCenter.getValue()[2] + rDist)); std::cerr << "Center: " << getSceneCenter() << std::endl; } }
void Slider::updateLayout(void) { UInt16 MajorAxis, MinorAxis; if(getOrientation() == VERTICAL_ORIENTATION) { MajorAxis = 1; } else { MajorAxis = 0; } MinorAxis = (MajorAxis+1)%2; updateSliderTrack(); //Update the Track if(getDrawTrack() && getTrackDrawObject() != NULL) { Pnt2f BorderTopLeft, BorderBottomRight; getInsideInsetsBounds(BorderTopLeft, BorderBottomRight); Vec2f Size(getTrackDrawObject()->getPreferredSize()); Pnt2f AlignedPosition; Size[MajorAxis] = getTrackLength(); if(getOrientation() == VERTICAL_ORIENTATION) { AlignedPosition = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Size, 0.5, getAlignment()); } else { AlignedPosition = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Size, getAlignment(), 0.5); } getTrackDrawObject()->setPosition(AlignedPosition); getTrackDrawObject()->setSize(Size); } //Update the MinorTickMarks if(getDrawMinorTicks() && getRangeModel() != NULL) { Pnt2f MinorTickTopLeft, MinorTickBottomRight; getDrawObjectBounds(*editMFMinorTickDrawObjects(), MinorTickTopLeft, MinorTickBottomRight); Vec2f Alignment; Real32 MaxLength(0.0); for(UInt32 i(0) ; i<getMFMinorTickDrawObjects()->size() ; ++i) { Pnt2f DrawObjectTopLeft, DrawObjectBottomRight; getMinorTickDrawObjects(i)->getBounds(DrawObjectTopLeft, DrawObjectBottomRight); MaxLength = osgMax(MaxLength, DrawObjectBottomRight.x()-DrawObjectTopLeft.x()); } editMFMinorTickPositions()->clear(); for(UInt32 i(0) ; i< osgAbs<Int32>(getMaximum() - getMinimum())/getMinorTickSpacing() ; ++i) { if( (i * getMinorTickSpacing())%getMajorTickSpacing() != 0 ) { Alignment[MajorAxis] = static_cast<Real32>(i * getMinorTickSpacing())/static_cast<Real32>(getMaximum() - getMinimum()); editMFMinorTickPositions()->push_back( calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), (MinorTickBottomRight - MinorTickTopLeft), Alignment.y(), Alignment.x())); if(getTicksOnRightBottom()) { editMFMinorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] + getTrackDrawObject()->getSize()[MinorAxis] + getTrackToTickOffset(); } else { editMFMinorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] - getTrackToTickOffset() - MaxLength; } } } } //Update the MajorTickMarks if(getDrawMajorTicks() && getRangeModel() != NULL) { Pnt2f MajorTickTopLeft, MajorTickBottomRight; getDrawObjectBounds(*editMFMajorTickDrawObjects(), MajorTickTopLeft, MajorTickBottomRight); Vec2f Alignment; Real32 MaxLength(0.0); for(UInt32 i(0) ; i<getMFMajorTickDrawObjects()->size() ; ++i) { Pnt2f DrawObjectTopLeft, DrawObjectBottomRight; getMajorTickDrawObjects(i)->getBounds(DrawObjectTopLeft, DrawObjectBottomRight); MaxLength = osgMax(MaxLength, DrawObjectBottomRight.x()-DrawObjectTopLeft.x()); } editMFMajorTickPositions()->clear(); for(UInt32 i(0) ; i<= osgAbs<Int32>(getMaximum() - getMinimum())/getMajorTickSpacing() ; ++i) { Alignment[MajorAxis] = static_cast<Real32>(i * getMajorTickSpacing())/static_cast<Real32>(getMaximum() - getMinimum()); editMFMajorTickPositions()->push_back( calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), (MajorTickBottomRight - MajorTickTopLeft), Alignment.y(), Alignment.x())); if(getTicksOnRightBottom()) { editMFMajorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] + getTrackDrawObject()->getSize()[MinorAxis] + getTrackToTickOffset(); } else { editMFMajorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] - getTrackToTickOffset() - MaxLength; } } } //Update the Labels if(getDrawLabels() && getRangeModel() != NULL) { Vec2f Alignment; Pnt2f Pos; FieldContainerMap::const_iterator Itor; for(Itor = getLabelMap().begin() ; Itor != getLabelMap().end() ; ++Itor) { Alignment[MajorAxis] = static_cast<Real32>((*Itor).first - getMinimum())/static_cast<Real32>(getMaximum() - getMinimum()); Pos = calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), dynamic_pointer_cast<Component>((*Itor).second)->getPreferredSize(), Alignment.y(), Alignment.x()); if(getTicksOnRightBottom()) { Pos[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] + getTrackDrawObject()->getSize()[MinorAxis] + getTrackToLabelOffset(); } else { Pos[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] - getTrackToLabelOffset() - dynamic_pointer_cast<Component>((*Itor).second)->getPreferredSize()[MinorAxis]; } dynamic_pointer_cast<Component>((*Itor).second)->setPosition(Pos); dynamic_pointer_cast<Component>((*Itor).second)->setSize(dynamic_pointer_cast<Component>((*Itor).second)->getPreferredSize()); } } }