59 lines
873 B
C++
59 lines
873 B
C++
|
/*
|
||
|
* Transform.cpp
|
||
|
*
|
||
|
* Created on: Dec 2, 2016
|
||
|
* Author: tibi
|
||
|
*/
|
||
|
|
||
|
#include <model/GameObject.h>
|
||
|
#include <model/Transform.h>
|
||
|
|
||
|
#include <iostream>
|
||
|
|
||
|
namespace farmlands {
|
||
|
namespace model {
|
||
|
|
||
|
Transform::Transform(GameObject* obj)
|
||
|
: x(0), y(0),
|
||
|
w(0), h(0),
|
||
|
gameObject(obj)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
float Transform::globalX() const
|
||
|
{
|
||
|
if (gameObject->parent())
|
||
|
return gameObject->parent()->transform.globalX() + x;
|
||
|
|
||
|
return x;
|
||
|
}
|
||
|
|
||
|
float Transform::globalY() const
|
||
|
{
|
||
|
if (gameObject->parent())
|
||
|
return gameObject->parent()->transform.globalY() + y;
|
||
|
|
||
|
return y;
|
||
|
}
|
||
|
|
||
|
void Transform::setGlobalX(float x)
|
||
|
{
|
||
|
if (gameObject->parent())
|
||
|
this->x = x - gameObject->parent()->transform.globalX();
|
||
|
|
||
|
this->x = x;
|
||
|
}
|
||
|
|
||
|
void Transform::setGlobalY(float y)
|
||
|
{
|
||
|
if (gameObject->parent())
|
||
|
this->y = y - gameObject->parent()->transform.globalY();
|
||
|
|
||
|
this->y = y;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
} /* namespace farmlands */
|
||
|
|
||
|
|