fix: some file didn't have the svn:eol-style native yet
This commit is contained in:
@@ -1,75 +1,75 @@
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
SET(CharacterDemo_SRCS
|
||||
|
||||
DynamicCharacterController.cpp
|
||||
DynamicCharacterController.h
|
||||
CharacterDemo.cpp
|
||||
CharacterDemo.h
|
||||
../BspDemo/BspConverter.cpp
|
||||
../BspDemo/BspConverter.h
|
||||
../BspDemo/BspLoader.cpp
|
||||
../BspDemo/BspLoader.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppCharacterDemo
|
||||
${CharacterDemo_SRCS}
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppCharacterDemo
|
||||
${CharacterDemo_SRCS}
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
IF (WIN32)
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
IF (CMAKE_CL_64)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppCharacterDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ELSE(CMAKE_CL_64)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppCharacterDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ENDIF(CMAKE_CL_64)
|
||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
ENDIF(WIN32)
|
||||
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppCharacterDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/BspDemo.bsp ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppCharacterDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppCharacterDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppCharacterDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
||||
|
||||
|
||||
# For every executable you have with a main method you should have an add_executable line below.
|
||||
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
|
||||
|
||||
|
||||
# You shouldn't have to modify anything below this line
|
||||
########################################################
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
|
||||
)
|
||||
|
||||
LINK_LIBRARIES(
|
||||
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
|
||||
)
|
||||
SET(CharacterDemo_SRCS
|
||||
|
||||
DynamicCharacterController.cpp
|
||||
DynamicCharacterController.h
|
||||
CharacterDemo.cpp
|
||||
CharacterDemo.h
|
||||
../BspDemo/BspConverter.cpp
|
||||
../BspDemo/BspConverter.h
|
||||
../BspDemo/BspLoader.cpp
|
||||
../BspDemo/BspLoader.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_EXECUTABLE(AppCharacterDemo
|
||||
${CharacterDemo_SRCS}
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc
|
||||
)
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(AppCharacterDemo
|
||||
${CharacterDemo_SRCS}
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
IF (WIN32)
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
IF (CMAKE_CL_64)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppCharacterDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ELSE(CMAKE_CL_64)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppCharacterDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ENDIF(CMAKE_CL_64)
|
||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
ENDIF(WIN32)
|
||||
|
||||
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET AppCharacterDemo
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/BspDemo.bsp ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||
|
||||
|
||||
|
||||
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppCharacterDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppCharacterDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppCharacterDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,153 +1,153 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef CHARACTER_DEMO_H
|
||||
#define CHARACTER_DEMO_H
|
||||
|
||||
|
||||
///DYNAMIC_CHARACTER_CONTROLLER is not fully implemented yet at the moment
|
||||
//#define DYNAMIC_CHARACTER_CONTROLLER 1
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
|
||||
|
||||
class btCharacterControllerInterface;
|
||||
class btDynamicCharacterController;
|
||||
class btKinematicCharacterController;
|
||||
|
||||
class btCollisionShape;
|
||||
|
||||
|
||||
#include "GlutDemoApplication.h"
|
||||
|
||||
///CharacterDemo shows how to setup and use the built-in raycast vehicle
|
||||
class CharacterDemo : public GlutDemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
#ifdef DYNAMIC_CHARACTER_CONTROLLER
|
||||
btCharacterControllerInterface* m_character;
|
||||
#else
|
||||
btKinematicCharacterController* m_character;
|
||||
class btPairCachingGhostObject* m_ghostObject;
|
||||
#endif
|
||||
|
||||
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
class btBroadphaseInterface* m_overlappingPairCache;
|
||||
|
||||
class btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
class btConstraintSolver* m_constraintSolver;
|
||||
|
||||
class btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
class btTriangleIndexVertexArray* m_indexVertexArrays;
|
||||
|
||||
btVector3* m_vertices;
|
||||
|
||||
void debugDrawContacts();
|
||||
|
||||
float m_cameraHeight;
|
||||
|
||||
float m_minCameraDistance;
|
||||
float m_maxCameraDistance;
|
||||
|
||||
|
||||
CharacterDemo();
|
||||
|
||||
virtual ~CharacterDemo();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
///a very basic camera following the character
|
||||
virtual void updateCamera();
|
||||
|
||||
virtual void specialKeyboard(int key, int x, int y);
|
||||
|
||||
virtual void specialKeyboardUp(int key, int x, int y);
|
||||
|
||||
void renderme();
|
||||
|
||||
void initPhysics();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
CharacterDemo* demo = new CharacterDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define QUAKE_BSP_IMPORTING 1
|
||||
#ifdef QUAKE_BSP_IMPORTING
|
||||
#include "../BspDemo/BspLoader.h"
|
||||
#include "../BspDemo/BspConverter.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class BspToBulletConverter : public BspConverter
|
||||
{
|
||||
CharacterDemo* m_demoApp;
|
||||
|
||||
public:
|
||||
|
||||
BspToBulletConverter(CharacterDemo* demoApp)
|
||||
:m_demoApp(demoApp)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void addConvexVerticesCollider(btAlignedObjectArray<btVector3>& vertices, bool isEntity, const btVector3& entityTargetLocation)
|
||||
{
|
||||
///perhaps we can do something special with entities (isEntity)
|
||||
///like adding a collision Triggering (as example)
|
||||
|
||||
if (vertices.size() > 0)
|
||||
{
|
||||
float mass = 0.f;
|
||||
btTransform startTransform;
|
||||
//can use a shift
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-10.0f,0.0f));
|
||||
//this create an internal copy of the vertices
|
||||
for (int i = 0; i < vertices.size(); i++)
|
||||
{
|
||||
vertices[i] *= btScalar(0.5);
|
||||
float t = vertices[i].getZ() * btScalar(0.75);
|
||||
vertices[i].setZ(-vertices[i].getY());
|
||||
vertices[i].setY(t);
|
||||
}
|
||||
|
||||
btCollisionShape* shape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||
m_demoApp->m_collisionShapes.push_back(shape);
|
||||
|
||||
//btRigidBody* body = m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif //QUAKE_BSP_IMPORTING
|
||||
|
||||
|
||||
#endif //CHARACTER_DEMO_H
|
||||
|
||||
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef CHARACTER_DEMO_H
|
||||
#define CHARACTER_DEMO_H
|
||||
|
||||
|
||||
///DYNAMIC_CHARACTER_CONTROLLER is not fully implemented yet at the moment
|
||||
//#define DYNAMIC_CHARACTER_CONTROLLER 1
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
|
||||
|
||||
class btCharacterControllerInterface;
|
||||
class btDynamicCharacterController;
|
||||
class btKinematicCharacterController;
|
||||
|
||||
class btCollisionShape;
|
||||
|
||||
|
||||
#include "GlutDemoApplication.h"
|
||||
|
||||
///CharacterDemo shows how to setup and use the built-in raycast vehicle
|
||||
class CharacterDemo : public GlutDemoApplication
|
||||
{
|
||||
public:
|
||||
|
||||
#ifdef DYNAMIC_CHARACTER_CONTROLLER
|
||||
btCharacterControllerInterface* m_character;
|
||||
#else
|
||||
btKinematicCharacterController* m_character;
|
||||
class btPairCachingGhostObject* m_ghostObject;
|
||||
#endif
|
||||
|
||||
|
||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
||||
|
||||
class btBroadphaseInterface* m_overlappingPairCache;
|
||||
|
||||
class btCollisionDispatcher* m_dispatcher;
|
||||
|
||||
class btConstraintSolver* m_constraintSolver;
|
||||
|
||||
class btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
class btTriangleIndexVertexArray* m_indexVertexArrays;
|
||||
|
||||
btVector3* m_vertices;
|
||||
|
||||
void debugDrawContacts();
|
||||
|
||||
float m_cameraHeight;
|
||||
|
||||
float m_minCameraDistance;
|
||||
float m_maxCameraDistance;
|
||||
|
||||
|
||||
CharacterDemo();
|
||||
|
||||
virtual ~CharacterDemo();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
///a very basic camera following the character
|
||||
virtual void updateCamera();
|
||||
|
||||
virtual void specialKeyboard(int key, int x, int y);
|
||||
|
||||
virtual void specialKeyboardUp(int key, int x, int y);
|
||||
|
||||
void renderme();
|
||||
|
||||
void initPhysics();
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
CharacterDemo* demo = new CharacterDemo();
|
||||
demo->myinit();
|
||||
demo->initPhysics();
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define QUAKE_BSP_IMPORTING 1
|
||||
#ifdef QUAKE_BSP_IMPORTING
|
||||
#include "../BspDemo/BspLoader.h"
|
||||
#include "../BspDemo/BspConverter.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class BspToBulletConverter : public BspConverter
|
||||
{
|
||||
CharacterDemo* m_demoApp;
|
||||
|
||||
public:
|
||||
|
||||
BspToBulletConverter(CharacterDemo* demoApp)
|
||||
:m_demoApp(demoApp)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void addConvexVerticesCollider(btAlignedObjectArray<btVector3>& vertices, bool isEntity, const btVector3& entityTargetLocation)
|
||||
{
|
||||
///perhaps we can do something special with entities (isEntity)
|
||||
///like adding a collision Triggering (as example)
|
||||
|
||||
if (vertices.size() > 0)
|
||||
{
|
||||
float mass = 0.f;
|
||||
btTransform startTransform;
|
||||
//can use a shift
|
||||
startTransform.setIdentity();
|
||||
startTransform.setOrigin(btVector3(0,-10.0f,0.0f));
|
||||
//this create an internal copy of the vertices
|
||||
for (int i = 0; i < vertices.size(); i++)
|
||||
{
|
||||
vertices[i] *= btScalar(0.5);
|
||||
float t = vertices[i].getZ() * btScalar(0.75);
|
||||
vertices[i].setZ(-vertices[i].getY());
|
||||
vertices[i].setY(t);
|
||||
}
|
||||
|
||||
btCollisionShape* shape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||
m_demoApp->m_collisionShapes.push_back(shape);
|
||||
|
||||
//btRigidBody* body = m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
m_demoApp->localCreateRigidBody(mass, startTransform,shape);
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif //QUAKE_BSP_IMPORTING
|
||||
|
||||
|
||||
#endif //CHARACTER_DEMO_H
|
||||
|
||||
|
||||
|
||||
@@ -1,204 +1,204 @@
|
||||
#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
|
||||
#include "LinearMath/btDefaultMotionState.h"
|
||||
#include "DynamicCharacterController.h"
|
||||
|
||||
DynamicCharacterController::DynamicCharacterController ()
|
||||
{
|
||||
m_rayLambda[0] = 1.0;
|
||||
m_rayLambda[1] = 1.0;
|
||||
m_halfHeight = 1.0;
|
||||
m_turnAngle = 0.0;
|
||||
m_maxLinearVelocity = 10.0;
|
||||
m_walkVelocity = 8.0; // meters/sec
|
||||
m_turnVelocity = 1.0; // radians/sec
|
||||
m_shape = NULL;
|
||||
m_rigidBody = NULL;
|
||||
}
|
||||
|
||||
DynamicCharacterController::~DynamicCharacterController ()
|
||||
{
|
||||
}
|
||||
|
||||
void DynamicCharacterController::setup (btScalar height, btScalar width, btScalar stepHeight)
|
||||
{
|
||||
btVector3 spherePositions[2];
|
||||
btScalar sphereRadii[2];
|
||||
|
||||
sphereRadii[0] = width;
|
||||
sphereRadii[1] = width;
|
||||
spherePositions[0] = btVector3 (0.0, (height/btScalar(2.0) - width), 0.0);
|
||||
spherePositions[1] = btVector3 (0.0, (-height/btScalar(2.0) + width), 0.0);
|
||||
|
||||
m_halfHeight = height/btScalar(2.0);
|
||||
|
||||
m_shape = new btMultiSphereShape (&spherePositions[0], &sphereRadii[0], 2);
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity ();
|
||||
startTransform.setOrigin (btVector3(0.0, 2.0, 0.0));
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo cInfo(1.0, myMotionState, m_shape);
|
||||
m_rigidBody = new btRigidBody(cInfo);
|
||||
// kinematic vs. static doesn't work
|
||||
//m_rigidBody->setCollisionFlags( m_rigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
m_rigidBody->setSleepingThresholds (0.0, 0.0);
|
||||
m_rigidBody->setAngularFactor (0.0);
|
||||
|
||||
}
|
||||
|
||||
void DynamicCharacterController::destroy ()
|
||||
{
|
||||
if (m_shape)
|
||||
{
|
||||
delete m_shape;
|
||||
}
|
||||
|
||||
if (m_rigidBody)
|
||||
{
|
||||
delete m_rigidBody;
|
||||
m_rigidBody = 0;
|
||||
}
|
||||
}
|
||||
|
||||
btCollisionObject* DynamicCharacterController::getCollisionObject ()
|
||||
{
|
||||
return m_rigidBody;
|
||||
}
|
||||
|
||||
void DynamicCharacterController::preStep (const btCollisionWorld* collisionWorld)
|
||||
{
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
btVector3 down = -xform.getBasis()[1];
|
||||
btVector3 forward = xform.getBasis()[2];
|
||||
down.normalize ();
|
||||
forward.normalize();
|
||||
|
||||
m_raySource[0] = xform.getOrigin();
|
||||
m_raySource[1] = xform.getOrigin();
|
||||
|
||||
m_rayTarget[0] = m_raySource[0] + down * m_halfHeight * btScalar(1.1);
|
||||
m_rayTarget[1] = m_raySource[1] + forward * m_halfHeight * btScalar(1.1);
|
||||
|
||||
class ClosestNotMe : public btCollisionWorld::ClosestRayResultCallback
|
||||
{
|
||||
public:
|
||||
ClosestNotMe (btRigidBody* me) : btCollisionWorld::ClosestRayResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0))
|
||||
{
|
||||
m_me = me;
|
||||
}
|
||||
|
||||
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
|
||||
{
|
||||
if (rayResult.m_collisionObject == m_me)
|
||||
return 1.0;
|
||||
|
||||
return ClosestRayResultCallback::addSingleResult (rayResult, normalInWorldSpace
|
||||
);
|
||||
}
|
||||
protected:
|
||||
btRigidBody* m_me;
|
||||
};
|
||||
|
||||
ClosestNotMe rayCallback(m_rigidBody);
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
rayCallback.m_closestHitFraction = 1.0;
|
||||
collisionWorld->rayTest (m_raySource[i], m_rayTarget[i], rayCallback);
|
||||
if (rayCallback.hasHit())
|
||||
{
|
||||
m_rayLambda[i] = rayCallback.m_closestHitFraction;
|
||||
} else {
|
||||
m_rayLambda[i] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicCharacterController::playerStep (const btCollisionWorld* dynaWorld,btScalar dt,
|
||||
int forward,
|
||||
int backward,
|
||||
int left,
|
||||
int right,
|
||||
int jump)
|
||||
{
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
|
||||
/* Handle turning */
|
||||
if (left)
|
||||
m_turnAngle -= dt * m_turnVelocity;
|
||||
if (right)
|
||||
m_turnAngle += dt * m_turnVelocity;
|
||||
|
||||
xform.setRotation (btQuaternion (btVector3(0.0, 1.0, 0.0), m_turnAngle));
|
||||
|
||||
btVector3 linearVelocity = m_rigidBody->getLinearVelocity();
|
||||
btScalar speed = m_rigidBody->getLinearVelocity().length();
|
||||
|
||||
btVector3 forwardDir = xform.getBasis()[2];
|
||||
forwardDir.normalize ();
|
||||
btVector3 walkDirection = btVector3(0.0, 0.0, 0.0);
|
||||
btScalar walkSpeed = m_walkVelocity * dt;
|
||||
|
||||
if (forward)
|
||||
walkDirection += forwardDir;
|
||||
if (backward)
|
||||
walkDirection -= forwardDir;
|
||||
|
||||
|
||||
|
||||
if (!forward && !backward && onGround())
|
||||
{
|
||||
/* Dampen when on the ground and not being moved by the player */
|
||||
linearVelocity *= btScalar(0.2);
|
||||
m_rigidBody->setLinearVelocity (linearVelocity);
|
||||
} else {
|
||||
if (speed < m_maxLinearVelocity)
|
||||
{
|
||||
btVector3 velocity = linearVelocity + walkDirection * walkSpeed;
|
||||
m_rigidBody->setLinearVelocity (velocity);
|
||||
}
|
||||
}
|
||||
|
||||
m_rigidBody->getMotionState()->setWorldTransform (xform);
|
||||
m_rigidBody->setCenterOfMassTransform (xform);
|
||||
}
|
||||
|
||||
bool DynamicCharacterController::canJump () const
|
||||
{
|
||||
return onGround();
|
||||
}
|
||||
|
||||
void DynamicCharacterController::jump ()
|
||||
{
|
||||
if (!canJump())
|
||||
return;
|
||||
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
btVector3 up = xform.getBasis()[1];
|
||||
up.normalize ();
|
||||
btScalar magnitude = (btScalar(1.0)/m_rigidBody->getInvMass()) * btScalar(8.0);
|
||||
m_rigidBody->applyCentralImpulse (up * magnitude);
|
||||
}
|
||||
|
||||
bool DynamicCharacterController::onGround () const
|
||||
{
|
||||
return m_rayLambda[0] < btScalar(1.0);
|
||||
}
|
||||
|
||||
void DynamicCharacterController::reset ()
|
||||
{
|
||||
}
|
||||
void DynamicCharacterController::warp (const btVector3& origin)
|
||||
{
|
||||
}
|
||||
void DynamicCharacterController::registerPairCacheAndDispatcher (btOverlappingPairCache* pairCache, btCollisionDispatcher* dispatcher)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
|
||||
#include "LinearMath/btDefaultMotionState.h"
|
||||
#include "DynamicCharacterController.h"
|
||||
|
||||
DynamicCharacterController::DynamicCharacterController ()
|
||||
{
|
||||
m_rayLambda[0] = 1.0;
|
||||
m_rayLambda[1] = 1.0;
|
||||
m_halfHeight = 1.0;
|
||||
m_turnAngle = 0.0;
|
||||
m_maxLinearVelocity = 10.0;
|
||||
m_walkVelocity = 8.0; // meters/sec
|
||||
m_turnVelocity = 1.0; // radians/sec
|
||||
m_shape = NULL;
|
||||
m_rigidBody = NULL;
|
||||
}
|
||||
|
||||
DynamicCharacterController::~DynamicCharacterController ()
|
||||
{
|
||||
}
|
||||
|
||||
void DynamicCharacterController::setup (btScalar height, btScalar width, btScalar stepHeight)
|
||||
{
|
||||
btVector3 spherePositions[2];
|
||||
btScalar sphereRadii[2];
|
||||
|
||||
sphereRadii[0] = width;
|
||||
sphereRadii[1] = width;
|
||||
spherePositions[0] = btVector3 (0.0, (height/btScalar(2.0) - width), 0.0);
|
||||
spherePositions[1] = btVector3 (0.0, (-height/btScalar(2.0) + width), 0.0);
|
||||
|
||||
m_halfHeight = height/btScalar(2.0);
|
||||
|
||||
m_shape = new btMultiSphereShape (&spherePositions[0], &sphereRadii[0], 2);
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity ();
|
||||
startTransform.setOrigin (btVector3(0.0, 2.0, 0.0));
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo cInfo(1.0, myMotionState, m_shape);
|
||||
m_rigidBody = new btRigidBody(cInfo);
|
||||
// kinematic vs. static doesn't work
|
||||
//m_rigidBody->setCollisionFlags( m_rigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
m_rigidBody->setSleepingThresholds (0.0, 0.0);
|
||||
m_rigidBody->setAngularFactor (0.0);
|
||||
|
||||
}
|
||||
|
||||
void DynamicCharacterController::destroy ()
|
||||
{
|
||||
if (m_shape)
|
||||
{
|
||||
delete m_shape;
|
||||
}
|
||||
|
||||
if (m_rigidBody)
|
||||
{
|
||||
delete m_rigidBody;
|
||||
m_rigidBody = 0;
|
||||
}
|
||||
}
|
||||
|
||||
btCollisionObject* DynamicCharacterController::getCollisionObject ()
|
||||
{
|
||||
return m_rigidBody;
|
||||
}
|
||||
|
||||
void DynamicCharacterController::preStep (const btCollisionWorld* collisionWorld)
|
||||
{
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
btVector3 down = -xform.getBasis()[1];
|
||||
btVector3 forward = xform.getBasis()[2];
|
||||
down.normalize ();
|
||||
forward.normalize();
|
||||
|
||||
m_raySource[0] = xform.getOrigin();
|
||||
m_raySource[1] = xform.getOrigin();
|
||||
|
||||
m_rayTarget[0] = m_raySource[0] + down * m_halfHeight * btScalar(1.1);
|
||||
m_rayTarget[1] = m_raySource[1] + forward * m_halfHeight * btScalar(1.1);
|
||||
|
||||
class ClosestNotMe : public btCollisionWorld::ClosestRayResultCallback
|
||||
{
|
||||
public:
|
||||
ClosestNotMe (btRigidBody* me) : btCollisionWorld::ClosestRayResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0))
|
||||
{
|
||||
m_me = me;
|
||||
}
|
||||
|
||||
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
|
||||
{
|
||||
if (rayResult.m_collisionObject == m_me)
|
||||
return 1.0;
|
||||
|
||||
return ClosestRayResultCallback::addSingleResult (rayResult, normalInWorldSpace
|
||||
);
|
||||
}
|
||||
protected:
|
||||
btRigidBody* m_me;
|
||||
};
|
||||
|
||||
ClosestNotMe rayCallback(m_rigidBody);
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
rayCallback.m_closestHitFraction = 1.0;
|
||||
collisionWorld->rayTest (m_raySource[i], m_rayTarget[i], rayCallback);
|
||||
if (rayCallback.hasHit())
|
||||
{
|
||||
m_rayLambda[i] = rayCallback.m_closestHitFraction;
|
||||
} else {
|
||||
m_rayLambda[i] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicCharacterController::playerStep (const btCollisionWorld* dynaWorld,btScalar dt,
|
||||
int forward,
|
||||
int backward,
|
||||
int left,
|
||||
int right,
|
||||
int jump)
|
||||
{
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
|
||||
/* Handle turning */
|
||||
if (left)
|
||||
m_turnAngle -= dt * m_turnVelocity;
|
||||
if (right)
|
||||
m_turnAngle += dt * m_turnVelocity;
|
||||
|
||||
xform.setRotation (btQuaternion (btVector3(0.0, 1.0, 0.0), m_turnAngle));
|
||||
|
||||
btVector3 linearVelocity = m_rigidBody->getLinearVelocity();
|
||||
btScalar speed = m_rigidBody->getLinearVelocity().length();
|
||||
|
||||
btVector3 forwardDir = xform.getBasis()[2];
|
||||
forwardDir.normalize ();
|
||||
btVector3 walkDirection = btVector3(0.0, 0.0, 0.0);
|
||||
btScalar walkSpeed = m_walkVelocity * dt;
|
||||
|
||||
if (forward)
|
||||
walkDirection += forwardDir;
|
||||
if (backward)
|
||||
walkDirection -= forwardDir;
|
||||
|
||||
|
||||
|
||||
if (!forward && !backward && onGround())
|
||||
{
|
||||
/* Dampen when on the ground and not being moved by the player */
|
||||
linearVelocity *= btScalar(0.2);
|
||||
m_rigidBody->setLinearVelocity (linearVelocity);
|
||||
} else {
|
||||
if (speed < m_maxLinearVelocity)
|
||||
{
|
||||
btVector3 velocity = linearVelocity + walkDirection * walkSpeed;
|
||||
m_rigidBody->setLinearVelocity (velocity);
|
||||
}
|
||||
}
|
||||
|
||||
m_rigidBody->getMotionState()->setWorldTransform (xform);
|
||||
m_rigidBody->setCenterOfMassTransform (xform);
|
||||
}
|
||||
|
||||
bool DynamicCharacterController::canJump () const
|
||||
{
|
||||
return onGround();
|
||||
}
|
||||
|
||||
void DynamicCharacterController::jump ()
|
||||
{
|
||||
if (!canJump())
|
||||
return;
|
||||
|
||||
btTransform xform;
|
||||
m_rigidBody->getMotionState()->getWorldTransform (xform);
|
||||
btVector3 up = xform.getBasis()[1];
|
||||
up.normalize ();
|
||||
btScalar magnitude = (btScalar(1.0)/m_rigidBody->getInvMass()) * btScalar(8.0);
|
||||
m_rigidBody->applyCentralImpulse (up * magnitude);
|
||||
}
|
||||
|
||||
bool DynamicCharacterController::onGround () const
|
||||
{
|
||||
return m_rayLambda[0] < btScalar(1.0);
|
||||
}
|
||||
|
||||
void DynamicCharacterController::reset ()
|
||||
{
|
||||
}
|
||||
void DynamicCharacterController::warp (const btVector3& origin)
|
||||
{
|
||||
}
|
||||
void DynamicCharacterController::registerPairCacheAndDispatcher (btOverlappingPairCache* pairCache, btCollisionDispatcher* dispatcher)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
#ifndef CHARACTER_CONTROLLER_H
|
||||
#define CHARACTER_CONTROLLER_H
|
||||
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
#include "BulletDynamics/Character/btCharacterControllerInterface.h"
|
||||
|
||||
class btCollisionShape;
|
||||
class btRigidBody;
|
||||
class btCollisionWorld;
|
||||
|
||||
///DynamicCharacterController is obsolete/unsupported at the moment
|
||||
class DynamicCharacterController : public btCharacterControllerInterface
|
||||
{
|
||||
protected:
|
||||
btScalar m_halfHeight;
|
||||
btCollisionShape* m_shape;
|
||||
btRigidBody* m_rigidBody;
|
||||
|
||||
btVector3 m_raySource[2];
|
||||
btVector3 m_rayTarget[2];
|
||||
btScalar m_rayLambda[2];
|
||||
btVector3 m_rayNormal[2];
|
||||
|
||||
btScalar m_turnAngle;
|
||||
|
||||
btScalar m_maxLinearVelocity;
|
||||
btScalar m_walkVelocity;
|
||||
btScalar m_turnVelocity;
|
||||
public:
|
||||
DynamicCharacterController ();
|
||||
~DynamicCharacterController ();
|
||||
void setup (btScalar height = 2.0, btScalar width = 0.25, btScalar stepHeight = 0.25);
|
||||
void destroy ();
|
||||
|
||||
virtual void reset ();
|
||||
virtual void warp (const btVector3& origin);
|
||||
virtual void registerPairCacheAndDispatcher (btOverlappingPairCache* pairCache, btCollisionDispatcher* dispatcher);
|
||||
|
||||
btCollisionObject* getCollisionObject ();
|
||||
|
||||
void preStep (const btCollisionWorld* collisionWorld);
|
||||
void playerStep (const btCollisionWorld* collisionWorld,btScalar dt,
|
||||
int forward,
|
||||
int backward,
|
||||
int left,
|
||||
int right,
|
||||
int jump);
|
||||
bool canJump () const;
|
||||
void jump ();
|
||||
|
||||
bool onGround () const;
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifndef CHARACTER_CONTROLLER_H
|
||||
#define CHARACTER_CONTROLLER_H
|
||||
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
#include "BulletDynamics/Character/btCharacterControllerInterface.h"
|
||||
|
||||
class btCollisionShape;
|
||||
class btRigidBody;
|
||||
class btCollisionWorld;
|
||||
|
||||
///DynamicCharacterController is obsolete/unsupported at the moment
|
||||
class DynamicCharacterController : public btCharacterControllerInterface
|
||||
{
|
||||
protected:
|
||||
btScalar m_halfHeight;
|
||||
btCollisionShape* m_shape;
|
||||
btRigidBody* m_rigidBody;
|
||||
|
||||
btVector3 m_raySource[2];
|
||||
btVector3 m_rayTarget[2];
|
||||
btScalar m_rayLambda[2];
|
||||
btVector3 m_rayNormal[2];
|
||||
|
||||
btScalar m_turnAngle;
|
||||
|
||||
btScalar m_maxLinearVelocity;
|
||||
btScalar m_walkVelocity;
|
||||
btScalar m_turnVelocity;
|
||||
public:
|
||||
DynamicCharacterController ();
|
||||
~DynamicCharacterController ();
|
||||
void setup (btScalar height = 2.0, btScalar width = 0.25, btScalar stepHeight = 0.25);
|
||||
void destroy ();
|
||||
|
||||
virtual void reset ();
|
||||
virtual void warp (const btVector3& origin);
|
||||
virtual void registerPairCacheAndDispatcher (btOverlappingPairCache* pairCache, btCollisionDispatcher* dispatcher);
|
||||
|
||||
btCollisionObject* getCollisionObject ();
|
||||
|
||||
void preStep (const btCollisionWorld* collisionWorld);
|
||||
void playerStep (const btCollisionWorld* collisionWorld,btScalar dt,
|
||||
int forward,
|
||||
int backward,
|
||||
int left,
|
||||
int right,
|
||||
int jump);
|
||||
bool canJump () const;
|
||||
void jump ();
|
||||
|
||||
bool onGround () const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user