X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?p=physics.git;a=blobdiff_plain;f=src%2Fmathw.cpp;h=2b71dece6336c80fc9ab372f1cdfc3327488c838;hp=eda47819fbfe6eea5f68763c221044967751c244;hb=9d6dea5f1cfd43cfa136241b352830371acfdc88;hpb=e86c86b38b25bcb463943dc166b60f236aa4af10 diff --git a/src/mathw.cpp b/src/mathw.cpp index eda4781..2b71dec 100644 --- a/src/mathw.cpp +++ b/src/mathw.cpp @@ -39,31 +39,31 @@ Vector2 vectorToLine float lineSize = (float) sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); if (lineSize == 0) - return Vector2(x1 - vec.x, y1 - vec.y); + return Vector2(x1 - vec.m_fX, y1 - vec.m_fY); - float u = ((vec.x - x1) * (x2 - x1) - + (vec.y - y1) * (y2 - y1)) / (lineSize * lineSize); + float u = ((vec.m_fX - x1) * (x2 - x1) + + (vec.m_fY - y1) * (y2 - y1)) / (lineSize * lineSize); if (u < 0) - return Vector2(x1 - vec.x, y1 - vec.y); + return Vector2(x1 - vec.m_fX, y1 - vec.m_fY); else if (u > 1) - return Vector2(x2 - vec.x, y2 - vec.y); + return Vector2(x2 - vec.m_fX, y2 - vec.m_fY); else { float ix = x1 + u * (x2 - x1); float iy = y1 + u * (y2 - y1); - return Vector2(ix - vec.x, iy - vec.y); + return Vector2(ix - vec.m_fX, iy - vec.m_fY); } } Vector2 perp(const Vector2& vec) { - return Vector2(-vec.y, vec.x); + return Vector2(-vec.m_fY, vec.m_fX); } float dot(const Vector2& vec1, const Vector2& vec2) { - return vec1.x * vec2.x + vec1.y * vec2.y; + return vec1.m_fX * vec2.m_fX + vec1.m_fY * vec2.m_fY; } //TODO float Vector2::projectionCoeff(const Vector2* vec) const;