Changeset 1869
 Timestamp:
 Sep 3, 2012, 10:21:09 PM (8 years ago)
 Location:
 trunk/test/Physics
 Files:

 4 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/Physics/Include/BulletCharacterController.h
r1834 r1869 36 36 #ifdef HAVE_PHYS_USE_BULLET 37 37 38 //SweepCallback used for Swweep Tests. 39 class ClosestNotMeConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback 40 { 41 public: 42 ClosestNotMeConvexResultCallback(btCollisionObject* NewMe, const vec3& NewUp, float MinSlopeDot) : 43 btCollisionWorld::ClosestConvexResultCallback(LOL2BTU_VEC3(vec3(.0f)), LOL2BTU_VEC3(vec3(.0f))), 44 m_me(NewMe), 45 m_up(NewUp), 46 m_min_slope_dot(MinSlopeDot) { } 47 48 virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& ConvexResult, bool NormalInWorld) 38 //SweepCallback used for Swweep Tests. 39 class ClosestNotMeConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback 49 40 { 50 //We hit ourselves, FAIL 51 if (ConvexResult.m_hitCollisionObject == m_me) 52 return btScalar(1.f); 53 54 vec3 WorldHitNomal(.0f); 55 if (NormalInWorld) 56 WorldHitNomal = BT2LOL_VEC3(ConvexResult.m_hitNormalLocal); 57 else //need to transform Normal into worldspace 58 { 59 btVector3 TmpWorldHitNormal = ConvexResult.m_hitCollisionObject>getWorldTransform().getBasis() * ConvexResult.m_hitNormalLocal; 60 WorldHitNomal = BT2LOL_VEC3(TmpWorldHitNormal); 61 } 62 63 float DotUp = dot(m_up, WorldHitNomal); 64 //We hit below the accepted slope_dot, FAIL 65 if (DotUp < m_min_slope_dot) 66 return btScalar(1.f); 67 68 //Continue to next. 69 return ClosestConvexResultCallback::addSingleResult(ConvexResult, NormalInWorld); 70 } 71 protected: 72 btCollisionObject* m_me; 73 const vec3 m_up; 74 float m_min_slope_dot; 75 }; 41 public: 42 ClosestNotMeConvexResultCallback(btCollisionObject* NewMe, const vec3& NewUp, float MinSlopeDot) : 43 btCollisionWorld::ClosestConvexResultCallback(LOL2BTU_VEC3(vec3(.0f)), LOL2BTU_VEC3(vec3(.0f))), 44 m_me(NewMe), 45 m_up(NewUp), 46 m_min_slope_dot(MinSlopeDot) 47 { 48 m_collisionFilterGroup = NewMe>getBroadphaseHandle()>m_collisionFilterGroup; 49 m_collisionFilterMask = NewMe>getBroadphaseHandle()>m_collisionFilterMask; 50 } 51 52 virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& ConvexResult, bool NormalInWorld) 53 { 54 //We hit ourselves, FAIL 55 if (ConvexResult.m_hitCollisionObject == m_me) 56 return btScalar(1.f); 57 58 vec3 WorldHitNomal(.0f); 59 if (NormalInWorld) 60 WorldHitNomal = BT2LOL_VEC3(ConvexResult.m_hitNormalLocal); 61 else //need to transform Normal into worldspace 62 { 63 btVector3 TmpWorldHitNormal = ConvexResult.m_hitCollisionObject>getWorldTransform().getBasis() * ConvexResult.m_hitNormalLocal; 64 WorldHitNomal = BT2LOL_VEC3(TmpWorldHitNormal); 65 } 66 67 float DotUp = dot(m_up, WorldHitNomal); 68 //We hit below the accepted slope_dot, FAIL 69 if (DotUp < m_min_slope_dot) 70 return btScalar(1.f); 71 72 //Continue to next. 73 return ClosestConvexResultCallback::addSingleResult(ConvexResult, NormalInWorld); 74 } 75 protected: 76 btCollisionObject* m_me; 77 const vec3 m_up; 78 float m_min_slope_dot; 79 }; 76 80 77 81 ///BulletKinematicCharacterController is an object that supports a sliding motion in a world. … … 81 85 { 82 86 public: 83 BulletKinematicCharacterController(btPairCachingGhostObject* NewGhostObject, btConvexShape* NewConvexShape, float NewStepHeight, int NewUpAxis=1) 84 { 87 BulletKinematicCharacterController(EasyCharacterController* NewCharacter, btPairCachingGhostObject* NewGhostObject, btConvexShape* NewConvexShape, float NewStepHeight, int NewUpAxis=1) 88 { 89 m_character = NewCharacter; 85 90 m_convex_shape = NewConvexShape; 86 91 m_i_up_axis = NewUpAxis; … … 119 124 120 125 //Returns the reflection Direction of a ray going 'Direction' hitting a surface with Normal 'Normal' from: http://wwwcsstudents.stanford.edu/~adityagp/final/node3.html 121 vec3 GetReflectedDir(const vec3& Direction, const vec3& Normal) 122 { 123 return Direction  (2.f * dot(Direction, Normal) * Normal); 124 } 126 vec3 GetReflectedDir(const vec3& Direction, const vec3& Normal) { return Direction  (2.f * dot(Direction, Normal) * Normal); } 125 127 //Returns the portion of 'direction' that is parallel to 'normal' 126 vec3 ProjectDirOnNorm(const vec3& Direction, const vec3& Normal) 127 { 128 return Normal * dot(Direction, Normal); 129 } 128 vec3 ProjectDirOnNorm(const vec3& Direction, const vec3& Normal) { return Normal * dot(Direction, Normal); } 130 129 //Returns the portion of 'Direction' that is perpindicular to 'Normal' 131 vec3 ProjectDirOnNormPerpindicular(const vec3& Direction, const vec3& Normal) 132 { 133 return Direction  ProjectDirOnNorm(Direction, Normal); 134 } 130 vec3 ProjectDirOnNormPerpindicular(const vec3& Direction, const vec3& Normal) { return Direction  ProjectDirOnNorm(Direction, Normal); } 135 131 //Returns Ghost Object. duh 136 btPairCachingGhostObject* GetGhostObject() 137 { 138 return m_ghost_object; 139 } 132 btPairCachingGhostObject* GetGhostObject() { return m_ghost_object; } 140 133 141 134 //"Real" war functions … … 159 152 void debugDraw(btIDebugDraw* debugDrawer) { } 160 153 161 void SetUpAxis(int NewAxis) 162 { 163 if (NewAxis < 0) 164 NewAxis = 0; 165 if (NewAxis > 2) 166 NewAxis = 2; 167 m_i_up_axis = NewAxis; 168 } 154 void SetUpAxis(int NewAxis) { m_i_up_axis = abs(NewAxis) % 3; } 169 155 170 156 //!!!!!! SHOULD DITCH THAT !!!!!! … … 230 216 private: 231 217 218 EasyCharacterController* m_character; 232 219 btPairCachingGhostObject* m_ghost_object; 233 220 btConvexShape* m_convex_shape; //is also in m_ghost_object, but it needs to be convex, so we store it here to avoid upcast 
trunk/test/Physics/Include/EasyCharacterController.h
r1819 r1869 42 42 43 43 #ifdef HAVE_PHYS_USE_BULLET 44 45 friend class BulletKinematicCharacterController; 44 46 45 47 public: … … 103 105 vec3 m_current_velocity; 104 106 107 //Feedback from Bullet collision : 108 //The idea is : we tell what to do to the BCC at each Hit 109 int MoveDidImpact(int HitType, const ClosestNotMeConvexResultCallback& SweepCallback); 110 105 111 #else // NO PHYSIC IMPLEMENTATION 106 112 
trunk/test/Physics/Src/BulletCharacterController.cpp
r1834 r1869 139 139 140 140 ClosestNotMeConvexResultCallback SweepCallback(m_ghost_object, SweepDirNeg, .0f); 141 SweepCallback.m_collisionFilterGroup = GetGhostObject()>getBroadphaseHandle()>m_collisionFilterGroup;142 SweepCallback.m_collisionFilterMask = GetGhostObject()>getBroadphaseHandle()>m_collisionFilterMask;143 141 144 142 //The sweep test is done with an added margin, so we use it and then discard it 
trunk/test/Physics/Src/EasyCharacterController.cpp
r1819 r1869 63 63 64 64 //m_character = new btKinematicCharacterController(m_pair_caching_object, m_convex_shape, m_step_height, m_up_axis); 65 m_character = new BulletKinematicCharacterController( m_pair_caching_object, m_convex_shape, m_step_height, m_up_axis);65 m_character = new BulletKinematicCharacterController(this, m_pair_caching_object, m_convex_shape, m_step_height, m_up_axis); 66 66 67 67 //Deactivate Character controller basic behaviour. … … 147 147 } 148 148 149 int EasyCharacterController::MoveDidImpact(int HitType, const ClosestNotMeConvexResultCallback& SweepCallback) 150 { 151 return 0; 152 } 153 149 154 #endif // HAVE_PHYS_USE_BULLET 150 155
Note: See TracChangeset
for help on using the changeset viewer.