Commit 3d900863 authored by Johannes Braun's avatar Johannes Braun
Browse files

Some things.

parent 969f57dd
......@@ -4,12 +4,12 @@ Size=353,64
Collapsed=0
[Scene]
Pos=-2,66
Size=352,837
Collapsed=0
Pos=29,64
Size=322,270
Collapsed=1
[Settings]
Pos=1125,0
Pos=173,7
Size=311,899
Collapsed=0
Collapsed=1
<linespace version="1.0">
<item name="subdivisions" value="20"/>
<item name="grid-subdivisions" value="2"/>
<item name="subdivisions" value="16"/>
<item name="grid-subdivisions" value="8"/>
<item name="radial-subdivision" value="50"/>
<item name="generator" value="gpu"/>
</linespace>
......@@ -15,7 +15,7 @@
#include <components/FramerateCounter.h>
#include <components/PlayerController.h>
#include "core/res/collada.h"
#include "components/Rotator.h"
#include "components/transformator.h"
using namespace glare;
......@@ -318,7 +318,10 @@ void drawSceneWindow()
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10));
if (ImGui::CollapsingHeader(component.typeName().c_str()))
{
ImGui::PopStyleVar();
ImGui::PopStyleVar();
bool active = component.isActive();
if (ImGui::Checkbox("Active", &active))
component.setActive(active);
component.debugGui();
if (ImGui::AntiFeatureButton("Delete", ImVec2(ImGui::GetContentRegionAvailWidth(), 24)))
{
......@@ -382,10 +385,10 @@ void drawSceneWindow()
selected_node->makeComponent<component::PlayerController>();
}
if (ImGui::Button("Rotator", ImVec2(180, 24)))
if (ImGui::Button("Transformator", ImVec2(180, 24)))
{
if (selected_node)
selected_node->makeComponent<component::Rotator>();
selected_node->makeComponent<component::Transformator>();
}
if (ImGui::Button("Framerate Counter", ImVec2(180, 24)))
......
#include "Rotator.h"
#include <core/time.h>
namespace glare::component
{
Rotator::Rotator()
: SceneComponent("Rotator")
{
}
Rotator::~Rotator()
{
}
void Rotator::onUpdate()
{
owner()->transform.rotate(glm::vec3(0, glm::radians(80.f), 0) * static_cast<float>(core::Time::deltaTime()));
}
}
#include "transformator.h"
#include <core/time.h>
#include <imgui/imgui_glfw.h>
#include <glm/ext.hpp>
namespace glare::component
{
Transformator::Transformator()
: SceneComponent("Transformator")
{
}
Transformator::~Transformator()
{
}
void Transformator::onUpdate()
{
glm::vec3 rotation;
rotation[m_rot_axis] = glm::radians(m_rot_speed);
owner()->transform.rotate(rotation * static_cast<float>(core::Time::deltaTime()));
owner()->transform.fromMatrix(glm::translate(owner()->transform.matrix(), m_direction * static_cast<float>(core::Time::deltaTime())));
}
void Transformator::onDebugGui()
{
ImGui::Spacing();
ImGui::Title("Rotation");
ImGui::DragInt("Axis", &m_rot_axis, 0.02f, 0, 3);
ImGui::DragFloat("Speed (Deg/s)", &m_rot_speed, 0.5f);
ImGui::Spacing();
ImGui::Title("Translation");
ImGui::DragFloat3("Move direction", glm::value_ptr(m_direction), 0.01f);
}
}
#ifndef __ROTATOR_H
#define __ROTATOR_H
#include <core/graph/component.h>
namespace glare::component
{
class Rotator : public core::SceneComponent
{
public:
Rotator();
~Rotator();
protected:
void onUpdate() override;
};
}
#endif //__ROTATOR_H
#ifndef __ROTATOR_H
#define __ROTATOR_H
#include <core/graph/component.h>
namespace glare::component
{
class Transformator : public core::SceneComponent
{
public:
Transformator();
~Transformator();
protected:
void onUpdate() override;
void onDebugGui() override;
private:
int m_rot_axis = 2;
float m_rot_speed = 80.f;
glm::vec3 m_direction = glm::vec3(0, -2, 0);
};
}
#endif //__ROTATOR_H
......@@ -13,7 +13,7 @@ namespace glare::core
}
void SceneNode::onTransform()
{
callAndTraverse(&Entity::notifyTransform);
callAndTraverse(&Entity::notifyTransform, true);
}
void SceneNode::onAttached(std::shared_ptr<SceneNode> node)
......@@ -35,27 +35,27 @@ namespace glare::core
void SceneNode::onStart()
{
callAndTraverse(&Entity::start);
callAndTraverse(&Entity::start, false);
}
void SceneNode::onActivate()
{
callAndTraverse(&Entity::setActive, true);
callAndTraverse(&Entity::setActive, false, true);
}
void SceneNode::onDeactivate()
{
callAndTraverse(&Entity::setActive, false);
callAndTraverse(&Entity::setActive, false, false);
}
void SceneNode::onEnd()
{
callAndTraverse(&Entity::end);
callAndTraverse(&Entity::end, false);
}
void SceneNode::onGui()
{
callAndTraverse(&Entity::gui);
callAndTraverse(&Entity::gui, true);
}
void SceneNode::onDebugGui()
......@@ -77,7 +77,7 @@ namespace glare::core
const glm::mat4 absolute_transform = parent() ? parent()->worldTransform().matrix() * transform.matrix() : glm::mat4(1.0f);
m_world_transform.fromMatrix(absolute_transform);
callAndTraverse(&Entity::update);
callAndTraverse(&Entity::update, true);
if (m_cached_transform != transform)
{
......@@ -89,7 +89,7 @@ namespace glare::core
void SceneNode::onDraw(DrawMode mode)
{
callAndTraverse(&Entity::draw, mode);
callAndTraverse(&Entity::draw, true, mode);
}
const math::Transform& SceneNode::worldTransform() const
......
......@@ -48,7 +48,7 @@ namespace glare::core
// A helper method for not having to write the same lines of code again and again.
// Calls an entity function on each component and then passes the call to it's children.
template<typename... Args>
void callAndTraverse(void(Entity::*node_function)(Args...), Args... args);
void callAndTraverse(void(Entity::*node_function)(Args...), bool if_active, Args... args);
math::Transform m_world_transform;
math::Transform m_cached_transform;
......@@ -57,11 +57,12 @@ namespace glare::core
};
template<typename... Args>
void SceneNode::callAndTraverse(void(Entity::*node_function)(Args...), Args... args)
void SceneNode::callAndTraverse(void(Entity::*node_function)(Args...), bool if_active, Args... args)
{
iterateComponentsStable([&args..., &node_function](SceneComponent& component)
iterateComponentsStable([&args..., &node_function, &if_active](SceneComponent& component)
{
(component.*node_function)(args...);
if(component.isActive() || !if_active)
(component.*node_function)(args...);
});
for (auto && child : m_children)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment