本文整理汇总了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();
}
示例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();
}
示例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);
}
示例4: Object
Cone::Cone(const QVector2D &pc, const QVector3D &pos)
: Object(AMBIENT, DIFFUSE, SPECULAR, SHININESS,REFLECTION, REFRACTION)
{
c = pc.normalized();
position = pos;
}
示例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();
}
示例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();
}
示例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;
}
//.........这里部分代码省略.........