jade-engine
0.0
|
#include <Transform.h>
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 ¢erPosition) |
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 |
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.
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.
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.
other | The transform that will become a child of this transform. |
localPosition | The 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. |
anchor | The point on this transform where the other transform otherAttachmentPoint will be placed. |
otherAnchor | The point on other transform that will placed where anchor of this is. |
void JadeEngine::Transform::Detach | ( | ) |
Detach the transform from its the parent.
The transform will remain in its current position.
|
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.
|
inline |
Returns the x and y coordinates of the center of the transform as a vector.
|
inline |
Returns the x coordinate of the center of the transform.
Same as GetCenterPosition().x
.
|
inline |
Returns the y coordinate of the center of the transform.
Same as GetCenterPosition().y
.
|
inline |
Returns the height of transform.
Same as GetSize().h
.
|
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.
|
inline |
Returns the x and y coordinates of the top-left corner of the transform as a vector.
|
inline |
Returns the width and height of the transform as a vector.
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.
|
inline |
Returns the width of the transform.
Same as GetSize().w
.
|
inline |
Returns the x coordinate of the top-left corner of the transform.
Same as GetPosition().x
.
|
inline |
Returns the y coordinate of the top-left corner of the transform.
Same as GetPosition().y
.
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.
void JadeEngine::Transform::Initialize | ( | const Vector2D_i32 & | position, |
const Vector2D_i32 & | size | ||
) |
Initializes the transform with position and size vectors.
position | Desired position of the game object as vector in pixels. |
size | Desired dimensions of the transform as vector in pixels. This might not always correspond to the size of the game object itself. |
bool JadeEngine::Transform::IsAttached | ( | ) | const |
Returns whether the transform is attached to a different transform - the parent.
bool JadeEngine::Transform::IsDirty | ( | const DirtyFlag | flag | ) | const |
Returns whether a property of transform has changed the previous frame.
flag | Which property to check for. |
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
void JadeEngine::Transform::Update | ( | ) |
Update the transform's dirty flags.