void TCompCharacterController::AddImpulse(const VEC3& impulse, bool prevalent) { PROFILE_FUNCTION("add impulse"); assert(isValid(m_speed)); if (prevalent) { if (!sameSign(m_speed.x, impulse.x)) m_speed.x = 0; if (!sameSign(m_speed.y, impulse.y)) m_speed.y = 0; if (!sameSign(m_speed.z, impulse.z)) m_speed.z = 0; } m_speed.x += impulse.x; m_speed.y += impulse.y; m_speed.z += impulse.z; assert(isValid(m_speed)); }
void operator*=(FValue & f1,FValue f2) { bool x = f1.isConstant() && f2.isConstant(); if(sameSign(f1,f2)) { if(nonZero(f1) && nonZero(f2)) { f1 = E_POSITIVE; if(x) f1.assertConst(); return; }; f1 = E_NONNEG; } else if(isSigned(f1) && isSigned(f2)) { if(nonZero(f1) && nonZero(f2)) { f1 = E_NEGATIVE; if(x) f1.assertConst(); return; }; f1 = E_NONPOS; } else { f1 = E_ALL; }; if(x) f1.assertConst(); };
// A slight modification of the false position algorithm on wikipedia. // This only works for the ROCsq-x functions. It might be nice to have // the function as an argument, but that would be awkward in java6. // NOTE: It is something to consider for java8 (or whenever lambda // expressions make it into the language), depending on how closures // and turn out. Same goes for the newton's method // algorithm in Helpers.java static jfloat falsePositionROCsqMinusX(Curve *pCurve, jfloat x0, jfloat x1, const jfloat x, const jfloat err) { const jint iterLimit = 100; jint side = 0; jfloat t = x1, ft = eliminateInf(ROCsq(pCurve, t) - x); jfloat s = x0, fs = eliminateInf(ROCsq(pCurve, s) - x); jfloat r = s, fr; jint i; for (i = 0; i < iterLimit && fabs(t - s) > err * fabs(t + s); i++) { r = (fs * t - ft * s) / (fs - ft); fr = ROCsq(pCurve, r) - x; if (sameSign(fr, ft)) { ft = fr; t = r; if (side < 0) { fs /= (1 << (-side)); side--; } else { side = -1; } } else if (fr * fs > 0) { fs = fr; s = r; if (side > 0) { ft /= (1 << side); side++; } else { side = 1; } } else { break; } } return r; }
template <class R> void CEchelonReducer_VersionA<R>::reduce() { rank = 0; int m = X.generatingVertices.size(); for (int j = 0; j < X.getSuperSpaceDimension(); j++) { // Search non-zero element in this column at row i (rank < i < m) bool found = false; for (int i0 = rank; (!found && (i0 < m)); i0++) { if (X(i0, j) != 0) found = true; } if (found) { pivotColumns.push_back(j); rank++; for (int i = m - 1; i >= rank; i--) { while (X(i, j) != 0) { R z = X(i - 1, j).getAbs() / X(i, j).getAbs(); R s = sameSign(X(i, j), X(i - 1, j)) ? -z : z; X.addVertices(i - 1, i, s, j); X.swapVertices(i - 1, i); } } } } }
bool QTessellatorPrivate::Edge::intersect(const Edge &other, Q27Dot5 *y, bool *det_positive) const { qint64 a1 = v1->y - v0->y; qint64 b1 = v0->x - v1->x; qint64 a2 = other.v1->y - other.v0->y; qint64 b2 = other.v0->x - other.v1->x; qint64 det = a1 * b2 - a2 * b1; if (det == 0) return false; qint64 c1 = qint64(v1->x) * v0->y - qint64(v0->x) * v1->y; qint64 r3 = a1 * other.v0->x + b1 * other.v0->y + c1; qint64 r4 = a1 * other.v1->x + b1 * other.v1->y + c1; // Check signs of r3 and r4. If both point 3 and point 4 lie on // same side of line 1, the line segments do not intersect. QDEBUG() << " " << r3 << r4; if (r3 != 0 && r4 != 0 && sameSign( r3, r4 )) return false; qint64 c2 = qint64(other.v1->x) * other.v0->y - qint64(other.v0->x) * other.v1->y; qint64 r1 = a2 * v0->x + b2 * v0->y + c2; qint64 r2 = a2 * v1->x + b2 * v1->y + c2; // Check signs of r1 and r2. If both point 1 and point 2 lie // on same side of second line segment, the line segments do not intersect. QDEBUG() << " " << r1 << r2; if (r1 != 0 && r2 != 0 && sameSign( r1, r2 )) return false; // The det/2 is to get rounding instead of truncating. It // is added or subtracted to the numerator, depending upon the // sign of the numerator. qint64 offset = det < 0 ? -det : det; offset >>= 1; qint64 num = a2 * c1 - a1 * c2; *y = ( num < 0 ? num - offset : num + offset ) / det; *det_positive = (det > 0); return true; }
void findNext() { sum = values[i]; while(i < values.size() - 1 && sameSign(values[i + 1], values[i])) { sum += values[i + 1]; i++; } }
void update(FValue & f1,FValue f2) { if(f1 == E_ZERO || f2 == E_ZERO) { f1 = mostExtreme(f1,f2); f1 = f1<2?FValue(f1.toInt()+2):f1; } else if(sameSign(f1,f2)) { f1 = max(f1,f2); } else f1 = E_ALL; };
void operator+=(FValue & f1,FValue f2) { bool x = f1.isConstant() && f2.isConstant(); if(sameSign(f1,f2)) { FValue f = mostExtreme(f1,f2); if(f1 == E_ZERO || f2 == E_ZERO) { f1 = f<2?FValue(f.toInt()+2):f; } } else { f1 = E_ALL; }; if(x) f1.assertConst(); };
template <class R> void CEchelonReducer_VersionC<R>::reduce() { rank = 0; for (int j = 0; j < X.getSuperSpaceDimension(); j++) { for (int i = X.generatingVertices.size() - 1; i > rank; i--) { while (X(i, j) != 0) { R z = X(i - 1, j).getAbs() / X(i, j).getAbs(); R s = sameSign(X(i, j), X(i - 1, j)) ? -z : z; X.addVertices(i - 1, i, s, j); X.swapVertices(i - 1, i); } } if (X(rank, j) != 0) { pivotColumns.push_back(j); rank++; } } }