CMake test for existance of Demos and Demos_ps3 directories
Updated character controller, see also http://code.google.com/p/bullet/issues/detail?id=198
This commit is contained in:
@@ -241,9 +241,20 @@ ENDIF(USE_GLUT)
|
|||||||
|
|
||||||
OPTION(BUILD_DEMOS "Set when you want to build the demos" ON)
|
OPTION(BUILD_DEMOS "Set when you want to build the demos" ON)
|
||||||
IF(BUILD_DEMOS)
|
IF(BUILD_DEMOS)
|
||||||
SUBDIRS(Demos)
|
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos)
|
||||||
|
SUBDIRS(Demos)
|
||||||
|
ENDIF()
|
||||||
ENDIF(BUILD_DEMOS)
|
ENDIF(BUILD_DEMOS)
|
||||||
|
|
||||||
|
# "Demos_ps3")
|
||||||
|
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||||
|
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos_ps3 AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos_ps3)
|
||||||
|
MESSAGE("Demos_ps3 found")
|
||||||
|
SUBDIRS(Demos_ps3)
|
||||||
|
ENDIF()
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
|
||||||
OPTION(BUILD_EXTRAS "Set when you want to build the extras" ON)
|
OPTION(BUILD_EXTRAS "Set when you want to build the extras" ON)
|
||||||
IF(BUILD_EXTRAS)
|
IF(BUILD_EXTRAS)
|
||||||
SUBDIRS(Extras)
|
SUBDIRS(Extras)
|
||||||
|
|||||||
@@ -141,11 +141,12 @@ btKinematicCharacterController::btKinematicCharacterController (btPairCachingGho
|
|||||||
m_velocityTimeInterval = 0.0;
|
m_velocityTimeInterval = 0.0;
|
||||||
m_verticalVelocity = 0.0;
|
m_verticalVelocity = 0.0;
|
||||||
m_verticalOffset = 0.0;
|
m_verticalOffset = 0.0;
|
||||||
m_gravity = 9.8; // 1G accelation.
|
m_gravity = 9.8 * 3 ; // 3G acceleration.
|
||||||
m_fallSpeed = 55.0; // Terminal velocity of a sky diver in m/s.
|
m_fallSpeed = 55.0; // Terminal velocity of a sky diver in m/s.
|
||||||
m_jumpSpeed = 10.0; // ?
|
m_jumpSpeed = 10.0; // ?
|
||||||
m_wasOnGround = false;
|
m_wasOnGround = false;
|
||||||
setMaxSlope(btRadians(50.0));
|
m_wasJumping = false;
|
||||||
|
setMaxSlope(btRadians(45.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
btKinematicCharacterController::~btKinematicCharacterController ()
|
btKinematicCharacterController::~btKinematicCharacterController ()
|
||||||
@@ -216,7 +217,7 @@ void btKinematicCharacterController::stepUp ( btCollisionWorld* world)
|
|||||||
{
|
{
|
||||||
// phase 1: up
|
// phase 1: up
|
||||||
btTransform start, end;
|
btTransform start, end;
|
||||||
m_targetPosition = m_currentPosition + getUpAxisDirections()[m_upAxis] * (m_stepHeight + (m_verticalOffset > btScalar(0.0)?m_verticalOffset:btScalar(0.0)));
|
m_targetPosition = m_currentPosition + getUpAxisDirections()[m_upAxis] * (m_stepHeight + (m_verticalOffset > 0.0?m_verticalOffset:0.0));
|
||||||
|
|
||||||
start.setIdentity ();
|
start.setIdentity ();
|
||||||
end.setIdentity ();
|
end.setIdentity ();
|
||||||
@@ -225,8 +226,7 @@ void btKinematicCharacterController::stepUp ( btCollisionWorld* world)
|
|||||||
start.setOrigin (m_currentPosition + getUpAxisDirections()[m_upAxis] * (m_convexShape->getMargin() + m_addedMargin));
|
start.setOrigin (m_currentPosition + getUpAxisDirections()[m_upAxis] * (m_convexShape->getMargin() + m_addedMargin));
|
||||||
end.setOrigin (m_targetPosition);
|
end.setOrigin (m_targetPosition);
|
||||||
|
|
||||||
// Find only sloped/flat surface hits, avoid wall and ceiling hits...
|
btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, -getUpAxisDirections()[m_upAxis], btScalar(0.7071));
|
||||||
btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, -getUpAxisDirections()[m_upAxis], btScalar(0.0));
|
|
||||||
callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup;
|
callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup;
|
||||||
callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask;
|
callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask;
|
||||||
|
|
||||||
@@ -241,9 +241,13 @@ void btKinematicCharacterController::stepUp ( btCollisionWorld* world)
|
|||||||
|
|
||||||
if (callback.hasHit())
|
if (callback.hasHit())
|
||||||
{
|
{
|
||||||
// we moved up only a fraction of the step height
|
// Only modify the position if the hit was a slope and not a wall or ceiling.
|
||||||
m_currentStepOffset = m_stepHeight * callback.m_closestHitFraction;
|
if(callback.m_hitNormalWorld.dot(getUpAxisDirections()[m_upAxis]) > 0.0)
|
||||||
m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
|
{
|
||||||
|
// we moved up only a fraction of the step height
|
||||||
|
m_currentStepOffset = m_stepHeight * callback.m_closestHitFraction;
|
||||||
|
m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
|
||||||
|
}
|
||||||
m_verticalVelocity = 0.0;
|
m_verticalVelocity = 0.0;
|
||||||
m_verticalOffset = 0.0;
|
m_verticalOffset = 0.0;
|
||||||
} else {
|
} else {
|
||||||
@@ -295,6 +299,7 @@ void btKinematicCharacterController::stepForwardAndStrafe ( btCollisionWorld* co
|
|||||||
// phase 2: forward and strafe
|
// phase 2: forward and strafe
|
||||||
btTransform start, end;
|
btTransform start, end;
|
||||||
m_targetPosition = m_currentPosition + walkMove;
|
m_targetPosition = m_currentPosition + walkMove;
|
||||||
|
|
||||||
start.setIdentity ();
|
start.setIdentity ();
|
||||||
end.setIdentity ();
|
end.setIdentity ();
|
||||||
|
|
||||||
@@ -302,11 +307,13 @@ void btKinematicCharacterController::stepForwardAndStrafe ( btCollisionWorld* co
|
|||||||
btScalar distance2 = (m_currentPosition-m_targetPosition).length2();
|
btScalar distance2 = (m_currentPosition-m_targetPosition).length2();
|
||||||
// printf("distance2=%f\n",distance2);
|
// printf("distance2=%f\n",distance2);
|
||||||
|
|
||||||
/*if (m_touchingContact)
|
if (m_touchingContact)
|
||||||
{
|
{
|
||||||
if (m_normalizedDirection.dot(m_touchingNormal) > btScalar(0.0))
|
if (m_normalizedDirection.dot(m_touchingNormal) > btScalar(0.0))
|
||||||
|
{
|
||||||
updateTargetPositionBasedOnCollision (m_touchingNormal);
|
updateTargetPositionBasedOnCollision (m_touchingNormal);
|
||||||
}*/
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int maxIter = 10;
|
int maxIter = 10;
|
||||||
|
|
||||||
@@ -314,8 +321,9 @@ void btKinematicCharacterController::stepForwardAndStrafe ( btCollisionWorld* co
|
|||||||
{
|
{
|
||||||
start.setOrigin (m_currentPosition);
|
start.setOrigin (m_currentPosition);
|
||||||
end.setOrigin (m_targetPosition);
|
end.setOrigin (m_targetPosition);
|
||||||
|
btVector3 sweepDirNegative(m_currentPosition - m_targetPosition);
|
||||||
|
|
||||||
btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, getUpAxisDirections()[m_upAxis], btScalar(-1.0));
|
btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, sweepDirNegative, btScalar(0.0));
|
||||||
callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup;
|
callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup;
|
||||||
callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask;
|
callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask;
|
||||||
|
|
||||||
@@ -340,14 +348,9 @@ void btKinematicCharacterController::stepForwardAndStrafe ( btCollisionWorld* co
|
|||||||
if (callback.hasHit())
|
if (callback.hasHit())
|
||||||
{
|
{
|
||||||
// we moved only a fraction
|
// we moved only a fraction
|
||||||
//btScalar hitDistance = (callback.m_hitPointWorld - m_currentPosition).length();
|
btScalar hitDistance = (callback.m_hitPointWorld - m_currentPosition).length();
|
||||||
|
|
||||||
/* If the distance is farther than the collision margin, move */
|
// m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
|
||||||
// if (hitDistance > m_addedMargin)
|
|
||||||
// {
|
|
||||||
// printf("callback.m_closestHitFraction=%f\n",callback.m_closestHitFraction);
|
|
||||||
// m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
|
|
||||||
// }
|
|
||||||
|
|
||||||
updateTargetPositionBasedOnCollision (callback.m_hitNormalWorld);
|
updateTargetPositionBasedOnCollision (callback.m_hitNormalWorld);
|
||||||
btVector3 currentDir = m_targetPosition - m_currentPosition;
|
btVector3 currentDir = m_targetPosition - m_currentPosition;
|
||||||
@@ -365,6 +368,7 @@ void btKinematicCharacterController::stepForwardAndStrafe ( btCollisionWorld* co
|
|||||||
// printf("currentDir: don't normalize a zero vector\n");
|
// printf("currentDir: don't normalize a zero vector\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// we moved whole way
|
// we moved whole way
|
||||||
m_currentPosition = m_targetPosition;
|
m_currentPosition = m_targetPosition;
|
||||||
@@ -381,11 +385,21 @@ void btKinematicCharacterController::stepDown ( btCollisionWorld* collisionWorld
|
|||||||
btTransform start, end;
|
btTransform start, end;
|
||||||
|
|
||||||
// phase 3: down
|
// phase 3: down
|
||||||
btScalar additionalDownStep = (m_wasOnGround /*&& !onGround()*/) ? m_stepHeight : btScalar(0.0);
|
/*btScalar additionalDownStep = (m_wasOnGround && !onGround()) ? m_stepHeight : 0.0;
|
||||||
btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + additionalDownStep);
|
btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + additionalDownStep);
|
||||||
btScalar downVelocity = (additionalDownStep == btScalar(0.0) && m_verticalVelocity<btScalar(0.0)?-m_verticalVelocity:btScalar(0.0)) * dt;
|
btScalar downVelocity = (additionalDownStep == 0.0 && m_verticalVelocity<0.0?-m_verticalVelocity:0.0) * dt;
|
||||||
btVector3 gravity_drop = getUpAxisDirections()[m_upAxis] * downVelocity;
|
btVector3 gravity_drop = getUpAxisDirections()[m_upAxis] * downVelocity;
|
||||||
m_targetPosition -= (step_drop + gravity_drop);
|
m_targetPosition -= (step_drop + gravity_drop);*/
|
||||||
|
|
||||||
|
btScalar downVelocity = (m_verticalVelocity<0.0?-m_verticalVelocity:0.0) * dt;
|
||||||
|
if(downVelocity > 0.0 && downVelocity < m_stepHeight
|
||||||
|
&& (m_wasOnGround || !m_wasJumping))
|
||||||
|
{
|
||||||
|
downVelocity = m_stepHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + downVelocity);
|
||||||
|
m_targetPosition -= step_drop;
|
||||||
|
|
||||||
start.setIdentity ();
|
start.setIdentity ();
|
||||||
end.setIdentity ();
|
end.setIdentity ();
|
||||||
@@ -411,6 +425,7 @@ void btKinematicCharacterController::stepDown ( btCollisionWorld* collisionWorld
|
|||||||
m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
|
m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
|
||||||
m_verticalVelocity = 0.0;
|
m_verticalVelocity = 0.0;
|
||||||
m_verticalOffset = 0.0;
|
m_verticalOffset = 0.0;
|
||||||
|
m_wasJumping = false;
|
||||||
} else {
|
} else {
|
||||||
// we dropped the full height
|
// we dropped the full height
|
||||||
|
|
||||||
@@ -475,7 +490,7 @@ void btKinematicCharacterController::preStep ( btCollisionWorld* collisionWorld
|
|||||||
m_touchingContact = true;
|
m_touchingContact = true;
|
||||||
if (numPenetrationLoops > 4)
|
if (numPenetrationLoops > 4)
|
||||||
{
|
{
|
||||||
// printf("character could not recover from penetration = %d\n", numPenetrationLoops);
|
//printf("character could not recover from penetration = %d\n", numPenetrationLoops);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -487,6 +502,8 @@ void btKinematicCharacterController::preStep ( btCollisionWorld* collisionWorld
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void btKinematicCharacterController::playerStep ( btCollisionWorld* collisionWorld, btScalar dt)
|
void btKinematicCharacterController::playerStep ( btCollisionWorld* collisionWorld, btScalar dt)
|
||||||
{
|
{
|
||||||
// printf("playerStep(): ");
|
// printf("playerStep(): ");
|
||||||
@@ -532,7 +549,7 @@ void btKinematicCharacterController::playerStep ( btCollisionWorld* collisionWo
|
|||||||
// how far will we move while we are moving?
|
// how far will we move while we are moving?
|
||||||
btVector3 move = m_walkDirection * dtMoving;
|
btVector3 move = m_walkDirection * dtMoving;
|
||||||
|
|
||||||
// printf(" dtMoving: %f", dtMoving);
|
//printf(" dtMoving: %f", dtMoving);
|
||||||
|
|
||||||
// okay, step
|
// okay, step
|
||||||
stepForwardAndStrafe(collisionWorld, move);
|
stepForwardAndStrafe(collisionWorld, move);
|
||||||
@@ -571,6 +588,7 @@ void btKinematicCharacterController::jump ()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_verticalVelocity = m_jumpSpeed;
|
m_verticalVelocity = m_jumpSpeed;
|
||||||
|
m_wasJumping = true;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
currently no jumping.
|
currently no jumping.
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ subject to the following restrictions:
|
|||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef KINEMATIC_CHARACTER_CONTROLLER_H
|
#ifndef KINEMATIC_CHARACTER_CONTROLLER_H
|
||||||
#define KINEMATIC_CHARACTER_CONTROLLER_H
|
#define KINEMATIC_CHARACTER_CONTROLLER_H
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ protected:
|
|||||||
btVector3 m_touchingNormal;
|
btVector3 m_touchingNormal;
|
||||||
|
|
||||||
bool m_wasOnGround;
|
bool m_wasOnGround;
|
||||||
|
bool m_wasJumping;
|
||||||
bool m_useGhostObjectSweepTest;
|
bool m_useGhostObjectSweepTest;
|
||||||
bool m_useWalkDirection;
|
bool m_useWalkDirection;
|
||||||
btScalar m_velocityTimeInterval;
|
btScalar m_velocityTimeInterval;
|
||||||
@@ -114,14 +116,14 @@ public:
|
|||||||
|
|
||||||
/// This should probably be called setPositionIncrementPerSimulatorStep.
|
/// This should probably be called setPositionIncrementPerSimulatorStep.
|
||||||
/// This is neither a direction nor a velocity, but the amount to
|
/// This is neither a direction nor a velocity, but the amount to
|
||||||
/// increment the position each simulation iteration, regardless
|
/// increment the position each simulation iteration, regardless
|
||||||
/// of dt.
|
/// of dt.
|
||||||
/// This call will reset any velocity set by setVelocityForTimeInterval().
|
/// This call will reset any velocity set by setVelocityForTimeInterval().
|
||||||
virtual void setWalkDirection(const btVector3& walkDirection);
|
virtual void setWalkDirection(const btVector3& walkDirection);
|
||||||
|
|
||||||
/// Caller provides a velocity with which the character should move for
|
/// Caller provides a velocity with which the character should move for
|
||||||
/// the given time period. After the time period, velocity is reset
|
/// the given time period. After the time period, velocity is reset
|
||||||
/// to zero.
|
/// to zero.
|
||||||
/// This call will reset any walk direction set by setWalkDirection().
|
/// This call will reset any walk direction set by setWalkDirection().
|
||||||
/// Negative time intervals will result in no motion.
|
/// Negative time intervals will result in no motion.
|
||||||
virtual void setVelocityForTimeInterval(const btVector3& velocity,
|
virtual void setVelocityForTimeInterval(const btVector3& velocity,
|
||||||
|
|||||||
Reference in New Issue
Block a user