本文整理汇总了C++中osg::Vec2类的典型用法代码示例。如果您正苦于以下问题:C++ Vec2类的具体用法?C++ Vec2怎么用?C++ Vec2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vec2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clamp
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: operator
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: projectWindowXYIntoObject
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: moveTo
void moveTo(const osg::Vec2& pos)
{
completeCurrentPrimitiveSet();
addVertex( osg::Vec3(pos.x(),pos.y(),0) );
}
示例5: calcCoordReprojTrans
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: acos
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: pairToVec2
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: getElement
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;
}
示例9: setPosition
/**
* \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: getValue
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: Create
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: printf
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: MapCelestialToScreen
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: SetSize
//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: conicTo
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;
}
}