예제 #1
0
void HUDView::updateRandomNumber(std::string number, osg::Vec2 normalizedPosition)
{
	if (number == "")
	{
		m_randomNumberText->setText("");
		m_backgroundGeode->setNodeMask(0); //invisible
		return;
	}
	

	float offset = m_width / 15;
	float halfextent = m_backgroundGeode->getBound().radius();
	float max_x = m_width - offset - halfextent;
	float max_y = m_height - offset;
	float p_x = clamp(halfextent, max_x, (normalizedPosition.x() * m_width));
	float p_y = clamp(halfextent + offset, max_y, (normalizedPosition.y() * m_height));


	osg::Vec2 position(p_x, p_y);

	m_backgroundGeode->setNodeMask(0xffffffff); //visible

	m_backgroundTransform->setMatrix(osg::Matrix::translate(osg::Vec3(position, 0)));
	m_randomNumberText->setPosition(osg::Vec3(position,0.0));
	m_randomNumberText->setText(number);


}
예제 #2
0
void Selector::operator ()(osg::Vec2 start, osg::Vec2 stop, bool select) {
	if (!this->m_viewer || !this->m_model) return;

	osg::ref_ptr<osgUtil::PolytopeIntersector> picker = new osgUtil::PolytopeIntersector(
			osgUtil::Intersector::CoordinateFrame::WINDOW, start.x(), start.y(), stop.x(), stop.y());
	picker->setDimensionMask(this->m_selection->mask());
	osgUtil::IntersectionVisitor visitor(picker);
	visitor.setTraversalMask(Role::Node::Pickable);
	this->m_viewer->getCamera()->accept(visitor);
	OcclusionTester tester(this->m_model);
	if (this->m_model->kdTree().valid()) {
		osg::Vec3 position(0.0f, 0.0f, 0.0f);
		this->m_viewer->getCamera()->getViewMatrixAsLookAt(position, osg::Vec3(), osg::Vec3());
		tester.setMask(this->m_selection->mask());
		tester.setPosition(algo::Util::toPoint(position));
	}
	if (picker->containsIntersections()) {
		const osgUtil::PolytopeIntersector::Intersections &intersections(picker->getIntersections());
		if (select) {
			for (osgUtil::PolytopeIntersector::Intersections::const_iterator iter = intersections.begin(); iter != intersections.end(); ++iter) {
				if (tester.occluded(iter->primitiveIndex)) continue;
				this->m_selection->indices().insert(iter->primitiveIndex);
			}
		} else {
			for (osgUtil::PolytopeIntersector::Intersections::const_iterator iter = intersections.begin(); iter != intersections.end(); ++iter) {
				if (tester.occluded(iter->primitiveIndex)) continue;
				this->m_selection->indices().remove(iter->primitiveIndex);
			}
		}
	}

	this->m_selection->update();
}
예제 #3
0
파일: Dragger.cpp 프로젝트: joevandyk/osg
bool PointerInfo::projectWindowXYIntoObject(const osg::Vec2& windowCoord, osg::Vec3& nearPoint, osg::Vec3& farPoint) const
{
    nearPoint = osg::Vec3(windowCoord.x(),windowCoord.y(),0.0f)*_inverseMVPW;
    farPoint = osg::Vec3(windowCoord.x(),windowCoord.y(),1.0f)*_inverseMVPW;

    return true;
}
예제 #4
0
    void moveTo(const osg::Vec2& pos)
    {
        completeCurrentPrimitiveSet();

        addVertex( osg::Vec3(pos.x(),pos.y(),0) );

    }
예제 #5
0
osg::Vec2 calcCoordReprojTrans(const osg::Vec3 &vert,const osg::Matrix &trans,const osg::Matrix &viewProj,const osg::Vec2 &size,const osg::Vec4 &ratio){
    osg::Vec4 v(vert.x(),vert.y(),vert.z(),1.0);
    v=v*trans;
    v=v*viewProj;
    v.x() /= v.w();
    v.y() /= v.w();
    v.z() /= v.w();
    v.w() /= v.w();
    //std::cout << "Pre shift " << v << std::endl;
    v.x() /= size.x();;
    v.y() /= size.y();


    v.x() -= (ratio.x()/size.x());
    v.y() -= (ratio.y()/size.y());
    //std::cout << "Post shift " << v << std::endl;


    //  std::cout << "PP shift " << v << std::endl;


    osg::Vec2 tc(v.x(),v.y());
    tc.x() *= ratio.z();
    tc.y() *=ratio.w();
    //tc.x()*=ratio.x();
    //tc.y()*=ratio.y();
    tc.x()/=(ratio.z());
    tc.y()/=(ratio.w());


    return tc;

}
예제 #6
0
double MultitouchPlugin::angleBetween2DVectors(osg::Vec2 v1, osg::Vec2 v2)
{
    // http://codered.sat.qc.ca/redmine/projects/spinframework/repository/revisions/b6245189c19a7c6ba4fdb126940321c41c44e228/raw/src/spin/osgUtil.cpp

    // normalize vectors (note: this must be done alone, not within any vector arithmetic. why?!)
    v1.normalize();
    v2.normalize();

    // Get the dot product of the vectors
    double dotProduct = v1 * v2;

    // for acos, the value has to be between -1.0 and 1.0, but due to numerical imprecisions it sometimes comes outside this range
    if (dotProduct > 1.0)
        dotProduct = 1.0;
    if (dotProduct < -1.0)
        dotProduct = -1.0;

    // Get the angle in radians between the 2 vectors (should this be -acos ? ie, negative?)
    double angle = acos(dotProduct);

    // Here we make sure that the angle is not a -1.#IND0000000 number, which means indefinite
    if (isnan(angle)) //__isnand(x)
        return 0;

    // Return the angle in radians
    return (angle);
}
예제 #7
0
osg::Vec2 CityModel::pixelToWorld(osg::Vec2 pixel)
{
	osg::Vec2 levelSize = pairToVec2(getLevelSize());
	osg::Vec2 picSize = osg::Vec2(m_collisionImage.width(), m_collisionImage.height());
	double x = ((pixel.x() / picSize.x()) * levelSize.x()) - levelSize.x() / 2;
	double y = ((pixel.y() / picSize.y()) * levelSize.y()) - levelSize.y() / 2;
	return osg::Vec2(x, y);
}
예제 #8
0
파일: Uniform.cpp 프로젝트: aalex/osg
bool Uniform::getElement( unsigned int index, osg::Vec2& v2 ) const
{
    if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC2) ) return false;
    unsigned int j = index * getTypeNumComponents(getType());
    v2.x() = (*_floatArray)[j];
    v2.y() = (*_floatArray)[j+1];
    return true;
}
/**
 * \fn	void MenuButton::setPosition(osg::Vec2 pos)
 *
 * \brief	Sets a position of button.
 *
 * \param	pos	The position.
 */
void MenuButton::setPosition(osg::Vec2 pos)
{
	osg::Vec3Array* verts = new osg::Vec3Array(4);
	(*verts)[0] = osg::Vec3( pos.x() - 0.5, 0, pos.y() - 0.5);
	(*verts)[1] = osg::Vec3( pos.x() + 0.5, 0, pos.y() - 0.5);
	(*verts)[2] = osg::Vec3( pos.x() + 0.5, 0, pos.y() + 0.5);
	(*verts)[3] = osg::Vec3( pos.x() - 0.5, 0, pos.y() + 0.5);
	this->setVertexArray(verts);
}
예제 #10
0
bool ContourLayer::getValue(unsigned int i, unsigned int j, osg::Vec2& value) const
{
    if (!_tf) return false;

    const osg::Vec4& v = _tf->getPixelValue(i);
    value.x() = v.x();
    value.y() = v.y();

    return true;
}
예제 #11
0
bool TextRegion::Create(osg::Vec2 corner, osg::Vec2 size, RegionStyle* style )
{
    //set ref height for scaling in setsize
    _scaleHeightRef = size.y();
    
	//
    //
	bool ret = StrokeRegion::Create(corner,size,style);
    //set ref height for scaling in setsize
    _scaleHeightRef = size.y();
    this->SetSize(_size);
    return ret;
}
예제 #12
0
osg::Matrix vpb::MyDataSet::getImageSection(vips::VImage &in,const osg::Vec2 minT, const osg::Vec2 maxT,int origX,int origY,osg::Vec4 &texsize,const osg::Matrix &toTex,osg::ref_ptr<osg::Image> &image,osg::Vec4 &ratio,int level){

    double downsampleFactor=pow(2,level);
    double downsampleRatio=1.0/downsampleFactor;
    // std::cout<< minT << " " << maxT<<std::endl;
    // printf("%f %f\n",downsampleRatio,downsampleRatio);
    int x=(int)std::max((int)floor(minT.x()),0);
    int y=(int)std::max((int)floor(minT.y()),0);
    int xMax=(int)std::min((int)ceil(maxT.x()),origX);
    int yMax=(int)std::min((int)ceil(maxT.y()),origY);
    int xRange=(xMax-x);
    int yRange=(yMax-y);
    //printf("X:%d -- %d Y:%d -- %d ",x,xMax,y,yMax);

    //Need bias of 1.0 or will round down
    double maxSide=std::max(osg::Image::computeNearestPowerOfTwo(xRange,1.0),osg::Image::computeNearestPowerOfTwo(yRange,1.0));
    osg::Vec2 subSize=osg::Vec2(maxSide,maxSide);
    if(downsampleRatio*maxSide < 1.0){
        printf("Clipping %f %f to",downsampleRatio,downsampleFactor);
        downsampleRatio=1.0/maxSide;
        downsampleFactor=maxSide;
        printf("%f %f\n",downsampleRatio,downsampleFactor);

    }
    texsize[0]=origX;
    texsize[1]=origY;
    texsize[2]=subSize.x();
    texsize[3]=subSize.y();
    osg::Vec2 downsampleSize(subSize.x(),subSize.y());
    downsampleSize.x()*=downsampleRatio;
    downsampleSize.y()*=downsampleRatio;

    // printf("Range %d %d\n",xRange,yRange);
    // printf("%f %f %f %f\n",subSize.x(),subSize.y(),downsampleSize.x(),downsampleSize.y());
    image = new osg::Image;
    image->allocateImage(downsampleSize.x(),downsampleSize.y(), 1, GL_RGB,GL_UNSIGNED_BYTE);
    if(image->data() == 0 ){
        fprintf(stderr,"Failed to allocate\n");
        exit(-1);
    }
    {
        OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_imageMutex);
        vips::VImage osgImage(image->data(),downsampleSize.x(),downsampleSize.y(),3,vips::VImage::FMTUCHAR);
        in.extract_area(x,y,xRange,yRange).embed(1,0,0,subSize.x(),subSize.y()).shrink(downsampleFactor,downsampleFactor).write(osgImage);
    }
    ratio=osg::Vec4(x,y,subSize.x(),subSize.y());
    //osg::Vec2 f(xRange-subSize.x(),yRange-subSize.y());
    //std::cout << f<<std::endl;
    return toTex;
}
예제 #13
0
void dtAnim::MapCelestialToScreen(float azimuth,
                                  float elevation,
                                  float maxDistance,                             
                                  float windowWidth,
                                  float windowHeight,
                                  const osg::Vec2 &screenOrigin,
                                  osg::Vec2 &outScreenPos)
{
   // Transform az/el values to values ranging from 0 to 1
   float normalizedAzimuth   = azimuth / maxDistance;
   float normalizedElevation = elevation / maxDistance;

   // Calculate the final screen position
   outScreenPos[0] = screenOrigin.x() + (windowWidth * normalizedAzimuth);
   outScreenPos[1] = screenOrigin.y() + (windowHeight * normalizedElevation);   
}
예제 #14
0
//overload SetSize so we can set the texts pixelheight independantly
void TextRegion::SetSize(const osg::Vec2& size)
{
	StrokeRegion::SetSize(size);
    
	//set the texts max sizes to the new size
	_text->setMaximumHeight(size.y());
	_text->setMaximumWidth(size.x());
    
    float scaler = 1.0f / _scaleHeightRef;
    float sizeScale = size.y()*scaler;
    
    _textScale->setMatrix(osg::Matrix::scale(osg::Vec3(sizeScale,sizeScale,sizeScale)));
    
	//set new centered position
	this->SetAlignment(_alignmentMode);
}
예제 #15
0
    void conicTo(const osg::Vec2& control, const osg::Vec2& pos)
    {
        osg::Vec3 p0 = _previous;
        osg::Vec3 p1 = osg::Vec3(control.x(),control.y(),0);
        osg::Vec3 p2 = osg::Vec3(pos.x(),pos.y(),0);

        double dt = 1.0/_numSteps;
        double u=0;
        for (int i=0; i<=_numSteps; ++i)
        {
            double w = 1;
            double bs = 1.0/( (1-u)*(1-u)+2*(1-u)*u*w +u*u );
            osg::Vec3 p = (p0*((1-u)*(1-u)) + p1*(2*(1-u)*u*w) + p2*(u*u))*bs;
            addVertex( p );

            u += dt;
        }
    }
예제 #16
0
파일: Utility.cpp 프로젝트: saedrna/osgpg
void Utility::SelectBox::Show(osg::Vec2 point1,osg::Vec2 point2 )
{
    if(!m_initialized) return;

    osg::Geometry* geom = m_selectbox->getDrawable(0)->asGeometry();
    if(geom)
    {
        osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
        vertices->at(0) = osg::Vec3(point1.x(),point1.y(),0.0);
        vertices->at(1) = osg::Vec3(point2.x(),point1.y(),0.0);
        vertices->at(2) = osg::Vec3(point2.x(),point2.y(),0.0);
        vertices->at(3) = osg::Vec3(point1.x(),point2.y(),0.0);
        m_selectbox->setNodeMask(CLASSCODE::PseudMouseDrawBox);

        geom->dirtyBound();
        geom->dirtyDisplayList();
    }
}
// <length是宽高,先宽后高>
//QuadPrimitive::QuadPrimitive(const osg::Vec3& center, const osg::Vec2& length, const osg::Vec3& localX, const osg::Vec3& localY):
//QuadPrimitive::QuadPrimitive()
void QuadPrimitive::updateQuad(const osg::Vec3& center, const osg::Vec2& length, const osg::Vec3& localX, const osg::Vec3& localY)
{
	m_center = center;
	m_width = length.x();
	m_height = length.y();
	m_unitLength = length / 2.0f;
	m_localX = localX;
	m_localY = localY;


	(*m_vertexArray)[0].set(center - localX * m_unitLength.x() - localY * m_unitLength.y());
	(*m_vertexArray)[1].set(center + localX * m_unitLength.x() - localY * m_unitLength.y());
	(*m_vertexArray)[2].set(center + localX * m_unitLength.x() + localY * m_unitLength.y());
	(*m_vertexArray)[3].set(center - localX * m_unitLength.x() + localY * m_unitLength.y());

	if (!m_geoEffect.empty())
	{
		m_geoEffect.get()(_geometry);
		applyGeoShader(_geometry->getOrCreateStateSet());
		_geometry->getOrCreateStateSet()->setAttributeAndModes(new osg::PolygonOffset(1.0f, 1.0f));
	}
	if (!m_lineEffect.empty())
	{
		m_lineEffect.get()(_outLine);
		osg::ref_ptr <osg::LineWidth> lineWidth = new osg::LineWidth;
		lineWidth->setWidth(1);
		_outLine->getOrCreateStateSet()->setAttributeAndModes(lineWidth.get(), osg::StateAttribute::ON);

		applyLineShader(_outLine->getOrCreateStateSet());
	}
	m_vertexArray->dirty();
	//_geometry->dirtyBound();
	if (m_drawOutLine)
	{
		_outLine->setNodeMask((unsigned int)-1);
	}
	else
	{
		_outLine->setNodeMask(0);
	}
	//_outLine->dirtyBound();
	_root->dirtyBound();
}
예제 #18
0
void MinimalShadowMap::ViewData::extendProjection
    ( osg::Matrixd & projection, osg::Viewport * viewport, const osg::Vec2& margin )
{
  double l,r,b,t,n,f;

  //osg::Matrix projection = camera.getProjectionMatrix();

  bool frustum = projection.getFrustum( l,r,b,t,n,f );

  if( !frustum && !projection.getOrtho( l,r,b,t,n,f ) ) {
    osg::notify( osg::WARN )
        << " Awkward projection matrix. ComputeExtendedProjection failed"
        << std::endl;
    return;
  }

  osg::Matrix window = viewport->computeWindowMatrix();
 
  osg::Vec3 vMin( viewport->x() - margin.x(), 
                 viewport->y() - margin.y(), 
                 0.0 );

  osg::Vec3 vMax( viewport->width() + margin.x() * 2  + vMin.x(), 
                  viewport->height() + margin.y() * 2  + vMin.y(), 
                  0.0 );
  
  osg::Matrix inversePW = osg::Matrix::inverse( projection * window );

  vMin = vMin * inversePW;
  vMax = vMax * inversePW;
  
  l = vMin.x(); 
  r = vMax.x();
  b = vMin.y(); 
  t = vMax.y();

  if( frustum )
    projection.makeFrustum( l,r,b,t,n,f );
  else 
    projection.makeOrtho( l,r,b,t,n,f );
}
예제 #19
0
    void cubicTo(const osg::Vec2& control1, const osg::Vec2& control2, const osg::Vec2& pos)
    {
        osg::Vec3 p0 = _previous;
        osg::Vec3 p1 = osg::Vec3(control1.x(),control1.y(),0);
        osg::Vec3 p2 = osg::Vec3(control2.x(),control2.y(),0);
        osg::Vec3 p3 = osg::Vec3(pos.x(),pos.y(),0);

        double cx = 3*(p1.x() - p0.x());
        double bx = 3*(p2.x() - p1.x()) - cx;
        double ax = p3.x() - p0.x() - cx - bx;
        double cy = 3*(p1.y() - p0.y());
        double by = 3*(p2.y() - p1.y()) - cy;
        double ay = p3.y() - p0.y() - cy - by;

        double dt = 1.0/_numSteps;
        double u=0;
        for (int i=0; i<=_numSteps; ++i)
        {
            osg::Vec3 p = osg::Vec3( ax*u*u*u + bx*u*u  + cx*u + p0.x(),ay*u*u*u + by*u*u  + cy*u + p0.y(),0 );
            addVertex( p );

            u += dt;
        }
    }
예제 #20
0
 void lineTo(const osg::Vec2& pos)
 {
     addVertex( osg::Vec3(pos.x(),pos.y(),0) );
 }
예제 #21
0
파일: TextBase.cpp 프로젝트: BodyViz/osg
void TextBase::positionCursor(const osg::Vec2 & endOfLine_coords, osg::Vec2 & cursor, unsigned int linelength)
{
    switch(_layout)
    {
        case LEFT_TO_RIGHT:
        {
            switch (_alignment)
            {
                // nothing to be done for these
                //case LEFT_TOP:
                //case LEFT_CENTER:
                //case LEFT_BOTTOM:
                //case LEFT_BASE_LINE:
                //case LEFT_BOTTOM_BASE_LINE:
                //  break;
                case CENTER_TOP:
                case CENTER_CENTER:
                case CENTER_BOTTOM:
                case CENTER_BASE_LINE:
                case CENTER_BOTTOM_BASE_LINE:
                    cursor.x() = (cursor.x() - endOfLine_coords.x()) * 0.5f;
                    break;
                case RIGHT_TOP:
                case RIGHT_CENTER:
                case RIGHT_BOTTOM:
                case RIGHT_BASE_LINE:
                case RIGHT_BOTTOM_BASE_LINE:
                    cursor.x() = cursor.x() - endOfLine_coords.x();
                    break;
                default:
                    break;
            }
            break;
        }
        case RIGHT_TO_LEFT:
        {
            switch (_alignment)
            {
                case LEFT_TOP:
                case LEFT_CENTER:
                case LEFT_BOTTOM:
                case LEFT_BASE_LINE:
                case LEFT_BOTTOM_BASE_LINE:
                    cursor.x() = 2*cursor.x() - endOfLine_coords.x();
                    break;
                case CENTER_TOP:
                case CENTER_CENTER:
                case CENTER_BOTTOM:
                case CENTER_BASE_LINE:
                case CENTER_BOTTOM_BASE_LINE:
                    cursor.x() = cursor.x() + (cursor.x() - endOfLine_coords.x()) * 0.5f;
                    break;
                    // nothing to be done for these
                    //case RIGHT_TOP:
                    //case RIGHT_CENTER:
                    //case RIGHT_BOTTOM:
                    //case RIGHT_BASE_LINE:
                    //case RIGHT_BOTTOM_BASE_LINE:
                    //  break;
                default:
                    break;
            }
            break;
        }
        case VERTICAL:
        {
            switch (_alignment)
            {
                // TODO: current behaviour top baselines lined up in both cases - need to implement
                //       top of characters aligment - Question is this neccesary?
                // ... otherwise, nothing to be done for these 6 cases
                //case LEFT_TOP:
                //case CENTER_TOP:
                //case RIGHT_TOP:
                //  break;
                //case LEFT_BASE_LINE:
                //case CENTER_BASE_LINE:
                //case RIGHT_BASE_LINE:
                //  break;
                case LEFT_CENTER:
                case CENTER_CENTER:
                case RIGHT_CENTER:
                    cursor.y() = cursor.y() + (cursor.y() - endOfLine_coords.y()) * 0.5f;
                    break;
                case LEFT_BOTTOM_BASE_LINE:
                case CENTER_BOTTOM_BASE_LINE:
                case RIGHT_BOTTOM_BASE_LINE:
                    cursor.y() = cursor.y() - (linelength * _characterHeight);
                    break;
                case LEFT_BOTTOM:
                case CENTER_BOTTOM:
                case RIGHT_BOTTOM:
                    cursor.y() = 2*cursor.y() - endOfLine_coords.y();
                    break;
                default:
                    break;
            }
            break;
        }
    }
}
예제 #22
0
osg::Vec2 EnMapView::calcPosition( const std::string& align, const osg::Vec2& mapsize, const osg::Vec2& screenSize )
{
    osg::Vec2 pos;

    if ( align == ALIGN_TOPLEFT )
    {
        pos._v[ 0 ] = 0.0f;
        pos._v[ 1 ] = 0.0f;
    }
    else if ( align == ALIGN_TOPMIDDLE )
    {
        pos._v[ 0 ] = screenSize.x() / 2.0f - mapsize.x() / 2.0f;
        pos._v[ 1 ] = 0.0f;
    }
    else if ( align == ALIGN_TOPRIGHT )
    {
        pos._v[ 0 ] = screenSize.x() - mapsize.x();
        pos._v[ 1 ] = 0.0f;
    }
    else if ( align == ALIGN_BOTTOMLEFT )
    {
        pos._v[ 0 ] = 0.0f;
        pos._v[ 1 ] = screenSize.y() - mapsize.y();
    }
    else if ( align == ALIGN_BOTTOMMIDDLE )
    {
        pos._v[ 0 ] = screenSize.x() / 2.0f - mapsize.x() / 2.0f;
        pos._v[ 1 ] = screenSize.y() - mapsize.y();
    }
    else if ( align == ALIGN_BOTTOMRIGHT )
    {
        pos._v[ 0 ] = screenSize.x() - mapsize.x();
        pos._v[ 1 ] = screenSize.y() - mapsize.y();
    }
    else
    {
        log_error << "EnMapView: invalid aligning '" << align << "'" << std::endl;

        log_out       << "           valid values are: " <<
                        ALIGN_TOPLEFT       << ", "  <<
                        ALIGN_TOPMIDDLE     << ", "  <<
                        ALIGN_TOPRIGHT      << ", "  <<
                        ALIGN_BOTTOMLEFT    << ", "  <<
                        ALIGN_BOTTOMMIDDLE  << ", "  <<
                        ALIGN_BOTTOMRIGHT   << std::endl;

        log_out       << "           set to default '" << ALIGN_TOPLEFT << "'" << std::endl;
    }

    return pos;
}
예제 #23
0
void DataOutputStream::writeVec2(const osg::Vec2& v){
    writeFloat(v.x());
    writeFloat(v.y());

    if (_verboseOutput) std::cout<<"read/writeVec2() ["<<v<<"]"<<std::endl;
}
예제 #24
0
String::iterator Text3D::computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last)
{
    if (_font.valid() == false) return last;

    bool kerning = true;
    unsigned int previous_charcode = 0;

    String::iterator lastChar = first;

    std::set<unsigned int> deliminatorSet;
    deliminatorSet.insert(' ');
    deliminatorSet.insert('\n');
    deliminatorSet.insert(':');
    deliminatorSet.insert('/');
    deliminatorSet.insert(',');
    deliminatorSet.insert(';');
    deliminatorSet.insert(':');
    deliminatorSet.insert('.');

    float maximumHeight = _maximumHeight / _font->getScale();
    float maximumWidth = _maximumWidth / _font->getScale();

    for(bool outOfSpace=false;lastChar!=last;++lastChar)
    {
        unsigned int charcode = *lastChar;

        if (charcode=='\n')
        {
            return lastChar;
        }

        Font3D::Glyph3D* glyph = _font->getGlyph(charcode);
        if (glyph)
        {
            const osg::BoundingBox & bb = glyph->getBoundingBox();

            // adjust cursor position w.r.t any kerning.
            if (previous_charcode)
            {

                if (_layout == RIGHT_TO_LEFT)
                {
                    cursor.x() -= glyph->getHorizontalAdvance();
                }

                if (kerning)
                {
                    switch (_layout)
                    {
                        case LEFT_TO_RIGHT:
                        {
                            cursor += _font->getKerning(previous_charcode, charcode, _kerningType);
                            break;
                        }
                        case RIGHT_TO_LEFT:
                        {
                            cursor -= _font->getKerning(charcode, previous_charcode, _kerningType);
                            break;
                        }
                        case VERTICAL:
                            break; // no kerning when vertical.
                    }
                }
            }
            else
            {
                switch (_layout)
                {
                    case LEFT_TO_RIGHT:
                    {
                        cursor.x() -= glyph->getHorizontalBearing().x();
                        break;
                    }
                    case RIGHT_TO_LEFT:
                    {
                        cursor.x() -= bb.xMax();
                        break;
                    }
                    case VERTICAL:
                        break;
                }

            }



            switch(_layout)
            {
              case LEFT_TO_RIGHT:
              {
                if (maximumWidth>0.0f && cursor.x()+bb.xMax()>maximumWidth) outOfSpace=true;
                if(maximumHeight>0.0f && cursor.y()<-maximumHeight) outOfSpace=true;
                break;
              }
              case RIGHT_TO_LEFT:
              {
                if (maximumWidth>0.0f && cursor.x()+bb.xMin()<-maximumWidth) outOfSpace=true;
                if(maximumHeight>0.0f && cursor.y()<-maximumHeight) outOfSpace=true;
                break;
              }
              case VERTICAL:
                if (maximumHeight>0.0f && cursor.y()<-maximumHeight) outOfSpace=true;
                break;
            }

            // => word boundary detection & wrapping
            if (outOfSpace) break;

            // move the cursor onto the next character.
            switch(_layout)
            {
              case LEFT_TO_RIGHT: cursor.x() += glyph->getHorizontalAdvance(); break;
              case RIGHT_TO_LEFT: break;
              case VERTICAL:      cursor.y() -= glyph->getVerticalAdvance(); break;
            }

            previous_charcode = charcode;

        }

    }

    // word boundary detection & wrapping
    if (lastChar!=last)
    {
        if (deliminatorSet.count(*lastChar)==0)
        {
            String::iterator lastValidChar = lastChar;
            while (lastValidChar!=first && deliminatorSet.count(*lastValidChar)==0)
            {
                --lastValidChar;

                //Substract off glyphs from the cursor position (to correctly center text)
                Font3D::Glyph3D* glyph = _font->getGlyph(*lastValidChar);
                if (glyph)
                {
                    switch(_layout)
                    {
                    case LEFT_TO_RIGHT: cursor.x() -= glyph->getHorizontalAdvance(); break;
                    case RIGHT_TO_LEFT: cursor.x() += glyph->getHorizontalAdvance(); break;
                    case VERTICAL:      cursor.y() += glyph->getVerticalAdvance(); break;
                    }
                }
            }

            if (first!=lastValidChar)
            {
                ++lastValidChar;
                lastChar = lastValidChar;
            }
        }
    }

    return lastChar;
}
예제 #25
0
파일: Trackball.cpp 프로젝트: 4og/avango
/* virtual */ void
av::utils::Trackball::evaluate()
{
  av::FieldContainer::evaluate();

  if(!Enable.getValue())
      return;

  if(mReset)
    reset();

  const bool newDragging =
    (RotateTrigger.getValue() || ZoomTrigger.getValue() || PanTrigger.getValue());

  const ::osg::Vec3 projected = projectToSphere(Direction.getValue());

  if (mDragging && newDragging)
  {
    if (RotateTrigger.getValue())
    {
      ::osg::Matrix rotMat = ::osg::Matrix::rotate(projected, mLastProjected);

      float fac = SpinningWeightingCoefficient.getValue();
      mRotation = rotMat * ::osg::Matrix::scale(fac,fac,fac) * mRotation;

      Matrix.setValue(mCenterTransInv * rotMat *
                      CenterTransform.getValue() * Matrix.getValue());
    }
    else if (ZoomTrigger.getValue())
    {
      const ::osg::Vec2 offset = mLastDirection - Direction.getValue();
      float zoomFactor = offset.y();
      zoomFactor *= BoundingSphere.getValue()->Radius.getValue()*ZoomPanFactor.getValue();

      if(AutoAdjustCenterTransform.getValue())
      {
        ::osg::Matrix mat = CenterTransform.getValue() * ::osg::Matrix::translate(0.0, 0.0, zoomFactor);
        CenterTransform.setValue(mat);
      }

      Matrix.setValue(mCenterTransInv * ::osg::Matrix::translate(0.0, 0.0, -zoomFactor) *
                      CenterTransform.getValue() * Matrix.getValue());
    }
    else if (PanTrigger.getValue())
    {
      const ::osg::Vec2 offset = mLastDirection - Direction.getValue();

      float xPanFactor = offset.x() * BoundingSphere.getValue()->Radius.getValue()*ZoomPanFactor.getValue();
      float yPanFactor = offset.y() * BoundingSphere.getValue()->Radius.getValue()*ZoomPanFactor.getValue();

      Matrix.setValue(mCenterTransInv * ::osg::Matrix::translate(xPanFactor, yPanFactor, 0.0) *
                      CenterTransform.getValue() * Matrix.getValue());
    }
    mSpinning = false;
  }
  else if (!mDragging && newDragging)
  {
    mRotation = ::osg::Matrix::identity();
    mTimeLastMovement = TimeIn.getValue();
  }
  else if (mDragging && !newDragging)
  {
    float timeSinceLastRecordEvent = TimeIn.getValue() - mTimeLastMovement;
    if (timeSinceLastRecordEvent < SpinningTimeThreshold.getValue())
    {
      mSpinning = true;
    }
  }

  if (mSpinning)
  {
    ::osg::Quat rot = mRotation.getRotate();
    Matrix.setValue(mCenterTransInv * ::osg::Matrix::rotate(rot) *
                    CenterTransform.getValue() * Matrix.getValue());
  }

  if (ResetTrigger.getValue())
  {
    reset();

    mSpinning = false;
  }

  mDragging = newDragging;
  mLastDirection = Direction.getValue();
  mLastProjected = projected;
}
예제 #26
0
//
//set the fonts glyph res in pixels
//
void TextRegion::SetFontResolution(const osg::Vec2& fontRes)
{
    _text->setFontResolution((int)fontRes.x(), (int)fontRes.y());
    _dirtyRenderState = true;
}
예제 #27
0
std::vector< CEGUI::Point > EnMapView::calcSnapPoints( const osg::Vec2& mapsize, const osg::Vec2& screenSize )
{
    CEGUI::Point snap;
    std::vector< CEGUI::Point > points;

    // top left
    snap.d_x = 0.0f;
    snap.d_y = 0.0f;
    points.push_back( snap );

    // top middle
    snap.d_x = screenSize.x() / 2.0f - mapsize.x() / 2.0f;
    snap.d_y = 0.0f;
    points.push_back( snap );

    // top right
    snap.d_x = screenSize.x() - mapsize.x();
    snap.d_y = 0.0f;
    points.push_back( snap );

    // bottom left
    snap.d_x = 0.0f;
    snap.d_y = screenSize.y() - mapsize.y();
    points.push_back( snap );

    // bottom middle
    snap.d_x = screenSize.x() / 2.0f - mapsize.x() / 2.0f;
    snap.d_y = screenSize.y() - mapsize.y();
    points.push_back( snap );

    // bottom right
    snap.d_x = screenSize.x() - mapsize.x();
    snap.d_y = screenSize.y() - mapsize.y();
    points.push_back( snap );

    return points;
}
예제 #28
0
bool HeightFieldLayer::getValue(unsigned int i, unsigned int j, osg::Vec2& value) const
{
    value.x() = _heightField->getHeight(i,j);
    value.y() = _defaultValue.y();
    return true;
}
예제 #29
0
osg::Vec2 CityModel::findCollisionEdge(std::vector<osg::Vec2> &points, std::vector<osg::Vec2> &checks, osg::Vec2 &resultVector)
{
	osg::Vec2 direction1, direction2;

	if (points.size() == 1)
	{
		int i=0;
		for (; i < 4; i++)
		{
			if (points.front() == checks[i])
				break;
		}

		direction1 = checks[(i + 1) % 4] - checks[i];
		direction2 = checks[posMod(i - 1,4)] - checks[i];

		// insert same again, to apply 2nd direction later
		points.push_back(points.front());
		
	}
	else if (points.size() == 2)
		for (int i = 0; i < 4; i++)
			if (contains(points, checks[i]) && contains(points, checks[(i + 1) % 4]))
			{
				direction1 = checks[posMod(i - 1, 4)] - checks[i];
				direction2 = checks[(i + 2) % 4] - checks[(i + 1) % 4];
				break;
			}

	else if (points.size() == 3)
		for (int i = 0; i < 4; i++)
			if (!contains(points, checks[i]))
			{
				direction1 = checks[posMod(i - 1, 4)] - checks[i];
				direction2 = checks[(i + 2) % 4] - checks[(i + 1) % 4];
				break;
			}

	direction1.normalize();
	direction2.normalize();
	osg::Vec2 pix1 = worldToPixelIndex(points[0]);
	osg::Vec2 pix2 = worldToPixelIndex(points[1]);

	osg::Vec2 p1 = pixelToWorld( findBorder(pix1, direction1) );
	osg::Vec2 p2 = pixelToWorld( findBorder(pix2, direction2) );



	if (debugging)
	{
		std::vector<osg::Vec2> redPoints{ findBorder(pix1, direction1), findBorder(pix2, direction2) };

		std::vector<osg::Vec2> markPoints2{ worldToPixelIndex(checks[0]),
			worldToPixelIndex(checks[1]),
			worldToPixelIndex(checks[2]),
			worldToPixelIndex(checks[3])
		};
		writeDebugImage(pix1.x(), pix1.y(), &redPoints, &markPoints2);
		resultVector.set((p2 - p1).x(), (p2 - p1).y());
		std::cout << "[CityModel] resultVector" << resultVector.x() << " " << resultVector.y() << std::endl;
		while (1);
	}

	
	//resultNormal.set(osg::Vec3(p2-p1,0)^osg::Vec3(0,0,1));
	resultVector.set((p2 - p1).x(),(p2-p1).y());
	//center
	return (p2 + p1) / 2;
}
예제 #30
0
 void    Frame(bool& request_warp, osg::Vec2& warp, bool& handled)
 {
     request_warp = true ;
     warp.set(0,0) ;
     handled = true ;
 }