本文整理汇总了C++中QVector2D::lengthSquared方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector2D::lengthSquared方法的具体用法?C++ QVector2D::lengthSquared怎么用?C++ QVector2D::lengthSquared使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector2D
的用法示例。
在下文中一共展示了QVector2D::lengthSquared方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: projection_on_curve
float Window::projection_on_curve(const QVector2D& projected) {
//This is the distance where the curves changed in terms of the window size
const float radius = 0.8f;
float z = 0.0f;
if (projected.lengthSquared() <= (0.5f * radius * radius)) {
//Inside the sphere
z = sqrt(radius * radius - projected.lengthSquared());
}
else {
//Outside of the sphere using hyperbolic sheet
z = (0.5f * radius * radius) / projected.length();
}
return z;
}
示例3:
/**
* Computes the intersection between two line segments on the XY plane
* Segments must intersect within their extents for the intersection to be valid
* z coordinate is ignored
**/
bool Polygon3D::segmentSegmentIntersectXY(QVector2D &a, QVector2D &b, QVector2D &c, QVector2D &d,
float *tab, float *tcd, bool segmentOnly, QVector2D &intPoint)
{
QVector2D u = b - a;
QVector2D v = d - c;
if( u.lengthSquared() < MTC_FLOAT_TOL || v.lengthSquared() < MTC_FLOAT_TOL )
{
return false;
}
float numer = v.x()*(c.y()-a.y()) + v.y()*(a.x()-c.x());
float denom = u.y()*v.x() - u.x()*v.y();
if (denom == 0.0f) {
// they are parallel
*tab = 0.0f;
*tcd = 0.0f;
return false;
}
float t0 = numer / denom;
QVector2D ipt = a + t0*u;
QVector2D tmp = ipt - c;
float t1;
if (QVector2D::dotProduct(tmp, v) > 0.0f){
t1 = tmp.length() / v.length();
}
else {
t1 = -1.0f * tmp.length() / v.length();
}
//Check if intersection is within segments
if( !( (t0 >= MTC_FLOAT_TOL) && (t0 <= 1.0f-MTC_FLOAT_TOL) && (t1 >= MTC_FLOAT_TOL) && (t1 <= 1.0f-MTC_FLOAT_TOL) ) ){
return false;
}
*tab = t0;
*tcd = t1;
QVector2D dirVec = b-a;
intPoint = a+(*tab)*dirVec;
return true;
}
示例4: 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;
}
示例5: p
static QList<int> bounce(QPoint & p0, QVector2D vel, QSize size, const QRectList & rectsIn)
{
QList<int> touched;
#if 0
QList<QPair<int, QRect> > rects;
QRect swept = QRect(p0, size).united(QRect(movedBy(p0, vel), size));
for (int i = 0; i < rectsIn.count(); ++i)
if (rectsIn.at(i).intersects(swept)) rects << qMakePair(i, rectsIn.at(i));
QVector2D p(p0.x(), p0.y());
QVector2D d(td.manhattanNormalize(vel));
while (vel.lengthSquared() > d.lengthSquared()) {
}
#endif
return touched;
}