本文整理汇总了C++中osg::Vec2类的典型用法代码示例。如果您正苦于以下问题:C++ Vec2类的具体用法?C++ Vec2怎么用?C++ Vec2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vec2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:MaxReimann,项目名称:troen-simulator,代码行数:28,代码来源:hudview.cpp
示例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();
}
开发者ID:NagaoKagetora,项目名称:geometric-terminal,代码行数:33,代码来源:Handler.cpp
示例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;
}
开发者ID:joevandyk,项目名称:osg,代码行数:7,代码来源:Dragger.cpp
示例4: moveTo
void moveTo(const osg::Vec2& pos)
{
completeCurrentPrimitiveSet();
addVertex( osg::Vec3(pos.x(),pos.y(),0) );
}
开发者ID:nsmoooose,项目名称:osg,代码行数:7,代码来源:FreeTypeFont.cpp
示例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;
}
开发者ID:SorinS,项目名称:structured,代码行数:33,代码来源:imageNode.cpp
示例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);
}
开发者ID:nixz,项目名称:covise,代码行数:27,代码来源:MultitouchPlugin.cpp
示例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);
}
开发者ID:MaxReimann,项目名称:troen-simulator,代码行数:8,代码来源:citymodel.cpp
示例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;
}
开发者ID:aalex,项目名称:osg,代码行数:8,代码来源:Uniform.cpp
示例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);
}
开发者ID:NobodysNightmare,项目名称:realistictowerdefense,代码行数:16,代码来源:menubutton.cpp
示例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;
}
开发者ID:dev2dev,项目名称:OpenSceneGraph-port-to-IOS,代码行数:10,代码来源:Layer.cpp
示例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;
}
开发者ID:crycrane,项目名称:hogbox,代码行数:13,代码来源:TextRegion.cpp
示例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;
}
开发者ID:SorinS,项目名称:structured,代码行数:50,代码来源:imageNode.cpp
示例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);
}
开发者ID:VRAC-WATCH,项目名称:deltajug,代码行数:16,代码来源:posemath.cpp
示例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);
}
开发者ID:crycrane,项目名称:hogbox,代码行数:17,代码来源:TextRegion.cpp
示例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;
}
}
开发者ID:nsmoooose,项目名称:osg,代码行数:18,代码来源:FreeTypeFont.cpp
示例16:
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();
}
}
开发者ID:saedrna,项目名称:osgpg,代码行数:18,代码来源:Utility.cpp
示例17: updateQuad
// <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();
}
开发者ID:LeonardoTech,项目名称:FunctionalUtilities,代码行数:46,代码来源:QuadPrimitive.cpp
示例18: vMin
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 );
}
开发者ID:BlitzMaxModules,项目名称:osg.mod,代码行数:41,代码来源:MinimalShadowMap.cpp
示例19: cubicTo
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;
}
}
开发者ID:nsmoooose,项目名称:osg,代码行数:24,代码来源:FreeTypeFont.cpp
示例20: lineTo
void lineTo(const osg::Vec2& pos)
{
addVertex( osg::Vec3(pos.x(),pos.y(),0) );
}
开发者ID:nsmoooose,项目名称:osg,代码行数:4,代码来源:FreeTypeFont.cpp
注:本文中的osg::Vec2类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论