diff --git a/src/dawn/display/CMakeLists.txt b/src/dawn/display/CMakeLists.txt index 713f8b81..32c99d2a 100644 --- a/src/dawn/display/CMakeLists.txt +++ b/src/dawn/display/CMakeLists.txt @@ -7,7 +7,6 @@ target_sources(${DAWN_TARGET_NAME} PRIVATE RenderPipeline.cpp - Transform.cpp Tileset.cpp Color.cpp ) diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index 8e17b87b..955c385a 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -105,7 +105,7 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr scene, std::shared // Update shader parameter buffers with current knowledge struct RenderPipelineShaderBufferData shaderBufferData; shaderBufferData.projection = camera->getProjection(); - shaderBufferData.view = camera->transform->getWorldTransform(); + shaderBufferData.view = camera->item->getWorldTransform(); shaderBuffer.buffer(&shaderBufferData); // Prepare a render context. This is just a nice way of letting renderables diff --git a/src/dawn/display/RenderPipeline.hpp b/src/dawn/display/RenderPipeline.hpp index 41b922f1..b78a06b7 100644 --- a/src/dawn/display/RenderPipeline.hpp +++ b/src/dawn/display/RenderPipeline.hpp @@ -54,7 +54,10 @@ namespace Dawn { * @param scene Scene to render. * @param camera Camera within the scene to render. */ - virtual void renderSceneCamera(std::shared_ptr scene, std::shared_ptr camera); + virtual void renderSceneCamera( + std::shared_ptr scene, + std::shared_ptr camera + ); /** * Cleanup a render pipeline that has been initialized. diff --git a/src/dawn/display/Transform.cpp b/src/dawn/display/Transform.cpp deleted file mode 100644 index 783945a5..00000000 --- a/src/dawn/display/Transform.cpp +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "Transform.hpp" -#include "scene/SceneItem.hpp" -#include "util/mathutils.hpp" - -using namespace Dawn; - -Transform::Transform(SceneItem *item) : - transformLocal(1.0f), - transformWorld(1.0f) -{ - assertNotNull(item, "Transform::Transform: Item cannot be null"); - - this->item = item; - this->updateLocalValuesFromLocalTransform(); -} - -void Transform::updateLocalValuesFromLocalTransform() { - glm::vec3 skew; - glm::vec4 perspective; - glm::decompose( - this->transformLocal, - this->localScale, - this->localRotation, - this->localPosition, - skew, perspective - ); -} - -void Transform::updateLocalTransformFromLocalValues() { - glm::mat4 translate = glm::translate(glm::mat4(1.0), this->localPosition); - glm::mat4 rotate = glm::mat4_cast(this->localRotation); - glm::mat4 scale = glm::scale(glm::mat4(1.0), this->localScale); - this->transformLocal = translate * rotate * scale; - this->updateWorldTransformFromLocalTransform(); -} - -void Transform::updateWorldTransformFromLocalTransform() { - auto parent = this->getParent(); - if(parent != nullptr) { - auto newWorld = parent->getWorldTransform(); - this->transformWorld = newWorld * transformLocal; - } else { - this->transformWorld = transformLocal; - } -} - -void Transform::updateLocalTransformFromWorldTransform() { - glm::mat4 parentMat(1.0f); - auto parent = this->getParent(); - if(parent != nullptr) parentMat = parent->getWorldTransform(); - this->transformLocal = parentMat / this->transformWorld; - this->updateLocalValuesFromLocalTransform(); -} - -void Transform::updateChildrenTransforms() { - auto it = this->children.begin(); - while(it != this->children.end()) { - (*it)->updateWorldTransformFromLocalTransform(); - ++it; - } -} - -void Transform::lookAt(glm::vec3 pos, glm::vec3 look) { - this->lookAt(pos, look, glm::vec3(0, 1, 0)); -} - -void Transform::lookAt(glm::vec3 pos, glm::vec3 look, glm::vec3 up) { - this->setWorldTransform(glm::lookAt(pos, look, up)); -} - -float_t Transform::lookAtPixelPerfect( - glm::vec3 position, glm::vec3 look, float_t viewportHeight, float_t fov -) { - float_t z = ( - tanf((mathDeg2Rad(180.0f) - fov) / 2.0f) * - (viewportHeight/2.0f) - ); - this->lookAt(glm::vec3(position.x, position.y, position.z + z), look); - return z; -} - -glm::vec3 Transform::getLocalPosition() { - return this->localPosition; -} - -void Transform::setLocalPosition(glm::vec3 position) { - this->localPosition = position; - this->updateLocalTransformFromLocalValues(); - this->updateChildrenTransforms(); - this->eventTransformUpdated.invoke(); -} - -glm::vec3 Transform::getLocalScale() { - return this->localScale; -} - -void Transform::setLocalScale(glm::vec3 scale) { - this->localScale = scale; - this->updateLocalTransformFromLocalValues(); - this->updateChildrenTransforms(); - this->eventTransformUpdated.invoke(); -} - -glm::quat Transform::getLocalRotation() { - return this->localRotation; -} - -void Transform::setLocalRotation(glm::quat rotation) { - this->localRotation = rotation; - this->updateLocalTransformFromLocalValues(); - this->updateChildrenTransforms(); - this->eventTransformUpdated.invoke(); -} - - -glm::mat4 Transform::getLocalTransform() { - return this->transformLocal; -} - -void Transform::setLocalTransform(glm::mat4 transform) { - this->transformLocal = transform; - - this->updateLocalValuesFromLocalTransform(); - this->updateChildrenTransforms(); - this->eventTransformUpdated.invoke(); -} - -glm::vec3 Transform::getWorldPosition() { - return this->transformWorld[3]; -} - -glm::mat4 Transform::getWorldTransform() { - return this->transformWorld; -} - -void Transform::setWorldTransform(glm::mat4 transform) { - this->transformWorld = transform; - this->updateLocalTransformFromWorldTransform(); - this->updateChildrenTransforms(); - this->eventTransformUpdated.invoke(); -} - - -void Transform::setParent(Transform *parent) { - assertTrue(parent == nullptr || parent != this, "Transform::setParent: Cannot set parent to self"); - - auto currentParent = this->getParent(); - if(currentParent == parent) return; - - if(currentParent != nullptr) { - auto it = currentParent->children.begin(); - while(it != currentParent->children.end()) { - if(*it == this) { - currentParent->children.erase(it); - break; - } - ++it; - } - } - - this->parent = parent; - if(parent != nullptr) parent->children.push_back(this); - - this->updateLocalTransformFromWorldTransform(); - this->updateChildrenTransforms(); - this->eventTransformUpdated.invoke(); -} - -Transform * Transform::getParent() { - return this->parent; -} - -bool_t Transform::isChildOf(Transform *parent) { - Transform *current = this->getParent(); - while(current != nullptr) { - if(current == parent) return true; - current = current->getParent(); - } - return false; -} - -Transform::~Transform() { - this->setParent(nullptr); - - auto it = this->children.begin(); - while(it != this->children.end()) { - (*it)->setParent(nullptr); - it = this->children.begin(); - } -} \ No newline at end of file diff --git a/src/dawn/display/Transform.hpp b/src/dawn/display/Transform.hpp deleted file mode 100644 index 54c211d1..00000000 --- a/src/dawn/display/Transform.hpp +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "dawnlibs.hpp" -#include "assert/assert.hpp" -#include "util/flag.hpp" -#include "state/StateEvent.hpp" - -namespace Dawn { - class SceneItem; - - class Transform { - private: - // Local (real) values - glm::vec3 localPosition; - glm::vec3 localScale; - glm::quat localRotation; - - // Cached (non-real) values - glm::mat4 transformLocal; - glm::mat4 transformWorld; - - // glm::vec3 position; - // glm::vec3 scale; - // glm::quat rotation; - - // Heirarchy - Transform *parent = nullptr; - std::vector children; - - // Hidden methods - void updateLocalValuesFromLocalTransform(); - void updateLocalTransformFromLocalValues(); - void updateWorldTransformFromLocalTransform(); - void updateLocalTransformFromWorldTransform(); - void updateChildrenTransforms(); - - public: - // I have no idea if I'm keeping this - // Event<> eventTransformUpdated; - StateEvent<> eventTransformUpdated; - SceneItem *item; - - /** - * Constructs a new transform instance. Currently I have bound transforms - * to their parent SceneItem, but in future I may allow them to become - * disconnected from each other, for example I really could use a special - * transform designed purely for UI elements, since they don't act like - * normal scene items, but for now Transforms and SceneItems are 1:1 - * - * @param item Item that this transform belongs to. - */ - Transform(SceneItem *item); - - /** - * Orients this transform to look at a given point in world space. - * - * @param position Position of the origin of this transform. - * @param look Position in world space this transform looks at. - */ - void lookAt(glm::vec3 position, glm::vec3 look); - void lookAt(glm::vec3 position, glm::vec3 look, glm::vec3 up); - - /** - * Shorthand combined for lookAt and perspectivePixelPerfectDistance - * to allow you to create pixel perfect lookAt camera view matricies. - * - * @param position Position of the camera. Z is for an offset. - * @param look Position in world space this transform looks at. - * @param viewportHeight Height of the viewport. - * @param fov Field of view (in radians). - * @return The Z distance that was calculated. - */ - float_t lookAtPixelPerfect( - glm::vec3 position, glm::vec3 look, float_t viewportHeight, float_t fov - ); - - /** - * Returns the local position (position relative to "my parent"). - * @return The 3D local position in parent-relative space. - */ - glm::vec3 getLocalPosition(); - - /** - * Update / Set the local position of this transform relative to my parent - * @param position Position to set for the local transform. - */ - void setLocalPosition(glm::vec3 position); - - /** - * Retusn the scale of this item, relative to my parent. - * @return 3D Scale vector of this item in parent-relative space. - */ - glm::vec3 getLocalScale(); - - /** - * Set the local scale of this item. - * @param scale Scale of this item, relative to its parent. - */ - void setLocalScale(glm::vec3 scale); - - /** - * Returns the local rotation for this transform. - * @return The local rotation (parent-relative). - */ - glm::quat getLocalRotation(); - - /** - * Set the local (parent-relative) rotation for this transform. - * @param rotation Rotation in parent relative space. - */ - void setLocalRotation(glm::quat rotation); - - /** - * Returns the transform matrix for this transform, in parent-relative - * space. - * @return The transform origin in parent-relative space. - */ - glm::mat4 getLocalTransform(); - - /** - * Sets the local transform matrix for this transform. - * @param transform Local (parent-relative) transform to set. - */ - void setLocalTransform(glm::mat4 transform); - - /** - * Returns the position of the origin of this transform in world-space. - * - * @return Transform origin in world-space. - */ - glm::vec3 getWorldPosition(); - - /** - * Returns the transformation matrix for this transform, in world-space. - * @return The transform origin in world-space. - */ - glm::mat4 getWorldTransform(); - - /** - * Updates the transform's world-space. - * @param transform Sets the transform position in world-space. - */ - void setWorldTransform(glm::mat4 transform); - - /** - * Updates the transform that this transform is a child of. Will also - * handle disconnecting any existing parent. - * - * @param p Parent that this transform is now a child of. - */ - void setParent(Transform *p); - - /** - * Returns the parent transform of this transform, or nullptr if there is - * no parent for this transform. - * @return Pointer to the parent transform, or nullptr. - */ - Transform * getParent(); - - /** - * Returns true if this transform is a child of the given transform, this - * climbs up the heirarchy until it finds a match. - * - * @param p Transform to check if this transform is a child of. - * @return True if this transform is a child of the given transform. - */ - bool_t isChildOf(Transform *p); - - /** - * Dispose and clenaup this transform, also removes self from parent. - */ - ~Transform(); - - friend SceneItem; - }; -} \ No newline at end of file diff --git a/src/dawn/games/vn/events/VNPositionEvent.hpp b/src/dawn/games/vn/events/VNPositionEvent.hpp index 7595e5a6..076b12b2 100644 --- a/src/dawn/games/vn/events/VNPositionEvent.hpp +++ b/src/dawn/games/vn/events/VNPositionEvent.hpp @@ -32,7 +32,7 @@ namespace Dawn { void onStart() override { assertNotNull(item); - auto start = item->transform.getLocalPosition(); + auto start = item->getLocalPosition(); if(from.x == VN_POSITION_EVENT_VALUE_UNCHANGED) start.x = from.x; if(from.y == VN_POSITION_EVENT_VALUE_UNCHANGED) start.y = from.y; if(from.z == VN_POSITION_EVENT_VALUE_UNCHANGED) start.z = from.z; @@ -45,7 +45,7 @@ namespace Dawn { } void setValue(glm::vec3 value) override { - this->item->transform.setLocalPosition(value); + this->item->setLocalPosition(value); } }; } \ No newline at end of file diff --git a/src/dawn/scene/SceneItem.cpp b/src/dawn/scene/SceneItem.cpp index bef45a04..1b48fa6b 100644 --- a/src/dawn/scene/SceneItem.cpp +++ b/src/dawn/scene/SceneItem.cpp @@ -5,14 +5,19 @@ #include "SceneItem.hpp" #include "SceneItemComponent.hpp" +#include "util/mathutils.hpp" using namespace Dawn; -SceneItem::SceneItem(Scene *scene, sceneitemid_t id) : transform(this) { +SceneItem::SceneItem(Scene *scene, sceneitemid_t id) : + transformLocal(1.0f), + transformWorld(1.0f) +{ assertNotNull(scene, "SceneItem::SceneItem: Scene cannot be null"); this->id = id; this->scene = scene; + this->updateLocalValuesFromLocalTransform(); } void SceneItem::init() { @@ -63,5 +68,185 @@ void SceneItem::destroy() { this->components.clear(); } +void SceneItem::updateLocalValuesFromLocalTransform() { + glm::vec3 skew; + glm::vec4 perspective; + glm::decompose( + this->transformLocal, + this->localScale, + this->localRotation, + this->localPosition, + skew, perspective + ); +} + +void SceneItem::updateLocalTransformFromLocalValues() { + glm::mat4 translate = glm::translate(glm::mat4(1.0), this->localPosition); + glm::mat4 rotate = glm::mat4_cast(this->localRotation); + glm::mat4 scale = glm::scale(glm::mat4(1.0), this->localScale); + this->transformLocal = translate * rotate * scale; + this->updateWorldTransformFromLocalTransform(); +} + +void SceneItem::updateWorldTransformFromLocalTransform() { + auto parent = this->getParent().lock(); + if(parent != nullptr) { + auto newWorld = parent->getWorldTransform(); + this->transformWorld = newWorld * transformLocal; + } else { + this->transformWorld = transformLocal; + } +} + + +void SceneItem::updateLocalTransformFromWorldTransform() { + glm::mat4 parentMat(1.0f); + auto parent = this->getParent().lock(); + if(parent != nullptr) parentMat = parent->getWorldTransform(); + this->transformLocal = parentMat / this->transformWorld; + this->updateLocalValuesFromLocalTransform(); +} + +void SceneItem::updateChildrenTransforms() { + auto it = this->children.begin(); + while(it != this->children.end()) { + auto childTrans = it->lock(); + if(childTrans) childTrans->updateWorldTransformFromLocalTransform(); + ++it; + } +} + +void SceneItem::lookAt(glm::vec3 pos, glm::vec3 look) { + this->lookAt(pos, look, glm::vec3(0, 1, 0)); +} + +void SceneItem::lookAt(glm::vec3 pos, glm::vec3 look, glm::vec3 up) { + this->setWorldTransform(glm::lookAt(pos, look, up)); +} + +float_t SceneItem::lookAtPixelPerfect( + glm::vec3 position, glm::vec3 look, float_t viewportHeight, float_t fov +) { + float_t z = ( + tanf((mathDeg2Rad(180.0f) - fov) / 2.0f) * + (viewportHeight/2.0f) + ); + this->lookAt(glm::vec3(position.x, position.y, position.z + z), look); + return z; +} + +glm::vec3 SceneItem::getLocalPosition() { + return this->localPosition; +} + +void SceneItem::setLocalPosition(glm::vec3 position) { + this->localPosition = position; + this->updateLocalTransformFromLocalValues(); + this->updateChildrenTransforms(); + this->eventTransformUpdated.invoke(); +} + +glm::vec3 SceneItem::getLocalScale() { + return this->localScale; +} + +void SceneItem::setLocalScale(glm::vec3 scale) { + this->localScale = scale; + this->updateLocalTransformFromLocalValues(); + this->updateChildrenTransforms(); + this->eventTransformUpdated.invoke(); +} + +glm::quat SceneItem::getLocalRotation() { + return this->localRotation; +} + +void SceneItem::setLocalRotation(glm::quat rotation) { + this->localRotation = rotation; + this->updateLocalTransformFromLocalValues(); + this->updateChildrenTransforms(); + this->eventTransformUpdated.invoke(); +} + + +glm::mat4 SceneItem::getLocalTransform() { + return this->transformLocal; +} + +void SceneItem::setLocalTransform(glm::mat4 transform) { + this->transformLocal = transform; + + this->updateLocalValuesFromLocalTransform(); + this->updateChildrenTransforms(); + this->eventTransformUpdated.invoke(); +} + +glm::vec3 SceneItem::getWorldPosition() { + return this->transformWorld[3]; +} + +glm::mat4 SceneItem::getWorldTransform() { + return this->transformWorld; +} + +void SceneItem::setWorldTransform(glm::mat4 transform) { + this->transformWorld = transform; + this->updateLocalTransformFromWorldTransform(); + this->updateChildrenTransforms(); + this->eventTransformUpdated.invoke(); +} + + +void SceneItem::setParent(std::shared_ptr parent) { + assertTrue( + parent == nullptr || parent != shared_from_this(), + "SceneItem::setParent: Cannot set parent to self" + ); + + auto currentParent = this->getParent().lock(); + if(currentParent == parent) return; + + if(currentParent != nullptr) { + auto it = currentParent->children.begin(); + while(it != currentParent->children.end()) { + auto child = (*it).lock(); + if(child == shared_from_this()) { + currentParent->children.erase(it); + break; + } + ++it; + } + } + + this->parent = parent; + if(parent != nullptr) parent->children.push_back(shared_from_this()); + + this->updateLocalTransformFromWorldTransform(); + this->updateChildrenTransforms(); + this->eventTransformUpdated.invoke(); +} + +std::weak_ptr SceneItem::getParent() { + return this->parent; +} + +bool_t SceneItem::isChildOf(std::shared_ptr parent) { + auto current = this->getParent(); + std::shared_ptr currentLocked; + while(currentLocked = current.lock()) { + if(currentLocked == parent) return true; + current = currentLocked->getParent(); + } + return false; +} + SceneItem::~SceneItem() { + this->setParent(nullptr); + + auto it = this->children.begin(); + while(it != this->children.end()) { + auto child = (*it).lock(); + if(child != nullptr) child->setParent(nullptr); + it = this->children.begin(); + } } \ No newline at end of file diff --git a/src/dawn/scene/SceneItem.hpp b/src/dawn/scene/SceneItem.hpp index 3e3b723c..33157f51 100644 --- a/src/dawn/scene/SceneItem.hpp +++ b/src/dawn/scene/SceneItem.hpp @@ -4,21 +4,47 @@ // https://opensource.org/licenses/MIT #pragma once -#include "display/Transform.hpp" #include "scene/Scene.hpp" #include "util/array.hpp" namespace Dawn { class SceneItemComponent; - class SceneItem : public StateOwner { + class SceneItem : + public StateOwner, + public std::enable_shared_from_this + { private: std::vector> components; + // Local (real) values + glm::vec3 localPosition; + glm::vec3 localScale; + glm::quat localRotation; + + // Cached (non-real) values + glm::mat4 transformLocal; + glm::mat4 transformWorld; + + // glm::vec3 position; + // glm::vec3 scale; + // glm::quat rotation; + + // Heirarchy + std::weak_ptr parent; + std::vector> children; + + // Hidden methods + void updateLocalValuesFromLocalTransform(); + void updateLocalTransformFromLocalValues(); + void updateWorldTransformFromLocalTransform(); + void updateLocalTransformFromWorldTransform(); + void updateChildrenTransforms(); public: Scene *scene; sceneitemid_t id; - Transform transform; + // I have no idea if I'm keeping this + StateEvent<> eventTransformUpdated; /** * Constructor for a SceneItem. Scene Items should only be called and @@ -106,10 +132,16 @@ namespace Dawn { */ template std::shared_ptr findChild() { - auto it = this->transform.children.begin(); - while(it != this->transform.children.end()) { - auto child = (*it)->item->getComponent(); - if(child != nullptr) return child; + auto it = this->children.begin(); + while(it != this->children.end()) { + auto childItem = it->lock(); + if(childItem == nullptr) { + ++it; + continue; + } + + auto childComponent = childItem->getComponent(); + if(childComponent != nullptr) return childComponent; ++it; } return nullptr; @@ -124,11 +156,16 @@ namespace Dawn { */ template std::vector> findChildren() { - auto it = this->transform.children.begin(); + auto it = this->children.begin(); std::vector> children; - while(it != this->transform.children.end()) { - auto child = (*it)->item->getComponent(); - if(child != nullptr) children.push_back(child); + while(it != this->children.end()) { + auto childItem = it->lock(); + if(childItem == nullptr) { + ++it; + continue; + } + auto childComponent = childItem->getComponent(); + if(childComponent != nullptr) children.push_back(childComponent); ++it; } return children; @@ -143,19 +180,146 @@ namespace Dawn { */ template std::vector> findChildrenDeep() { - std::vector transformsToCheck = this->transform.children; + auto childrenToCheck = this->children; std::vector> itemsFound; - while(transformsToCheck.size() > 0) { - Transform *tras = *transformsToCheck.begin(); - vectorAppend(transformsToCheck, tras->children); - auto component = tras->item->getComponent(); + while(childrenToCheck.size() > 0) { + auto it = *childrenToCheck.begin(); + auto otherItem = it.lock(); + if(otherItem != nullptr) { + vectorAppend(childrenToCheck, otherItem->children); + } + auto component = otherItem->getComponent(); if(component != nullptr) itemsFound.push_back(component); - transformsToCheck.erase(transformsToCheck.begin()); + childrenToCheck.erase(childrenToCheck.begin()); } return itemsFound; } + + // // // // // // // // // // // // // // // // // // // // // // // // // + + /** + * Orients this transform to look at a given point in world space. + * + * @param position Position of the origin of this transform. + * @param look Position in world space this transform looks at. + */ + void lookAt(const glm::vec3 position, const glm::vec3 look); + void lookAt( + const glm::vec3 position, + const glm::vec3 look, + const glm::vec3 up + ); + + /** + * Shorthand combined for lookAt and perspectivePixelPerfectDistance + * to allow you to create pixel perfect lookAt camera view matricies. + * + * @param position Position of the camera. Z is for an offset. + * @param look Position in world space this transform looks at. + * @param viewportHeight Height of the viewport. + * @param fov Field of view (in radians). + * @return The Z distance that was calculated. + */ + float_t lookAtPixelPerfect( + const glm::vec3 position, + const glm::vec3 look, + const float_t viewportHeight, + const float_t fov + ); + + /** + * Returns the local position (position relative to "my parent"). + * @return The 3D local position in parent-relative space. + */ + glm::vec3 getLocalPosition(); + + /** + * Update / Set the local position of this transform relative to my parent + * @param position Position to set for the local transform. + */ + void setLocalPosition(const glm::vec3 position); + + /** + * Retusn the scale of this item, relative to my parent. + * @return 3D Scale vector of this item in parent-relative space. + */ + glm::vec3 getLocalScale(); + + /** + * Set the local scale of this item. + * @param scale Scale of this item, relative to its parent. + */ + void setLocalScale(const glm::vec3 scale); + + /** + * Returns the local rotation for this transform. + * @return The local rotation (parent-relative). + */ + glm::quat getLocalRotation(); + + /** + * Set the local (parent-relative) rotation for this transform. + * @param rotation Rotation in parent relative space. + */ + void setLocalRotation(const glm::quat rotation); + + /** + * Returns the transform matrix for this transform, in parent-relative + * space. + * @return The transform origin in parent-relative space. + */ + glm::mat4 getLocalTransform(); + + /** + * Sets the local transform matrix for this transform. + * @param transform Local (parent-relative) transform to set. + */ + void setLocalTransform(const glm::mat4 transform); + + /** + * Returns the position of the origin of this transform in world-space. + * + * @return Transform origin in world-space. + */ + glm::vec3 getWorldPosition(); + + /** + * Returns the transformation matrix for this transform, in world-space. + * @return The transform origin in world-space. + */ + glm::mat4 getWorldTransform(); + + /** + * Updates the transform's world-space. + * @param transform Sets the transform position in world-space. + */ + void setWorldTransform(const glm::mat4 transform); + + /** + * Updates the transform that this transform is a child of. Will also + * handle disconnecting any existing parent. + * + * @param p Parent that this transform is now a child of. + */ + void setParent(const std::shared_ptr p); + + /** + * Returns the parent transform of this transform, or nullptr if there is + * no parent for this transform. + * @return Pointer to the parent transform, or nullptr. + */ + std::weak_ptr getParent(); + + /** + * Returns true if this transform is a child of the given transform, this + * climbs up the heirarchy until it finds a match. + * + * @param p Transform to check if this transform is a child of. + * @return True if this transform is a child of the given transform. + */ + bool_t isChildOf(std::shared_ptr p); /** * Destroy this SceneItem. diff --git a/src/dawn/scene/SceneItemComponent.cpp b/src/dawn/scene/SceneItemComponent.cpp index 8a6fd777..95f664b4 100644 --- a/src/dawn/scene/SceneItemComponent.cpp +++ b/src/dawn/scene/SceneItemComponent.cpp @@ -13,7 +13,6 @@ using namespace Dawn; SceneItemComponent::SceneItemComponent(SceneItem *item) { assertNotNull(item, "SceneItemComponent::SceneItemComponent: Item cannot be null"); this->item = item; - this->transform = &item->transform; } void SceneItemComponent::init() { diff --git a/src/dawn/scene/SceneItemComponent.hpp b/src/dawn/scene/SceneItemComponent.hpp index f93922d1..bcf396a4 100644 --- a/src/dawn/scene/SceneItemComponent.hpp +++ b/src/dawn/scene/SceneItemComponent.hpp @@ -5,7 +5,6 @@ #pragma once #include "dawnlibs.hpp" -#include "display/Transform.hpp" #include "scene/SceneItem.hpp" #include "state/StateOwner.hpp" @@ -15,7 +14,6 @@ namespace Dawn { class SceneItemComponent : public StateOwner { public: SceneItem *item; - Transform *transform; bool_t hasInitialized = false; /** diff --git a/src/dawn/scene/components/display/Camera.cpp b/src/dawn/scene/components/display/Camera.cpp index 3efa64d0..d8aa856d 100644 --- a/src/dawn/scene/components/display/Camera.cpp +++ b/src/dawn/scene/components/display/Camera.cpp @@ -66,7 +66,7 @@ glm::vec3 Camera::getRayDirectionFromScreenSpace(glm::vec2 screenSpace) { glm::vec4 eyeCoords = inverseProjectionMatrix * clipCoords; eyeCoords = glm::vec4(eyeCoords.x, eyeCoords.y, -1.0f, 0.0f); - glm::mat4 inverseViewMatrix = glm::inverse(transform->getWorldTransform()); + glm::mat4 inverseViewMatrix = glm::inverse(item->getWorldTransform()); glm::vec4 t = inverseViewMatrix * eyeCoords; return glm::normalize(glm::vec3(t.x, t.y, t.z)); diff --git a/src/dawn/scene/components/display/PixelPerfectCamera.cpp b/src/dawn/scene/components/display/PixelPerfectCamera.cpp index 1072019b..c4341f07 100644 --- a/src/dawn/scene/components/display/PixelPerfectCamera.cpp +++ b/src/dawn/scene/components/display/PixelPerfectCamera.cpp @@ -33,13 +33,13 @@ void PixelPerfectCamera::updateDimensions() { break; case CAMERA_TYPE_PERSPECTIVE: - this->transform->lookAtPixelPerfect( + item->lookAtPixelPerfect( glm::vec3(0, 0, 0), glm::vec3(0, 0, 0), target->getHeight() / this->scale, this->camera->fov ); - // this->transform->lookAt(glm::vec3(360, 360, 360), glm::vec3(0, 0, 0)); + // this->lookAt(glm::vec3(360, 360, 360), glm::vec3(0, 0, 0)); break; default: diff --git a/src/dawn/scene/components/example/ExampleSpin.cpp b/src/dawn/scene/components/example/ExampleSpin.cpp index f5ef392f..235e89e2 100644 --- a/src/dawn/scene/components/example/ExampleSpin.cpp +++ b/src/dawn/scene/components/example/ExampleSpin.cpp @@ -29,10 +29,10 @@ ExampleSpin::ExampleSpin(SceneItem *item) : void ExampleSpin::onStart() { useEvent([&](float_t delta){ - auto quat = this->transform->getLocalRotation(); + auto quat = item->getLocalRotation(); quat = glm::rotate(quat, delta, glm::vec3(0, 1, 0)); quat = glm::rotate(quat, delta / 2.0f, glm::vec3(1, 0, 0)); quat = glm::rotate(quat, delta / 4.0f, glm::vec3(0, 0, 1)); - this->transform->setLocalRotation(quat); + item->setLocalRotation(quat); }, getScene()->eventSceneUnpausedUpdate); } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/CharacterController2D.cpp b/src/dawn/scene/components/physics/2d/CharacterController2D.cpp index 88dcc6fb..c452d372 100644 --- a/src/dawn/scene/components/physics/2d/CharacterController2D.cpp +++ b/src/dawn/scene/components/physics/2d/CharacterController2D.cpp @@ -38,7 +38,7 @@ void CharacterController2D::onStart() { while(itColliders != allColliders.end()) { auto c = *itColliders; ++itColliders; - if(c->item == this->item || c->transform->isChildOf(this->transform)) continue; + if(c->item == this->item || c->item->isChildOf(item->shared_from_this())) continue; result = c->getCollidingResult( velocity, myCollider, @@ -65,8 +65,8 @@ void CharacterController2D::onStart() { } if(moveAmount != glm::vec2(0, 0)) { - transform->setLocalPosition( - transform->getLocalPosition() + (glm::vec3(moveAmount.x, 0, moveAmount.y) * delta) + item->setLocalPosition( + item->getLocalPosition() + (glm::vec3(moveAmount.x, 0, moveAmount.y) * delta) ); } @@ -76,7 +76,7 @@ void CharacterController2D::onStart() { while(itTriggers != allTriggers.end()) { auto c = *itTriggers; ++itTriggers; - if(c->item == this->item || c->transform->isChildOf(this->transform)) continue; + if(c->item == this->item || c->item->isChildOf(item->shared_from_this())) continue; if(c->getCollidingResult(myCollider)) { c->eventTriggerEnter.invoke(this); } diff --git a/src/dawn/scene/components/physics/2d/SolidController2D.cpp b/src/dawn/scene/components/physics/2d/SolidController2D.cpp index 4ffbe945..31f45a4a 100644 --- a/src/dawn/scene/components/physics/2d/SolidController2D.cpp +++ b/src/dawn/scene/components/physics/2d/SolidController2D.cpp @@ -29,7 +29,7 @@ bool_t SolidController2D::getCollidingResult( assertNotNull(movingObject, "SolidController2D::getCollidingResult: Moving object cannot be null"); if(movement.x == 0 && movement.y == 0) return false; - auto myPos = physics3Dto2D(movingObject->transform->getWorldPosition()); + auto myPos = physics3Dto2D(movingObject->item->getWorldPosition()); // Check what the moving object is switch(movingObject->getColliderType()) { @@ -42,7 +42,7 @@ bool_t SolidController2D::getCollidingResult( case COLLIDER2D_TYPE_BOX: { auto box2 = std::static_pointer_cast(this->collider); assertNotNull(box2, "SolidController2D::getCollidingResult: Collider is not a BoxCollider"); - auto otherPos = physics3Dto2D(box2->transform->getWorldPosition()); + auto otherPos = physics3Dto2D(box2->item->getWorldPosition()); return boxCheckCollision( myPos, box1->min, box1->max, diff --git a/src/dawn/scene/components/physics/2d/TriggerController2D.cpp b/src/dawn/scene/components/physics/2d/TriggerController2D.cpp index d52251c3..8d7cf409 100644 --- a/src/dawn/scene/components/physics/2d/TriggerController2D.cpp +++ b/src/dawn/scene/components/physics/2d/TriggerController2D.cpp @@ -32,8 +32,8 @@ bool_t TriggerController2D::getCollidingResult(std::shared_ptr movin auto box2 = std::static_pointer_cast(collider); assertNotNull(box2, "TriggerController2D::getCollidingResult: Collider is not a BoxCollider"); return boxIsBoxColliding( - physics3Dto2D(box1->transform->getWorldPosition()), box1->min, box1->max, - physics3Dto2D(box2->transform->getWorldPosition()), box2->min, box2->max + physics3Dto2D(box1->item->getWorldPosition()), box1->min, box1->max, + physics3Dto2D(box2->item->getWorldPosition()), box2->min, box2->max ); } diff --git a/src/dawn/scene/components/physics/3d/CapsuleCollider.cpp b/src/dawn/scene/components/physics/3d/CapsuleCollider.cpp index 99be5625..9e54385a 100644 --- a/src/dawn/scene/components/physics/3d/CapsuleCollider.cpp +++ b/src/dawn/scene/components/physics/3d/CapsuleCollider.cpp @@ -22,7 +22,7 @@ bool_t CapsuleCollider::performRaycast( { .height = this->height, .radius = this->radius, - .origin = this->transform->getWorldPosition() + .origin = item->getWorldPosition() }, &result->point, &result->normal, diff --git a/src/dawn/scene/components/physics/3d/CharacterController3D.cpp b/src/dawn/scene/components/physics/3d/CharacterController3D.cpp index 9cbba876..74a77597 100644 --- a/src/dawn/scene/components/physics/3d/CharacterController3D.cpp +++ b/src/dawn/scene/components/physics/3d/CharacterController3D.cpp @@ -30,6 +30,6 @@ void CharacterController3D::onStart() { // } // Move / Update - transform->setLocalPosition(transform->getLocalPosition() + (velocity * delta)); + item->setLocalPosition(item->getLocalPosition() + (velocity * delta)); }, getScene()->eventSceneUpdate); } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/3d/CubeCollider.cpp b/src/dawn/scene/components/physics/3d/CubeCollider.cpp index 2f2eba87..a0127f21 100644 --- a/src/dawn/scene/components/physics/3d/CubeCollider.cpp +++ b/src/dawn/scene/components/physics/3d/CubeCollider.cpp @@ -20,7 +20,7 @@ bool_t CubeCollider::performRaycast( return Dawn::raytestCube( ray, { .min = this->min, .max = this->max }, - this->transform->getWorldTransform(), + item->getWorldTransform(), &result->point, &result->normal, &result->distance diff --git a/src/dawn/scene/components/physics/3d/SphereCollider.cpp b/src/dawn/scene/components/physics/3d/SphereCollider.cpp index 4988a034..8d26dfaa 100644 --- a/src/dawn/scene/components/physics/3d/SphereCollider.cpp +++ b/src/dawn/scene/components/physics/3d/SphereCollider.cpp @@ -23,7 +23,7 @@ bool_t SphereCollider::performRaycast( return raytestSphere( ray, - { .center = transform->getLocalPosition(), .radius = this->radius }, + { .center = item->getLocalPosition(), .radius = this->radius }, &result->point, &result->normal, &result->distance diff --git a/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp b/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp index e647e719..9a7898ca 100644 --- a/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp +++ b/src/dawn/scene/components/scene/SubSceneCameraAlign.cpp @@ -23,7 +23,7 @@ void SubSceneCameraAlign::realign() { float_t myRatio = this->camera->getAspect(); this->camera->type = CAMERA_TYPE_ORTHONOGRAPHIC; - this->camera->transform->lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0)); + this->camera->item->lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0)); if(ratio > myRatio) { // My Ratio is narrower diff --git a/src/dawn/scene/components/ui/UIBorder.cpp b/src/dawn/scene/components/ui/UIBorder.cpp index e3a95974..bf30323a 100644 --- a/src/dawn/scene/components/ui/UIBorder.cpp +++ b/src/dawn/scene/components/ui/UIBorder.cpp @@ -37,7 +37,7 @@ std::vector UIBorder::getUIRenderPasses() { item.shader = shader; item.colorValues[shader->paramColor] = COLOR_WHITE; item.parameterBuffers[shader->bufferUiCanvas] = &this->getCanvas()->shaderBuffer; - item.matrixValues[shader->paramModel] = this->transform->getWorldTransform(); + item.matrixValues[shader->paramModel] = this->item->getWorldTransform(); if(this->texture == nullptr) { item.boolValues[shader->paramHasTexture] = false; } else { @@ -45,7 +45,7 @@ std::vector UIBorder::getUIRenderPasses() { item.textureSlots[0] = this->texture; item.textureValues[shader->paramTexture] = 0; } - item.w = this->transform->getWorldPosition().z; + item.w = this->item->getWorldPosition().z; item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND; item.mesh = &mesh; diff --git a/src/dawn/scene/components/ui/UICanvas.cpp b/src/dawn/scene/components/ui/UICanvas.cpp index dc2523ba..0f8435a0 100644 --- a/src/dawn/scene/components/ui/UICanvas.cpp +++ b/src/dawn/scene/components/ui/UICanvas.cpp @@ -26,7 +26,7 @@ void UICanvas::rebufferShaderParameters() { switch(this->drawType) { case UI_DRAW_TYPE_WORLD_ABSOLUTE: data.projection = camera->getProjection(); - data.view = camera->transform->getWorldTransform(); + data.view = camera->item->getWorldTransform(); break; case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE: diff --git a/src/dawn/scene/components/ui/UIComponent.cpp b/src/dawn/scene/components/ui/UIComponent.cpp index 733c7b78..8d4f19f5 100644 --- a/src/dawn/scene/components/ui/UIComponent.cpp +++ b/src/dawn/scene/components/ui/UIComponent.cpp @@ -22,9 +22,9 @@ UIComponent::UIComponent(SceneItem *item) : } std::shared_ptr UIComponent::getParentDimensional() { - auto parent = this->transform->getParent(); + auto parent = item->getParent().lock(); if(parent == nullptr) return nullptr; - auto dimensional = parent->item->getComponent(); + auto dimensional = parent->getComponent(); assertNotNull(dimensional, "UIComponent::getParentDimensional: Parent must have a UIComponentDimensional"); return dimensional; } @@ -34,7 +34,7 @@ void UIComponent::updateAlignment() { auto align = (glm::vec4)this->alignment; auto dimensional = this->getParentDimensional(); - auto translate = this->transform->getLocalPosition(); + auto translate = item->getLocalPosition(); assertNotNull(dimensional, "UIComponent::updateAlignment: Parent must have a UIComponentDimensional"); @@ -99,7 +99,7 @@ void UIComponent::updateAlignment() { translate.x += dimensional->getChildOffsetX(); translate.y += dimensional->getChildOffsetY(); - this->transform->setLocalPosition(translate); + item->setLocalPosition(translate); this->alignmentNeedsUpdating = false; this->eventAlignmentUpdated.invoke(); } @@ -240,11 +240,11 @@ void UIComponent::calculateDimensions( std::shared_ptr UIComponent::getCanvas() { // TODO: Cache this on first hit. - auto parent = this->transform->getParent(); - while(parent != nullptr) { - auto canvas = parent->item->getComponent(); + auto parent = item->getParent().lock(); + while(parent) { + auto canvas = parent->getComponent(); if(canvas != nullptr) return canvas; - parent = parent->getParent(); + parent = parent->getParent().lock(); } assertUnreachable("UIComponent::getCanvas: No canvas found"); return nullptr; diff --git a/src/dawn/scene/components/ui/UIImage.cpp b/src/dawn/scene/components/ui/UIImage.cpp index a4974b36..55ad08e7 100644 --- a/src/dawn/scene/components/ui/UIImage.cpp +++ b/src/dawn/scene/components/ui/UIImage.cpp @@ -32,7 +32,7 @@ std::vector UIImage::getUIRenderPasses() { item.shader = shader; item.colorValues[shader->paramColor] = this->color; item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer; - item.matrixValues[shader->paramModel] = this->transform->getWorldTransform(); + item.matrixValues[shader->paramModel] = this->item->getWorldTransform(); if(this->texture == nullptr) { item.boolValues[shader->paramHasTexture] = false; } else { @@ -40,7 +40,7 @@ std::vector UIImage::getUIRenderPasses() { item.textureSlots[0] = this->texture; item.textureValues[shader->paramTexture] = 0; } - item.w = this->transform->getWorldPosition().z; + item.w = this->item->getWorldPosition().z; item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND; item.mesh = &mesh; return { item }; diff --git a/src/dawn/scene/components/ui/UIMesh.cpp b/src/dawn/scene/components/ui/UIMesh.cpp index 25cf81b9..63755567 100644 --- a/src/dawn/scene/components/ui/UIMesh.cpp +++ b/src/dawn/scene/components/ui/UIMesh.cpp @@ -26,23 +26,23 @@ float_t UIMesh::getContentHeight() { } std::vector UIMesh::getUIRenderPasses() { - struct ShaderPassItem item; + struct ShaderPassItem shaderItem; auto shader = getGame()->renderManager->uiShader; - item.shader = shader; - item.colorValues[shader->paramColor] = this->color; - item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer; - item.matrixValues[shader->paramModel] = this->transform->getWorldTransform(); + shaderItem.shader = shader; + shaderItem.colorValues[shader->paramColor] = this->color; + shaderItem.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer; + shaderItem.matrixValues[shader->paramModel] = item->getWorldTransform(); if(this->texture == nullptr) { - item.boolValues[shader->paramHasTexture] = false; + shaderItem.boolValues[shader->paramHasTexture] = false; } else { - item.boolValues[shader->paramHasTexture] = true; - item.textureSlots[0] = this->texture; - item.textureValues[shader->paramTexture] = 0; + shaderItem.boolValues[shader->paramHasTexture] = true; + shaderItem.textureSlots[0] = this->texture; + shaderItem.textureValues[shader->paramTexture] = 0; } - item.w = this->transform->getWorldPosition().z; - item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND; - item.mesh = &mesh; - return { item }; + shaderItem.w = item->getWorldPosition().z; + shaderItem.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND; + shaderItem.mesh = &mesh; + return { shaderItem }; } void UIMesh::onStart() { diff --git a/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp b/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp index 414d4df7..de344673 100644 --- a/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp +++ b/src/dawn/scene/components/ui/menu/UISimpleMenu.cpp @@ -75,7 +75,7 @@ void UISimpleMenu::onStart() { case UI_DRAW_TYPE_WORLD_ABSOLUTE: mouse *= 2.0f; mouse -= glm::vec2(1, 1); - ray.origin = canvas->camera->transform->getWorldPosition(); + ray.origin = canvas->camera->item->getWorldPosition(); ray.direction = canvas->camera->getRayDirectionFromScreenSpace(mouse); break; @@ -107,7 +107,7 @@ void UISimpleMenu::onStart() { if(!raytestQuad( ray, glm::vec2(0, 0), size, - highlight->transform->getWorldTransform(), + highlight->item->getWorldTransform(), &point, &normal, &distance diff --git a/src/dawn/scene/components/ui/text/UILabel.cpp b/src/dawn/scene/components/ui/text/UILabel.cpp index 539986a9..953f41a9 100644 --- a/src/dawn/scene/components/ui/text/UILabel.cpp +++ b/src/dawn/scene/components/ui/text/UILabel.cpp @@ -90,7 +90,7 @@ std::vector UILabel::getUIRenderPasses() { auto shader = getGame()->renderManager->fontShader; // Translate - glm::mat4 model = transform->getWorldTransform(); + glm::mat4 model = item->getWorldTransform(); model = glm::translate(model, glm::vec3(this->textOffset, 0.0f)); struct ShaderPassItem item; diff --git a/src/dawn/scenes/TestScene.hpp b/src/dawn/scenes/TestScene.hpp index 6353f574..986253ca 100644 --- a/src/dawn/scenes/TestScene.hpp +++ b/src/dawn/scenes/TestScene.hpp @@ -15,7 +15,7 @@ namespace Dawn { void stage() override { camera = Camera::create(this); - camera->transform->lookAt(glm::vec3(5, 5, 5), glm::vec3(0, 0, 0)); + camera->lookAt(glm::vec3(5, 5, 5), glm::vec3(0, 0, 0)); cube = SimpleSpinningCubePrefab::prefabCreate(this); } diff --git a/src/dawnhelloworld/scenes/HelloWorldScene.hpp b/src/dawnhelloworld/scenes/HelloWorldScene.hpp index 5d600e0b..445a402c 100644 --- a/src/dawnhelloworld/scenes/HelloWorldScene.hpp +++ b/src/dawnhelloworld/scenes/HelloWorldScene.hpp @@ -17,7 +17,7 @@ namespace Dawn { void stage() override { camera = Camera::create(this); - camera->transform->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0)); + camera->item->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0)); cube = SimpleSpinningCubePrefab::create(this); diff --git a/src/dawnopenal/scene/components/audio/AudioListener.cpp b/src/dawnopenal/scene/components/audio/AudioListener.cpp index f09aaf3b..85e64e86 100644 --- a/src/dawnopenal/scene/components/audio/AudioListener.cpp +++ b/src/dawnopenal/scene/components/audio/AudioListener.cpp @@ -17,17 +17,17 @@ void AudioListener::onStart() { ALfloat listenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 }; alListenerfv(AL_ORIENTATION, listenerOri); - glm::vec3 position = this->transform->getLocalPosition(); + glm::vec3 position = this->item->getLocalPosition(); alListener3f(AL_POSITION, position.x, position.y, position.z); - this->transform->eventTransformUpdated.addListener(this, &AudioListener::onTransformUpdate); + this->item->eventTransformUpdated.addListener(this, &AudioListener::onTransformUpdate); } void AudioListener::onDispose() { - this->transform->eventTransformUpdated.removeListener(this, &AudioListener::onTransformUpdate); + this->item->eventTransformUpdated.removeListener(this, &AudioListener::onTransformUpdate); } void AudioListener::onTransformUpdate() { - glm::vec3 position = this->transform->getWorldPosition(); + glm::vec3 position = this->item->getWorldPosition(); alListener3f(AL_POSITION, position.x, position.y, position.z); } \ No newline at end of file diff --git a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp index d2bfa7d6..9a03d8d0 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp +++ b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp @@ -36,7 +36,7 @@ std::vector onlyPass.mesh = mesh->mesh; onlyPass.shader = shader; onlyPass.colorValues[shader->paramColor] = this->color; - onlyPass.matrixValues[shader->paramModel] = this->transform->getWorldTransform(); + onlyPass.matrixValues[shader->paramModel] = item->getWorldTransform(); onlyPass.parameterBuffers[shader->bufferRenderPipeline] = &context.renderPipeline->shaderBuffer ; diff --git a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp index 1273cb57..13c5f4c0 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp +++ b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp @@ -38,7 +38,7 @@ std::vector onlyPass.shader = shader; onlyPass.colorValues[shader->paramColor] = this->color; onlyPass.matrixValues[shader->paramModel] = - this->transform->getWorldTransform() + item->getWorldTransform() ; onlyPass.parameterBuffers[ shader->bufferRenderPipeline diff --git a/src/dawnrose/scene/components/GameCamera.cpp b/src/dawnrose/scene/components/GameCamera.cpp index 13666464..b85b0c51 100644 --- a/src/dawnrose/scene/components/GameCamera.cpp +++ b/src/dawnrose/scene/components/GameCamera.cpp @@ -21,10 +21,10 @@ void GameCamera::onStart() { assertNotNull(this->player); useEvent([&]{ - glm::vec3 lookOffset = player->transform->getLocalRotation() * glm::vec3(0, 0, 1.0f); + glm::vec3 lookOffset = player->getLocalRotation() * glm::vec3(0, 0, 1.0f); glm::vec2 target = glm::vec2(lookOffset.x, lookOffset.z) * lookOffsetScale; slowTarget += (target - slowTarget) * getGame()->timeManager.delta * movementScrollSpeed; - }, this->player->transform->eventTransformUpdated); + }, this->player->eventTransformUpdated); useEvent([&](float_t delta){ if(current != slowTarget) { @@ -37,7 +37,7 @@ void GameCamera::onStart() { } glm::vec3 current3 = glm::vec3(current.x, 0, current.y); - glm::vec3 t0 = player->transform->getLocalPosition(); - camera->transform->lookAt(t0 + current3 + zoomOffset, t0 + current3); + glm::vec3 t0 = player->getLocalPosition(); + camera->lookAt(t0 + current3 + zoomOffset, t0 + current3); }, getScene()->eventSceneUpdate); } \ No newline at end of file