Пример #1
0
/// Returns the depth of point in the scene.
float GraphicsView::depth(const Point3f &point) const
{
    Eigen::Matrix<float, 4, 1> viewPoint;
    viewPoint[0] = point.x();
    viewPoint[1] = point.y();
    viewPoint[2] = point.z();
    viewPoint[3] = 1;

    GraphicsTransform transform = projectionTransform() * modelViewTransform();
    viewPoint = transform.multiply(viewPoint);
    viewPoint *= 1.0 / viewPoint[3];

    float winZ = (viewPoint[2] + 1) / 2;

    return winZ;
}
/// \brief Use the given vectors to set the camera's orientation,
/// position, and focal point at the end of the transition.
///
/// This does <emph>not</emph> set the parallel scale.
vesKiwiCameraTransition::Ptr vesKiwiCameraTransition::setFinalFrame(
  const vesVector3f& cameraPosn,
  const vesVector3f& focalPoint,
  const vesVector3f& up)
{
  this->setFinalFocus(focalPoint);
  this->setFinalDistance((cameraPosn - focalPoint).norm());
  vesMatrix4x4f modelViewTransform = vesLookAt(cameraPosn, focalPoint, up);
  float tmp[3][3];
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j)
      tmp[i][j] = modelViewTransform(j,i);
  this->mFinalOrientation.FromMatrix3x3(tmp);
  this->mFinalOrientationSet = true;
  return shared_from_this();
}
Пример #3
0
/// Unprojects a point from the window to the scene.
Point3f GraphicsView::unproject(qreal x, qreal y, qreal z) const
{
    // flip y
    y = height() - y;

    // adjust point to normalized window coordinates
    Eigen::Matrix<float, 4, 1> point;
    point[0] = 2 * x / width() - 1;
    point[1] = 2 * y / height() - 1;
    point[2] = 2 * z - 1;
    point[3] = 1;

    // map to object-space coordinates
    GraphicsTransform transform = projectionTransform() * modelViewTransform();
    point = transform.inverseMultiply(point);
    point *= 1.0 / point[3];

    return Point3f(point[0], point[1], point[2]);
}
Пример #4
0
/// Projects a point from the scene to the window.
QPointF GraphicsView::project(const Point3f &point) const
{
    Eigen::Matrix<float, 4, 1> vector;
    vector[0] = point.x();
    vector[1] = point.y();
    vector[2] = point.z();
    vector[3] = 0;

    GraphicsTransform transform = projectionTransform() * modelViewTransform();
    vector = transform.multiply(vector);
    vector *= 1.0 / vector[3];

    float winX = width() * (vector[0] + 1) / 2;
    float winY = height() * (vector[1] + 1) / 2;
    float winZ = (vector[2] + 1) / 2;

    // if winZ is greater than 1.0 the point is not
    // visible (it is either in front of the near clip
    // plane or behind the far clip plane).
    if(winZ > 1.0)
        return QPointF();
    else
        return QPointF(winX, height() - winY);
}