Testing some event stuff

This commit is contained in:
2023-11-17 22:40:08 -06:00
parent 0c46c328fa
commit 26b5ec2c7f
20 changed files with 260 additions and 30 deletions

View File

@@ -43,9 +43,6 @@ namespace Dawn {
this->components.push_back(
static_pointer_cast<SceneComponent>(component)
);
// Init compoonent and return
component->init(sceneItemComponentsSelf());
return component;
}

View File

@@ -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();

View File

@@ -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.