Panda3D
transformBlend.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file transformBlend.h
10  * @author drose
11  * @date 2005-03-24
12  */
13 
14 #ifndef TRANSFORMBLEND_H
15 #define TRANSFORMBLEND_H
16 
17 #include "pandabase.h"
18 #include "vertexTransform.h"
19 #include "pointerTo.h"
20 #include "pvector.h"
21 #include "ordered_vector.h"
22 #include "cycleData.h"
23 #include "cycleDataLockedReader.h"
24 #include "cycleDataReader.h"
25 #include "cycleDataWriter.h"
26 #include "pipelineCycler.h"
27 
28 /**
29  * This defines a single entry in a TransformBlendTable. It represents a
30  * unique combination of VertexTransform pointers and blend amounts.
31  */
32 class EXPCL_PANDA_GOBJ TransformBlend {
33 PUBLISHED:
34  INLINE TransformBlend();
35  INLINE TransformBlend(const VertexTransform *transform0, PN_stdfloat weight0);
36  INLINE TransformBlend(const VertexTransform *transform0, PN_stdfloat weight0,
37  const VertexTransform *transform1, PN_stdfloat weight1);
38  INLINE TransformBlend(const VertexTransform *transform0, PN_stdfloat weight0,
39  const VertexTransform *transform1, PN_stdfloat weight1,
40  const VertexTransform *transform2, PN_stdfloat weight2);
41  INLINE TransformBlend(const VertexTransform *transform0, PN_stdfloat weight0,
42  const VertexTransform *transform1, PN_stdfloat weight1,
43  const VertexTransform *transform2, PN_stdfloat weight2,
44  const VertexTransform *transform3, PN_stdfloat weight3);
45  INLINE TransformBlend(const TransformBlend &copy);
46  INLINE void operator = (const TransformBlend &copy);
47  INLINE ~TransformBlend();
48 
49  int compare_to(const TransformBlend &other) const;
50  INLINE bool operator < (const TransformBlend &other) const;
51  INLINE bool operator == (const TransformBlend &other) const;
52  INLINE bool operator != (const TransformBlend &other) const;
53 
54  void add_transform(const VertexTransform *transform, PN_stdfloat weight);
55  void remove_transform(const VertexTransform *transform);
56  void limit_transforms(int max_transforms);
57  void normalize_weights();
58  bool has_transform(const VertexTransform *transform) const;
59  PN_stdfloat get_weight(const VertexTransform *transform) const;
60 
61  INLINE size_t get_num_transforms() const;
62  INLINE const VertexTransform *get_transform(size_t n) const;
63  MAKE_SEQ(get_transforms, get_num_transforms, get_transform);
64  INLINE PN_stdfloat get_weight(size_t n) const;
65  INLINE void remove_transform(size_t n);
66  INLINE void set_transform(size_t n, const VertexTransform *transform);
67  INLINE void set_weight(size_t n, PN_stdfloat weight);
68 
69  MAKE_SEQ_PROPERTY(transforms, get_num_transforms, get_transform,
70  set_transform, remove_transform);
71  MAKE_MAP_PROPERTY(weights, has_transform, get_weight);
72  MAKE_MAP_KEYS_SEQ(weights, get_num_transforms, get_transform);
73 
74  INLINE void update_blend(Thread *current_thread) const;
75 
76  INLINE void get_blend(LMatrix4 &result, Thread *current_thread) const;
77 
78  INLINE void transform_point(LPoint4f &point, Thread *current_thread) const;
79  INLINE void transform_point(LPoint3f &point, Thread *current_thread) const;
80  INLINE void transform_vector(LVector3f &point, Thread *current_thread) const;
81 
82  INLINE void transform_point(LPoint4d &point, Thread *current_thread) const;
83  INLINE void transform_point(LPoint3d &point, Thread *current_thread) const;
84  INLINE void transform_vector(LVector3d &point, Thread *current_thread) const;
85 
86  INLINE UpdateSeq get_modified(Thread *current_thread = Thread::get_current_thread()) const;
87  MAKE_PROPERTY(modified, get_modified);
88 
89  void output(std::ostream &out) const;
90  void write(std::ostream &out, int indent_level) const;
91 
92 private:
93  class CData;
94 
95  void recompute_result(CData *cdata, Thread *current_thread);
96  void clear_result(Thread *current_thread);
97 
98  class TransformEntry {
99  public:
100  INLINE bool operator < (const TransformEntry &other) const;
101 
102  CPT(VertexTransform) _transform;
103  PN_stdfloat _weight;
104  };
105  typedef ov_set<TransformEntry> Entries;
106  Entries _entries;
107 
108  // This is the data that must be cycled between pipeline stages; it is just
109  // a local cache.
110  class EXPCL_PANDA_GOBJ CData : public CycleData {
111  public:
112  INLINE CData();
113  INLINE CData(const CData &copy);
114  virtual CycleData *make_copy() const;
115  virtual TypeHandle get_parent_type() const {
116  return TransformBlend::get_class_type();
117  }
118 
119  LMatrix4 _result;
120  UpdateSeq _modified;
121  UpdateSeq _global_modified;
122  };
123 
124  PipelineCycler<CData> _cycler;
125  typedef CycleDataLockedReader<CData> CDLockedReader;
126  typedef CycleDataReader<CData> CDReader;
127  typedef CycleDataWriter<CData> CDWriter;
128 
129 public:
130  void write_datagram(BamWriter *manager, Datagram &dg) const;
132  void fillin(DatagramIterator &scan, BamReader *manager);
133 
134  friend class VertexTransform;
135 
136 public:
137  static TypeHandle get_class_type() {
138  return _type_handle;
139  }
140  static void init_type() {
141  register_type(_type_handle, "TransformBlend");
142  }
143 
144 private:
145  static TypeHandle _type_handle;
146 };
147 
148 INLINE std::ostream &operator << (std::ostream &out, const TransformBlend &obj);
149 
150 #include "transformBlend.I"
151 
152 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:47
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:76
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
virtual void write_datagram(BamWriter *, Datagram &) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: cycleData.cxx:32
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract base class that holds a pointer to some transform, computed in some arbitrary way...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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().
Definition: cycleData.cxx:48
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines a single entry in a TransformBlendTable.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
Definition: cycleData.cxx:58
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:73
A thread; that is, a lightweight process.
Definition: thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.