Added base class for character controllers, in oder to allow C++ developers to replace the default implementation with their own.

This commit is contained in:
enn0x 2012-02-11 10:02:25 +00:00
parent 9afc789755
commit fd1f1e19b3
12 changed files with 253 additions and 138 deletions

View File

@ -0,0 +1,15 @@
// Filename: bulletBaseCharacterControllerNode.I
// Created by: enn0x (21Nov10)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,134 @@
// Filename: bulletBaseCharacterControllerNode.cxx
// Created by: enn0x (21Nov10)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#include "bulletBaseCharacterControllerNode.h"
TypeHandle BulletBaseCharacterControllerNode::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: BulletBaseCharacterControllerNode::Constructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
BulletBaseCharacterControllerNode::
BulletBaseCharacterControllerNode(const char *name) : PandaNode(name) {
// Default collide mask
set_into_collide_mask(CollideMask::all_on());
}
////////////////////////////////////////////////////////////////////
// Function: BulletBaseCharacterControllerNode::get_legal_collide_mask
// Access: Public, virtual
// Description: Returns the subset of CollideMask bits that may be
// set for this particular type of PandaNode. For
// CharacterControllerNodes this returns all bits on.
////////////////////////////////////////////////////////////////////
CollideMask BulletBaseCharacterControllerNode::
get_legal_collide_mask() const {
return CollideMask::all_on();
}
////////////////////////////////////////////////////////////////////
// Function: BulletBaseCharacterControllerNode::safe_to_flatten
// Access: Public, Virtual
// Description: Returns true if it is generally safe to flatten out
// this particular kind of Node by duplicating
// instances, false otherwise (for instance, a Camera
// cannot be safely flattened, because the Camera
// pointer itself is meaningful).
////////////////////////////////////////////////////////////////////
bool BulletBaseCharacterControllerNode::
safe_to_flatten() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletBaseCharacterControllerNode::safe_to_modify_transform
// Access: Public, Virtual
// Description: Returns true if it is safe to automatically adjust
// the transform on this kind of node. Usually, this is
// only a bad idea if the user expects to find a
// particular transform on the node.
//
// ModelNodes with the preserve_transform flag set are
// presently the only kinds of nodes that should not
// have their transform even adjusted.
////////////////////////////////////////////////////////////////////
bool BulletBaseCharacterControllerNode::
safe_to_modify_transform() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletBaseCharacterControllerNode::safe_to_combine
// Access: Public, Virtual
// Description: Returns true if it is generally safe to combine this
// particular kind of PandaNode with other kinds of
// PandaNodes of compatible type, adding children or
// whatever. For instance, an LODNode should not be
// combined with any other PandaNode, because its set of
// children is meaningful.
////////////////////////////////////////////////////////////////////
bool BulletBaseCharacterControllerNode::
safe_to_combine() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletBaseCharacterControllerNode::safe_to_combine_children
// Access: Public, Virtual
// Description: Returns true if it is generally safe to combine the
// children of this PandaNode with each other. For
// instance, an LODNode's children should not be
// combined with each other, because the set of children
// is meaningful.
////////////////////////////////////////////////////////////////////
bool BulletBaseCharacterControllerNode::
safe_to_combine_children() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletBaseCharacterControllerNode::safe_to_flatten_below
// Access: Public, Virtual
// Description: Returns true if a flatten operation may safely
// continue past this node, or false if nodes below this
// node may not be molested.
////////////////////////////////////////////////////////////////////
bool BulletBaseCharacterControllerNode::
safe_to_flatten_below() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletBaseCharacterControllerNode::safe_to_transform
// Access: Public, Virtual
// Description: Returns true if it is generally safe to transform
// this particular kind of Node by calling the xform()
// method, false otherwise. For instance, it's usually
// a bad idea to attempt to xform a Character.
////////////////////////////////////////////////////////////////////
bool BulletBaseCharacterControllerNode::
safe_to_transform() const {
return false;
}

View File

@ -0,0 +1,77 @@
// Filename: bulletBaseCharacterControllerNode.h
// Created by: enn0x (21Nov10)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#ifndef __BULLET_BASE_CHARACTER_CONTROLLER_NODE_H__
#define __BULLET_BASE_CHARACTER_CONTROLLER_NODE_H__
#include "pandabase.h"
#include "bullet_includes.h"
#include "bullet_utils.h"
#include "bulletShape.h"
#include "pandaNode.h"
#include "collideMask.h"
////////////////////////////////////////////////////////////////////
// Class : BulletBaseCharacterControllerNode
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_PANDABULLET BulletBaseCharacterControllerNode : public PandaNode {
PUBLISHED:
BulletBaseCharacterControllerNode(const char *name="character");
public:
virtual CollideMask get_legal_collide_mask() const;
virtual bool safe_to_flatten() const;
virtual bool safe_to_transform() const;
virtual bool safe_to_modify_transform() const;
virtual bool safe_to_combine() const;
virtual bool safe_to_combine_children() const;
virtual bool safe_to_flatten_below() const;
INLINE virtual btPairCachingGhostObject *get_ghost() const = 0;
INLINE virtual btCharacterControllerInterface *get_character() const = 0;
virtual void sync_p2b(PN_stdfloat dt, int num_substeps) = 0;
virtual void sync_b2p() = 0;
////////////////////////////////////////////////////////////////////
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
PandaNode::init_type();
register_type(_type_handle, "BulletBaseCharacterControllerNode",
PandaNode::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {
init_type();
return get_class_type();
}
private:
static TypeHandle _type_handle;
};
#include "bulletBaseCharacterControllerNode.I"
#endif // __BULLET_BASE_CHARACTER_CONTROLLER_NODE_H__

View File

@ -39,7 +39,7 @@ get_ghost() const {
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE btKinematicCharacterController *BulletCharacterControllerNode::
INLINE btCharacterControllerInterface *BulletCharacterControllerNode::
get_character() const {
return _character;

View File

@ -22,7 +22,7 @@ TypeHandle BulletCharacterControllerNode::_type_handle;
// Description:
////////////////////////////////////////////////////////////////////
BulletCharacterControllerNode::
BulletCharacterControllerNode(BulletShape *shape, PN_stdfloat step_height, const char *name) : PandaNode(name) {
BulletCharacterControllerNode(BulletShape *shape, PN_stdfloat step_height, const char *name) : BulletBaseCharacterControllerNode(name) {
// Synchronised transform
_sync = TransformState::make_identity();
@ -64,111 +64,7 @@ BulletCharacterControllerNode(BulletShape *shape, PN_stdfloat step_height, const
_shape = shape;
// Default collide mask
set_into_collide_mask(CollideMask::all_on());
}
////////////////////////////////////////////////////////////////////
// Function: BulletCharacterControllerNode::get_legal_collide_mask
// Access: Public, virtual
// Description: Returns the subset of CollideMask bits that may be
// set for this particular type of PandaNode. For
// CharacterControllerNodes this returns all bits on.
////////////////////////////////////////////////////////////////////
CollideMask BulletCharacterControllerNode::
get_legal_collide_mask() const {
return CollideMask::all_on();
}
////////////////////////////////////////////////////////////////////
// Function: BulletCharacterControllerNode::safe_to_flatten
// Access: Public, Virtual
// Description: Returns true if it is generally safe to flatten out
// this particular kind of Node by duplicating
// instances, false otherwise (for instance, a Camera
// cannot be safely flattened, because the Camera
// pointer itself is meaningful).
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
safe_to_flatten() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletCharacterControllerNode::safe_to_modify_transform
// Access: Public, Virtual
// Description: Returns true if it is safe to automatically adjust
// the transform on this kind of node. Usually, this is
// only a bad idea if the user expects to find a
// particular transform on the node.
//
// ModelNodes with the preserve_transform flag set are
// presently the only kinds of nodes that should not
// have their transform even adjusted.
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
safe_to_modify_transform() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletCharacterControllerNode::safe_to_combine
// Access: Public, Virtual
// Description: Returns true if it is generally safe to combine this
// particular kind of PandaNode with other kinds of
// PandaNodes of compatible type, adding children or
// whatever. For instance, an LODNode should not be
// combined with any other PandaNode, because its set of
// children is meaningful.
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
safe_to_combine() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletCharacterControllerNode::safe_to_combine_children
// Access: Public, Virtual
// Description: Returns true if it is generally safe to combine the
// children of this PandaNode with each other. For
// instance, an LODNode's children should not be
// combined with each other, because the set of children
// is meaningful.
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
safe_to_combine_children() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletCharacterControllerNode::safe_to_flatten_below
// Access: Public, Virtual
// Description: Returns true if a flatten operation may safely
// continue past this node, or false if nodes below this
// node may not be molested.
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
safe_to_flatten_below() const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: BulletCharacterControllerNode::safe_to_transform
// Access: Public, Virtual
// Description: Returns true if it is generally safe to transform
// this particular kind of Node by calling the xform()
// method, false otherwise. For instance, it's usually
// a bad idea to attempt to xform a Character.
////////////////////////////////////////////////////////////////////
bool BulletCharacterControllerNode::
safe_to_transform() const {
return false;
// TODO set_into_collide_mask(CollideMask::all_on());
}
////////////////////////////////////////////////////////////////////

View File

@ -20,9 +20,8 @@
#include "bullet_includes.h"
#include "bullet_utils.h"
#include "bulletShape.h"
#include "bulletBaseCharacterControllerNode.h"
#include "pandaNode.h"
#include "collideMask.h"
#include "luse.h"
#include "transformState.h"
#include "nodePath.h"
@ -31,7 +30,7 @@
// Class : BulletCharacterControllerNode
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_PANDABULLET BulletCharacterControllerNode : public PandaNode {
class EXPCL_PANDABULLET BulletCharacterControllerNode : public BulletBaseCharacterControllerNode {
PUBLISHED:
BulletCharacterControllerNode(BulletShape *shape, PN_stdfloat step_height, const char *name="character");
@ -57,20 +56,11 @@ PUBLISHED:
void do_jump();
public:
virtual CollideMask get_legal_collide_mask() const;
INLINE virtual btPairCachingGhostObject *get_ghost() const;
INLINE virtual btCharacterControllerInterface *get_character() const;
virtual bool safe_to_flatten() const;
virtual bool safe_to_transform() const;
virtual bool safe_to_modify_transform() const;
virtual bool safe_to_combine() const;
virtual bool safe_to_combine_children() const;
virtual bool safe_to_flatten_below() const;
INLINE btPairCachingGhostObject *get_ghost() const;
INLINE btKinematicCharacterController *get_character() const;
void sync_p2b(PN_stdfloat dt, int num_substeps);
void sync_b2p();
virtual void sync_p2b(PN_stdfloat dt, int num_substeps);
virtual void sync_b2p();
protected:
virtual void transform_changed();
@ -96,9 +86,9 @@ public:
return _type_handle;
}
static void init_type() {
PandaNode::init_type();
BulletBaseCharacterControllerNode::init_type();
register_type(_type_handle, "BulletCharacterControllerNode",
PandaNode::get_class_type());
BulletBaseCharacterControllerNode::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();

View File

@ -69,7 +69,7 @@ parents_changed() {
if (BulletRigidBodyNode::get_class_type() == type ||
BulletSoftBodyNode::get_class_type() == type ||
BulletGhostNode::get_class_type() == type ||
BulletCharacterControllerNode::get_class_type() == type) {
type.is_derived_from(BulletBaseCharacterControllerNode::get_class_type())) {
_sync_local = true;
return;

View File

@ -172,7 +172,7 @@ get_num_characters() const {
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE BulletCharacterControllerNode *BulletWorld::
INLINE BulletBaseCharacterControllerNode *BulletWorld::
get_character(int idx) const {
nassertr(idx >= 0 && idx < (int)_characters.size(), NULL);

View File

@ -446,12 +446,12 @@ remove_ghost(BulletGhostNode *node) {
// Description:
////////////////////////////////////////////////////////////////////
void BulletWorld::
attach_character(BulletCharacterControllerNode *node) {
attach_character(BulletBaseCharacterControllerNode *node) {
nassertv(node);
BulletCharacterControllers::iterator found;
PT(BulletCharacterControllerNode) ptnode = node;
PT(BulletBaseCharacterControllerNode) ptnode = node;
found = find(_characters.begin(), _characters.end(), ptnode);
if (found == _characters.end()) {
@ -474,12 +474,12 @@ attach_character(BulletCharacterControllerNode *node) {
// Description:
////////////////////////////////////////////////////////////////////
void BulletWorld::
remove_character(BulletCharacterControllerNode *node) {
remove_character(BulletBaseCharacterControllerNode *node) {
nassertv(node);
BulletCharacterControllers::iterator found;
PT(BulletCharacterControllerNode) ptnode = node;
PT(BulletBaseCharacterControllerNode) ptnode = node;
found = find(_characters.begin(), _characters.end(), ptnode);
if (found == _characters.end()) {
@ -715,8 +715,8 @@ get_collision_object(PandaNode *node) {
else if (node->is_of_type(BulletGhostNode::get_class_type())) {
return ((BulletGhostNode *)node)->get_object();
}
else if (node->is_of_type(BulletCharacterControllerNode::get_class_type())) {
return ((BulletCharacterControllerNode *)node)->get_ghost();
else if (node->is_of_type(BulletBaseCharacterControllerNode::get_class_type())) {
return ((BulletBaseCharacterControllerNode *)node)->get_ghost();
}
else if (node->is_of_type(BulletSoftBodyNode::get_class_type())) {
return ((BulletSoftBodyNode *)node)->get_object();

View File

@ -25,7 +25,7 @@
#include "bulletClosestHitSweepResult.h"
#include "bulletContactResult.h"
#include "bulletDebugNode.h"
#include "bulletCharacterControllerNode.h"
#include "bulletBaseCharacterControllerNode.h"
#include "bulletConstraint.h"
#include "bulletGhostNode.h"
#include "bulletRigidBodyNode.h"
@ -88,11 +88,11 @@ PUBLISHED:
MAKE_SEQ(get_soft_bodies, get_num_soft_bodies, get_soft_body);
// Character controller
void attach_character(BulletCharacterControllerNode *node);
void remove_character(BulletCharacterControllerNode *node);
void attach_character(BulletBaseCharacterControllerNode *node);
void remove_character(BulletBaseCharacterControllerNode *node);
INLINE int get_num_characters() const;
INLINE BulletCharacterControllerNode *get_character(int idx) const;
INLINE BulletBaseCharacterControllerNode *get_character(int idx) const;
MAKE_SEQ(get_characters, get_num_characters, get_character);
// Vehicle
@ -166,7 +166,7 @@ private:
typedef PTA(PT(BulletRigidBodyNode)) BulletRigidBodies;
typedef PTA(PT(BulletSoftBodyNode)) BulletSoftBodies;
typedef PTA(PT(BulletGhostNode)) BulletGhosts;
typedef PTA(PT(BulletCharacterControllerNode)) BulletCharacterControllers;
typedef PTA(PT(BulletBaseCharacterControllerNode)) BulletCharacterControllers;
typedef PTA(PT(BulletVehicle)) BulletVehicles;
typedef PTA(PT(BulletConstraint)) BulletConstraints;

View File

@ -14,6 +14,7 @@
#include "config_bullet.h"
#include "bulletBaseCharacterControllerNode.h"
#include "bulletBodyNode.h"
#include "bulletBoxShape.h"
#include "bulletCapsuleShape.h"
@ -144,6 +145,7 @@ init_libbullet() {
// Initialize types
//
BulletBaseCharacterControllerNode::init_type();
BulletBodyNode::init_type();
BulletBoxShape::init_type();
BulletCapsuleShape::init_type();

View File

@ -1,6 +1,7 @@
#include "config_bullet.cxx"
#include "bullet_utils.cxx"
#include "bulletAllHitsRayResult.cxx"
#include "bulletBaseCharacterControllerNode.cxx"
#include "bulletBodyNode.cxx"
#include "bulletBoxShape.cxx"
#include "bulletCapsuleShape.cxx"