Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions transform_hierarchy/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "object_transform.h"

#include <vector>
#include <iostream>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is iostream needed?

#include <list>

ObjectTransform PlayerBase;
Expand Down Expand Up @@ -67,6 +68,8 @@ void GameInit()
GunModel = LoadModel("resources/blasterD.glb");

OverlayTexture = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());


Comment on lines +71 to +72
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why two extra spaces?

}

bool GameUpdate()
Expand All @@ -92,6 +95,9 @@ bool GameUpdate()
if (IsKeyDown(KEY_D))
PlayerBase.MoveH(GetFrameTime() * -10);

if (IsKeyPressed(KEY_SPACE))
GunNode.Detach();

Comment on lines +98 to +100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should tell the user what the keys do now that there is more than one

return true;
}

Expand Down
25 changes: 25 additions & 0 deletions transform_hierarchy/object_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ class ObjectTransform
ObjectTransform* Parent = nullptr;
std::vector<ObjectTransform*> Children;

inline ObjectTransform* RemoveChild(ObjectTransform* child)
{
// if the node has no children, return a null pointer
if (Children.empty())
{
return nullptr;
}

// find the child's position in the children list
auto childIter = std::find(Children.begin(), Children.end(), child);

// if the children list doesn't contain the child, return a nullptr
if (childIter == Children.end())
{
return nullptr;
}

// remove the child
Children.erase(childIter);

return child;
}

public:

ObjectTransform(bool faceY = true)
Expand Down Expand Up @@ -108,6 +131,8 @@ class ObjectTransform

Orientation = QuaternionFromMatrix(WorldMatrix);

GetParent()->RemoveChild(this);

Reparent(nullptr);
}

Expand Down