本文整理汇总了C++中SbViewVolume::projectToScreen方法的典型用法代码示例。如果您正苦于以下问题:C++ SbViewVolume::projectToScreen方法的具体用法?C++ SbViewVolume::projectToScreen怎么用?C++ SbViewVolume::projectToScreen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SbViewVolume
的用法示例。
在下文中一共展示了SbViewVolume::projectToScreen方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cut
void ViewProviderStructured::cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer)
{
// create the polygon from the picked points
Base::Polygon2D cPoly;
for (std::vector<SbVec2f>::const_iterator it = picked.begin(); it != picked.end(); ++it) {
cPoly.Add(Base::Vector2D((*it)[0],(*it)[1]));
}
// get a reference to the point feature
Points::Feature* fea = static_cast<Points::Feature*>(pcObject);
const Points::PointKernel& points = fea->Points.getValue();
SoCamera* pCam = Viewer.getSoRenderManager()->getCamera();
SbViewVolume vol = pCam->getViewVolume();
// search for all points inside/outside the polygon
Points::PointKernel newKernel;
newKernel.reserve(points.size());
bool invalidatePoints = false;
double nan = std::numeric_limits<double>::quiet_NaN();
for (Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); ++jt) {
// valid point?
Base::Vector3d vec(*jt);
if (!(boost::math::isnan(jt->x) || boost::math::isnan(jt->y) || boost::math::isnan(jt->z))) {
SbVec3f pt(jt->x,jt->y,jt->z);
// project from 3d to 2d
vol.projectToScreen(pt, pt);
if (cPoly.Contains(Base::Vector2D(pt[0],pt[1]))) {
invalidatePoints = true;
vec.Set(nan, nan, nan);
}
}
newKernel.push_back(vec);
}
if (invalidatePoints) {
//Remove the points from the cloud and open a transaction object for the undo/redo stuff
Gui::Application::Instance->activeDocument()->openCommand("Cut points");
// sets the points outside the polygon to update the Inventor node
fea->Points.setValue(newKernel);
// unset the modified flag because we don't need the features' execute() to be called
Gui::Application::Instance->activeDocument()->commitCommand();
fea->purgeTouched();
}
}
示例2: cut
void ViewProviderPoints::cut(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer)
{
// create the polygon from the picked points
Base::Polygon2D cPoly;
for (std::vector<SbVec2f>::const_iterator it = picked.begin(); it != picked.end(); ++it) {
cPoly.Add(Base::Vector2D((*it)[0],(*it)[1]));
}
// get a reference to the point feature
Points::Feature* fea = (Points::Feature*)pcObject;
const Points::PointKernel& points = fea->Points.getValue();
SoCamera* pCam = Viewer.getSoRenderManager()->getCamera();
SbViewVolume vol = pCam->getViewVolume();
// search for all points inside/outside the polygon
Points::PointKernel newKernel;
for ( Points::PointKernel::const_iterator jt = points.begin(); jt != points.end(); ++jt ) {
SbVec3f pt(jt->x,jt->y,jt->z);
// project from 3d to 2d
vol.projectToScreen(pt, pt);
if (!cPoly.Contains(Base::Vector2D(pt[0],pt[1])))
newKernel.push_back(*jt);
}
if (newKernel.size() == points.size())
return; // nothing needs to be done
//Remove the points from the cloud and open a transaction object for the undo/redo stuff
Gui::Application::Instance->activeDocument()->openCommand("Cut points");
// sets the points outside the polygon to update the Inventor node
fea->Points.setValue(newKernel);
// unset the modified flag because we don't need the features' execute() to be called
Gui::Application::Instance->activeDocument()->commitCommand();
fea->purgeTouched();
}
示例3: paintGL
void GLFlagWindow::paintGL()
{
// draw lines for the flags
if (_flagLayout) {
// it can happen that the GL widget gets replaced internally (SoQt only, not with quarter) which
// causes to destroy the FlagLayout instance
int ct = _flagLayout->count();
const SbViewportRegion vp = _viewer->getSoRenderManager()->getViewportRegion();
SbVec2s size = vp.getViewportSizePixels();
float aspectratio = float(size[0])/float(size[1]);
SbViewVolume vv = _viewer->getSoRenderManager()->getCamera()->getViewVolume(aspectratio);
for (int i=0; i<ct;i++) {
Flag* flag = qobject_cast<Flag*>(_flagLayout->itemAt(i)->widget());
if (flag) {
SbVec3f pt = flag->getOrigin();
vv.projectToScreen(pt, pt);
int tox = (int)(pt[0] * size[0]);
int toy = (int)((1.0f-pt[1]) * size[1]);
flag->drawLine(_viewer, tox, toy);
}
}
}
}
示例4: GLRender
/**
* Renders the label.
*/
void SoTextLabel::GLRender(SoGLRenderAction *action)
{
if (!this->shouldGLRender(action)) return;
// only draw text without background
if (!this->background.getValue()) {
inherited::GLRender(action);
return;
}
SoState * state = action->getState();
state->push();
SoLazyElement::setLightModel(state, SoLazyElement::BASE_COLOR);
SbBox3f box;
SbVec3f center;
this->computeBBox(action, box, center);
if (!SoCullElement::cullTest(state, box, TRUE)) {
SoMaterialBundle mb(action);
mb.sendFirst();
const SbMatrix & mat = SoModelMatrixElement::get(state);
//const SbViewVolume & vv = SoViewVolumeElement::get(state);
const SbMatrix & projmatrix = (mat * SoViewingMatrixElement::get(state) *
SoProjectionMatrixElement::get(state));
const SbViewportRegion & vp = SoViewportRegionElement::get(state);
SbVec2s vpsize = vp.getViewportSizePixels();
// font stuff
//float space = this->spacing.getValue();
//float fontsize = SoFontSizeElement::get(state);
SbName fontname = SoFontNameElement::get(state);
int lines = this->string.getNum();
// get left bottom corner of the label
SbVec3f nilpoint(0.0f, 0.0f, 0.0f);
projmatrix.multVecMatrix(nilpoint, nilpoint);
nilpoint[0] = (nilpoint[0] + 1.0f) * 0.5f * vpsize[0];
nilpoint[1] = (nilpoint[1] + 1.0f) * 0.5f * vpsize[1];
#if 1
// Unfortunately, the size of the label is stored in the pimpl class of
// SoText2 which cannot be accessed directly. However, there is a trick
// to get the required information: set model, viewing and projection
// matrix to the identity matrix and also view volume to some default
// values. SoText2::computeBBox() then calls SoText2P::getQuad which
// returns the sizes in form of the bounding box. These values can be
// reverse-engineered to get width and height.
state->push();
SoModelMatrixElement::set(state,this,SbMatrix::identity());
SoViewingMatrixElement::set(state,this,SbMatrix::identity());
SoProjectionMatrixElement::set(state,this,SbMatrix::identity());
SbViewVolume vv;
vv.ortho(-1,1,-1,1,-1,1);
SoViewVolumeElement::set(state,this,vv);
SbBox3f box;
SbVec3f center;
this->computeBBox(action, box, center);
state->pop();
float xmin,ymin,zmin,xmax,ymax,zmax;
box.getBounds(xmin,ymin,zmin,xmax,ymax,zmax);
SbVec3f v0(xmin,ymax,zmax);
SbVec3f v1(xmax,ymax,zmax);
SbVec3f v2(xmax,ymin,zmax);
SbVec3f v3(xmin,ymin,zmax);
vv.projectToScreen(v0,v0);
vv.projectToScreen(v1,v1);
vv.projectToScreen(v2,v2);
vv.projectToScreen(v3,v3);
float width,height;
width = (v1[0]-v0[0])*vpsize[0];
height = (v1[1]-v3[1])*vpsize[1];
switch (this->justification.getValue()) {
case SoText2::RIGHT:
nilpoint[0] -= width;
break;
case SoText2::CENTER:
nilpoint[0] -= 0.5f*width;
break;
default:
break;
}
if (lines > 1) {
nilpoint[1] -= (float(lines-1)/(float)lines*height);
}
#else
// Unfortunately, the required size (in pixels) is stored in a non-accessible way
// in the subclass SoText2. Thus, we try to get a satisfactory solution with Qt
// methods.
// The font name is of the form "family:style". If 'style' is given it can be
// 'Bold', 'Italic' or 'Bold Italic'.
QFont font;
//.........这里部分代码省略.........
示例5: projectTelePointer
//======================================================================
//
// Description:
// projection of telepointer
//
//
// Use: private
//======================================================================
void TPHandler::projectTelePointer(TelePointer *, const SbVec3f pos, float aspectRatio,
SbVec3f &intersection, InvExaminerViewer *viewer)
{
const int xOffset = 61;
const int yOffset = 33;
float xs, ys, zs; // normalized screen coordinates
SbVec3f screen;
SbVec2s size = viewer->getSize();
if (viewer->isDecoration())
{
// !! Attention: SoXtRenderArea with offset
size[0] = size[0] - xOffset;
size[1] = size[1] - yOffset;
}
float aspRat = size[0] / (float)size[1];
// set aspect ratio explicitely
tp_camera->aspectRatio.setValue(aspRat);
// default setting
tp_camera->height.setValue(2.0);
// scale height
tp_camera->scaleHeight(1 / aspRat);
/*
float h = tp_camera->height.getValue();
fprintf(stderr, "Height Camera: %.6f\n", h);
*/
// get the view volume -> rectangular box
SbViewVolume viewVolume = tp_camera->getViewVolume();
// determine mouse position
viewVolume.projectToScreen(pos, screen);
screen.getValue(xs, ys, zs);
/*
cerr << "xs: " << xs << endl;
cerr << "ys: " << ys << endl;
*/
// project the mouse point to a line
SbVec3f p0, p1;
viewVolume.projectPointToLine(SbVec2f(xs, ys), p0, p1);
// take the midpoint of the line as telepointer position
intersection = (p0 + p1) / 2.0f;
// adapt telepointer position to the aspect ratio
if (aspectRatio > 1.0)
{
intersection[0] = intersection[0] * aspectRatio / aspRat;
intersection[1] = intersection[1] * aspectRatio / aspRat;
}
if (aspectRatio < 1.0)
{
// in this case the aspect ratio submitted to the function
// and belonging to the delivered position leads to wrong projection point
// => local correction for x-, y-value
intersection[0] = intersection[0] / aspRat;
intersection[1] = intersection[1] / aspRat;
}
/*
float fx,fy,fz;
intersection.getValue(fx,fy,fz);
cerr << "TP: (" << fx << "," << fy << "," << fz << ")" << endl;
*/
}