Indicates a coordinate-system transform on vertices. More...
#include "transformState.h"
Public Member Functions | |
TransformState (const TransformState ©)=delete | |
virtual | ~TransformState () |
The destructor is responsible for removing the TransformState from the global set if it is there. More... | |
void | cache_ref () const |
bool | cache_unref () const |
int | compare_to (const TransformState &other) const |
Provides an arbitrary ordering among all unique TransformStates, so we can store the essentially different ones in a big set and throw away the rest. More... | |
int | compare_to (const TransformState &other, bool uniquify_matrix) const |
Provides an arbitrary ordering among all unique TransformStates, so we can store the essentially different ones in a big set and throw away the rest. More... | |
bool | components_given () const |
Returns true if the transform was specified componentwise, or false if it was specified with a general 4x4 matrix. More... | |
CPT (TransformState) set_pos(const LVecBase3 &pos) const | |
CPT (TransformState) set_hpr(const LVecBase3 &hpr) const | |
CPT (TransformState) set_quat(const LQuaternion &quat) const | |
CPT (TransformState) set_scale(const LVecBase3 &scale) const | |
CPT (TransformState) set_shear(const LVecBase3 &shear) const | |
CPT (TransformState) set_pos2d(const LVecBase2 &pos) const | |
CPT (TransformState) set_rotate2d(PN_stdfloat rotate) const | |
CPT (TransformState) set_scale2d(const LVecBase2 &scale) const | |
CPT (TransformState) set_shear2d(PN_stdfloat shear) const | |
CPT (TransformState) compose(const TransformState *other) const | |
CPT (TransformState) invert_compose(const TransformState *other) const | |
CPT (TransformState) get_inverse() const | |
CPT (TransformState) get_unique() const | |
virtual TypeHandle | force_init_type () |
size_t | get_composition_cache_num_entries () const |
const TransformState * | get_composition_cache_result (size_t n) const |
size_t | get_composition_cache_size () const |
const TransformState * | get_composition_cache_source (size_t n) const |
int | get_geom_rendering (int geom_rendering) const |
size_t | get_hash () const |
Returns a suitable hash value for phash_map. More... | |
const LVecBase3 & | get_hpr () const |
size_t | get_invert_composition_cache_num_entries () const |
const TransformState * | get_invert_composition_cache_result (size_t n) const |
size_t | get_invert_composition_cache_size () const |
const TransformState * | get_invert_composition_cache_source (size_t n) const |
const LMatrix4 & | get_mat () const |
LMatrix3 | get_mat3 () const |
Returns the 3x3 matrix that describes the 2-d transform. More... | |
const LQuaternion & | get_norm_quat () const |
const LPoint3 & | get_pos () const |
LVecBase2 | get_pos2d () const |
Returns the pos component of the 2-d transform. More... | |
const LQuaternion & | get_quat () const |
PN_stdfloat | get_rotate2d () const |
Returns the rotation component of the 2-d transform as an angle in degrees clockwise about the origin. More... | |
const LVecBase3 & | get_scale () const |
LVecBase2 | get_scale2d () const |
Returns the scale component of the 2-d transform. More... | |
const LVecBase3 & | get_shear () const |
PN_stdfloat | get_shear2d () const |
Returns the shear component of the 2-d transform. More... | |
virtual TypeHandle | get_type () const |
PN_stdfloat | get_uniform_scale () const |
Returns the scale component of the transform, as a single number. More... | |
bool | has_components () const |
Returns true if the transform can be described by separate pos, hpr, and scale components. More... | |
bool | has_hpr () const |
Returns true if the transform's rotation component can be extracted out separately and described as a set of Euler angles. More... | |
bool | has_identity_scale () const |
Returns true if the scale is uniform 1.0, or false if the scale has some real value. More... | |
bool | has_mat () const |
Returns true if the transform can be described as a matrix. More... | |
bool | has_nonzero_shear () const |
Returns true if the shear component is non-zero, false if it is zero or if the matrix cannot be decomposed. More... | |
bool | has_pos () const |
Returns true if the transform's pos component can be extracted out separately. More... | |
bool | has_quat () const |
Returns true if the transform's rotation component can be extracted out separately and described as a quaternion. More... | |
bool | has_scale () const |
Returns true if the transform's scale component can be extracted out separately. More... | |
bool | has_shear () const |
Returns true if the transform's shear component can be extracted out separately. More... | |
bool | has_uniform_scale () const |
Returns true if the scale is uniform across all three axes (and therefore can be expressed as a single number), or false if the transform has a different scale in different dimensions. More... | |
bool | hpr_given () const |
Returns true if the rotation was specified via a trio of Euler angles, false otherwise. More... | |
bool | is_2d () const |
Returns true if the transform has been constructed entirely using the 2-d transform operations, e.g. More... | |
bool | is_identity () const |
Returns true if the transform represents the identity matrix, false otherwise. More... | |
bool | is_invalid () const |
Returns true if the transform represents an invalid matrix, for instance the result of inverting a singular matrix, or false if the transform is valid. More... | |
bool | is_singular () const |
Returns true if the transform represents a singular transform (that is, it has a zero scale, and it cannot be inverted), or false otherwise. More... | |
void | node_ref () const |
bool | node_unref () const |
bool | operator != (const TransformState &other) const |
Opposite of operator ==. More... | |
TransformState & | operator= (const TransformState ©)=delete |
bool | operator== (const TransformState &other) const |
Tests equivalence between two transform states. More... | |
void | output (std::ostream &out) const |
bool | quat_given () const |
Returns true if the rotation was specified via a quaternion, false otherwise. More... | |
virtual bool | unref () const |
Explicitly decrements the reference count. More... | |
bool | validate_composition_cache () const |
void | write (std::ostream &out, int indent_level) const |
void | write_composition_cache (std::ostream &out, int indent_level) const |
virtual void | write_datagram (BamWriter *manager, Datagram &dg) |
Writes the contents of this object to the datagram for shipping out to a Bam file. More... | |
![]() | |
int | get_node_ref_count () const |
Returns the current reference count. More... | |
int | get_referenced_bits () const |
Returns the union of the values defined in the Referenced enum that represents the various things that appear to be holding a pointer to this object. More... | |
void | node_ref () const |
Explicitly increments the reference count. More... | |
bool | node_unref () const |
Explicitly decrements the node reference count and the normal reference count simultaneously. More... | |
bool | test_ref_count_integrity () const |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
![]() | |
void | cache_ref () const |
Explicitly increments the cache reference count and the normal reference count simultaneously. More... | |
void | cache_ref_only () const |
Decrements the cache reference count without affecting the normal reference count. More... | |
bool | cache_unref () const |
Explicitly decrements the cache reference count and the normal reference count simultaneously. More... | |
int | get_cache_ref_count () const |
bool | test_ref_count_integrity () const |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
![]() | |
TypedWritableReferenceCount (const TypedWritableReferenceCount ©) | |
virtual ReferenceCount * | as_reference_count () |
Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type. More... | |
void | operator= (const TypedWritableReferenceCount ©) |
![]() | |
TypedWritable (const TypedWritable ©) | |
virtual int | complete_pointers (TypedWritable **p_list, BamReader *manager) |
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin(). More... | |
vector_uchar | encode_to_bam_stream () const |
Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a bytes object. More... | |
bool | encode_to_bam_stream (vector_uchar &data, BamWriter *writer=nullptr) const |
Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string. More... | |
virtual void | finalize (BamReader *manager) |
Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed. More... | |
UpdateSeq | get_bam_modified () const |
Returns the current bam_modified counter. More... | |
void | mark_bam_modified () |
Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams. More... | |
void | operator= (const TypedWritable ©) |
virtual bool | require_fully_complete () const |
Some objects require all of their nested pointers to have been completed before the objects themselves can be completed. More... | |
virtual void | update_bam_nested (BamWriter *manager) |
Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates. More... | |
![]() | |
TypedObject (const TypedObject ©)=default | |
TypedObject * | as_typed_object () |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
const TypedObject * | as_typed_object () const |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
int | get_best_parent_from_Set (const std::set< int > &) const |
int | get_type_index () const |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More... | |
bool | is_exact_type (TypeHandle handle) const |
Returns true if the current object is the indicated type exactly. More... | |
bool | is_of_type (TypeHandle handle) const |
Returns true if the current object is or derives from the indicated type. More... | |
TypedObject & | operator= (const TypedObject ©)=default |
![]() | |
int | get_ref_count () const |
WeakReferenceList * | get_weak_list () const |
Returns the WeakReferenceList associated with this ReferenceCount object. More... | |
bool | has_weak_list () const |
Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More... | |
void | local_object () |
This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More... | |
void | ref () const |
Explicitly increments the reference count. More... | |
bool | ref_if_nonzero () const |
Atomically increases the reference count of this object if it is not zero. More... | |
bool | test_ref_count_integrity () const |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
bool | test_ref_count_nonzero () const |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More... | |
WeakReferenceList * | weak_ref () |
Adds the indicated PointerToVoid as a weak reference to this object. More... | |
void | weak_unref () |
Removes the indicated PointerToVoid as a weak reference to this object. More... | |
Static Public Member Functions | |
static int | clear_cache () |
static | CPT (TransformState) make_identity() |
static | CPT (TransformState) make_invalid() |
static | CPT (TransformState) make_pos(const LVecBase3 &pos) |
static | CPT (TransformState) make_hpr(const LVecBase3 &hpr) |
static | CPT (TransformState) make_quat(const LQuaternion &quat) |
static | CPT (TransformState) make_pos_hpr(const LVecBase3 &pos |
static | CPT (TransformState) make_scale(PN_stdfloat scale) |
static | CPT (TransformState) make_scale(const LVecBase3 &scale) |
static | CPT (TransformState) make_shear(const LVecBase3 &shear) |
static | CPT (TransformState) make_pos_hpr_scale(const LVecBase3 &pos |
static | CPT (TransformState) make_pos_quat_scale(const LVecBase3 &pos |
static | CPT (TransformState) make_pos_hpr_scale_shear(const LVecBase3 &pos |
static | CPT (TransformState) make_pos_quat_scale_shear(const LVecBase3 &pos |
static | CPT (TransformState) make_mat(const LMatrix4 &mat) |
static | CPT (TransformState) make_pos2d(const LVecBase2 &pos) |
static | CPT (TransformState) make_rotate2d(PN_stdfloat rotate) |
static | CPT (TransformState) make_pos_rotate2d(const LVecBase2 &pos |
static | CPT (TransformState) make_scale2d(PN_stdfloat scale) |
static | CPT (TransformState) make_scale2d(const LVecBase2 &scale) |
static | CPT (TransformState) make_shear2d(PN_stdfloat shear) |
static | CPT (TransformState) make_pos_rotate_scale2d(const LVecBase2 &pos |
static | CPT (TransformState) make_pos_rotate_scale_shear2d(const LVecBase2 &pos |
static | CPT (TransformState) make_mat3(const LMatrix3 &mat) |
static void | flush_level () |
static int | garbage_collect () |
static TypeHandle | get_class_type () |
static int | get_num_states () |
static int | get_num_unused_states () |
static void | init_states () |
static void | init_type () |
static void | list_cycles (std::ostream &out) |
static void | list_states (std::ostream &out) |
static | PT (TypedWritableReferenceCount) change_this(TypedWritableReferenceCount *old_ptr |
static void | register_with_read_factory () |
static bool | validate_states () |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
static | PT (TypedWritableReferenceCount) decode_from_bam_stream(vector_uchar data |
![]() | |
static bool | decode_raw_from_bam_stream (TypedWritable *&ptr, ReferenceCount *&ref_ptr, vector_uchar data, BamReader *reader=nullptr) |
Reads the bytes created by a previous call to encode_to_bam_stream(), and extracts the single object on those bytes. More... | |
static TypeHandle | get_class_type () |
static void | init_type () |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
This function is declared non-inline to work around a compiler bug in g++ 2.96. More... | |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
Public Attributes | |
get_hpr | |
Returns the rotation component of the transform as a trio of Euler angles. More... | |
get_mat | |
Returns the matrix that describes the transform. More... | |
get_norm_quat | |
Returns the rotation component of the transform as a quaternion. More... | |
get_pos | |
Returns the pos component of the transform. More... | |
get_quat | |
Returns the rotation component of the transform as a quaternion. More... | |
get_scale | |
Returns the scale component of the transform. More... | |
get_shear | |
Returns the shear component of the transform. More... | |
static const LVecBase3 & | hpr |
static BamReader * | manager |
static const LQuaternion & | quat |
static PN_stdfloat | rotate |
static const LVecBase3 const LVecBase3 & | scale |
static const LQuaternion const LVecBase3 & | scale |
static PN_stdfloat const LVecBase2 & | scale |
static const LVecBase3 const LVecBase3 const LVecBase3 & | shear |
static const LQuaternion const LVecBase3 const LVecBase3 & | shear |
static PN_stdfloat const LVecBase2 PN_stdfloat | shear |
![]() | |
get_cache_ref_count | |
Returns the current reference count. More... | |
![]() | |
static BamReader * | reader = nullptr) |
![]() | |
get_type | |
![]() | |
get_ref_count | |
Returns the current reference count. More... | |
Friends | |
class | Extension< TransformState > |
Additional Inherited Members | |
![]() | |
enum | Referenced { R_node = 0x001, R_cache = 0x002 } |
![]() | |
static TypedWritable *const | Null = nullptr |
Indicates a coordinate-system transform on vertices.
TransformStates are the primary means for storing transformations on the scene graph.
Transforms may be specified in one of two ways: componentwise, with a pos- hpr-scale, or with an arbitrary transform matrix. If you specify a transform componentwise, it will remember its original components.
TransformState objects are managed very much like RenderState objects. They are immutable and reference-counted automatically.
You should not attempt to create or modify a TransformState object directly. Instead, call one of the make() functions to create one for you. And instead of modifying a TransformState object, create a new one.
Definition at line 54 of file transformState.h.
|
virtual |
The destructor is responsible for removing the TransformState from the global set if it is there.
Definition at line 78 of file transformState.cxx.
|
inline |
Provides an arbitrary ordering among all unique TransformStates, so we can store the essentially different ones in a big set and throw away the rest.
Note that if this returns 0, it doesn't necessarily imply that operator == returns true; it uses a very slightly different comparison threshold.
Definition at line 30 of file transformState.I.
int TransformState::compare_to | ( | const TransformState & | other, |
bool | uniquify_matrix | ||
) | const |
Provides an arbitrary ordering among all unique TransformStates, so we can store the essentially different ones in a big set and throw away the rest.
Note that if this returns 0, it doesn't necessarily imply that operator == returns true; it uses a very slightly different comparison threshold.
If uniquify_matrix is true, then matrix-defined TransformStates are also uniqified. If uniquify_matrix is false, then only component-defined TransformStates are uniquified, which is less expensive.
Definition at line 117 of file transformState.cxx.
References get_mat.
|
inline |
Returns true if the transform was specified componentwise, or false if it was specified with a general 4x4 matrix.
If this is true, the components returned by get_pos() and get_scale() will be exactly those that were set; otherwise, these functions will return computed values. If this is true, the rotation may have been set either with a hpr trio or with a quaternion; hpr_given() or quat_given() can resolve the difference.
Definition at line 260 of file transformState.I.
|
inline |
Returns a suitable hash value for phash_map.
Definition at line 38 of file transformState.I.
|
inline |
Returns the 3x3 matrix that describes the 2-d transform.
It is an error to call this if is_2d() returned false.
Definition at line 526 of file transformState.I.
|
inline |
Returns the pos component of the 2-d transform.
It is an error to call this if has_pos() or is_2d() returned false.
Definition at line 471 of file transformState.I.
|
inline |
Returns the rotation component of the 2-d transform as an angle in degrees clockwise about the origin.
It is an error to call this if has_components() or is_2d() returned false.
Definition at line 483 of file transformState.I.
|
inline |
Returns the scale component of the 2-d transform.
It is an error to call this if has_components() or is_2d() returned false.
Definition at line 504 of file transformState.I.
|
inline |
Returns the shear component of the 2-d transform.
It is an error to call this if has_components() or is_2d() returned false.
Definition at line 515 of file transformState.I.
|
inline |
Returns the scale component of the transform, as a single number.
It is an error to call this if has_uniform_scale() returned false.
Definition at line 439 of file transformState.I.
|
inline |
Returns true if the transform can be described by separate pos, hpr, and scale components.
Most transforms we use in everyday life can be so described, but some kinds of transforms (for instance, those involving a skew) cannot.
This is not related to whether the transform was originally described componentwise. Even a transform that was constructed with a 4x4 may return true here if the matrix is a simple affine matrix with no skew.
If this returns true, you may safely call get_hpr() and get_scale() to retrieve the components. (You may always safely call get_pos() whether this returns true or false.)
Definition at line 246 of file transformState.I.
Referenced by CompassEffect::adjust_transform(), has_hpr(), has_quat(), has_scale(), and has_shear().
|
inline |
Returns true if the transform's rotation component can be extracted out separately and described as a set of Euler angles.
This is generally true only when has_components() is true.
Definition at line 300 of file transformState.I.
References has_components().
|
inline |
Returns true if the scale is uniform 1.0, or false if the scale has some real value.
Definition at line 328 of file transformState.I.
|
inline |
Returns true if the transform can be described as a matrix.
This is generally always true, unless is_invalid() is true.
Definition at line 368 of file transformState.I.
References is_invalid().
|
inline |
Returns true if the shear component is non-zero, false if it is zero or if the matrix cannot be decomposed.
Definition at line 358 of file transformState.I.
|
inline |
Returns true if the transform's pos component can be extracted out separately.
This is generally always true, unless the transform is invalid (i.e. is_invalid() returns true).
Definition at line 290 of file transformState.I.
References is_invalid().
|
inline |
Returns true if the transform's rotation component can be extracted out separately and described as a quaternion.
This is generally true only when has_components() is true.
Definition at line 310 of file transformState.I.
References has_components().
|
inline |
Returns true if the transform's scale component can be extracted out separately.
This is generally true only when has_components() is true.
Definition at line 319 of file transformState.I.
References has_components().
|
inline |
Returns true if the transform's shear component can be extracted out separately.
This is generally true only when has_components() is true.
Definition at line 349 of file transformState.I.
References has_components().
|
inline |
Returns true if the scale is uniform across all three axes (and therefore can be expressed as a single number), or false if the transform has a different scale in different dimensions.
Definition at line 339 of file transformState.I.
|
inline |
Returns true if the rotation was specified via a trio of Euler angles, false otherwise.
If this is true, get_hpr() will be exactly as set; otherwise, it will return a computed value.
Definition at line 270 of file transformState.I.
|
inline |
Returns true if the transform has been constructed entirely using the 2-d transform operations, e.g.
make_pos2d(), and therefore operates strictly in two-dimensional space on X and Y only.
Definition at line 227 of file transformState.I.
|
inline |
Returns true if the transform represents the identity matrix, false otherwise.
Definition at line 197 of file transformState.I.
Referenced by CollisionLevelState< MaskType >::apply_transform(), CullTraverserData::apply_transform(), and PT().
|
inline |
Returns true if the transform represents an invalid matrix, for instance the result of inverting a singular matrix, or false if the transform is valid.
Definition at line 207 of file transformState.I.
|
inline |
Returns true if the transform represents a singular transform (that is, it has a zero scale, and it cannot be inverted), or false otherwise.
Definition at line 216 of file transformState.I.
Referenced by CullTraverserData::apply_transform().
|
inline |
bool TransformState::operator== | ( | const TransformState & | other | ) | const |
Tests equivalence between two transform states.
We use this instead of compare_to since this is faster, and we don't need an ordering between TransformStates because we use a hash map.
If uniquify_matrix is true, then matrix-defined TransformStates are also uniqified. If uniquify_matrix is false, then only component-defined TransformStates are uniquified, which is less expensive.
Definition at line 186 of file transformState.cxx.
References get_mat.
Referenced by operator !=().
|
inline |
Returns true if the rotation was specified via a quaternion, false otherwise.
If this is true, get_quat() will be exactly as set; otherwise, it will return a computed value.
Definition at line 280 of file transformState.I.
|
virtual |
Explicitly decrements the reference count.
Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic.) However, see the helper function unref_delete().
User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.
This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.
The return value is true if the new reference count is nonzero, false if it is zero.
Reimplemented from ReferenceCount.
Writes the contents of this object to the datagram for shipping out to a Bam file.
Reimplemented from TypedWritable.
|
inline |
Returns the rotation component of the transform as a trio of Euler angles.
It is an error to call this if has_components() returned false.
Definition at line 151 of file transformState.h.
Referenced by PartGroup::apply_freeze().
|
inline |
Returns the matrix that describes the transform.
Definition at line 156 of file transformState.h.
Referenced by DXGraphicsStateGuardian9::bind_light(), compare_to(), NodePath::get_mat(), and operator==().
|
inline |
Returns the rotation component of the transform as a quaternion.
Unlike the result of get_quat(), the return value of this method is guaranteed to be normalized. It is an error to call this if has_components() returned false.
Definition at line 153 of file transformState.h.
|
inline |
Returns the pos component of the transform.
It is an error to call this if has_pos() returned false.
Definition at line 150 of file transformState.h.
Referenced by CompassEffect::adjust_transform(), and PartGroup::apply_freeze().
|
inline |
Returns the rotation component of the transform as a quaternion.
The return value will be normalized if a normalized quaternion was given to the constructor (or if the quaternion was computed implicitly); it will be non- normalized if a non-normalized quaternion was given to the constructor. See also get_norm_quat().
It is an error to call this if has_components() returned false.
Definition at line 152 of file transformState.h.
Referenced by CompassEffect::adjust_transform().
|
inline |
Returns the scale component of the transform.
It is an error to call this if has_components() returned false.
Definition at line 154 of file transformState.h.
Referenced by CompassEffect::adjust_transform(), and PartGroup::apply_freeze().
|
inline |
Returns the shear component of the transform.
It is an error to call this if has_components() returned false.
Definition at line 155 of file transformState.h.