Testing some event stuff
This commit is contained in:
@@ -43,9 +43,6 @@ namespace Dawn {
|
||||
this->components.push_back(
|
||||
static_pointer_cast<SceneComponent>(component)
|
||||
);
|
||||
|
||||
// Init compoonent and return
|
||||
component->init(sceneItemComponentsSelf());
|
||||
return component;
|
||||
}
|
||||
|
||||
|
@@ -64,6 +64,29 @@ void SceneItemTransform::updateWorldTransformFromParent() {
|
||||
this->updateChildrenWorldTransforms();
|
||||
}
|
||||
|
||||
void SceneItemTransform::updateLocalTransformFromLocalValues() {
|
||||
this->transformLocal = glm::translate(
|
||||
glm::mat4(1.0f),
|
||||
this->localPosition
|
||||
) * glm::mat4_cast(this->localRotation) * glm::scale(
|
||||
glm::mat4(1.0f),
|
||||
this->localScale
|
||||
);
|
||||
this->updateWorldTransformFromLocalTransform();
|
||||
}
|
||||
|
||||
void SceneItemTransform::updateWorldTransformFromLocalTransform() {
|
||||
auto parent = this->getParent();
|
||||
if(!parent) {
|
||||
this->transformWorld = this->transformLocal;
|
||||
} else {
|
||||
this->transformWorld = (
|
||||
parent->transformWorld * this->transformLocal
|
||||
);
|
||||
}
|
||||
this->updateChildrenWorldTransforms();
|
||||
}
|
||||
|
||||
std::shared_ptr<SceneItem> SceneItemTransform::getParent() {
|
||||
return parent.lock();
|
||||
}
|
||||
@@ -88,12 +111,39 @@ glm::mat4 SceneItemTransform::getWorldTransform() {
|
||||
return this->transformWorld;
|
||||
}
|
||||
|
||||
glm::vec3 SceneItemTransform::getLocalPosition() {
|
||||
return this->localPosition;
|
||||
}
|
||||
|
||||
glm::vec3 SceneItemTransform::getLocalScale() {
|
||||
return this->localScale;
|
||||
}
|
||||
|
||||
glm::quat SceneItemTransform::getLocalRotation() {
|
||||
return this->localRotation;
|
||||
}
|
||||
|
||||
void SceneItemTransform::setWorldTransform(const glm::mat4 transform) {
|
||||
this->transformWorld = transform;
|
||||
this->updateLocalTransformFromWorldTransform();
|
||||
this->updateChildrenWorldTransforms();
|
||||
}
|
||||
|
||||
void SceneItemTransform::setLocalPosition(const glm::vec3 position) {
|
||||
this->localPosition = position;
|
||||
this->updateLocalTransformFromLocalValues();
|
||||
}
|
||||
|
||||
void SceneItemTransform::setLocalScale(const glm::vec3 scale) {
|
||||
this->localScale = scale;
|
||||
this->updateLocalTransformFromLocalValues();
|
||||
}
|
||||
|
||||
void SceneItemTransform::setLocalRotation(const glm::quat rotation) {
|
||||
this->localRotation = rotation;
|
||||
this->updateLocalTransformFromLocalValues();
|
||||
}
|
||||
|
||||
bool_t SceneItemTransform::isChildOf(std::shared_ptr<SceneItem> item) {
|
||||
assertNotNull(item, "Cannot check if child of null item.");
|
||||
auto parent = this->getParent();
|
||||
|
@@ -45,6 +45,16 @@ namespace Dawn {
|
||||
*/
|
||||
void updateWorldTransformFromParent();
|
||||
|
||||
/**
|
||||
* Updates the local transform of this item from the local values.
|
||||
*/
|
||||
void updateLocalTransformFromLocalValues();
|
||||
|
||||
/**
|
||||
* Updates the world transform from this items local transform.
|
||||
*/
|
||||
void updateWorldTransformFromLocalTransform();
|
||||
|
||||
public:
|
||||
SceneItemTransform();
|
||||
|
||||
@@ -75,6 +85,27 @@ namespace Dawn {
|
||||
* @return World transform of this item.
|
||||
*/
|
||||
glm::mat4 getWorldTransform();
|
||||
|
||||
/**
|
||||
* Gets the local position of this item (relative to its parent).
|
||||
*
|
||||
* @return Local position of this item.
|
||||
*/
|
||||
glm::vec3 getLocalPosition();
|
||||
|
||||
/**
|
||||
* Local scale of this item (relative to its parent).
|
||||
*
|
||||
* @return Local scale of this item.
|
||||
*/
|
||||
glm::vec3 getLocalScale();
|
||||
|
||||
/**
|
||||
* Local rotation of this item (relative to its parent).
|
||||
*
|
||||
* @return Local rotation of this item.
|
||||
*/
|
||||
glm::quat getLocalRotation();
|
||||
|
||||
/**
|
||||
* Sets the transform of this item within world space (relative to scene
|
||||
@@ -84,6 +115,27 @@ namespace Dawn {
|
||||
*/
|
||||
void setWorldTransform(const glm::mat4 transform);
|
||||
|
||||
/**
|
||||
* Sets the local position of this item (relative to its parent).
|
||||
*
|
||||
* @param position Local position of this item.
|
||||
*/
|
||||
void setLocalPosition(const glm::vec3 position);
|
||||
|
||||
/**
|
||||
* Sets the local scale of this item (relative to its parent).
|
||||
*
|
||||
* @param scale Local scale of this item.
|
||||
*/
|
||||
void setLocalScale(const glm::vec3 scale);
|
||||
|
||||
/**
|
||||
* Sets the local rotation of this item (relative to its parent).
|
||||
*
|
||||
* @param rotation Local rotation of this item.
|
||||
*/
|
||||
void setLocalRotation(const glm::quat rotation);
|
||||
|
||||
/**
|
||||
* Returns whether or not this item is a child of the given item. This
|
||||
* will traverse up the entire heirarchy to confirm.
|
||||
|
Reference in New Issue
Block a user