eggTransform.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 eggTransform.h
  10. * @author drose
  11. * @date 2002-06-21
  12. */
  13. #ifndef EGGTRANSFORM_H
  14. #define EGGTRANSFORM_H
  15. #include "pandabase.h"
  16. #include "luse.h"
  17. #include "memoryBase.h"
  18. #include "eggObject.h"
  19. /**
  20. * This represents the <Transform> entry of a group or texture node: a list of
  21. * component transform operations, applied in order, that describe a net
  22. * transform matrix.
  23. *
  24. * This may be either a 3-d transform, and therefore described by a 4x4
  25. * matrix, or a 2-d transform, described by a 3x3 matrix.
  26. */
  27. class EXPCL_PANDA_EGG EggTransform : public MemoryBase {
  28. PUBLISHED:
  29. EggTransform();
  30. EggTransform(const EggTransform &copy);
  31. EggTransform &operator = (const EggTransform &copy);
  32. virtual ~EggTransform();
  33. INLINE void clear_transform();
  34. void add_translate2d(const LVector2d &translate);
  35. void add_translate3d(const LVector3d &translate);
  36. void add_rotate2d(double angle);
  37. void add_rotx(double angle);
  38. void add_roty(double angle);
  39. void add_rotz(double angle);
  40. void add_rotate3d(double angle, const LVector3d &axis);
  41. void add_rotate3d(const LQuaterniond &quat);
  42. void add_scale2d(const LVecBase2d &scale);
  43. void add_scale3d(const LVecBase3d &scale);
  44. void add_uniform_scale(double scale);
  45. INLINE void add_matrix3(const LMatrix3d &mat);
  46. INLINE void add_matrix4(const LMatrix4d &mat);
  47. INLINE bool has_transform() const;
  48. INLINE bool has_transform2d() const;
  49. INLINE void set_transform2d(const LMatrix3d &mat);
  50. INLINE bool has_transform3d() const;
  51. INLINE void set_transform3d(const LMatrix4d &mat);
  52. INLINE LMatrix3d get_transform2d() const;
  53. INLINE const LMatrix4d &get_transform3d() const;
  54. INLINE bool transform_is_identity() const;
  55. enum ComponentType {
  56. CT_invalid,
  57. CT_translate2d,
  58. CT_translate3d,
  59. CT_rotate2d,
  60. CT_rotx,
  61. CT_roty,
  62. CT_rotz,
  63. CT_rotate3d,
  64. CT_scale2d,
  65. CT_scale3d,
  66. CT_uniform_scale,
  67. CT_matrix3,
  68. CT_matrix4
  69. };
  70. INLINE int get_num_components() const;
  71. INLINE ComponentType get_component_type(int n) const;
  72. INLINE double get_component_number(int n) const;
  73. INLINE const LVecBase2d &get_component_vec2(int n) const;
  74. INLINE const LVecBase3d &get_component_vec3(int n) const;
  75. INLINE const LMatrix3d &get_component_mat3(int n) const;
  76. INLINE const LMatrix4d &get_component_mat4(int n) const;
  77. void write(std::ostream &out, int indent_level,
  78. const std::string &label) const;
  79. protected:
  80. void internal_clear_transform();
  81. void internal_add_matrix(const LMatrix3d &mat);
  82. void internal_add_matrix(const LMatrix4d &mat);
  83. INLINE void internal_set_transform(const LMatrix3d &mat);
  84. INLINE void internal_set_transform(const LMatrix4d &mat);
  85. virtual void transform_changed();
  86. private:
  87. class Component {
  88. public:
  89. INLINE Component(ComponentType type, double number = 0.0);
  90. INLINE Component(const Component &copy);
  91. INLINE void operator = (const Component &copy);
  92. INLINE ~Component();
  93. ComponentType _type;
  94. double _number;
  95. LVecBase2d *_vec2;
  96. LVecBase3d *_vec3;
  97. LMatrix3d *_mat3;
  98. LMatrix4d *_mat4;
  99. };
  100. bool _is_transform_2d;
  101. typedef pvector<Component> Components;
  102. Components _components;
  103. LMatrix4d _transform;
  104. };
  105. #include "eggTransform.I"
  106. #endif