From 2a4f07171a1caf4a774d985a41d162ee5866df16 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 18 Jan 2014 20:08:47 +0200 Subject: [PATCH] cosmetix --- src/jelly/Body.cpp | 12 +-- src/jelly/Body.h | 307 +++++++++++++++++++++++++++-------------------------- 2 files changed, 160 insertions(+), 159 deletions(-) rewrite src/jelly/Body.h (94%) diff --git a/src/jelly/Body.cpp b/src/jelly/Body.cpp index 2f192df..9c2b3b4 100644 --- a/src/jelly/Body.cpp +++ b/src/jelly/Body.cpp @@ -8,7 +8,7 @@ namespace JellyPhysics { - void Body::BodyBoundary::log() + void Body::BodyBoundary::log() const { printf("%s(%p)[%4.2f] |", (type == Begin ? "B" : (type == End ? "E" : "V")), body, value); } @@ -340,7 +340,7 @@ namespace JellyPhysics } //-------------------------------------------------------------------- - bool Body::contains( const Vector2& pt ) + bool Body::contains( const Vector2& pt ) const { // basic idea: draw a line from the point to a point known to be outside the body. count the number of // lines in the polygon it intersects. if that number is odd, we are inside. if it's even, we are outside. @@ -378,7 +378,7 @@ namespace JellyPhysics } //-------------------------------------------------------------------- - float Body::getClosestPoint( const Vector2& pt, Vector2& hitPt, Vector2& norm, int& pointA, int& pointB, float& edgeD ) + float Body::getClosestPoint( const Vector2& pt, Vector2& hitPt, Vector2& norm, int& pointA, int& pointB, float& edgeD ) const { hitPt = Vector2::Zero; pointA = -1; @@ -415,7 +415,7 @@ namespace JellyPhysics } //-------------------------------------------------------------------- - float Body::getClosestPointOnEdge( const Vector2& pt, int edgeNum, Vector2& hitPt, Vector2& norm, float& edgeD ) + float Body::getClosestPointOnEdge( const Vector2& pt, int edgeNum, Vector2& hitPt, Vector2& norm, float& edgeD ) const { hitPt = Vector2::Zero; norm = Vector2::Zero; @@ -472,7 +472,7 @@ namespace JellyPhysics } //-------------------------------------------------------------------- - float Body::getClosestPointOnEdgeSquared( const Vector2& pt, int edgeNum, Vector2& hitPt, Vector2& norm, float& edgeD ) + float Body::getClosestPointOnEdgeSquared( const Vector2& pt, int edgeNum, Vector2& hitPt, Vector2& norm, float& edgeD ) const { hitPt = Vector2::Zero; norm = Vector2::Zero; @@ -538,7 +538,7 @@ namespace JellyPhysics } //-------------------------------------------------------------------- - int Body::getClosestPointMass( const Vector2& pos, float& dist ) + int Body::getClosestPointMass( const Vector2& pos, float& dist ) const { float closestSQD = 100000.0f; int closest = -1; diff --git a/src/jelly/Body.h b/src/jelly/Body.h dissimilarity index 94% index d4ed291..e63499a 100644 --- a/src/jelly/Body.h +++ b/src/jelly/Body.h @@ -1,153 +1,154 @@ -#ifndef _BODY_H -#define _BODY_H - -#include - -#include "JellyPrerequisites.h" - -#include "AABB.h" -#include "Bitmask.h" -#include "ClosedShape.h" -#include "PointMass.h" -#include "Vector2.h" - -namespace JellyPhysics -{ - class World; - - class Body - { - protected: - typedef std::vector PointMassList; - - struct EdgeInfo - { - Vector2 dir; // normalized direction vector for this edge. - float length; // length of the edge. - float slope; // slope of the line described by this edge. - }; - - typedef std::vector EdgeInfoList; - - World* mWorld; - ClosedShape mBaseShape; - Vector2List mGlobalShape; - PointMassList mPointMasses; - EdgeInfoList mEdgeInfo; - Vector2 mScale; - Vector2 mDerivedPos; - Vector2 mDerivedVel; - float mDerivedAngle; - float mDerivedOmega; - float mLastAngle; - AABB mAABB; - int mMaterial; - bool mIsStatic; - bool mKinematic; - void* mObjectTag; - float mVelDamping; - - int mPointCount; - float mInvPC; - - bool mIgnoreMe; - - public: - struct BodyBoundary - { - enum BoundaryType { Begin, End, VoidMarker }; - - BoundaryType type; - float value; - - BodyBoundary* next; - BodyBoundary* prev; - - Body* body; - - BodyBoundary() : type(Begin), value(0.0f), next(0), prev(0), body(0) { } - BodyBoundary( Body* b, BoundaryType t, float v ) : next(0), prev(0) { body = b; type = t; value = v; } - - void log(); - }; - - //Bitmask mBitMaskX; - Bitmask mBitMaskY; - - BodyBoundary mBoundStart; - BodyBoundary mBoundEnd; - - Body( World* w ); - Body( World* w, const ClosedShape& shape, float massPerPoint, Vector2 position, float angleInRadians, Vector2 scale, bool kinematic); - Body( World* w, const ClosedShape& shape, std::vector pointMasses, Vector2 position, float angleInRadians, Vector2 scale, bool kinematic); - virtual ~Body(); - - void setShape(ClosedShape shape); - - void setMassAll(float mass); - void setMassIndividual( int index, float mass ); - void setMassFromList( std::vector masses ); - - int getMaterial() { return mMaterial; } - void setMaterial( int val ) { mMaterial = val; } - - void setPositionAngle( const Vector2& pos, float angleInRadians, const Vector2& scale ); - - virtual void setKinematicPosition( const Vector2& pos ) { mDerivedPos = pos; } - virtual void setKinematicAngle( float angleInRadians ) { mDerivedAngle = angleInRadians; } - virtual void setKinematicScale( const Vector2& scale ) { mScale = scale; } - - void derivePositionAndAngle(float elapsed); - - void updateEdgeInfo(bool forceUpdate = false); - - virtual void updateBoundaryValues(bool forceUpdate = false); - - Vector2 getDerivedPosition() { return mDerivedPos; } - float getDerivedAngle() { return mDerivedAngle; } - Vector2 getDerivedVelocity() { return mDerivedVel; } - float getDerivedOmega() { return mDerivedOmega; } - - Vector2 getScale() { return mScale; } - - virtual void accumulateInternalForces() {} - virtual void accumulateExternalForces() {} - - void integrate( float elapsed ); - void dampenVelocity(); - - void updateAABB(float elapsed, bool forceUpdate = false); - const AABB& getAABB() { return mAABB; } - - bool contains( const Vector2& pt ); - - float getClosestPoint( const Vector2& pt, Vector2& hitPt, Vector2& norm, int& pointA, int& pointB, float& edgeD ); - float getClosestPointOnEdge( const Vector2& pt, int edgeNum, Vector2& hitPt, Vector2& norm, float& edgeD ); - float getClosestPointOnEdgeSquared( const Vector2& pt, int edgeNum, Vector2& hitPt, Vector2& norm, float& edgeD ); - int getClosestPointMass( const Vector2& pos, float& dist ); - - int getPointMassCount() { return mPointCount; } - PointMass* getPointMass( int index ) { return &mPointMasses[index]; } - - void addGlobalForce( const Vector2& pt, const Vector2& force ); - - - bool getIsStatic() { return mIsStatic; } - void setIsStatic( bool val ) { mIsStatic = val; } - - bool getIsKinematic() { return mKinematic; } - void setIsKinematic( bool val ) { mKinematic = val; } - - float getVelocityDamping() { return mVelDamping; } - void setVelocityDamping( float val ) { mVelDamping = val; } - - void* getObjectTag() { return mObjectTag; } - void setObjectTag( void* obj ) { mObjectTag = obj; } - - bool getIgnoreMe() { return mIgnoreMe; } - void setIgnoreMe( bool setting ) { mIgnoreMe = setting; } - - }; -} - -#endif // _BODY_H +#ifndef _BODY_H +#define _BODY_H + +#include + +#include "JellyPrerequisites.h" + +#include "AABB.h" +#include "Bitmask.h" +#include "ClosedShape.h" +#include "PointMass.h" +#include "Vector2.h" + + +namespace JellyPhysics { + +class World; + +class Body { +public: + struct BodyBoundary { + enum BoundaryType { Begin, End, VoidMarker }; + + BoundaryType type; + float value; + + BodyBoundary *next; + BodyBoundary *prev; + + Body *body; + + BodyBoundary () : type(Begin), value(0.0f), next(0), prev(0), body(0) {} + BodyBoundary (Body *b, BoundaryType t, float v) : next(0), prev(0) { body = b; type = t; value = v; } + + void log () const; + }; + +public: + Body (World *w); + Body (World *w, const ClosedShape &shape, float massPerPoint, Vector2 position, float angleInRadians, Vector2 scale, bool kinematic); + Body (World *w, const ClosedShape &shape, std::vector pointMasses, Vector2 position, float angleInRadians, Vector2 scale, bool kinematic); + virtual ~Body(); + + void setShape (ClosedShape shape); + + void setMassAll (float mass); + void setMassIndividual (int index, float mass); + void setMassFromList (std::vector masses); + + int getMaterial () const { return mMaterial; } + void setMaterial (int val) { mMaterial = val; } + + void setPositionAngle (const Vector2 &pos, float angleInRadians, const Vector2 &scale); + + virtual void setKinematicPosition (const Vector2 &pos) { mDerivedPos = pos; } + virtual void setKinematicAngle (float angleInRadians) { mDerivedAngle = angleInRadians; } + virtual void setKinematicScale (const Vector2 &scale) { mScale = scale; } + + void derivePositionAndAngle (float elapsed); + + void updateEdgeInfo (bool forceUpdate=false); + + virtual void updateBoundaryValues (bool forceUpdate=false); + + Vector2 getDerivedPosition () const { return mDerivedPos; } + float getDerivedAngle () const { return mDerivedAngle; } + Vector2 getDerivedVelocity () const { return mDerivedVel; } + float getDerivedOmega () const { return mDerivedOmega; } + + Vector2 getScale () const { return mScale; } + + virtual void accumulateInternalForces () {} + virtual void accumulateExternalForces () {} + + void integrate (float elapsed); + void dampenVelocity (); + + void updateAABB (float elapsed, bool forceUpdate=false); + const AABB &getAABB () const { return mAABB; } + + bool contains (const Vector2 &pt) const; + + float getClosestPoint (const Vector2 &pt, Vector2 &hitPt, Vector2 &norm, int &pointA, int &pointB, float &edgeD) const; + float getClosestPointOnEdge (const Vector2 &pt, int edgeNum, Vector2 &hitPt, Vector2 &norm, float &edgeD) const; + float getClosestPointOnEdgeSquared (const Vector2 &pt, int edgeNum, Vector2 &hitPt, Vector2 &norm, float &edgeD) const; + int getClosestPointMass (const Vector2 &pos, float &dist) const; + + int getPointMassCount () const { return mPointCount; } + PointMass *getPointMass (int index) { return &mPointMasses[index]; } + + void addGlobalForce (const Vector2 &pt, const Vector2 &force); + + bool getIsStatic () const { return mIsStatic; } + void setIsStatic (bool val) { mIsStatic = val; } + + bool getIsKinematic () const { return mKinematic; } + void setIsKinematic (bool val) { mKinematic = val; } + + float getVelocityDamping () const { return mVelDamping; } + void setVelocityDamping (float val) { mVelDamping = val; } + + void* getObjectTag () const { return mObjectTag; } + void setObjectTag (void *obj) { mObjectTag = obj; } + + bool getIgnoreMe () const { return mIgnoreMe; } + void setIgnoreMe (bool setting) { mIgnoreMe = setting; } + +public: + //Bitmask mBitMaskX; + Bitmask mBitMaskY; + + BodyBoundary mBoundStart; + BodyBoundary mBoundEnd; + +protected: + typedef std::vector PointMassList; + + struct EdgeInfo { + Vector2 dir; // normalized direction vector for this edge + float length; // length of the edge + float slope; // slope of the line described by this edge + }; + + typedef std::vector EdgeInfoList; + +protected: + World *mWorld; + ClosedShape mBaseShape; + Vector2List mGlobalShape; + PointMassList mPointMasses; + EdgeInfoList mEdgeInfo; + Vector2 mScale; + Vector2 mDerivedPos; + Vector2 mDerivedVel; + float mDerivedAngle; + float mDerivedOmega; + float mLastAngle; + AABB mAABB; + int mMaterial; + bool mIsStatic; + bool mKinematic; + void *mObjectTag; + float mVelDamping; + + int mPointCount; + float mInvPC; + + bool mIgnoreMe; +}; + +} + + +#endif -- 2.11.4.GIT