diff --git a/panda/src/bullet/bulletBaseCharacterControllerNode.I b/panda/src/bullet/bulletBaseCharacterControllerNode.I new file mode 100644 index 0000000000..6bb8200b0c --- /dev/null +++ b/panda/src/bullet/bulletBaseCharacterControllerNode.I @@ -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." +// +//////////////////////////////////////////////////////////////////// + + diff --git a/panda/src/bullet/bulletBaseCharacterControllerNode.cxx b/panda/src/bullet/bulletBaseCharacterControllerNode.cxx new file mode 100644 index 0000000000..d226bd89fd --- /dev/null +++ b/panda/src/bullet/bulletBaseCharacterControllerNode.cxx @@ -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; +} + diff --git a/panda/src/bullet/bulletBaseCharacterControllerNode.h b/panda/src/bullet/bulletBaseCharacterControllerNode.h new file mode 100644 index 0000000000..6b408c73d1 --- /dev/null +++ b/panda/src/bullet/bulletBaseCharacterControllerNode.h @@ -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__ + diff --git a/panda/src/bullet/bulletCharacterControllerNode.I b/panda/src/bullet/bulletCharacterControllerNode.I index b791855a21..e2aae1dc66 100644 --- a/panda/src/bullet/bulletCharacterControllerNode.I +++ b/panda/src/bullet/bulletCharacterControllerNode.I @@ -39,7 +39,7 @@ get_ghost() const { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE btKinematicCharacterController *BulletCharacterControllerNode:: +INLINE btCharacterControllerInterface *BulletCharacterControllerNode:: get_character() const { return _character; diff --git a/panda/src/bullet/bulletCharacterControllerNode.cxx b/panda/src/bullet/bulletCharacterControllerNode.cxx index 20c0e2e4fc..74fd8f3235 100644 --- a/panda/src/bullet/bulletCharacterControllerNode.cxx +++ b/panda/src/bullet/bulletCharacterControllerNode.cxx @@ -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()); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/bullet/bulletCharacterControllerNode.h b/panda/src/bullet/bulletCharacterControllerNode.h index ef83cc0f37..667bb0a7a3 100644 --- a/panda/src/bullet/bulletCharacterControllerNode.h +++ b/panda/src/bullet/bulletCharacterControllerNode.h @@ -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(); diff --git a/panda/src/bullet/bulletGhostNode.cxx b/panda/src/bullet/bulletGhostNode.cxx index 13c17ee064..d60278ff98 100644 --- a/panda/src/bullet/bulletGhostNode.cxx +++ b/panda/src/bullet/bulletGhostNode.cxx @@ -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; diff --git a/panda/src/bullet/bulletWorld.I b/panda/src/bullet/bulletWorld.I index 89a76039d3..5a85cab4b6 100644 --- a/panda/src/bullet/bulletWorld.I +++ b/panda/src/bullet/bulletWorld.I @@ -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); diff --git a/panda/src/bullet/bulletWorld.cxx b/panda/src/bullet/bulletWorld.cxx index 45bdc6491a..d107eb7cf9 100644 --- a/panda/src/bullet/bulletWorld.cxx +++ b/panda/src/bullet/bulletWorld.cxx @@ -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(); diff --git a/panda/src/bullet/bulletWorld.h b/panda/src/bullet/bulletWorld.h index 8ed8671c65..5581a308a7 100644 --- a/panda/src/bullet/bulletWorld.h +++ b/panda/src/bullet/bulletWorld.h @@ -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; diff --git a/panda/src/bullet/config_bullet.cxx b/panda/src/bullet/config_bullet.cxx index d4a4175d43..90131ced62 100644 --- a/panda/src/bullet/config_bullet.cxx +++ b/panda/src/bullet/config_bullet.cxx @@ -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(); diff --git a/panda/src/bullet/p3bullet_composite.cxx b/panda/src/bullet/p3bullet_composite.cxx index 88de24c4ac..b8789875bb 100644 --- a/panda/src/bullet/p3bullet_composite.cxx +++ b/panda/src/bullet/p3bullet_composite.cxx @@ -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"