当前位置: 首页>>代码示例>>C++>>正文


C++ QVector2D::normalized方法代码示例

本文整理汇总了C++中QVector2D::normalized方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector2D::normalized方法的具体用法?C++ QVector2D::normalized怎么用?C++ QVector2D::normalized使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QVector2D的用法示例。


在下文中一共展示了QVector2D::normalized方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getLimitPos

QPointF ImageMarker::getLimitPos(QPointF newPos)
{
    qreal loLen;
    qreal hiLen;

    if (!m_limit) {
        return QPointF();
    }

    QVector2D ownVector = QVector2D(newPos);
    QVector2D limVector = QVector2D(m_limit->pos());

    if (m_outerLimit) {
        loLen = ownVector.length();
        hiLen = limVector.length();
    }
    else {
        loLen = limVector.length();
        hiLen = ownVector.length();
    }

    if (loLen <= hiLen) {
        return QPointF();
    }

    return (ownVector.normalized() * (m_outerLimit ? hiLen : loLen)).toPointF();
}
开发者ID:m4ktub,项目名称:Unwrap360,代码行数:27,代码来源:imagemarker.cpp

示例2: advance

void Particle::advance(int phase){

    if(active()) {
        QVector2D force;
        foreach(Planet* planet, gameScene()->planets()) {
            QVector2D r = QVector2D(this->position() - planet->position());
            // save the length and lengthSquared to memory to avoid recalculations (with square roots!)
    //        double distance = r.length();
            double distanceSquared = r.lengthSquared();
            QVector2D rn = r.normalized();
            if(distanceSquared != 0) {
                QVector2D gravity = - rn * GravityConstant * planet->mass() / distanceSquared;
                force += gravity;

                if (r.lengthSquared() < planet->radius()*planet->radius()) { //Vj: Temporary fix while testing :O)
                    planet->collideWithParticle();
                    gameScene()->removeParticle(this);
                    return;
                }
            }
        }
        QVector2D acceleration = force / 1.0;
        _velocity += acceleration * gameScene()->dt();
        _position += _velocity * gameScene()->dt();
        resized();
    }
开发者ID:dragly,项目名称:particleflow,代码行数:26,代码来源:particle.cpp

示例3: projection

QVector2D Geometry::projection(QVector2D const &projected, QVector2D const &target)
{
	QVector2D const normalizedTarget = target.normalized();
	// Scalar product is a projection lenght
	return normalizedTarget * scalarProduct(normalizedTarget, projected);
}
开发者ID:ASabina,项目名称:qreal,代码行数:6,代码来源:geometry.cpp

示例4: Object

Cone::Cone(const QVector2D &pc, const QVector3D &pos)
	: Object(AMBIENT, DIFFUSE, SPECULAR, SHININESS,REFLECTION, REFRACTION)
{
	c = pc.normalized();
	position = pos;
}
开发者ID:artyrian,项目名称:graphicon,代码行数:6,代码来源:Object.cpp

示例5: return

inline QVector2D CFruchtermanReingold::HookeForce(const int firstVertexIndex, const int secondVertexIndex) const {
       QVector2D direction = QVector2D(vgc_vertices[secondVertexIndex].v_coordinates - vgc_vertices[firstVertexIndex].v_coordinates);
       return  (SPRING_CONSTANT / vgc_coeff) * (Distance(vgc_vertices[firstVertexIndex].v_coordinates,
                                 vgc_vertices[secondVertexIndex].v_coordinates) / SPRING_LENGTH) * direction.normalized();
}
开发者ID:maked0n,项目名称:GraphAlgorithmVisualizer,代码行数:5,代码来源:cfruchtermanreingold.cpp

示例6: Distance

inline QVector2D CFruchtermanReingold::CoulombForce(const int firstVertexIndex, const int secondVertexIndex) const {
       QVector2D direction = QVector2D(vgc_vertices[firstVertexIndex].v_coordinates - vgc_vertices[secondVertexIndex].v_coordinates);
       return vgc_coeff * vgc_coeff  / Distance(vgc_vertices[firstVertexIndex].v_coordinates,
                                                vgc_vertices[secondVertexIndex].v_coordinates) * direction.normalized();
}
开发者ID:maked0n,项目名称:GraphAlgorithmVisualizer,代码行数:5,代码来源:cfruchtermanreingold.cpp

示例7: draw

/*! \internal
  
  Draws the line ending with the specified \a painter at the position \a pos. The direction of the
  line ending is controlled with \a dir.
*/
void QCPLineEnding::draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const
{
  if (mStyle == esNone)
    return;
  
  QVector2D lengthVec(dir.normalized());
  if (lengthVec.isNull())
    lengthVec = QVector2D(1, 0);
  QVector2D widthVec(-lengthVec.y(), lengthVec.x());
  lengthVec *= (float)(mLength*(mInverted ? -1 : 1));
  widthVec *= (float)(mWidth*0.5*(mInverted ? -1 : 1));
  
  QPen penBackup = painter->pen();
  QBrush brushBackup = painter->brush();
  QPen miterPen = penBackup;
  miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey
  QBrush brush(painter->pen().color(), Qt::SolidPattern);
  switch (mStyle)
  {
    case esNone: break;
    case esFlatArrow:
    {
      QPointF points[3] = {pos.toPointF(),
                           (pos-lengthVec+widthVec).toPointF(),
                           (pos-lengthVec-widthVec).toPointF()
                          };
      painter->setPen(miterPen);
      painter->setBrush(brush);
      painter->drawConvexPolygon(points, 3);
      painter->setBrush(brushBackup);
      painter->setPen(penBackup);
      break;
    }
    case esSpikeArrow:
    {
      QPointF points[4] = {pos.toPointF(),
                           (pos-lengthVec+widthVec).toPointF(),
                           (pos-lengthVec*0.8f).toPointF(),
                           (pos-lengthVec-widthVec).toPointF()
                          };
      painter->setPen(miterPen);
      painter->setBrush(brush);
      painter->drawConvexPolygon(points, 4);
      painter->setBrush(brushBackup);
      painter->setPen(penBackup);
      break;
    }
    case esLineArrow:
    {
      QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(),
                           pos.toPointF(),
                           (pos-lengthVec-widthVec).toPointF()
                          };
      painter->setPen(miterPen);
      painter->drawPolyline(points, 3);
      painter->setPen(penBackup);
      break;
    }
    case esDisc:
    {
      painter->setBrush(brush);
      painter->drawEllipse(pos.toPointF(),  mWidth*0.5, mWidth*0.5);
      painter->setBrush(brushBackup);
      break;
    }
    case esSquare:
    {
      QVector2D widthVecPerp(-widthVec.y(), widthVec.x());
      QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(),
                           (pos-widthVecPerp-widthVec).toPointF(),
                           (pos+widthVecPerp-widthVec).toPointF(),
                           (pos+widthVecPerp+widthVec).toPointF()
                          };
      painter->setPen(miterPen);
      painter->setBrush(brush);
      painter->drawConvexPolygon(points, 4);
      painter->setBrush(brushBackup);
      painter->setPen(penBackup);
      break;
    }
    case esDiamond:
    {
      QVector2D widthVecPerp(-widthVec.y(), widthVec.x());
      QPointF points[4] = {(pos-widthVecPerp).toPointF(),
                           (pos-widthVec).toPointF(),
                           (pos+widthVecPerp).toPointF(),
                           (pos+widthVec).toPointF()
                          };
      painter->setPen(miterPen);
      painter->setBrush(brush);
      painter->drawConvexPolygon(points, 4);
      painter->setBrush(brushBackup);
      painter->setPen(penBackup);
      break;
    }
//.........这里部分代码省略.........
开发者ID:alagoutte,项目名称:QCustomPlot,代码行数:101,代码来源:lineending.cpp


注:本文中的QVector2D::normalized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。