From 5f1fbae1581a954d4854c0826b976bcb846b0293 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 19 Jan 2014 21:26:19 +0200 Subject: [PATCH] removed VectorTools namespace --- src/jelly/Body.cpp | 4 +- src/jelly/ClosedShape.cpp | 4 +- src/jelly/SpringBody.cpp | 8 ++-- src/jelly/VectorTools.cpp | 8 ++-- src/jelly/VectorTools.h | 96 +++++++++++++++++++++++------------------------ src/main.cpp | 4 +- 6 files changed, 60 insertions(+), 64 deletions(-) diff --git a/src/jelly/Body.cpp b/src/jelly/Body.cpp index db04429..85f08df 100644 --- a/src/jelly/Body.cpp +++ b/src/jelly/Body.cpp @@ -211,7 +211,7 @@ void Body::derivePositionAndAngle (float elapsed) { if (dot > 1.0f) dot = 1.0f; if (dot < -1.0f) dot = -1.0f; float thisAngle = acosf(dot); - if (!JellyPhysics::VectorTools::isCCW(baseNorm, curNorm)) thisAngle = -thisAngle; + if (!isCCW(baseNorm, curNorm)) thisAngle = -thisAngle; if (i == 0) { originalSign = (thisAngle >= 0.0f ? 1 : -1); originalAngle = thisAngle; @@ -447,7 +447,7 @@ void Body::addGlobalForce (const Vector2 &pt, const Vector2 &force) { float torqueF = R.crossProduct(force); for (PointMassList::iterator it = mPointMasses.begin(); it != mPointMasses.end(); ++it) { Vector2 toPt = (*it).Position-mDerivedPos; - Vector2 torque = JellyPhysics::VectorTools::rotateVector(toPt, -HALF_PI); + Vector2 torque = rotateVector(toPt, -HALF_PI); (*it).Force += torque*torqueF; (*it).Force += force; } diff --git a/src/jelly/ClosedShape.cpp b/src/jelly/ClosedShape.cpp index 57d4639..1ac686c 100644 --- a/src/jelly/ClosedShape.cpp +++ b/src/jelly/ClosedShape.cpp @@ -58,7 +58,7 @@ Vector2List ClosedShape::transformVertices (const Vector2 &worldPos, float angle for (unsigned int i = 0; i < c; ++i) { // rotate the point, and then translate v = ret[i]*scale; - v = JellyPhysics::VectorTools::rotateVector(v, angleInRadians); + v = rotateVector(v, angleInRadians); v += worldPos; ret[i] = v; } @@ -73,7 +73,7 @@ void ClosedShape::transformVertices (const Vector2 &worldPos, float angleInRadia for (Vector2List::const_iterator it = mLocalVertices.begin(); it != mLocalVertices.end(); ++it, ++out) { // rotate the point, and then translate Vector2 v =(*it)*scale; - v = JellyPhysics::VectorTools::rotateVector(v, c, s); + v = rotateVector(v, c, s); v += worldPos; (*out) = v; } diff --git a/src/jelly/SpringBody.cpp b/src/jelly/SpringBody.cpp index d493a94..bb897a7 100644 --- a/src/jelly/SpringBody.cpp +++ b/src/jelly/SpringBody.cpp @@ -131,10 +131,10 @@ void SpringBody::accumulateInternalForces () { PointMass& pmB = mPointMasses[s.pointMassB]; if (i < mPointCount) { // spring forces for the edges of the shape can used the cached edge information to reduce calculations - force = VectorTools::calculateSpringForce(-mEdgeInfo[i].dir, mEdgeInfo[i].length, pmA.Velocity, pmB.Velocity, s.springD, s.springK, s.damping); + force = calculateSpringForce(-mEdgeInfo[i].dir, mEdgeInfo[i].length, pmA.Velocity, pmB.Velocity, s.springD, s.springK, s.damping); } else { // these are other internal springs, they must be fully calculated each frame - force = VectorTools::calculateSpringForce(pmA.Position, pmA.Velocity, pmB.Position, pmB.Velocity, s.springD, s.springK, s.damping); + force = calculateSpringForce(pmA.Position, pmA.Velocity, pmB.Position, pmB.Velocity, s.springD, s.springK, s.damping); } pmA.Force += force; pmB.Force -= force; @@ -146,9 +146,9 @@ void SpringBody::accumulateInternalForces () { PointMass& pmA = mPointMasses[i]; if (mShapeSpringK > 0) { if (!mKinematic) { - force = VectorTools::calculateSpringForce(pmA.Position, pmA.Velocity, mGlobalShape[i], pmA.Velocity, 0.0f, mShapeSpringK, mShapeSpringDamp); + force = calculateSpringForce(pmA.Position, pmA.Velocity, mGlobalShape[i], pmA.Velocity, 0.0f, mShapeSpringK, mShapeSpringDamp); } else { - force = VectorTools::calculateSpringForce(pmA.Position, pmA.Velocity, mGlobalShape[i], Vector2::Zero, 0.0f, mShapeSpringK, mShapeSpringDamp); + force = calculateSpringForce(pmA.Position, pmA.Velocity, mGlobalShape[i], Vector2::Zero, 0.0f, mShapeSpringK, mShapeSpringDamp); } pmA.Force += force; } diff --git a/src/jelly/VectorTools.cpp b/src/jelly/VectorTools.cpp index bcd927e..da052ed 100644 --- a/src/jelly/VectorTools.cpp +++ b/src/jelly/VectorTools.cpp @@ -25,7 +25,7 @@ namespace JellyPhysics { -bool VectorTools::lineIntersect (const Vector2 &ptA, const Vector2 &ptB, const Vector2 &ptC, const Vector2 &ptD, Vector2 &hitPt, float &Ua, float &Ub) { +bool lineIntersect (const Vector2 &ptA, const Vector2 &ptB, const Vector2 &ptC, const Vector2 &ptD, Vector2 &hitPt, float &Ua, float &Ub) { hitPt = Vector2::Zero; Ua = Ub = 0.0f; float denom = ((ptD.Y-ptC.Y)*(ptB.X-ptA.X))-((ptD.X-ptC.X)*(ptB.Y-ptA.Y)); @@ -44,13 +44,13 @@ bool VectorTools::lineIntersect (const Vector2 &ptA, const Vector2 &ptB, const V } -bool VectorTools::lineIntersect (const Vector2 &ptA, const Vector2 &ptB, const Vector2 &ptC, const Vector2 &ptD, Vector2 &hitPt) { +bool lineIntersect (const Vector2 &ptA, const Vector2 &ptB, const Vector2 &ptC, const Vector2 &ptD, Vector2 &hitPt) { float Ua, Ub; return lineIntersect(ptA, ptB, ptC, ptD, hitPt, Ua, Ub); } -Vector2 VectorTools::calculateSpringForce ( +Vector2 calculateSpringForce ( const Vector2 &posA, const Vector2 &velA, const Vector2 &posB, const Vector2 &velB, float springD, float springK, float damping) @@ -66,7 +66,7 @@ Vector2 VectorTools::calculateSpringForce ( } -Vector2 VectorTools::calculateSpringForce ( +Vector2 calculateSpringForce ( const Vector2 &dir, float length, const Vector2 &velA, const Vector2 &velB, float springD, float springK, float damping) diff --git a/src/jelly/VectorTools.h b/src/jelly/VectorTools.h index 47befd4..f509368 100644 --- a/src/jelly/VectorTools.h +++ b/src/jelly/VectorTools.h @@ -32,56 +32,52 @@ namespace JellyPhysics { -class VectorTools { -public: - static inline Vector2 rotateVector (const Vector2 &vecIn, float angleRadians) { - Vector2 ret; - float c = cosf(angleRadians); - float s = sinf(angleRadians); - ret.X = (c*vecIn.X)-(s*vecIn.Y); - ret.Y = (c*vecIn.Y)+(s*vecIn.X); - return ret; - } - - static inline Vector2 rotateVector (const Vector2 &vecIn, float cosAngle, float sinAngle) { - Vector2 ret; - ret.X = (cosAngle*vecIn.X)-(sinAngle*vecIn.Y); - ret.Y = (cosAngle*vecIn.Y)+(sinAngle*vecIn.X); - return ret; - } - - static inline Vector2 reflectVector (const Vector2 &V, const Vector2 &N) { - return V-(N*(V.dotProduct(N)*2.0f)); - } - - static inline void reflectVector (const Vector2 &V, const Vector2 &N, Vector2 &vOut) { - float dot = V.dotProduct(N); - vOut = V-(N*(2.0f*dot)); - } - - static inline bool isCCW (const Vector2 &A, const Vector2 &B) { - Vector2 perp = A.getPerpendicular(); - float dot = B.dotProduct(perp); - return (dot >= 0.0f); - } - - static bool lineIntersect (const Vector2 &ptA, const Vector2 &ptB, const Vector2 &ptC, const Vector2 &ptD, Vector2 &hitPt, float &Ua, float &Ub); - static bool lineIntersect (const Vector2 &ptA, const Vector2 &ptB, const Vector2 &ptC, const Vector2 &ptD, Vector2 &hitPt); - - static Vector2 calculateSpringForce ( - const Vector2 &posA, const Vector2 &velA, - const Vector2 &posB, const Vector2 &velB, - float springD, float springK, float damping); - - static Vector2 calculateSpringForce ( - const Vector2 &dir, float length, - const Vector2 &velA, const Vector2 &velB, - float springD, float springK, float damping); - - static inline float degToRad (float deg) { return deg*(PI_OVER_ONE_EIGHTY); } - static inline float radToDeg (float rad) { return rad*(ONE_EIGHTY_OVER_PI); } - -}; +static inline Vector2 rotateVector (const Vector2 &vecIn, float angleRadians) { + Vector2 ret; + float c = cosf(angleRadians); + float s = sinf(angleRadians); + ret.X = (c*vecIn.X)-(s*vecIn.Y); + ret.Y = (c*vecIn.Y)+(s*vecIn.X); + return ret; +} + +static inline Vector2 rotateVector (const Vector2 &vecIn, float cosAngle, float sinAngle) { + Vector2 ret; + ret.X = (cosAngle*vecIn.X)-(sinAngle*vecIn.Y); + ret.Y = (cosAngle*vecIn.Y)+(sinAngle*vecIn.X); + return ret; +} + +static inline Vector2 reflectVector (const Vector2 &V, const Vector2 &N) { + return V-(N*(V.dotProduct(N)*2.0f)); +} + +static inline void reflectVector (const Vector2 &V, const Vector2 &N, Vector2 &vOut) { + float dot = V.dotProduct(N); + vOut = V-(N*(2.0f*dot)); +} + +static inline bool isCCW (const Vector2 &A, const Vector2 &B) { + Vector2 perp = A.getPerpendicular(); + float dot = B.dotProduct(perp); + return (dot >= 0.0f); +} + +bool lineIntersect (const Vector2 &ptA, const Vector2 &ptB, const Vector2 &ptC, const Vector2 &ptD, Vector2 &hitPt, float &Ua, float &Ub); +bool lineIntersect (const Vector2 &ptA, const Vector2 &ptB, const Vector2 &ptC, const Vector2 &ptD, Vector2 &hitPt); + +Vector2 calculateSpringForce ( + const Vector2 &posA, const Vector2 &velA, + const Vector2 &posB, const Vector2 &velB, + float springD, float springK, float damping); + +Vector2 calculateSpringForce ( + const Vector2 &dir, float length, + const Vector2 &velA, const Vector2 &velB, + float springD, float springK, float damping); + +static inline float degToRad (float deg) { return deg*(PI_OVER_ONE_EIGHTY); } +static inline float radToDeg (float rad) { return rad*(ONE_EIGHTY_OVER_PI); } } diff --git a/src/main.cpp b/src/main.cpp index 082810c..506a17e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -154,7 +154,7 @@ static void createBall (float x, float y) { ClosedShape ball; ball.begin(); for (int i = 0; i < 360; i += 20) { - ball.addVertex(Vector2(cosf(VectorTools::degToRad((float)-i)), sinf(VectorTools::degToRad((float)-i)))); + ball.addVertex(Vector2(cosf(degToRad((float)-i)), sinf(degToRad((float)-i)))); } ball.finish(); new FallingPressureBody(mWorld, ball, 1.0f, 40.0f, 10.0f, 1.0f, 300.0f, 20.0f, Vector2(x, y), 0, Vector2::One); @@ -225,7 +225,7 @@ static void process_mousedown (SDL_MouseButtonEvent *ev) { shape.addVertex(Vector2( 0.0f, -1.0f)); shape.finish(); - FallingBody *body = new FallingBody(mWorld, shape, 1.0f, 300.0f, 10.0f, Vector2(x, y), VectorTools::degToRad((float)rand()/RAND_MAX*360.0f), Vector2::One); + FallingBody *body = new FallingBody(mWorld, shape, 1.0f, 300.0f, 10.0f, Vector2(x, y), degToRad((float)rand()/RAND_MAX*360.0f), Vector2::One); body->addInternalSpring(0, 2, 400.0f, 12.0f); body->addInternalSpring(1, 3, 400.0f, 12.0f); return; -- 2.11.4.GIT