Panda3D
Loading...
Searching...
No Matches
eggTransform.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 eggTransform.h
10 * @author drose
11 * @date 2002-06-21
12 */
13
14#ifndef EGGTRANSFORM_H
15#define EGGTRANSFORM_H
16
17#include "pandabase.h"
18#include "luse.h"
19#include "eggObject.h"
20
21/**
22 * This represents the <Transform> entry of a group or texture node: a list of
23 * component transform operations, applied in order, that describe a net
24 * transform matrix.
25 *
26 * This may be either a 3-d transform, and therefore described by a 4x4
27 * matrix, or a 2-d transform, described by a 3x3 matrix.
28 */
29class EXPCL_PANDA_EGG EggTransform {
30PUBLISHED:
31 EggTransform();
32 EggTransform(const EggTransform &copy);
33 EggTransform &operator = (const EggTransform &copy);
34 virtual ~EggTransform();
35
36 INLINE void clear_transform();
37
38 void add_translate2d(const LVector2d &translate);
39 void add_translate3d(const LVector3d &translate);
40 void add_rotate2d(double angle);
41 void add_rotx(double angle);
42 void add_roty(double angle);
43 void add_rotz(double angle);
44 void add_rotate3d(double angle, const LVector3d &axis);
45 void add_rotate3d(const LQuaterniond &quat);
46 void add_scale2d(const LVecBase2d &scale);
47 void add_scale3d(const LVecBase3d &scale);
48 void add_uniform_scale(double scale);
49 INLINE void add_matrix3(const LMatrix3d &mat);
50 INLINE void add_matrix4(const LMatrix4d &mat);
51
52 INLINE bool has_transform() const;
53 INLINE bool has_transform2d() const;
54 INLINE void set_transform2d(const LMatrix3d &mat);
55 INLINE bool has_transform3d() const;
56 INLINE void set_transform3d(const LMatrix4d &mat);
57 INLINE LMatrix3d get_transform2d() const;
58 INLINE const LMatrix4d &get_transform3d() const;
59 INLINE bool transform_is_identity() const;
60
61 enum ComponentType {
62 CT_invalid,
63 CT_translate2d,
64 CT_translate3d,
65 CT_rotate2d,
66 CT_rotx,
67 CT_roty,
68 CT_rotz,
69 CT_rotate3d,
70 CT_scale2d,
71 CT_scale3d,
72 CT_uniform_scale,
73 CT_matrix3,
74 CT_matrix4
75 };
76
77 INLINE int get_num_components() const;
78 INLINE ComponentType get_component_type(int n) const;
79 INLINE double get_component_number(int n) const;
80 INLINE const LVecBase2d &get_component_vec2(int n) const;
81 INLINE const LVecBase3d &get_component_vec3(int n) const;
82 INLINE const LMatrix3d &get_component_mat3(int n) const;
83 INLINE const LMatrix4d &get_component_mat4(int n) const;
84
85 void write(std::ostream &out, int indent_level,
86 const std::string &label) const;
87
88protected:
89 void internal_clear_transform();
90 void internal_add_matrix(const LMatrix3d &mat);
91 void internal_add_matrix(const LMatrix4d &mat);
92 INLINE void internal_set_transform(const LMatrix3d &mat);
93 INLINE void internal_set_transform(const LMatrix4d &mat);
94
95 virtual void transform_changed();
96
97private:
98 class Component {
99 public:
100 INLINE Component(ComponentType type, double number = 0.0);
101 INLINE Component(const Component &copy);
102 INLINE void operator = (const Component &copy);
103 INLINE ~Component();
104
105 ComponentType _type;
106 double _number;
107 LVecBase2d *_vec2;
108 LVecBase3d *_vec3;
109 LMatrix3d *_mat3;
110 LMatrix4d *_mat4;
111 };
112
113 bool _is_transform_2d;
114 typedef pvector<Component> Components;
115 Components _components;
116 LMatrix4d _transform;
117};
118
119#include "eggTransform.I"
120
121#endif
const LMatrix4d & get_transform3d() const
Returns the overall transform as a 4x4 matrix.
void add_rotz(double angle)
Appends a rotation about the Z axis to the current transform.
bool has_transform() const
Returns true if the transform is nonempty, false if it is empty (no transform components have been ad...
void add_rotate2d(double angle)
Appends a 2-d rotation to the current transform.
const LVecBase3d & get_component_vec3(int n) const
Returns the 3-component vector associated with the nth component.
ComponentType get_component_type(int n) const
Returns the type of the nth component.
bool has_transform3d() const
Returns true if the transform is specified as a 3-d transform, e.g.
void clear_transform()
Resets the transform to empty, identity.
void add_scale3d(const LVecBase3d &scale)
Appends a possibly non-uniform scale to the current transform.
void set_transform3d(const LMatrix4d &mat)
Sets the overall transform as a 4x4 matrix.
void add_rotx(double angle)
Appends a rotation about the X axis to the current transform.
const LVecBase2d & get_component_vec2(int n) const
Returns the 2-component vector associated with the nth component.
bool has_transform2d() const
Returns true if the transform is specified as a 2-d transform, e.g.
int get_num_components() const
Returns the number of components that make up the transform.
const LMatrix3d & get_component_mat3(int n) const
Returns the 3x3 matrix associated with the nth component.
void add_matrix4(const LMatrix4d &mat)
Appends an arbitrary 4x4 matrix to the current transform.
const LMatrix4d & get_component_mat4(int n) const
Returns the 4x4 matrix associated with the nth component.
void add_uniform_scale(double scale)
Appends a uniform scale to the current transform.
void add_translate3d(const LVector3d &translate)
Appends a 3-d translation operation to the current transform.
void set_transform2d(const LMatrix3d &mat)
Sets the overall transform as a 3x3 matrix.
void write(std::ostream &out, int indent_level, const std::string &label) const
Writes the transform to the indicated stream in Egg format.
void add_roty(double angle)
Appends a rotation about the Y axis to the current transform.
void add_scale2d(const LVecBase2d &scale)
Appends a possibly non-uniform scale to the current transform.
void add_rotate3d(double angle, const LVector3d &axis)
Appends a 3-d rotation about an arbitrary axis to the current transform.
void add_translate2d(const LVector2d &translate)
Appends a 2-d translation operation to the current transform.
double get_component_number(int n) const
Returns the solitary number associated with the nth component.
LMatrix3d get_transform2d() const
Returns the overall transform as a 3x3 matrix.
bool transform_is_identity() const
Returns true if the described transform is identity, false otherwise.
void add_matrix3(const LMatrix3d &mat)
Appends an arbitrary 3x3 matrix to the current transform.
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.