Panda3D
 All Classes Functions Variables Enumerations
collisionNode.h
1 // Filename: collisionNode.h
2 // Created by: drose (16Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef COLLISIONNODE_H
16 #define COLLISIONNODE_H
17 
18 #include "pandabase.h"
19 
20 #include "collisionSolid.h"
21 
22 #include "collideMask.h"
23 #include "pandaNode.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : CollisionNode
27 // Description : A node in the scene graph that can hold any number of
28 // CollisionSolids. This may either represent a bit of
29 // static geometry in the scene that things will collide
30 // with, or an animated object twirling around in the
31 // world and running into things.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_PANDA_COLLIDE CollisionNode : public PandaNode {
34 PUBLISHED:
35  CollisionNode(const string &name);
36 
37 protected:
38  CollisionNode(const CollisionNode &copy);
39 
40 public:
41  virtual ~CollisionNode();
42  virtual PandaNode *make_copy() const;
43  virtual bool preserve_name() const;
44  virtual void xform(const LMatrix4 &mat);
45  virtual PandaNode *combine_with(PandaNode *other);
46  virtual CollideMask get_legal_collide_mask() const;
47 
48  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
49  virtual bool is_renderable() const;
50  virtual bool is_collision_node() const;
51 
52  virtual void output(ostream &out) const;
53 
54 PUBLISHED:
55  INLINE void set_collide_mask(CollideMask mask);
56  void set_from_collide_mask(CollideMask mask);
57  INLINE void set_into_collide_mask(CollideMask mask);
58  INLINE CollideMask get_from_collide_mask() const;
59  INLINE CollideMask get_into_collide_mask() const;
60 
61  INLINE void clear_solids();
62  INLINE int get_num_solids() const;
63  INLINE CPT(CollisionSolid) get_solid(int n) const;
64  MAKE_SEQ(get_solids, get_num_solids, get_solid);
65  INLINE PT(CollisionSolid) modify_solid(int n);
66  INLINE void set_solid(int n, CollisionSolid *solid);
67  INLINE void remove_solid(int n);
68  INLINE int add_solid(const CollisionSolid *solid);
69 
70  INLINE int get_collider_sort() const;
71  INLINE void set_collider_sort(int sort);
72 
73  INLINE static CollideMask get_default_collide_mask();
74 
75 protected:
76  virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
77  int &internal_vertices,
78  int pipeline_stage,
79  Thread *current_thread) const;
80 
81 private:
82  CPT(RenderState) get_last_pos_state();
83 
84  // This data is not cycled, for now. We assume the collision
85  // traversal will take place in App only. Perhaps we will revisit
86  // this later.
87  CollideMask _from_collide_mask;
88  int _collider_sort;
89 
91  Solids _solids;
92 
93 public:
94  static void register_with_read_factory();
95  virtual void write_datagram(BamWriter *manager, Datagram &dg);
96  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
97 
98 protected:
99  static TypedWritable *make_from_bam(const FactoryParams &params);
100  void fillin(DatagramIterator &scan, BamReader *manager);
101 
102 public:
103  static TypeHandle get_class_type() {
104  return _type_handle;
105  }
106  static void init_type() {
107  PandaNode::init_type();
108  register_type(_type_handle, "CollisionNode",
109  PandaNode::get_class_type());
110  }
111  virtual TypeHandle get_type() const {
112  return get_class_type();
113  }
114  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
115 
116 private:
117  static TypeHandle _type_handle;
118 };
119 
120 #include "collisionNode.I"
121 
122 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:4164
virtual bool is_collision_node() const
A simple downcast check.
Definition: pandaNode.cxx:2516
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
virtual PandaNode * combine_with(PandaNode *other)
Collapses this PandaNode with the other PandaNode, if possible, and returns a pointer to the combined...
Definition: pandaNode.cxx:397
The abstract base class for all things that can collide with other things in the world, and all the things they can collide with (except geometry).
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
CollideMask get_into_collide_mask() const
Returns the "into" collide mask for this node.
Definition: pandaNode.I:582
This collects together the pieces of data that are accumulated for each node while walking the scene ...
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:4153
virtual bool preserve_name() const
Returns true if the node's name has extrinsic meaning and must be preserved across a flatten operatio...
Definition: pandaNode.cxx:319
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so...
Definition: pandaNode.cxx:377
virtual CollideMask get_legal_collide_mask() const
Returns the subset of CollideMask bits that may be set for this particular type of PandaNode...
Definition: pandaNode.cxx:2069
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void set_into_collide_mask(CollideMask mask)
Sets the "into" CollideMask.
Definition: pandaNode.cxx:2037
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
Definition: pandaNode.cxx:578
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
A thread; that is, a lightweight process.
Definition: thread.h:51
A node in the scene graph that can hold any number of CollisionSolids.
Definition: collisionNode.h:33
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
Definition: pandaNode.cxx:477