Panda3D
Loading...
Searching...
No Matches
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"
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 */
32class EXPCL_PANDA_GOBJ TransformBlend {
33PUBLISHED:
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,
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
92private:
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
129public:
130 void write_datagram(BamWriter *manager, Datagram &dg) const;
131 int complete_pointers(TypedWritable **plist, BamReader *manager);
132 void fillin(DatagramIterator &scan, BamReader *manager);
133
134 friend class VertexTransform;
135
136public:
137 static TypeHandle get_class_type() {
138 return _type_handle;
139 }
140 static void init_type() {
141 register_type(_type_handle, "TransformBlend");
142 }
143
144private:
145 static TypeHandle _type_handle;
146};
147
148INLINE std::ostream &operator << (std::ostream &out, const TransformBlend &obj);
149
150#include "transformBlend.I"
151
152#endif
A single page of data maintained by a PipelineCycler.
Definition cycleData.h:50
A thread; that is, a lightweight process.
Definition thread.h:46
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109
This defines a single entry in a TransformBlendTable.
void limit_transforms(int max_transforms)
If the total number of transforms in the blend exceeds max_transforms, removes the n least-important ...
void update_blend(Thread *current_thread) const
Recomputes the internal representation of the blend value, if necessary.
get_num_transforms
Returns the number of transforms stored in the blend object.
void transform_vector(LVector3f &point, Thread *current_thread) const
Transforms the indicated vector by the blend matrix.
has_transform
Returns true if the blend has the indicated transform, false otherwise.
get_weight
Returns the weight associated with the indicated transform, or 0 if there is no entry for the transfo...
void set_weight(size_t n, PN_stdfloat weight)
Replaces the weight associated with the nth transform stored in the blend object.
int compare_to(const TransformBlend &other) const
Defines an arbitrary ordering for TransformBlend objects.
void get_blend(LMatrix4 &result, Thread *current_thread) const
Returns the current value of the blend, based on the current value of all of the nested transform obj...
void transform_point(LPoint4f &point, Thread *current_thread) const
Transforms the indicated point by the blend matrix.
remove_transform
Removes the indicated transform from the blend.
set_transform
Replaces the nth transform stored in the blend object.
get_transform
Returns the nth transform stored in the blend object.
get_modified
Returns a counter which is guaranteed to increment at least as often as the result of get_blend() cha...
void normalize_weights()
Rescales all of the weights on the various transforms so that they sum to 1.0.
void add_transform(const VertexTransform *transform, PN_stdfloat weight)
Adds a new transform to the blend.
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
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.