Cogs.Core
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Cogs::Core::TransformComponent Class Reference

Defines a 4x4 transformation matrix for the entity and a global offset for root entities. More...

#include <TransformComponent.h>

Inheritance diagram for Cogs::Core::TransformComponent:
Cogs::ComponentModel::Component

Public Member Functions

 TransformComponent ()
 Constructs a new transform component.
 
- Public Member Functions inherited from Cogs::ComponentModel::Component
class EntitygetContainer () const
 Get the container currently owning this component instance.
 
void setContainer (class Entity *container)
 Set the container owning this component instance.
 
template<typename ComponentType >
ComponentType * getComponent () const
 
COGSFOUNDATION_API ComponentgetComponent (const Reflection::Name &name) const
 
COGSFOUNDATION_API ComponentgetComponent (const Reflection::TypeId &id) const
 
template<typename ComponentType >
ComponentHandle getComponentHandle () const
 
COGSFOUNDATION_API ComponentHandle getComponentHandle (const Reflection::Name &name) const
 
COGSFOUNDATION_API ComponentHandle getComponentHandle (const Reflection::TypeId &id) const
 
void setActive ()
 Sets the component to the ComponentFlags::Active state.
 
bool isActive () const
 Gets if the component is currently set to the ComponentFlags::Active state.
 
void setChanged ()
 Sets the component to the ComponentFlags::Changed state with carry.
 
void setChangedTransient ()
 Sets the component to the ComponentFlags::Changed state without carry.
 
void setFieldChanged (const Reflection::FieldId fieldId)
 Sets the component to the ComponentFlags::Changed state without carry.
 
template<typename ClassType , typename FieldType >
void setFieldChanged (FieldType ClassType::*field)
 Sets a flag indicating that the given field has changed.
 
void setFieldChangedTransient (const Reflection::FieldId fieldId)
 Sets the component to the ComponentFlags::Changed state without carry.
 
bool hasChanged () const
 
bool hasAnyfieldChanged () const
 Gets if any fields have been changed.
 
bool hasFieldChanged (const Reflection::FieldId fieldId) const
 Gets if the field with the given id on this component instance has changed.
 
template<typename ClassType , typename FieldType >
bool hasFieldChanged (FieldType ClassType::*field) const
 Gets if the given field has changed.
 
void resetCarryChanged ()
 Reset the CarryChanged flag. Called at start of redraw. See ComponentFlags::CarryChanged.
 
void resetChanged ()
 Resets the changed state of the component, respecting any carry state set.
 
template<typename ClassType , typename FieldType >
Reflection::FieldId getFieldId (FieldType ClassType::*field) const
 Gets field ID of the given field.
 
void resetFieldsChanged ()
 Resets the state of all changed field flags.
 
void resetFieldChanged (const Reflection::FieldId fieldId)
 Resets the changed state of the given fieldId.
 
template<typename ClassType , typename FieldType >
void resetFieldChanged (FieldType ClassType::*field)
 Resets the changed state of the given field.
 
constexpr void setFlags (const uint32_t flags)
 Override all flags of the Component, setting the given flags.
 
constexpr void setFlag (const uint32_t flag)
 Set the given flags. Does not override the currently set flags.
 
constexpr void unsetFlag (const uint32_t flag)
 Unset the given flag. Does not remove the status of other than the given flags.
 
constexpr bool isSet (const uint32_t flag) const
 Checks if the given flag is set. Requires exact bit match if test of several bits.
 
constexpr void setTypeId (const Reflection::TypeId typeId)
 Set the Reflection::TypeId of the component.
 
constexpr Reflection::TypeId getTypeId () const
 Get the Reflection::TypeId of the component.
 
COGSFOUNDATION_API const Reflection::TypegetType () const
 Get the full Reflection::Type of the component.
 
constexpr void setIndex (const ComponentIndex index)
 Set the components pool index. For internal use only.
 
constexpr ComponentIndex getIndex () const
 Get the components pool index. For internal use only.
 
constexpr void setGeneration (uint16_t generation)
 Sets the component generation.
 
constexpr uint16_t getGeneration () const
 Gets the component generation.
 
size_t hash (size_t hashValue=Cogs::hash()) const
 Calculates a hash of this component's members.
 

Static Public Member Functions

static void registerType ()
 Register the type in the type system.
 
- Static Public Member Functions inherited from Cogs::ComponentModel::Component
static COGSFOUNDATION_API void registerType ()
 Register the Component type in the global type database.
 
static COGSFOUNDATION_API Reflection::TypeId getComponentTypeId (const StringView &name)
 Get the type id of the component type with the given name.
 

Public Attributes

glm::dvec3 coordinates
 Global coordinates.
 
union {
   struct {
      glm::vec3   position
 Local position relative to the global coordinates, or the parent coordinate system if the parent field is set. More...
 
      glm::quat   rotation
 Rotation given as a quaternion. More...
 
      glm::vec3   scale
 Scale factor to apply to each of the axes. More...
 
   } 
 
   glm::mat4   transform
 Complete transformation. More...
 
}; 
 Usage of the transform field and the TRS fields is exclusive to one or the other, so the data is stored in a union.
 
uint32_t transformFlags = 0
 Transform flags.
 
ComponentModel::ComponentHandle parent = ComponentModel::ComponentHandle::Empty()
 Parent transform of the component.
 

Detailed Description

Defines a 4x4 transformation matrix for the entity and a global offset for root entities.

The transformation can either be set using position, scaling and orientation or by explicit setting of the 4x4 matrix.

Transforms can also be parented by setting the parent field. This makes the transform data of a component instance relative to the parent transform.

Definition at line 21 of file TransformComponent.h.

Constructor & Destructor Documentation

◆ TransformComponent()

Cogs::Core::TransformComponent::TransformComponent ( )

Constructs a new transform component.

Definition at line 7 of file TransformComponent.cpp.

Member Function Documentation

◆ registerType()

void Cogs::Core::TransformComponent::registerType ( )
static

Register the type in the type system.

Definition at line 16 of file TransformComponent.cpp.

References coordinates, position, rotation, scale, transform, and transformFlags.

Member Data Documentation

◆ 

union { ... } Cogs::Core::TransformComponent::@1

Usage of the transform field and the TRS fields is exclusive to one or the other, so the data is stored in a union.

The transformFlags field is used to determine which fields are active.

◆ coordinates

glm::dvec3 Cogs::Core::TransformComponent::coordinates

Global coordinates.

The global coordinates are absolute and are used to compute the offset from the global origin coordinate stored in the TransformSystem. After computing the offset value, this is combined with the position to form the final translation of the component.

Component World coordinate offset = (coordinates - Origin + position).

If the Entity is a child entity, the coordinate field is ignored.

Definition at line 41 of file TransformComponent.h.

Referenced by Cogs::Core::PotreeSystem::preUpdate(), registerType(), Cogs::Core::TrajectoryLayoutSystem::update(), and Cogs::Core::writeEntity().

◆ parent

ComponentModel::ComponentHandle Cogs::Core::TransformComponent::parent = ComponentModel::ComponentHandle::Empty()

Parent transform of the component.

Set internally in Cogs.Core EntityStore when this entity is added as a child. When set, the position, rotation and scale fields become relative to the parent transformation, and the final computed transformation of the parent is combined with the local transform of this component to form the final transform.

Definition at line 92 of file TransformComponent.h.

Referenced by Cogs::Core::EntityStore::addChild(), Cogs::Core::EntityStore::getEntityParent(), Cogs::Core::EntityStore::removeChild(), and Cogs::Core::EntityStore::removeChildren().

◆ position

glm::vec3 Cogs::Core::TransformComponent::position

Local position relative to the global coordinates, or the parent coordinate system if the parent field is set.

Do Not set or get if transformFlags is non-zero.

Definition at line 56 of file TransformComponent.h.

Referenced by Cogs::Core::TranslateCommand::apply(), registerType(), Cogs::Core::TrajectoryAlignedComponent::update(), Cogs::Core::OverlaySystem::update(), Cogs::Core::EchoSounder::PingIsoSystem::update(), Cogs::Core::StaticModelSystem::update(), and Cogs::Core::writeEntity().

◆ rotation

glm::quat Cogs::Core::TransformComponent::rotation

◆ scale

glm::vec3 Cogs::Core::TransformComponent::scale

Scale factor to apply to each of the axes.

Do Not set or get if transformFlags is non-zero.

Definition at line 68 of file TransformComponent.h.

Referenced by Cogs::Core::ScaleCommand::apply(), registerType(), and Cogs::Core::writeEntity().

◆ transform

glm::mat4 Cogs::Core::TransformComponent::transform

Complete transformation.

Only used if field transformFlags is set. Do Not set or get if transformFlags is zero.

Definition at line 75 of file TransformComponent.h.

Referenced by Cogs::Core::OGC3DTilesSystem::addModelToScene(), and registerType().

◆ transformFlags

uint32_t Cogs::Core::TransformComponent::transformFlags = 0

Transform flags.

Set to 0 if individual scale, rotate, translate fields shall be used. Non-zero if the Field transform shall be used. If the transform field has been used and switching back to value 0 if this field, all the fields: rotation, position and scale must be set.

Definition at line 83 of file TransformComponent.h.

Referenced by Cogs::Core::OGC3DTilesSystem::addModelToScene(), registerType(), and Cogs::Core::writeEntity().


The documentation for this class was generated from the following files: