From: Patrik Gornicz Date: Wed, 21 Jan 2009 15:59:49 +0000 (-0500) Subject: fixed polygon penitration due to CoR X-Git-Tag: physics-premerge~59 X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=commitdiff_plain;h=19c2da50f7f1ce9854c718e6c1c545ccc2afbb5f;p=libbear.git fixed polygon penitration due to CoR --- diff --git a/Makefile b/Makefile index f3e6ad8..77463d3 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,8 @@ ${BLDDIRS}: ${Q1}${PRNTFMT} "mkdir" "$@" ${Q2}mkdir -p $@ +#${SRCSDIR}%.cpp: ${SRCSDIR}%.h + # cause the below directory rules to work out .SECONDEXPANSION: diff --git a/src/Entities/PhysicsEntity.cpp b/src/Entities/PhysicsEntity.cpp index 9daff3a..d42d271 100644 --- a/src/Entities/PhysicsEntity.cpp +++ b/src/Entities/PhysicsEntity.cpp @@ -85,3 +85,8 @@ void PhysicsEntity::applyImpulse(const Vector2& impulse, const Vector2& at) { velocity += impulse; } + +void PhysicsEntity::applyNudge(const Vector2& vecPush) +{ + position += vecPush; +} diff --git a/src/Entities/PhysicsEntity.h b/src/Entities/PhysicsEntity.h index b4b5b9e..8e83266 100644 --- a/src/Entities/PhysicsEntity.h +++ b/src/Entities/PhysicsEntity.h @@ -43,6 +43,8 @@ class PhysicsEntity: public Entity virtual void applyImpulse(const Vector2& impulse); virtual void applyImpulse(const Vector2& impulse, const Vector2& at); + virtual void applyNudge(const Vector2& vecPush); + //protected: Vector2 force; diff --git a/src/collisionManager.cpp b/src/collisionManager.cpp index 8aa2dc7..95a2193 100644 --- a/src/collisionManager.cpp +++ b/src/collisionManager.cpp @@ -273,8 +273,8 @@ void applyCollision(Polygon* pPoly, Ball* pBall) // CoR penetration fix, adds the jitters // from center to point - //Vector2 CollP = normal / normal.Length * Ball.Radius; - //Ball.Position = Info.Point + CollP; + Vector2 vecCollP = vecNorm / vecNorm.length() * pBall->radius; + pBall->applyNudge(cInfo.point + vecCollP - pBall->positionRaw()); } bool getInfo(const Ball* b1, const Ball* b2, CollisionInfo* pcInfo)