jade-engine  0.0
JadeEngine::Transform Class Reference

#include <Transform.h>

Inheritance diagram for JadeEngine::Transform:

Public Member Functions

 Transform ()
 
void Initialize (const Vector2D_i32 &position, const Vector2D_i32 &size)
 
void Initialize (const int32_t x, const int32_t y, const int32_t w, const int32_t h)
 
int32_t GetX () const
 
int32_t GetY () const
 
int32_t GetWidth () const
 
int32_t GetHeight () const
 
int32_t GetCenterX () const
 
int32_t GetCenterY () const
 
Vector2D_i32 GetPosition () const
 
Vector2D_i32 GetCenterPosition () const
 
Vector2D_i32 GetSize () const
 
Box_i32 GetBox () const
 
Box_i32 GetBoundingBox () const
 
Box_i32 GetTestingBox () const
 
bool IsAttached () const
 
Vector2D_i32 GetLocalPosition () const
 
void SetPosition (const Vector2D_i32 &position)
 
void SetPosition (const int32_t x, const int32_t y)
 
void SetCenterPosition (const Vector2D_i32 &centerPosition)
 
void SetCenterPosition (const int32_t centerX, const int32_t centerY)
 
void SetPositionAnchor (const Vector2D_i32 &position, const Anchor &point)
 
void SetPositionAnchor (const int32_t x, const int32_t y, const Anchor &point)
 
void SetHeight (const int32_t height)
 
void SetWidth (const int32_t width)
 
void SetSize (const Vector2D_i32 &size)
 
void SetSize (const int32_t width, const int32_t height)
 
void SetBoundingBox (const Box_i32 &box)
 
void SetLocalPosition (const Vector2D_i32 &position)
 
void SetLocalPosition (const int32_t x, const int32_t y)
 
void Attach (const std::shared_ptr< Transform > &other, const Vector2D_i32 &localPosition=kZeroVector2D_i32, const Anchor &anchor=kDefaultAnchor, const Anchor &otherAnchor=kDefaultAnchor)
 
void Detach ()
 
void Update ()
 
bool IsDirty (const DirtyFlag flag) const
 

Detailed Description

Transform is a game object's property that specify their position and size in a coordinate system.

The transform itself does not have concept of the coordinate system, that is entirely driven by the owning game object. The coordinate system will usually be either world or screen coordinate system.

Constructor & Destructor Documentation

◆ Transform()

JadeEngine::Transform::Transform ( )

Default constructor for transform that initializes the position and size to 0s.

The bounding box will have position and size 0,0. The transform will have no parent.

Member Function Documentation

◆ Attach()

void JadeEngine::Transform::Attach ( const std::shared_ptr< Transform > &  other,
const Vector2D_i32 localPosition = kZeroVector2D_i32,
const Anchor &  anchor = kDefaultAnchor,
const Anchor &  otherAnchor = kDefaultAnchor 
)

Attach other transform to this transform, making the other transform a child of this - parent - transform.

Attachment essentially means that when the parent transform moves the child transform moves with it.

As part of this call the child transform will be moved to have correct relative position to the parent respecting localPosition, parentAnchor and childAnchor parameters.

Parameters
otherThe transform that will become a child of this transform.
localPositionThe initial local position in pixels. Local position is essentially a vector from the position of parent's anchor to the position of the child anchor.
anchorThe point on this transform where the other transform otherAttachmentPoint will be placed.
otherAnchorThe point on other transform that will placed where anchor of this is.
See also
Transform::SetLocalPosition, Transform::GetLocalPosition, Transform::IsAttached, Anchor

◆ Detach()

void JadeEngine::Transform::Detach ( )

Detach the transform from its the parent.

The transform will remain in its current position.

Precondition
The transform must have been previously attached to another transform via Transform::Attach. You can check whether transform is attached via Transform::IsAttached.
See also
Transform::IsAttached, Transform::Attach

◆ GetBoundingBox()

Box_i32 JadeEngine::Transform::GetBoundingBox ( ) const
inline

Returns the transform's bounding box.

A bounding box that represents non-empty content of the transform box and its position is relative to the transform x,y.

◆ GetBox()

Box_i32 JadeEngine::Transform::GetBox ( ) const
inline

Returns the transform representation as Box.

◆ GetCenterPosition()

Vector2D_i32 JadeEngine::Transform::GetCenterPosition ( ) const
inline

Returns the x and y coordinates of the center of the transform as a vector.

◆ GetCenterX()

int32_t JadeEngine::Transform::GetCenterX ( ) const
inline

Returns the x coordinate of the center of the transform.

Same as GetCenterPosition().x.

◆ GetCenterY()

int32_t JadeEngine::Transform::GetCenterY ( ) const
inline

Returns the y coordinate of the center of the transform.

Same as GetCenterPosition().y.

◆ GetHeight()

int32_t JadeEngine::Transform::GetHeight ( ) const
inline

Returns the height of transform.

Same as GetSize().h.

◆ GetLocalPosition()

Vector2D_i32 JadeEngine::Transform::GetLocalPosition ( ) const
inline

Returns local position of the transform. This value only has effect when IsAttached() is true.

Local position is essentially a vector from the position of parent's anchor to the position of this (child) anchor as they were specified in Attach call.

See also
Transform::Attach, Transform::IsAttached, Anchor

◆ GetPosition()

Vector2D_i32 JadeEngine::Transform::GetPosition ( ) const
inline

Returns the x and y coordinates of the top-left corner of the transform as a vector.

◆ GetSize()

Vector2D_i32 JadeEngine::Transform::GetSize ( ) const
inline

Returns the width and height of the transform as a vector.

◆ GetTestingBox()

Box_i32 JadeEngine::Transform::GetTestingBox ( ) const

Returns the transform's testing box.

A testing box is a bounding box transformed by the transform position. That is a bounding box whose position was added up with transform's position.

◆ GetWidth()

int32_t JadeEngine::Transform::GetWidth ( ) const
inline

Returns the width of the transform.

Same as GetSize().w.

◆ GetX()

int32_t JadeEngine::Transform::GetX ( ) const
inline

Returns the x coordinate of the top-left corner of the transform.

Same as GetPosition().x.

◆ GetY()

int32_t JadeEngine::Transform::GetY ( ) const
inline

Returns the y coordinate of the top-left corner of the transform.

Same as GetPosition().y.

◆ Initialize() [1/2]

void JadeEngine::Transform::Initialize ( const int32_t  x,
const int32_t  y,
const int32_t  w,
const int32_t  h 
)

Initializes the transform with position and size vector elements. See the vector version for more information.

◆ Initialize() [2/2]

void JadeEngine::Transform::Initialize ( const Vector2D_i32 position,
const Vector2D_i32 size 
)

Initializes the transform with position and size vectors.

Parameters
positionDesired position of the game object as vector in pixels.
sizeDesired dimensions of the transform as vector in pixels. This might not always correspond to the size of the game object itself.
SomeGameObject::SomeGameObject(const SomeObjectParams& params)
{
// Assuming params contains `Vector initialPosition` and `Vector size`
transform.InitializeVectors(initialPosition, size);
}

◆ IsAttached()

bool JadeEngine::Transform::IsAttached ( ) const

Returns whether the transform is attached to a different transform - the parent.

◆ IsDirty()

bool JadeEngine::Transform::IsDirty ( const DirtyFlag  flag) const

Returns whether a property of transform has changed the previous frame.

Note
As the order of game objects updates is not guaranteed, the dirty flag won't be "dirtied" the same frame the change in the property has occurred.
Parameters
flagWhich property to check for.
Returns
True if property has changed the previous frame, false otherwise.
See also
DirtyFlag

◆ SetBoundingBox()

void JadeEngine::Transform::SetBoundingBox ( const Box_i32 box)

Set the bounding box of the transform.

A bounding box that represents non-empty content of the transform box and its position is relative to the transform x,y. The bounding box's size is by default tied to the transform's size until this function is called. This will dirty the kDirtyFlag_BoundingBox flag for the next frame.

See also
Transform::GetBoundingBox, Transform::SetSize

◆ SetCenterPosition() [1/2]

void JadeEngine::Transform::SetCenterPosition ( const int32_t  centerX,
const int32_t  centerY 
)

Set the transform's center x and y position as a vector's element in pixels. See the vector version for more information.

◆ SetCenterPosition() [2/2]

void JadeEngine::Transform::SetCenterPosition ( const Vector2D_i32 centerPosition)

Set the transform's center x and y position as a vector in pixels.

This will dirty the kDirtyFlag_Position and kDirtyFlag_CenterPosition flags for the next frame. This will cause all children to be immediately moved as well.

See also
Transform::Attach, Transform::SetPosition, Transform::GetCenterPosition

◆ SetHeight()

void JadeEngine::Transform::SetHeight ( const int32_t  height)

Set the height of the transform in pixels. Internally calls Transform::SetSize, see that for more information.

See also
Transform::SetSize

◆ SetLocalPosition() [1/2]

void JadeEngine::Transform::SetLocalPosition ( const int32_t  x,
const int32_t  y 
)

Set the transform's x and y of the local position in pixels. See the vector version for more information.

◆ SetLocalPosition() [2/2]

void JadeEngine::Transform::SetLocalPosition ( const Vector2D_i32 position)

Set the transform's x and y of the local position in pixels.

Local position is essentially a vector from the position of parent's anchor to the position of this (child) anchor as they were specified in Attach call.

Precondition
The transform must have been previously attached to another transform via Transform::Attach. You can check whether transform is attached via Transform::IsAttached.
See also
Transform::Attach, Transform::IsAttached, Anchor

◆ SetPosition() [1/2]

void JadeEngine::Transform::SetPosition ( const int32_t  x,
const int32_t  y 
)

Set the transform x and y position as vector's element in pixels. See the vector version for more information.

◆ SetPosition() [2/2]

void JadeEngine::Transform::SetPosition ( const Vector2D_i32 position)

Set the transform x and y position as a vector in pixels.

This will kDirtyFlag_Position and kDirtyFlag_CenterPosition flags to be dirtied until the end of the next frame. This will cause all children to be immediately moved as well.

See also
Transform::Attach, Transform::SetCenterPosition, Transform::GetPosition

◆ SetPositionAnchor() [1/2]

void JadeEngine::Transform::SetPositionAnchor ( const int32_t  x,
const int32_t  y,
const Anchor &  point 
)

Set transforms x and y position so that the passed anchor point will be positioned exactly at the passed position as vector's elements in pixels. See the vector version for more information.

◆ SetPositionAnchor() [2/2]

void JadeEngine::Transform::SetPositionAnchor ( const Vector2D_i32 position,
const Anchor &  point 
)

Set transforms x and y position so that the passed anchor point will be positioned exactly at the passed position as vector in pixels.

If the kAnchor_Center is passed this is the same as calling SetCenterPosition including dirty flag effects. If the kAnchor_LeftTop is passed this is the same as calling SetPosition including dirty flag effects. Otherwise this will internally call SetPosition, including dirty flag effects, with appropriate offset.

See also
Anchor, Transform::SetPosition, Transform::SetCenterPosition

◆ SetSize() [1/2]

void JadeEngine::Transform::SetSize ( const int32_t  width,
const int32_t  height 
)

Set the width and height of the transform in pixels. See the vector version for more information.

◆ SetSize() [2/2]

void JadeEngine::Transform::SetSize ( const Vector2D_i32 size)

Set the width and height of the transform in pixels.

If bounding box was not previously explicitly set (via Transform::SetBoundingBox), the bounding box will be resized to make its size match transform's size. This will dirty the kDirtyFlag_Size and kDirtyFlag_CenterPosition flags for the next frame. In the case bounding box was modified, kDirtyFlag_BoundingBox flag will be dirtied as well. This will cause all children to be immediately moved as well unless they were attached with kAnchor_LeftTop as parent anchor.

See also
Transform::SetBoundingBox

◆ SetWidth()

void JadeEngine::Transform::SetWidth ( const int32_t  width)

Set the width of the transform in pixels. Internally calls Transform::SetSize, see that for more information.

See also
Transform::SetSize

◆ Update()

void JadeEngine::Transform::Update ( )

Update the transform's dirty flags.

Warning
Used internally by the Jade Engine and there is very little reason to call this as a user.

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