本文整理汇总了C++中QVector2D::isNull方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector2D::isNull方法的具体用法?C++ QVector2D::isNull怎么用?C++ QVector2D::isNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector2D
的用法示例。
在下文中一共展示了QVector2D::isNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: distanceToPoint
/*!
\since 5.1
Returns the distance that this vertex is from a line defined
by \a point and the unit vector \a direction.
If \a direction is a null vector, then it does not define a line.
In that case, the distance from \a point to this vertex is returned.
\sa distanceToPoint()
*/
float QVector2D::distanceToLine
(const QVector2D& point, const QVector2D& direction) const
{
if (direction.isNull())
return (*this - point).length();
QVector2D p = point + dotProduct(*this - point, direction) * direction;
return (*this - p).length();
}
示例2: Shoot
Bullet* Cannon::Shoot(Enemy *enemy, long elapsed)
{
if (elapsed - lastshot < shotinterval) return 0;
int xa = this->pixmap.size().width() - this->SizeX;
int ya = this->pixmap.size().height() - this->SizeY;
QVector2D tcenter(center.x() - xa * 0.5, center.y() - ya * 0.5);
QVector2D target = GetInterSect(enemy->center, enemy->next_checkpoint,
Bullet::speed, Enemy::speed,
tcenter, enemy->center);
if (target.isNull())
target = GetInterSect2((enemy->center - enemy->next_checkpoint).length(),
enemy->next_checkpoint, enemy->next_checkpoint2,
Bullet::speed, Enemy::speed,
tcenter, enemy->center);
if (target.isNull() || (this->center - target).length() > this->range)
return 0;
lastshot = elapsed;
Bullet*b = new Bullet(tcenter, target, elapsed, QPixmap("bullet.png"));
b->enemy = enemy;
return b;
}
示例3: rayCircleIntersection
QVector2D NavigationMath::rayCircleIntersection(
bool & valid
, const QVector2D & origin
, const QVector2D & ray
, const float radius)
{
if(ray.isNull())
{
valid = false;
return QVector2D();
}
const float a = ray.lengthSquared();
const float b = 2. * QVector2D::dotProduct(ray, origin);
const float c = origin.lengthSquared() - static_cast<float>(radius * radius);
const float delta = b * b - 4. * a * c;
if (delta < 0.0)
{
valid = false;
return QVector2D();
}
const float s = sqrt(delta);
// the two intersections
const float t0 = (-b + s) / (2.0 * a);
const float t1 = (-b - s) / (2.0 * a);
// nearest one
const float t = qMin<float>(t0, t1);
valid = true;
return t * ray + origin;
}