void GradientLayer::drawGradient(Graphics* const TheGraphics, const Pnt2f& Origin, const Vec2f& Size, const Vec2f& UAxis, const Real32& Start, const Real32& End, const Real32& Opacity) const
{
	glPushMatrix();
	Matrix Transformation;
	Transformation.setTransform(Vec3f(Origin.x()+Start*UAxis.x()*Size.x(), Origin.y()+Start*UAxis.y()*Size.x(),0.0f), Quaternion(Vec3f(1.0f,0.0f,0.0f),Vec3f(UAxis.x(), UAxis.y(), 0.0f)), Vec3f(Size.x()*(End-Start), Size.y(),0.0f));
	glMultMatrixf(Transformation.getValues());

	if (osgMin(getMFColors()->size(),getMFStops()->size()) > 1)
	{
		if(getMFColors()->size() != getMFStops()->size())
		{    
			SWARNING << "GradientLayer::drawGradient: The number of colors and the number of stops are not equal." << std::endl;
		}

		UInt32 NumStops = osgMin(getMFColors()->size(),getMFStops()->size());
		Real32 CurentRelaviteStop= 0.0f;
			
		for(UInt32 i(0) ; i<NumStops-1 ; ++i)
		{
			TheGraphics->drawQuad(Pnt2f(getStops(i),0.0f),
				                  Pnt2f(getStops(i+1),0.0f),
				                  Pnt2f(getStops(i+1),1.0f),
				                  Pnt2f(getStops(i),1.0f),
								  getColors(i),
								  getColors(i+1),
								  getColors(i+1),
								  getColors(i),
								  Opacity);
		}
	}
	glPopMatrix();
}
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]);
    }
}
Example #4
0
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;
}
Example #5
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 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);
}
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;
}
Example #8
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;
}
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;
    }
}
Example #10
0
void BinaryDataHandler::readBuffer(void)
{
    BuffersT::iterator i;
    UInt32             size,nsize;
    UInt32             readSize;

    // read buffer size
    read(reinterpret_cast<MemoryHandle>(&nsize), sizeof(UInt32));
    size = osgntohl(nsize);

    // read rest of buffer
    for(i = readBufBegin(); size != 0; ++i)
    {
        if(i == readBufEnd())
        {
            SFATAL << "Read buffer is to small. " << size
                   << "bytes missing" << std::endl;

            throw ReadError("Read buffer to small for whole block");
        }

        readSize = osgMin(size, i->getSize());

        read(i->getMem(), readSize);

        i->setDataSize(readSize);

        size -= readSize;
    }

    for(; i != readBufEnd(); ++i)
    {
        i->setDataSize(0);
    }
}
Example #11
0
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 VarianceShadowMapHandler::configureShadowMaps(void)
{
    ShadowStageData::ShadowMapStore &vShadowMaps = _pStageData->getShadowMaps();

    UInt32 uiSHMSize = vShadowMaps.size();

    UInt32 uiMapSize = _pStage-> getMapSize ();

    Real32 maximumAnistropy;

    glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnistropy);

    maximumAnistropy = osgMin(maximumAnistropy, Real32(8.0));

    for(UInt32 i = 0; i < uiSHMSize; ++i)
    {
        if(vShadowMaps[i].uiType == 
                                ShadowStageData::ShadowMapElem::DepthShadowMap)
        {
            vShadowMaps[i].pTexO->setCompareMode(GL_NONE);

            vShadowMaps[i].pTexO->setMinFilter     (GL_LINEAR_MIPMAP_LINEAR);
            vShadowMaps[i].pTexO->setMagFilter     (GL_LINEAR              );

            vShadowMaps[i].pTexO->setInternalFormat(GL_RGBA16F_ARB);
            vShadowMaps[i].pTexO->setExternalFormat(GL_RGBA);

            vShadowMaps[i].pTexO->setAnisotropy    (maximumAnistropy       );

            vShadowMaps[i].pTexO->setWrapS         (GL_REPEAT              );
            vShadowMaps[i].pTexO->setWrapT         (GL_REPEAT              );


            vShadowMaps[i].pImage->set(Image::OSG_RGBA_PF, 
                                uiMapSize, uiMapSize, 1,
                                1, 1, 0.f, 
                                NULL,
                                Image::OSG_FLOAT16_IMAGEDATA,
                                false);

            vShadowMaps[i].pFBO->setColorAttachment(
                vShadowMaps[i].pFBO->getDepthAttachment(), 0);


            RenderBufferUnrecPtr pDepthRB = RenderBuffer::createLocal();
            
            pDepthRB->setInternalFormat(GL_DEPTH_COMPONENT24);

            vShadowMaps[i].pFBO->setDepthAttachment(pDepthRB);

            vShadowMaps[i].pFBO->setSize(uiMapSize, uiMapSize);

            vShadowMaps[i].uiType = 
                                ShadowStageData::ShadowMapElem::ColorShadowMap;

        }
    }

    _bShadowMapsConfigured = true;
}
void PolygonUIDrawObject::getBounds(Pnt2f& TopLeft, Pnt2f& BottomRight) const
{
    if(getMFVerticies()->size() > 0)
    {
        TopLeft = getVerticies(0);
        BottomRight = TopLeft;
        //Determine Top Left And Bottom Right
        for(UInt32 i(0) ; i<getMFVerticies()->size(); ++i)
        {
            TopLeft.setValues( osgMin(TopLeft.x(), getVerticies(i).x()),
                               osgMin(TopLeft.y(), getVerticies(i).y()) );

            BottomRight.setValues(osgMax<Real32>(BottomRight.x(), getVerticies(i).x()),
                                  osgMax<Real32>(BottomRight.y(), getVerticies(i).y()) );
        }
    }
}
Example #15
0
void UIDrawObjectCanvas::getDrawObjectBounds(Pnt2f& TopLeft, Pnt2f& BottomRight) const
{
    if(getMFDrawObjects()->size() > 0)
    {
        Pnt2f TempTopLeft, TempBottomRight;
        getDrawObjects(0)->getBounds(TopLeft, BottomRight);
        //Determine Top Left And Bottom Right
        for(UInt32 i(0) ; i<getMFDrawObjects()->size(); ++i)
        {
            getDrawObjects(i)->getBounds(TempTopLeft, TempBottomRight);
            TopLeft.setValues( osgMin(TopLeft.x(), TempTopLeft.x()),
                               osgMin(TopLeft.y(), TempTopLeft.y()) );

            BottomRight.setValues(osgMax<Real32>(BottomRight.x(), TempBottomRight.x()),
                                  osgMax<Real32>(BottomRight.y(), TempBottomRight.y()) );
        }
    }
}
void DrawEnv::activate(State         *pState,
                       StateOverride *pOverride)
{
    MFUnrecStateChunkPtr::const_iterator cIt  = pState->getMFChunks()->begin();
    MFUnrecStateChunkPtr::const_iterator cEnd = pState->getMFChunks()->end  (); 

    StateOverride::ChunkStoreConstIt     overIt = pOverride->begin();

    Int32                     ind    = 0;
    UInt32                    cind   = osgMin(State::SkipNumChunks, 
                                              pState->getMFChunks()->size32());

    UInt32 const              climit = pState->getCoreGLChunkLimit();

    OSG_SKIP_IT    (cIt, cind);

    for(; (cIt != cEnd) && (cind < climit); ++cIt, ++cind)
    {
        if(overIt != pOverride->end() && overIt->first == cind)
        {
            if(overIt->second->getIgnore() == false)
            {
                overIt->second->activate(this, UInt32(ind));
            }

            ++overIt;
        }
        else
        {
            if(*cIt != NULL && (*cIt)->getIgnore() == false)
            {
                (*cIt)->activate(this, UInt32(ind));
            }
        }

        if(++ind >= StateChunkClass::getNumSlots(cind))
            ind = 0;
    }

    while(overIt != pOverride->end())
    {
        if(overIt->first >= climit)
            break;

        if(overIt->second->getIgnore() == false)
        {
            overIt->second->activate(this,
                                     UInt32(overIt->first -
                                            overIt->second->getClassId()));
        }

        ++overIt;
    }

    ++_uiNumStateChanges;
}
Example #17
0
void BinaryDataHandler::get(void *dst, UInt32 size)
{
    MemoryHandle data = static_cast<MemoryHandle>(dst);

    if(_zeroCopyThreshold && size >= _zeroCopyThreshold)
    {
        if(_zeroCopyThreshold > 1)
        {
            UInt8 tag;

            // we have to read the tag, to force reading of data blocks
            // if the first data field was zero copied
            get(&tag, sizeof(tag));
        }

        // read direct into destination
        read(data, size);
    }
    else
    {
        UInt32 copySize;

        while(size != 0)
        {
            // read new data if nothing left
            if(_currentReadBuffer == readBufEnd())
            {
                pullBuffer();
            }

            // num bytes to copy
            copySize = osgMin((_currentReadBuffer->getDataSize() -
                               _currentReadBufferPos),
                              size);

            // no data in buffer ?
            if(copySize != 0)
            {
                memcpy( data,
                       _currentReadBuffer->getMem() + _currentReadBufferPos,
                        copySize);

                 size                 -= copySize;
                _currentReadBufferPos += copySize;
                 data                 += copySize;
            }

            // skip to next buffer if current buffer is full
            if(_currentReadBufferPos == _currentReadBuffer->getDataSize())
            {
                _currentReadBuffer++;
                _currentReadBufferPos = 0;
            }
        }
    }
}
Example #18
0
void State::changeFrom(DrawEnv *pEnv, State *pOld) const
{
    MFChunksType::const_iterator cIt    = _mfChunks.begin();
    MFChunksType::const_iterator cEnd   = _mfChunks.end  ();
    Int32                        ind    = 0;
    UInt32                       i;
    UInt32                       cind   = osgMin(State::SkipNumChunks,
                                                 _mfChunks.size32()  );
    UInt32 const                 climit = _uiCoreGLChunkLimit;

    OSG_SKIP_IT(cIt, cind);

    for(; (cIt != cEnd) && (cind < climit); ++cIt, ++cind)
    {
        StateChunk *o = pOld->getChunk(cind);
        StateChunk *n = *cIt;

        if(n != NULL && n->getIgnore() == false)
        {
            if(o != NULL && o->getIgnore() == false)
            {
                n->changeFrom(pEnv, o, UInt32(ind));
            }
            else
            {
                n->activate(pEnv, UInt32(ind));
            }
        }
        else if(o != NULL && o->getIgnore() == false)
        {
            o->deactivate(pEnv, UInt32(ind));
        }

        if(++ind >= StateChunkClass::getNumSlots(cind))
            ind = 0;
    }

    if(ind >= StateChunkClass::getNumSlots(cind))
        ind = 0;

    for(i = cind; (i < pOld->getMFChunks()->size()) && (i < climit); ++i)
    {
        StateChunk *o = pOld->getChunk(i);

        if(o != NULL && o->getIgnore() == false)
        {
            o->deactivate(pEnv, UInt32(ind));
        }

        if(++ind >= StateChunkClass::getNumSlots(i))
        {
            ind = 0;
        }
    }
}
Example #19
0
void BinaryDataHandler::put(void const *src, UInt32 size)
{
    UInt8 const *data = static_cast<UInt8 const *>(src);

    if(_zeroCopyThreshold && size >= _zeroCopyThreshold)
    {
        if(_zeroCopyThreshold == 1)
        {
            write(const_cast<MemoryHandle>(data), size);
        }
        else
        {
            UInt8 tag = 1;

            // we have to write a tag, to indicate the membership
            // of this zero copy block to the current data block
            put(&tag, sizeof(tag));

            _zeroCopyBuffers.push_back(
                MemoryBlock(const_cast<MemoryHandle>(data), size, size));
        }
    }
    else
    {
        UInt32 copySize;

        while(size != 0)
        {
            if(_currentWriteBuffer == writeBufEnd())
            {
                pushBuffer();
            }

            copySize = osgMin((_currentWriteBuffer->getSize() -
                               _currentWriteBufferPos),
                              size);

            memcpy(_currentWriteBuffer->getMem() + _currentWriteBufferPos,
                    data,
                    copySize);

             size                  -= copySize;
            _currentWriteBufferPos += copySize;
             data                  += copySize;

            // skip to next buffer if current buffer is full
            if(_currentWriteBufferPos == _currentWriteBuffer->getSize())
            {
                _currentWriteBuffer->setDataSize(_currentWriteBufferPos);
                _currentWriteBuffer++;
                _currentWriteBufferPos = 0;
            }
        }
    }
}
Example #20
0
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;
}
Example #21
0
void DrawEnv::deactivate(State         *pState,
                         StateOverride *pOverride  )
{
    MFUnrecStateChunkPtr::const_iterator cIt  = pState->getMFChunks()->begin();
    MFUnrecStateChunkPtr::const_iterator cEnd = pState->getMFChunks()->end  ();

    StateOverride::ChunkStoreIt          overIt = pOverride->begin();

    Int32                     ind  = 0;
    SizeT                     cind = osgMin(State::SkipNumChunks, 
                                            pState->getMFChunks()->size());

    OSG_SKIP_IT(cIt, cind);

    for(; cIt != cEnd; ++cIt, ++cind)
    {
        if(overIt != pOverride->end() && overIt->first == cind)
        {
            if(overIt->second->getIgnore() == false)
            {
                overIt->second->deactivate(this, UInt32(ind));
            }

            ++overIt;
        }
        else
        {
            if(*cIt != NULL && (*cIt)->getIgnore() == false)
            {
                (*cIt)->deactivate(this, UInt32(ind));
            }
        }

        if(++ind >= StateChunkClass::getNumSlots(cind))
            ind = 0;
    }

    while(overIt !=  pOverride->end())
    {
        if(overIt->second->getIgnore() == false)
        {
            overIt->second->deactivate(this,
                                       UInt32(overIt->first -
                                              overIt->second->getClassId()));
        }

        ++overIt;
    }
}
FieldContainerTransitPtr deepClone(
          OSG::FieldContainer const                        *src,
    const std::vector<const OSG::ReflexiveContainerType *> &shareTypes,
    const std::vector<const OSG::ReflexiveContainerType *> &ignoreTypes,
    const std::vector<OSG::UInt16>                         &shareGroupIds,
    const std::vector<OSG::UInt16>                         &ignoreGroupIds)
{
    if(src == NULL)
        return FieldContainerTransitPtr(NULL);

    const FieldContainerType &fcType  = src->getType();
    FieldContainerTransitPtr  fcClone = fcType.createContainer();

    UInt32 fCount = osgMin(fcType            .getNumFieldDescs(),
                           fcClone->getType().getNumFieldDescs() );

    for(UInt32 i = 1; i <= fCount; ++i)
    {
        const FieldDescriptionBase *fDesc = fcType.getFieldDesc(i);

        if(fDesc->isInternal())
            continue;

        GetFieldHandlePtr  srcField = src    ->getField (i);
        EditFieldHandlePtr dstField = fcClone->editField(i);

        if(dstField == NULL || dstField->isValid() == false || 
           srcField == NULL || srcField->isValid() == false)
        {
            continue;
        }

        if(srcField->isPointerField() == false)
        {
            dstField->copyValues(srcField);
        }
        else
        {
            dstField->cloneValues(srcField, 
                                  shareTypes,    
                                  ignoreTypes,
                                  shareGroupIds, 
                                  ignoreGroupIds);
        }
    }

    return fcClone;
}
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()));
}
void ShaderShadowMapEngine::calcPointLightRange(
    const PointLight *pointL,      Real32  lightThreshold,
          Real32      defaultNear, Real32  defaultFar,
          Real32     &outNear,     Real32 &outFar         )
{
    outNear = defaultNear;
    outFar  = defaultFar;

    Real32 kQ = pointL->getQuadraticAttenuation();
    Real32 kL = pointL->getLinearAttenuation   ();
    Real32 kC = pointL->getConstantAttenuation ();

    if(osgAbs(kQ) > TypeTraits<Real32>::getDefaultEps())
    {
        Real32 det = kL * kL  - 4.f * kQ * (kC - 1.f / lightThreshold);

        if(det >= 0)
        {
            det       = osgSqrt(det);
            Real32 r1 = - kL + det / (2.f * kQ);
            Real32 r2 = - kL - det / (2.f * kQ);

            if(r1 > 0.f && r2 > 0.f)
            {
                outFar = osgMin(r1, r2);
            }
            else if(r1 > 0.f)
            {
                outFar = r1;
            }
            else if(r2 > 0.f)
            {
                outFar = r2;
            }
        }
    }
    else if(osgAbs(kL) > TypeTraits<Real32>::getDefaultEps())
    {
        Real32 r = (1.f / lightThreshold - kC) / kL;

        if(r > 0.f)
        {
            outFar = r;
        }
    }
}
Example #25
0
void State::deactivate(DrawEnv *pEnv) const
{
    MFChunksType::const_iterator cIt    = _mfChunks.begin();
    MFChunksType::const_iterator cEnd   = _mfChunks.end  ();
    Int32                        ind    = 0;
    UInt32                       cind   = osgMin(State::SkipNumChunks,
                                                 _mfChunks.size32()  );
    UInt32 const                 climit = _uiCoreGLChunkLimit;

    OSG_SKIP_IT(cIt, cind);

    for(; (cIt != cEnd) && (cind < climit); ++cIt, ++cind)
    {
        if(*cIt != NULL && (*cIt)->getIgnore() == false)
            (*cIt)->deactivate(pEnv, UInt32(ind));

        if(++ind >= StateChunkClass::getNumSlots(cind))
            ind = 0;
    }
}
Example #26
0
void DrawEnv::update(State         *pState,
                     StateOverride *pOverride)
{
#if 0
    MFUnrecStateChunkPtr::const_iterator cIt  = pState->getMFChunks()->begin();
    MFUnrecStateChunkPtr::const_iterator cEnd = pState->getMFChunks()->end  ();

    StateOverride::ChunkStoreIt          overIt = pOverride->begin();

    Int32                     ind  = 0;
    UInt32                    cind = osgMin(State::SkipNumChunks, 
                                            pState->getMFChunks()->size());
    StateChunk               *c    = NULL;

    OSG_SKIP_IT(cIt, cind);

    for(; cIt != cEnd && cind < State::UpdateBelow; ++cIt, ++cind)
    {
        if(overIt != pOverride->end() && overIt->first == cind)
        {
            c = overIt->second;
            ++overIt;
        }
        else
        {
            c = *cIt;
        }

        if(c != NULL && c->getIgnore() == false)
        {
            c->changeFrom(this, c, UInt32(ind));
        }

        if(++ind >= StateChunkClass::getNumSlots(cind))
            ind = 0;
    }
#endif
}
Example #27
0
void DrawEnv::update(State *pState)
{
#if 0
    MFUnrecStateChunkPtr::const_iterator cIt  = pState->getMFChunks()->begin();
    MFUnrecStateChunkPtr::const_iterator cEnd = pState->getMFChunks()->end  ();

    Int32                     ind  = 0;
    UInt32                    cind = osgMin(State::SkipNumChunks, 
                                            pState->getMFChunks()->size());

    OSG_SKIP_IT(cIt, cind);

    for(; cIt != cEnd && cind < State::UpdateBelow; ++cIt, ++cind)
    {
        if(*cIt != NULL && (*cIt)->getIgnore() == false)
        {
            (*cIt)->changeFrom(this, *cIt, UInt32(ind));
        }

        if(++ind >= StateChunkClass::getNumSlots(cind))
            ind = 0;
    }
#endif
}
void VarianceShadowMapHandler::initShadowMaps(void)
{
    ShadowStageData::ShadowMapStore &vShadowMaps = _pStageData->getShadowMaps();

    const ShadowStageData::LightStore  &vLights  = _pStageData->getLights();


    if(vLights.size() < vShadowMaps.size())
    {
        vShadowMaps.resize(vLights.size());
    }
    else
    {
        Real32 maximumAnistropy;

        glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnistropy);

        maximumAnistropy = osgMin(maximumAnistropy, Real32(8.0));


        UInt32 uiLSize   =  vLights.size();
        UInt32 uiMapSize = _pStage-> getMapSize ();

        if(vShadowMaps.size() == 0) 
        {
            _uiMapSize = uiMapSize;
        }

        for(UInt32 i = vShadowMaps.size(); i < uiLSize; ++i)
        {
            ShadowStageData::ShadowMapElem tmpElem;

            tmpElem.uiType = ShadowStageData::ShadowMapElem::ColorShadowMap;

            tmpElem.pImage = Image            ::createLocal();
            tmpElem.pTexO  = TextureObjChunk  ::createLocal();
            tmpElem.pTexE  = TextureEnvChunk  ::createLocal();
            tmpElem.pFBO   = FrameBufferObject::createLocal();

            tmpElem.pImage->set(Image::OSG_RGBA_PF, 
                                uiMapSize, uiMapSize, 1,
                                1, 1, 0.f, 
                                NULL,
                                Image::OSG_FLOAT16_IMAGEDATA,
                                false);

            TextureBufferUnrecPtr pDepthTex = TextureBuffer::createLocal();

            pDepthTex->setTexture(tmpElem.pTexO);

            tmpElem.pFBO ->setColorAttachment(pDepthTex, 0);

            tmpElem.pTexO->setImage(tmpElem.pImage);

            tmpElem.pTexO->setInternalFormat(GL_RGBA16F_ARB);
            tmpElem.pTexO->setExternalFormat(GL_RGBA);

            tmpElem.pTexO->setMinFilter     (GL_LINEAR_MIPMAP_LINEAR);
            tmpElem.pTexO->setMagFilter     (GL_LINEAR              );

            tmpElem.pTexO->setAnisotropy    (maximumAnistropy       );

            tmpElem.pTexO->setWrapS         (GL_REPEAT              );
            tmpElem.pTexO->setWrapT         (GL_REPEAT              );

            tmpElem.pTexO->setTarget(GL_TEXTURE_2D);



            RenderBufferUnrecPtr pDepthRB = RenderBuffer::create();
            
            pDepthRB->setInternalFormat(GL_DEPTH_COMPONENT24);

            tmpElem.pFBO->setDepthAttachment(pDepthRB);

            tmpElem.pFBO->setSize(uiMapSize, uiMapSize);


            vShadowMaps.push_back(tmpElem);
        }
    }
}
Example #29
0
void GridLayout::updateLayout(const MFUnrecChildComponentPtr* Components, const Component* ParentComponent) const
{
	Pnt2f borderTopLeft, borderBottomRight;
	dynamic_cast<const ComponentContainer*>(ParentComponent)->getInsideInsetsBounds(borderTopLeft, borderBottomRight);
	Vec2f borderSize(borderBottomRight-borderTopLeft);

	Real32 Xpos = 0;
	Real32 Ypos = 0;
	Real32 maxSizeX = (borderSize.x()-getHorizontalGap()*(getColumns()-1)) / static_cast<Real32>(getColumns());
	Real32 maxSizeY = 0.0f;//(borderSize.y()-getVerticalGap()*getRows()) / static_cast<Real32>(getRows());
	Int32 numComp = Components->size();
	Real32 buttonXSize, buttonYSize;

	//set the size to the perfered sizes
	for(UInt16 i = 0; i<Components->size(); i++)
    {
		if ((*Components)[i] != NULL) 
		{
			if((*Components)[i]->getPreferredSize().x()>maxSizeX)
				maxSizeX = (*Components)[i]->getPreferredSize().x();
			if((*Components)[i]->getPreferredSize().y()>maxSizeY)
				maxSizeY = (*Components)[i]->getPreferredSize().y();
		}
	}
	//set the  size of the button
	for(UInt16 i = 0; i < Components->size(); i++)
    {
		if ((*Components)[i] != NULL) 
		{
			if(maxSizeX < (*Components)[i]->getMaxSize().x())
            {
				buttonXSize = maxSizeX;
            }
			else
				buttonXSize = (*Components)[i]->getMaxSize().x();
			if(maxSizeY<(*Components)[i]->getMaxSize().y())
            {
				buttonYSize = maxSizeY;
            }
			else
            {
				buttonYSize = (*Components)[i]->getMaxSize().y();
            }
            
            if((*Components)[i]->getSize() != Vec2f(buttonXSize, buttonYSize))
            {
			   (*Components)[i]->setSize(Vec2f(buttonXSize, buttonYSize));
            }
		}
	}


	//position each component
	for(UInt16 i = 0; i < osgMin(getRows(), numComp/getColumns()); i++)
    {
		if ((*Components)[i] != NULL) 
		{
            Pnt2f Pos;
			for(UInt16 j = 0; j < osgMin(getColumns(),numComp - i*getColumns()) ; j++)
            {
                Pos = borderTopLeft + Vec2f(Xpos, Ypos);
                if((*Components)[i*getColumns()+j]->getPosition() != Pos)
                {
                    (*Components)[i*getColumns()+j]->setPosition(Pos);
                }
				Xpos = Xpos + (maxSizeX+getHorizontalGap());
			}
			Xpos = 0;
			Ypos += maxSizeY+getVerticalGap();
		}
	}
}
void Graphics3DExtrude::drawQuad(const Pnt2f& p1, const Pnt2f& p2, const Pnt2f& p3, const Pnt2f& p4, 
						const Color4f& c1, const Color4f& c2, const Color4f& c3, const Color4f& c4,
						const Real32& Opacity) const
{
	Real32 MinAlpha( osgMin(osgMin(c1.alpha(), c2.alpha()), osgMin(c3.alpha(), c4.alpha())) * Opacity * getOpacity());
	if(MinAlpha < 1.0)
	{
		//Setup the Blending equations properly
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_BLEND);
	}
	
	glBegin(GL_QUADS);

	   
	   //Front
	   glNormal3f(0.0,0.0,1.0);
	   glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() );
	   glVertex3f(p1.x(), p1.y(), 0.0);
	   glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() );
	   glVertex3f(p4.x(), p4.y(), 0.0);
	   glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() );
	   glVertex3f(p3.x(), p3.y(), 0.0);
	   glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() );
	   glVertex3f(p2.x(), p2.y(), 0.0);

	   //Back
	   glNormal3f(0.0,0.0,-1.0);
	   glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() );
	   glVertex3f(p1.x(), p1.y(), getExtrudeLength());
	   glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() );
	   glVertex3f(p2.x(), p2.y(), getExtrudeLength());
	   glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() );
	   glVertex3f(p3.x(), p3.y(), getExtrudeLength());
	   glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() );
	   glVertex3f(p4.x(), p4.y(), getExtrudeLength());
	   
	   //Top
	   glNormal3f(0.0,-1.0,0.0);
	   glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() );
	   glVertex3f(p1.x(), p1.y(), 0.0);
	   glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() );
	   glVertex3f(p2.x(), p2.y(), 0.0);
	   glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() );
	   glVertex3f(p2.x(), p2.y(), getExtrudeLength());
	   glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() );
	   glVertex3f(p1.x(), p1.y(), getExtrudeLength());

	   //Bottom
	   glNormal3f(0.0,1.0,0.0);
	   glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() );
	   glVertex3f(p3.x(), p3.y(), 0.0);
	   glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() );
	   glVertex3f(p4.x(), p4.y(), 0.0);
	   glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() );
	   glVertex3f(p4.x(), p4.y(), getExtrudeLength());
	   glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() );
	   glVertex3f(p3.x(), p3.y(), getExtrudeLength());
	   
	   //Right
	   glNormal3f(1.0,0.0,0.0);
	   glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() );
	   glVertex3f(p2.x(), p2.y(), 0.0);
	   glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() );
	   glVertex3f(p3.x(), p3.y(), 0.0);
	   glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() );
	   glVertex3f(p3.x(), p3.y(), getExtrudeLength());
	   glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() );
	   glVertex3f(p2.x(), p2.y(), getExtrudeLength());

	   //Left
	   glNormal3f(-1.0,0.0,0.0);
	   glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() );
	   glVertex3f(p1.x(), p1.y(), 0.0);
	   glVertex3f(p1.x(), p1.y(), getExtrudeLength());
	   glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() );
	   glVertex3f(p4.x(), p4.y(), getExtrudeLength());
	   glVertex3f(p4.x(), p4.y(), 0.0);
	glEnd();

	if(MinAlpha < 1.0)
	{
		glDisable(GL_BLEND);
	}
}