Panda3D
|
00001 // Filename: transformBlend.h 00002 // Created by: drose (24Mar05) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef TRANSFORMBLEND_H 00016 #define TRANSFORMBLEND_H 00017 00018 #include "pandabase.h" 00019 #include "vertexTransform.h" 00020 #include "pointerTo.h" 00021 #include "pvector.h" 00022 #include "ordered_vector.h" 00023 #include "cycleData.h" 00024 #include "cycleDataLockedReader.h" 00025 #include "cycleDataReader.h" 00026 #include "cycleDataWriter.h" 00027 #include "pipelineCycler.h" 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Class : TransformBlend 00031 // Description : This defines a single entry in a 00032 // TransformBlendTable. It represents a unique 00033 // combination of VertexTransform pointers and blend 00034 // amounts. 00035 //////////////////////////////////////////////////////////////////// 00036 class EXPCL_PANDA_GOBJ TransformBlend { 00037 PUBLISHED: 00038 INLINE TransformBlend(); 00039 INLINE TransformBlend(const VertexTransform *transform0, float weight0); 00040 INLINE TransformBlend(const VertexTransform *transform0, float weight0, 00041 const VertexTransform *transform1, float weight1); 00042 INLINE TransformBlend(const VertexTransform *transform0, float weight0, 00043 const VertexTransform *transform1, float weight1, 00044 const VertexTransform *transform2, float weight2); 00045 INLINE TransformBlend(const VertexTransform *transform0, float weight0, 00046 const VertexTransform *transform1, float weight1, 00047 const VertexTransform *transform2, float weight2, 00048 const VertexTransform *transform3, float weight3); 00049 INLINE TransformBlend(const TransformBlend ©); 00050 INLINE void operator = (const TransformBlend ©); 00051 INLINE ~TransformBlend(); 00052 00053 int compare_to(const TransformBlend &other) const; 00054 INLINE bool operator < (const TransformBlend &other) const; 00055 INLINE bool operator == (const TransformBlend &other) const; 00056 INLINE bool operator != (const TransformBlend &other) const; 00057 00058 void add_transform(const VertexTransform *transform, float weight); 00059 void remove_transform(const VertexTransform *transform); 00060 void normalize_weights(); 00061 bool has_transform(const VertexTransform *transform) const; 00062 float get_weight(const VertexTransform *transform) const; 00063 00064 INLINE int get_num_transforms() const; 00065 INLINE const VertexTransform *get_transform(int n) const; 00066 MAKE_SEQ(get_transforms, get_num_transforms, get_transform); 00067 INLINE float get_weight(int n) const; 00068 INLINE void set_transform(int n, const VertexTransform *transform); 00069 INLINE void set_weight(int n, float weight); 00070 00071 INLINE void update_blend(Thread *current_thread) const; 00072 00073 INLINE void get_blend(LMatrix4f &result, Thread *current_thread) const; 00074 INLINE void transform_point(LPoint4f &point, Thread *current_thread) const; 00075 INLINE void transform_point(LPoint3f &point, Thread *current_thread) const; 00076 INLINE void transform_vector(LVector3f &point, Thread *current_thread) const; 00077 INLINE UpdateSeq get_modified(Thread *current_thread) const; 00078 00079 void output(ostream &out) const; 00080 void write(ostream &out, int indent_level) const; 00081 00082 private: 00083 class CData; 00084 00085 void recompute_result(CData *cdata, Thread *current_thread); 00086 void clear_result(Thread *current_thread); 00087 00088 class TransformEntry { 00089 public: 00090 INLINE bool operator < (const TransformEntry &other) const; 00091 00092 CPT(VertexTransform) _transform; 00093 float _weight; 00094 }; 00095 typedef ov_set<TransformEntry> Entries; 00096 Entries _entries; 00097 00098 // This is the data that must be cycled between pipeline stages; it 00099 // is just a local cache. 00100 class EXPCL_PANDA_GOBJ CData : public CycleData { 00101 public: 00102 INLINE CData(); 00103 INLINE CData(const CData ©); 00104 virtual CycleData *make_copy() const; 00105 virtual TypeHandle get_parent_type() const { 00106 return TransformBlend::get_class_type(); 00107 } 00108 00109 LMatrix4f _result; 00110 UpdateSeq _modified; 00111 UpdateSeq _global_modified; 00112 }; 00113 00114 PipelineCycler<CData> _cycler; 00115 typedef CycleDataLockedReader<CData> CDLockedReader; 00116 typedef CycleDataReader<CData> CDReader; 00117 typedef CycleDataWriter<CData> CDWriter; 00118 00119 public: 00120 void write_datagram(BamWriter *manager, Datagram &dg) const; 00121 int complete_pointers(TypedWritable **plist, BamReader *manager); 00122 void fillin(DatagramIterator &scan, BamReader *manager); 00123 00124 friend class VertexTransform; 00125 00126 public: 00127 static TypeHandle get_class_type() { 00128 return _type_handle; 00129 } 00130 static void init_type() { 00131 register_type(_type_handle, "TransformBlend"); 00132 } 00133 00134 private: 00135 static TypeHandle _type_handle; 00136 }; 00137 00138 INLINE ostream &operator << (ostream &out, const TransformBlend &obj); 00139 00140 #include "transformBlend.I" 00141 00142 #endif