Nameless Engine
|
#include <SpatialNode.h>
Classes | |
struct | LocalSpaceInformation |
struct | WorldMatrixInformation |
Public Member Functions | |
SpatialNode (const std::string &sNodeName) | |
void | setRelativeLocation (const glm::vec3 &location) |
void | setRelativeRotation (const glm::vec3 &rotation) |
void | setRelativeScale (const glm::vec3 &scale) |
void | setWorldLocation (const glm::vec3 &location) |
void | setWorldRotation (const glm::vec3 &rotation) |
void | setWorldScale (const glm::vec3 &scale) |
glm::vec3 | getRelativeLocation () const |
glm::vec3 | getRelativeRotation () const |
glm::vec3 | getRelativeScale () const |
glm::mat4x4 | getRelativeRotationMatrix () |
glm::vec3 | getWorldLocation () |
glm::vec3 | getWorldRotation () |
glm::quat | getWorldRotationQuaternion () |
glm::vec3 | getWorldScale () |
glm::vec3 | getWorldForwardDirection () |
glm::vec3 | getWorldRightDirection () |
glm::vec3 | getWorldUpDirection () |
glm::mat4x4 | getWorldMatrix () |
std::pair< std::recursive_mutex, sgc::GcPtr< SpatialNode > > * | getClosestSpatialParent () |
Public Member Functions inherited from ne::Node | |
Node () | |
Node (const std::string &sName) | |
Node (const Node &)=delete | |
Node & | operator= (const Node &)=delete |
Node (Node &&)=delete | |
Node & | operator= (Node &&)=delete |
virtual | ~Node () override |
void | setNodeName (const std::string &sName) |
void | detachFromParentAndDespawn () |
void | addChildNode (const sgc::GcPtr< Node > &pNode, AttachmentRule locationRule=AttachmentRule::KEEP_WORLD, AttachmentRule rotationRule=AttachmentRule::KEEP_WORLD, AttachmentRule scaleRule=AttachmentRule::KEEP_WORLD) |
void | setSerialize (bool bSerialize) |
std::optional< Error > | serializeNodeTree (const std::filesystem::path &pathToFile, bool bEnableBackup) |
std::string | getNodeName () const |
sgc::GcPtr< Node > | getWorldRootNode () |
std::pair< std::recursive_mutex, sgc::GcPtr< Node > > * | getParentNode () |
std::pair< std::recursive_mutex, sgc::GcVector< sgc::GcPtr< Node > > > * | getChildNodes () |
template<typename NodeType > requires std::derived_from<NodeType, Node> | |
sgc::GcPtr< NodeType > | getParentNodeOfType (const std::string &sParentNodeName="") |
template<typename NodeType > requires std::derived_from<NodeType, Node> | |
sgc::GcPtr< NodeType > | getChildNodeOfType (const std::string &sChildNodeName="") |
TickGroup | getTickGroup () const |
std::optional< size_t > | getNodeId () const |
bool | isCalledEveryFrame () |
bool | isReceivingInput () |
bool | isSpawned () |
bool | isParentOf (Node *pNode) |
bool | isChildOf (Node *pNode) |
bool | isSerialized () const |
Public Member Functions inherited from ne::Serializable | |
std::optional< Error > | serialize (std::filesystem::path pathToFile, bool bEnableBackup, const std::unordered_map< std::string, std::string > &customAttributes={}) |
std::variant< std::string, Error > | serialize (toml::value &tomlData, const std::string &sEntityId="", const std::unordered_map< std::string, std::string > &customAttributes={}, const std::optional< std::filesystem::path > &optionalPathToFile={}, bool bEnableBackup=false) |
std::variant< std::string, Error > | serialize (toml::value &tomlData, Serializable *pOriginalObject, std::string sEntityId="", const std::unordered_map< std::string, std::string > &customAttributes={}, const std::optional< std::filesystem::path > &optionalPathToFile={}, bool bEnableBackup=false) |
std::optional< std::pair< std::string, std::string > > | getPathDeserializedFromRelativeToRes () const |
Protected Member Functions | |
virtual void | onAfterDeserialized () override |
virtual void | onSpawning () override |
virtual void | onAfterAttachedToNewParent (bool bThisNodeBeingAttached) override |
virtual void | onWorldLocationRotationScaleChanged () |
Protected Member Functions inherited from ne::Node | |
void | setIsCalledEveryFrame (bool bEnable) |
void | setTickGroup (TickGroup tickGroup) |
void | setIsReceivingInput (bool bEnable) |
Timer * | createTimer (const std::string &sTimerName) |
template<typename FunctionType > | |
NodeNotificationBroadcaster< FunctionType > * | createNotificationBroadcaster () |
std::pair< std::recursive_mutex, std::unordered_map< unsigned int, std::function< void(KeyboardModifiers, bool)> > > * | getActionEventBindings () |
std::pair< std::recursive_mutex, std::unordered_map< unsigned int, std::function< void(KeyboardModifiers, float)> > > * | getAxisEventBindings () |
std::recursive_mutex * | getSpawnDespawnMutex () |
virtual void | onMouseMove (double xOffset, double yOffset) |
virtual void | onMouseScrollMove (int iOffset) |
virtual void | onBeforeNewFrame (float timeSincePrevFrameInSec) |
virtual void | onSpawning () |
virtual void | onChildNodesSpawned () |
virtual void | onDespawning () |
virtual void | onBeforeDetachedFromParent (bool bThisNodeBeingDetached) |
virtual void | onAfterAttachedToNewParent (bool bThisNodeBeingAttached) |
virtual void | onAfterDeserialized () |
Private Member Functions | |
void | applyAttachmentRule (Node::AttachmentRule locationRule, const glm::vec3 &worldLocationBeforeAttachment, Node::AttachmentRule rotationRule, const glm::vec3 &worldRotationBeforeAttachment, Node::AttachmentRule scaleRule, const glm::vec3 &worldScaleBeforeAttachment) |
void | recalculateWorldMatrix (bool bNotifyChildren=true) |
void | recalculateLocalMatrix () |
void | recalculateWorldMatrixForNodeAndNotifyChildren (Node *pNode) |
Private Attributes | |
glm::vec3 | relativeLocation = glm::vec3(0.0F, 0.0F, 0.0F) |
glm::vec3 | relativeRotation = glm::vec3(0.0F, 0.0F, 0.0F) |
glm::vec3 | relativeScale = glm::vec3(1.0F, 1.0F, 1.0F) |
std::pair< std::recursive_mutex, sgc::GcPtr< SpatialNode > > | mtxSpatialParent {} |
std::pair< std::recursive_mutex, LocalSpaceInformation > | mtxLocalSpace {} |
std::pair< std::recursive_mutex, WorldMatrixInformation > | mtxWorldMatrix {} |
Friends | |
class | Node |
Additional Inherited Members | |
Public Types inherited from ne::Node | |
enum class | AttachmentRule { RESET_RELATIVE , KEEP_RELATIVE , KEEP_WORLD } |
Static Public Member Functions inherited from ne::Node | |
static size_t | getAliveNodeCount () |
static std::variant< sgc::GcPtr< Node >, Error > | deserializeNodeTree (const std::filesystem::path &pathToFile) |
static GameInstance * | getGameInstance () |
Static Public Member Functions inherited from ne::Serializable | |
static std::variant< std::pair< std::set< std::string >, toml::value >, Error > | getIdsFromFile (std::filesystem::path pathToFile) |
static std::optional< Error > | serializeMultiple (std::filesystem::path pathToFile, std::vector< SerializableObjectInformation > vObjects, bool bEnableBackup) |
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type> requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>) | |
static std::variant< SmartPointer, Error > | deserialize (const std::filesystem::path &pathToFile) |
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type> requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>) | |
static std::variant< SmartPointer, Error > | deserialize (const std::filesystem::path &pathToFile, std::unordered_map< std::string, std::string > &customAttributes) |
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type> requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>) | |
static std::variant< SmartPointer, Error > | deserialize (std::filesystem::path pathToFile, std::unordered_map< std::string, std::string > &customAttributes, const std::string &sEntityId) |
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type> requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>) | |
static std::variant< SmartPointer, Error > | deserialize (const std::filesystem::path &pathToFile, const std::string &sEntityId) |
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type> requires std::same_as<SmartPointer, sgc::GcPtr<Serializable>> || std::same_as<SmartPointer, std::unique_ptr<Serializable>> | |
static std::variant< std::vector< DeserializedObjectInformation< SmartPointer > >, Error > | deserializeMultiple (std::filesystem::path pathToFile) |
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type> requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>) | |
static std::variant< SmartPointer, Error > | deserialize (const toml::value &tomlData, std::unordered_map< std::string, std::string > &customAttributes, std::string sEntityId="", const std::optional< std::filesystem::path > &optionalPathToFile={}) |
Represents a node that can have a location, rotation and a scale in a 3D space.
ne::SpatialNode::SpatialNode | ( | const std::string & | sNodeName | ) |
Creates a new node with the specified name.
sNodeName | Name of this node. |
|
private |
Called by Node
class after we have attached to a new parent node and now need to apply attachment rules based on this new parent node.
locationRule | Defines how location should change. |
worldLocationBeforeAttachment | World location of this node before being attached. |
rotationRule | Defines how rotation should change. |
worldRotationBeforeAttachment | World rotation of this node before being attached. |
scaleRule | Defines how scale should change. |
worldScaleBeforeAttachment | World scale of this node before being attached. |
std::pair< std::recursive_mutex, sgc::GcPtr< SpatialNode > > * ne::SpatialNode::getClosestSpatialParent | ( | ) |
Returns the first (most closer to this node) spatial node in the parent node chain (i.e. cached result of getParentNodeOfType<SpatialNode>
that can be used without any search operations).
nullptr
as a gc pointer (second value in the pair) if there is no SpatialNode in the parent node chain, otherwise closest SpatialNode in the parent node chain.
|
inline |
Returns node's relative location (see setRelativeLocation).
|
inline |
Returns node's relative rotation in degrees (see setRelativeRotation). Also see getRelativeRotationMatrix.
glm::mat4x4 ne::SpatialNode::getRelativeRotationMatrix | ( | ) |
Returns a rotation matrix that applies node's relative rotation.
|
inline |
Returns node's relative scale (see setRelativeScale).
glm::vec3 ne::SpatialNode::getWorldForwardDirection | ( | ) |
Returns node's forward direction in world space.
glm::vec3 ne::SpatialNode::getWorldLocation | ( | ) |
Returns node's world location (see setWorldLocation).
glm::mat4x4 ne::SpatialNode::getWorldMatrix | ( | ) |
Returns node's world matrix (matrix that transforms node's data (for example vertices) to world space).
glm::vec3 ne::SpatialNode::getWorldRightDirection | ( | ) |
Returns node's right direction in world space.
glm::vec3 ne::SpatialNode::getWorldRotation | ( | ) |
Returns node's world rotation in degrees (see setWorldRotation). Also see getWorldRotationQuaternion.
glm::quat ne::SpatialNode::getWorldRotationQuaternion | ( | ) |
Returns node's world rotation in the quaternion form (see getWorldRotation).
glm::vec3 ne::SpatialNode::getWorldScale | ( | ) |
Returns node's world scale (see setWorldScale).
glm::vec3 ne::SpatialNode::getWorldUpDirection | ( | ) |
Returns node's up direction in world space.
|
overrideprotectedvirtual |
Called after this node or one of the node's parents (in the parent hierarchy) was attached to a new parent node.
bThisNodeBeingAttached | true if this node was attached to a parent, false if some node in the parent hierarchy was attached to a parent. |
Reimplemented from ne::Node.
Reimplemented in ne::EditorCameraNode.
|
overrideprotectedvirtual |
Called after the object was successfully deserialized. Used to execute post-deserialization logic.
Reimplemented from ne::Serializable.
Reimplemented in ne::DirectionalLightNode, ne::PointLightNode, ne::SpotlightNode, and ne::MeshNode.
|
overrideprotectedvirtual |
Called when this node was not spawned previously and it was either attached to a parent node that is spawned or set as world's root node to execute custom spawn logic.
Reimplemented from ne::Node.
Reimplemented in ne::DirectionalLightNode, ne::PointLightNode, ne::SpotlightNode, and ne::MeshNode.
|
inlineprotectedvirtual |
Called after node's world location/rotation/scale was changed.
Reimplemented in ne::CameraNode, ne::DirectionalLightNode, ne::PointLightNode, ne::SpotlightNode, and ne::MeshNode.
|
private |
Recalculates node's local matrix based on local location/rotation/scale.
|
private |
Recalculates node's world matrix based on the parent world matrix (can be identity if there's node parent) and optionally notifies spatial child nodes.
bNotifyChildren | Whether to notify spatial child nodes so that could recalculate their world matrix or not. |
|
private |
Checks if the specified node is a SpatialNode and calls recalculateWorldMatrix, otherwise calls this function on all child nodes.
pNode | Node to recalculate world matrix for (if SpatialNode). |
void ne::SpatialNode::setRelativeLocation | ( | const glm::vec3 & | location | ) |
Sets node's relative location, if there is another SpatialNode in the parent chain then this location is relative to the first SpatialNode in the parent chain, otherwise if there is no SpatialNode in the parent chain, this location is relative to the world.
location | Relative location. |
void ne::SpatialNode::setRelativeRotation | ( | const glm::vec3 & | rotation | ) |
Sets node's relative rotation (roll, pitch, yaw in degrees), if there is another SpatialNode in the parent chain then this rotation is relative to the first SpatialNode in the parent chain, otherwise if there is no SpatialNode in the parent chain, this rotation is relative to the world.
rotation | Relative rotation. |
void ne::SpatialNode::setRelativeScale | ( | const glm::vec3 & | scale | ) |
Sets node's relative scale, if there is another SpatialNode in the parent chain then this scale is relative to the first SpatialNode in the parent chain, otherwise if there is no SpatialNode in the parent chain, this scale is relative to the world.
scale | Relative scale. |
void ne::SpatialNode::setWorldLocation | ( | const glm::vec3 & | location | ) |
Sets relative location in the way that the resulting node's location in the world would match the specified location.
location | Location that the node should take in the world. |
void ne::SpatialNode::setWorldRotation | ( | const glm::vec3 & | rotation | ) |
Sets relative rotation (roll, pitch, yaw in degrees) in the way that the resulting node's rotation in the world would match the specified rotation.
rotation | Rotation that the node should take in the world. |
void ne::SpatialNode::setWorldScale | ( | const glm::vec3 & | scale | ) |
Sets relative scale in the way that the resulting node's scale in the world would match the specified scale.
scale | Scale that the node should take in the world. |
|
private |
Matrix that describes basis vectors that define node's local space.
|
private |
First (most closer to this node) spatial node in the parent chain.
|
private |
World related information, must be used with mutex.
|
private |
Node's location, if there is another SpatialNode in the parent chain then this location is relative to the first SpatialNode in the parent chain, otherwise if there is no SpatialNode in the parent chain, relative to the world.
|
private |
Node's rotation in degrees, if there is another SpatialNode in the parent chain then this rotation is relative to the first SpatialNode in the parent chain, otherwise if there is no SpatialNode in the parent chain, relative to the world.
|
private |
Node's scale, if there is another SpatialNode in the parent chain then this scale is relative to the first SpatialNode in the parent chain, otherwise if there is no SpatialNode in the parent chain, relative to the world.