Changeset 1834 for trunk/test
 Timestamp:
 Aug 29, 2012, 11:20:20 PM (8 years ago)
 Location:
 trunk/test
 Files:

 4 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/BtPhysTest.cpp
r1819 r1834 53 53 #define USE_PLATFORM 1 54 54 #define USE_ROPE 0 55 #define USE_BODIES 055 #define USE_BODIES 1 56 56 #define USE_ROTATION 0 57 57 #define USE_CHARACTER 1 … … 59 59 #define IPT_MOVE_FORWARD "Move_Forward" 60 60 #define IPT_MOVE_BACKWARD "Move_Backward" 61 #define IPT_MOVE_STRAFE_LEFT "Strafe_Left" 62 #define IPT_MOVE_STRAFE_RIGHT "Strafe_right" 61 #define IPT_MOVE_LEFT "Move_Left" 62 #define IPT_MOVE_RIGHT "Move_Right" 63 #define IPT_MOVE_UP "Move_Up" 64 #define IPT_MOVE_DOWN "Move_Down" 63 65 #define IPT_MOVE_JUMP "Move_Jump" 64 66 … … 172 174 Input::LinkActionToKey(IPT_MOVE_FORWARD, Key::Up); 173 175 Input::LinkActionToKey(IPT_MOVE_BACKWARD, Key::Down); 174 Input::LinkActionToKey(IPT_MOVE_ STRAFE_LEFT,Key::Left);175 Input::LinkActionToKey(IPT_MOVE_ STRAFE_RIGHT,Key::Right);176 Input::LinkActionToKey(IPT_MOVE_LEFT, Key::Left); 177 Input::LinkActionToKey(IPT_MOVE_RIGHT, Key::Right); 176 178 Input::LinkActionToKey(IPT_MOVE_JUMP, Key::Space); 179 Input::LinkActionToKey(IPT_MOVE_UP, Key::PageUp); 180 Input::LinkActionToKey(IPT_MOVE_DOWN, Key::PageDown); 177 181 178 182 //NewPhyobj>GetCharacter()>AttachTo(BasePhyobj>GetPhysic(), true, true); … … 315 319 mat4 CtlrMx = Character>GetTransform(); 316 320 317 int HMovement = Input::GetStatus(IPT_MOVE_ STRAFE_RIGHT)  Input::GetStatus(IPT_MOVE_STRAFE_LEFT);321 int HMovement = Input::GetStatus(IPT_MOVE_RIGHT)  Input::GetStatus(IPT_MOVE_LEFT); 318 322 int VMovement = Input::GetStatus(IPT_MOVE_FORWARD)  Input::GetStatus(IPT_MOVE_BACKWARD); 319 int RMovement = 0;//Input::GetButtonState(280 /*SDLK_PAGEUP*/)  Input::GetButtonState(281 /*SDLK_PAGEDOWN*/);323 int RMovement = Input::GetStatus(IPT_MOVE_UP)  Input::GetStatus(IPT_MOVE_DOWN); 320 324 vec3 CharMove = vec3((float)VMovement * seconds * 4.f, (float)RMovement * seconds * 10.f, (float)HMovement * seconds * 4.f); 321 325 
trunk/test/PhysicObject.h
r1785 r1834 97 97 Array<char const *> MeshRand; 98 98 99 MeshRand << "[sc#add afcb2 2 2 .1]"; 100 MeshRand << "[sc#dad afcb2 2 2 .1]"; 101 MeshRand << "[sc#dda afcb2 2 2 .1]"; 102 MeshRand << "[sc#daa afcb2 2 2 .1]"; 103 MeshRand << "[sc#ada afcb2 2 2 .1]"; 104 MeshRand << "[sc#aad afcb2 2 2 .1]"; 99 //MeshRand << "[sc#add afcb2 2 2 .1]"; 100 //MeshRand << "[sc#dad afcb2 2 2 .1]"; 101 //MeshRand << "[sc#dda afcb2 2 2 .1]"; 102 //MeshRand << "[sc#daa afcb2 2 2 .1]"; 103 //MeshRand << "[sc#ada afcb2 2 2 .1]"; 104 //MeshRand << "[sc#aad afcb2 2 2 .1]"; 105 MeshRand << "[sc#add afcb1.7 1.7 1.7 0][sc#000 afcb1.9 1.9 1.9 0 sx1 sy1 sz1]"; 106 MeshRand << "[sc#dad afcb1.7 1.7 1.7 0][sc#000 afcb1.9 1.9 1.9 0 sx1 sy1 sz1]"; 107 MeshRand << "[sc#dda afcb1.7 1.7 1.7 0][sc#000 afcb1.9 1.9 1.9 0 sx1 sy1 sz1]"; 108 MeshRand << "[sc#daa afcb1.7 1.7 1.7 0][sc#000 afcb1.9 1.9 1.9 0 sx1 sy1 sz1]"; 109 MeshRand << "[sc#ada afcb1.7 1.7 1.7 0][sc#000 afcb1.9 1.9 1.9 0 sx1 sy1 sz1]"; 110 MeshRand << "[sc#aad afcb1.7 1.7 1.7 0][sc#000 afcb1.9 1.9 1.9 0 sx1 sy1 sz1]"; 105 111 106 112 int SphereLimit = MeshRand.Count(); 
trunk/test/Physics/Include/BulletCharacterController.h
r1819 r1834 35 35 #ifdef USE_LOL_CTRLR_CHARAC 36 36 #ifdef HAVE_PHYS_USE_BULLET 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) 49 { 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 }; 37 76 38 77 ///BulletKinematicCharacterController is an object that supports a sliding motion in a world. … … 45 84 { 46 85 m_convex_shape = NewConvexShape; 47 m_ up_axis = NewUpAxis;86 m_i_up_axis = NewUpAxis; 48 87 m_ghost_object = NewGhostObject; 49 88 m_step_height = NewStepHeight; … … 57 96 m_vertical_velocity = .0f; 58 97 m_vertical_offset = .0f; 59 m_ gravity = 9.8f * 3.f; // 3G acceleration.98 m_f_gravity = 9.8f * 3.f; // 3G acceleration. 60 99 m_fall_speed = 55.f; // Terminal velocity of a sky diver in m/s. 61 100 m_jump_speed = 10.f; // ? … … 103 142 bool RecoverFromPenetration(btCollisionWorld* CollisionWorld); 104 143 void UpdateTargetOnHit(const vec3& hit_normal, float TangentMag = .0f, float NormalMag = 1.f); 105 void StepUp(btCollisionWorld* CollisionWorld); 106 void StepForwardAndStrafe(btCollisionWorld* CollisionWorld, const vec3& MoveStep); 107 void StepDown(btCollisionWorld* CollisionWorld, float DeltaTime); 144 void DoMove(btCollisionWorld* CollisionWorld, const vec3& MoveStep, float DeltaTime); 108 145 109 146 public: … … 128 165 if (NewAxis > 2) 129 166 NewAxis = 2; 130 m_ up_axis = NewAxis;167 m_i_up_axis = NewAxis; 131 168 } 132 169 … … 179 216 180 217 //NewGravity functions 181 void SetGravity(float NewGravity) { m_ gravity = NewGravity; }182 float GetGravity() const { return m_ gravity; }218 void SetGravity(float NewGravity) { m_f_gravity = NewGravity; } 219 float GetGravity() const { return m_f_gravity; } 183 220 184 221 //The max slope determines the maximum angle that the controller can walk up. … … 208 245 float m_max_slope_radians; // Slope angle that is set (used for returning the exact value) 209 246 float m_max_slope_cosine; // Cosine equivalent of m_max_slope_radians (calculated once when set, for optimization) 210 float m_ gravity;247 float m_f_gravity; 211 248 float m_turn_angle; 212 249 float m_step_height; … … 229 266 bool m_do_gobject_sweep_test; 230 267 bool m_use_walk_direction; 231 int m_up_axis; 268 int m_i_up_axis; 269 270 // 271 //NEW INTERNAL VARS 272 // 273 274 //Gravity in vec3 275 vec3 m_gravity; 276 277 //Current Velocity 278 vec3 m_velocity; 232 279 }; 233 280 
trunk/test/Physics/Src/BulletCharacterController.cpp
r1819 r1834 42 42 #ifdef USE_LOL_CTRLR_CHARAC 43 43 #ifdef HAVE_PHYS_USE_BULLET 44 45 //SweepCallback used for Swweep Tests.46 class ClosestNotMeConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback47 {48 public:49 ClosestNotMeConvexResultCallback(btCollisionObject* NewMe, const vec3& NewUp, float MinSlopeDot) :50 btCollisionWorld::ClosestConvexResultCallback(LOL2BTU_VEC3(vec3(.0f)), LOL2BTU_VEC3(vec3(.0f))),51 m_me(NewMe),52 m_up(NewUp),53 m_min_slope_dot(MinSlopeDot) { }54 55 virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& ConvexResult, bool NormalInWorld)56 {57 //We hit ourselves, FAIL58 if (ConvexResult.m_hitCollisionObject == m_me)59 return btScalar(1.f);60 61 vec3 WorldHitNomal(.0f);62 if (NormalInWorld)63 WorldHitNomal = BT2LOL_VEC3(ConvexResult.m_hitNormalLocal);64 else //need to transform Normal into worldspace65 {66 btVector3 TmpWorldHitNormal = ConvexResult.m_hitCollisionObject>getWorldTransform().getBasis() * ConvexResult.m_hitNormalLocal;67 WorldHitNomal = BT2LOL_VEC3(TmpWorldHitNormal);68 }69 70 float DotUp = dot(m_up, WorldHitNomal);71 //We hit below the accepted slope_dot, FAIL72 if (DotUp < m_min_slope_dot)73 return btScalar(1.f);74 75 //Continue to next.76 return ClosestConvexResultCallback::addSingleResult(ConvexResult, NormalInWorld);77 }78 protected:79 btCollisionObject* m_me;80 const vec3 m_up;81 float m_min_slope_dot;82 };83 44 84 45 //When called, will try to remove Character controller from its collision. … … 153 114 } 154 115 155 //Handles the StepUp : Currently taking into account Stair step & Jump.156 void BulletKinematicCharacterController::StepUp(btCollisionWorld* world)157 {158 // phase 1: up159 vec3 UpDir = GetUpAxisDirections()[m_up_axis];160 btTransform SweepStart, SweepEnd;161 SweepStart.setIdentity();162 SweepEnd.setIdentity();163 164 m_target_position = m_current_position + UpDir * (m_step_height + (m_vertical_offset > 0.f ? m_vertical_offset : 0.f));165 166 /* FIXME: Handle HasPenetration properly */167 SweepStart.setOrigin(LOL2BTU_VEC3(m_current_position + UpDir * (m_convex_shape>getMargin() + m_added_margin)));168 SweepEnd.setOrigin(LOL2BTU_VEC3(m_target_position));169 170 ClosestNotMeConvexResultCallback SweepCallback(m_ghost_object, UpDir, float(0.7071));171 SweepCallback.m_collisionFilterGroup = GetGhostObject()>getBroadphaseHandle()>m_collisionFilterGroup;172 SweepCallback.m_collisionFilterMask = GetGhostObject()>getBroadphaseHandle()>m_collisionFilterMask;173 174 if (m_do_gobject_sweep_test)175 m_ghost_object>convexSweepTest(m_convex_shape, SweepStart, SweepEnd, SweepCallback, world>getDispatchInfo().m_allowedCcdPenetration);176 else177 world>convexSweepTest(m_convex_shape, SweepStart, SweepEnd, SweepCallback);178 179 if (SweepCallback.hasHit())180 {181 // Only modify the position if the hit was a slope and not a wall or ceiling.182 if(SweepCallback.m_hitNormalWorld.dot(LOL2BTU_VEC3(UpDir)) > .0f)183 {184 // we moved up only a Fraction of the step height185 m_current_step_offset = m_step_height * SweepCallback.m_closestHitFraction;186 btVector3 InterpolPos; //TODO : REPLACE BY INTERPOLATE3/LERP(VEC3)187 InterpolPos.setInterpolate3(LOL2BTU_VEC3(m_current_position), LOL2BTU_VEC3(m_target_position), SweepCallback.m_closestHitFraction);188 m_current_position = BT2LOLU_VEC3(InterpolPos);189 }190 m_vertical_velocity = .0f;191 m_vertical_offset = .0f;192 }193 else194 {195 m_current_step_offset = m_step_height;196 m_current_position = m_target_position;197 }198 }199 200 116 //Handles the actual Movement. It actually moves in the 3 dimensions, function name is confusing. 201 void BulletKinematicCharacterController:: StepForwardAndStrafe(btCollisionWorld* CollisionWorld, const vec3& MoveStep)117 void BulletKinematicCharacterController::DoMove(btCollisionWorld* CollisionWorld, const vec3& MoveStep, float DeltaTime) 202 118 { 203 119 // phase 2: forward and strafe … … 260 176 } 261 177 262 //Handles the Stepdown : We go back on the ground at the end of the MoveStep.263 void BulletKinematicCharacterController::StepDown(btCollisionWorld* CollisionWorld, float DeltaTime)264 {265 // phase 3: down266 vec3 UpDir = GetUpAxisDirections()[m_up_axis];267 btTransform SweepStart, SweepEnd;268 SweepStart.setIdentity();269 SweepEnd.setIdentity();270 271 float DownVel = (m_vertical_velocity < 0.f ? m_vertical_velocity : 0.f) * DeltaTime;272 if (DownVel > .0f && DownVel < m_step_height && (m_was_on_ground  !m_was_jumping))273 DownVel = m_step_height;274 275 vec3 StepDrop = UpDir * (m_current_step_offset + DownVel);276 m_target_position = StepDrop;277 278 SweepStart.setOrigin(LOL2BTU_VEC3(m_current_position));279 SweepEnd.setOrigin(LOL2BTU_VEC3(m_target_position));280 281 ClosestNotMeConvexResultCallback SweepCallback(m_ghost_object, UpDir, m_max_slope_cosine);282 SweepCallback.m_collisionFilterGroup = GetGhostObject()>getBroadphaseHandle()>m_collisionFilterGroup;283 SweepCallback.m_collisionFilterMask = GetGhostObject()>getBroadphaseHandle()>m_collisionFilterMask;284 285 if (m_do_gobject_sweep_test)286 m_ghost_object>convexSweepTest(m_convex_shape, SweepStart, SweepEnd, SweepCallback, CollisionWorld>getDispatchInfo().m_allowedCcdPenetration);287 else288 CollisionWorld>convexSweepTest(m_convex_shape, SweepStart, SweepEnd, SweepCallback, CollisionWorld>getDispatchInfo().m_allowedCcdPenetration);289 290 if (SweepCallback.hasHit())291 {292 // we dropped a Fraction of the height > hit floor293 btVector3 InterpolPos; //TODO : REPLACE BY INTERPOLATE3/LERP(VEC3)294 InterpolPos.setInterpolate3(LOL2BTU_VEC3(m_current_position), LOL2BTU_VEC3(m_target_position), SweepCallback.m_closestHitFraction);295 m_current_position = BT2LOLU_VEC3(InterpolPos);296 m_vertical_velocity = .0f;297 m_vertical_offset = .0f;298 m_was_jumping = false;299 }300 else // we dropped the full height301 m_current_position = m_target_position;302 }303 304 178 //The PreStepis done in order to recover from any HasPenetration. 305 179 void BulletKinematicCharacterController::PreStep(btCollisionWorld* CollisionWorld) … … 328 202 return; // no motion 329 203 330 m_was_on_ground = OnGround();331 332 204 // Update fall velocity. 333 m_vertical_velocity = m_gravity * DeltaTime; 334 if(m_vertical_velocity > .0f && m_vertical_velocity > m_jump_speed) 335 m_vertical_velocity = m_jump_speed; 336 337 if(m_vertical_velocity < .0f && btFabs(m_vertical_velocity) > btFabs(m_fall_speed)) 338 m_vertical_velocity = btFabs(m_fall_speed); 339 m_vertical_offset = m_vertical_velocity * DeltaTime; 205 //m_velocity = m_gravity * DeltaTime; 340 206 341 207 btTransform NewTransform; … … 356 222 357 223 //Okay, step ! 358 StepUp(CollisionWorld); 359 StepForwardAndStrafe(CollisionWorld, MoveStep); 360 StepDown(CollisionWorld, DeltaTime); 224 DoMove(CollisionWorld, MoveStep, DeltaTime); 361 225 362 226 //Movement finished, update World transform
Note: See TracChangeset
for help on using the changeset viewer.