Panda3D
transformBlend.h
1 // Filename: transformBlend.h
2 // Created by: drose (24Mar05)
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 TRANSFORMBLEND_H
16 #define TRANSFORMBLEND_H
17 
18 #include "pandabase.h"
19 #include "vertexTransform.h"
20 #include "pointerTo.h"
21 #include "pvector.h"
22 #include "ordered_vector.h"
23 #include "cycleData.h"
24 #include "cycleDataLockedReader.h"
25 #include "cycleDataReader.h"
26 #include "cycleDataWriter.h"
27 #include "pipelineCycler.h"
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : TransformBlend
31 // Description : This defines a single entry in a
32 // TransformBlendTable. It represents a unique
33 // combination of VertexTransform pointers and blend
34 // amounts.
35 ////////////////////////////////////////////////////////////////////
36 class EXPCL_PANDA_GOBJ TransformBlend {
37 PUBLISHED:
38  INLINE TransformBlend();
39  INLINE TransformBlend(const VertexTransform *transform0, PN_stdfloat weight0);
40  INLINE TransformBlend(const VertexTransform *transform0, PN_stdfloat weight0,
41  const VertexTransform *transform1, PN_stdfloat weight1);
42  INLINE TransformBlend(const VertexTransform *transform0, PN_stdfloat weight0,
43  const VertexTransform *transform1, PN_stdfloat weight1,
44  const VertexTransform *transform2, PN_stdfloat weight2);
45  INLINE TransformBlend(const VertexTransform *transform0, PN_stdfloat weight0,
46  const VertexTransform *transform1, PN_stdfloat weight1,
47  const VertexTransform *transform2, PN_stdfloat weight2,
48  const VertexTransform *transform3, PN_stdfloat weight3);
49  INLINE TransformBlend(const TransformBlend &copy);
50  INLINE void operator = (const TransformBlend &copy);
51  INLINE ~TransformBlend();
52 
53  int compare_to(const TransformBlend &other) const;
54  INLINE bool operator < (const TransformBlend &other) const;
55  INLINE bool operator == (const TransformBlend &other) const;
56  INLINE bool operator != (const TransformBlend &other) const;
57 
58  void add_transform(const VertexTransform *transform, PN_stdfloat weight);
59  void remove_transform(const VertexTransform *transform);
60  void limit_transforms(int max_transforms);
61  void normalize_weights();
62  bool has_transform(const VertexTransform *transform) const;
63  PN_stdfloat get_weight(const VertexTransform *transform) const;
64 
65  INLINE int get_num_transforms() const;
66  INLINE const VertexTransform *get_transform(int n) const;
67  MAKE_SEQ(get_transforms, get_num_transforms, get_transform);
68  INLINE PN_stdfloat get_weight(int n) const;
69  INLINE void set_transform(int n, const VertexTransform *transform);
70  INLINE void set_weight(int n, PN_stdfloat weight);
71 
72  INLINE void update_blend(Thread *current_thread) const;
73 
74  INLINE void get_blend(LMatrix4 &result, Thread *current_thread) const;
75 
76  INLINE void transform_point(LPoint4f &point, Thread *current_thread) const;
77  INLINE void transform_point(LPoint3f &point, Thread *current_thread) const;
78  INLINE void transform_vector(LVector3f &point, Thread *current_thread) const;
79 
80  INLINE void transform_point(LPoint4d &point, Thread *current_thread) const;
81  INLINE void transform_point(LPoint3d &point, Thread *current_thread) const;
82  INLINE void transform_vector(LVector3d &point, Thread *current_thread) const;
83 
84  INLINE UpdateSeq get_modified(Thread *current_thread) const;
85 
86  void output(ostream &out) const;
87  void write(ostream &out, int indent_level) const;
88 
89 private:
90  class CData;
91 
92  void recompute_result(CData *cdata, Thread *current_thread);
93  void clear_result(Thread *current_thread);
94 
95  class TransformEntry {
96  public:
97  INLINE bool operator < (const TransformEntry &other) const;
98 
99  CPT(VertexTransform) _transform;
100  PN_stdfloat _weight;
101  };
103  Entries _entries;
104 
105  // This is the data that must be cycled between pipeline stages; it
106  // is just a local cache.
107  class EXPCL_PANDA_GOBJ CData : public CycleData {
108  public:
109  INLINE CData();
110  INLINE CData(const CData &copy);
111  virtual CycleData *make_copy() const;
112  virtual TypeHandle get_parent_type() const {
113  return TransformBlend::get_class_type();
114  }
115 
116  LMatrix4 _result;
117  UpdateSeq _modified;
118  UpdateSeq _global_modified;
119  };
120 
121  PipelineCycler<CData> _cycler;
125 
126 public:
127  void write_datagram(BamWriter *manager, Datagram &dg) const;
128  int complete_pointers(TypedWritable **plist, BamReader *manager);
129  void fillin(DatagramIterator &scan, BamReader *manager);
130 
131  friend class VertexTransform;
132 
133 public:
134  static TypeHandle get_class_type() {
135  return _type_handle;
136  }
137  static void init_type() {
138  register_type(_type_handle, "TransformBlend");
139  }
140 
141 private:
142  static TypeHandle _type_handle;
143 };
144 
145 INLINE ostream &operator << (ostream &out, const TransformBlend &obj);
146 
147 #include "transformBlend.I"
148 
149 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This is a four-component point in space.
Definition: lpoint4.h:457
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
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
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This is an abstract base class that holds a pointer to some transform, computed in some arbitrary way...
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
This defines a single entry in a TransformBlendTable.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:760
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:79
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:544
This is a four-component point in space.
Definition: lpoint4.h:91
A thread; that is, a lightweight process.
Definition: thread.h:51
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
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43