<commit_before>#include <iostream>
#include <vector>
#include <fstream>

#include "sre/Texture.hpp"
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"

#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/rotate_vector.hpp>


using namespace sre;

class Node;

Node* cameraNode;

class Node {
public:
    Node() {}

    Node(Node *parent) : parent(parent) {}

    glm::vec3 position = glm::vec3(0,0,0);
    glm::vec3 rotationEuler = glm::vec3(0,0,0);
    glm::vec3 scale = glm::vec3(1,1,1);

    glm::mat4 localToWorld(){
        // compute trs
        auto rotationEulerRadian = glm::radians(rotationEuler);
        auto res = glm::translate(position)
                   * glm::eulerAngleYXZ(rotationEulerRadian.y,rotationEulerRadian.x,rotationEulerRadian.z)
                   * glm::scale(scale);
        if (parent){
            res = parent->localToWorld() * res;
        }
        return res;
    }

    std::vector<Node> children;
    Node* parent = nullptr;

    void gui(int level = 0){
        ImGui::PushID(this);
        ImGui::Indent(level*20);

        if (ImGui::CollapsingHeader(this == cameraNode?"Camera": "Node")){
            ImGui::DragFloat3("Local Position",&position.x);
            ImGui::DragFloat3("Local Rotation",&rotationEuler.x);
            ImGui::DragFloat3("Local Scale",&scale.x);
            auto globalPos = localToWorld() * glm::vec4(0,0,0,1); // transform 0,0,0 (pivot point) from local coordinate frame to global coordinate frame
            bool changed = ImGui::DragFloat3("Global Position",&globalPos.x);
            if (changed){
                glm::vec3 deltaPositionInLocalSpace = glm::inverse(localToWorld()) * globalPos;
                position = position + deltaPositionInLocalSpace;
            }
            if (ImGui::Button("Add child")){
                children.emplace_back(this);
            }
            if (ImGui::Button("Make camera")){
                cameraNode = this;
            }
            for (auto & n : children){
                n.gui(level+1);
            }
        }
        ImGui::Unindent(level*20);
        ImGui::PopID();
    }
};<commit_msg>Fix set global position when current object has rotation or scale<commit_after>#include <iostream>
#include <vector>
#include <fstream>

#include "sre/Texture.hpp"
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"
#include "sre/SDLRenderer.hpp"

#include <glm/gtx/euler_angles.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/rotate_vector.hpp>


using namespace sre;

class Node;

Node* cameraNode;

class Node {
public:
    Node() {}

    Node(Node *parent) : parent(parent) {}

    glm::vec3 position = glm::vec3(0,0,0);
    glm::vec3 rotationEuler = glm::vec3(0,0,0);
    glm::vec3 scale = glm::vec3(1,1,1);

    glm::mat4 localToWorld(){
        // compute trs
        auto rotationEulerRadian = glm::radians(rotationEuler);
        auto res = glm::translate(position)
                   * glm::eulerAngleYXZ(rotationEulerRadian.y,rotationEulerRadian.x,rotationEulerRadian.z)
                   * glm::scale(scale);
        if (parent){
            res = parent->localToWorld() * res;
        }
        return res;
    }

    std::vector<Node> children;
    Node* parent = nullptr;

    void gui(int level = 0){
        ImGui::PushID(this);
        ImGui::Indent(level*20);

        if (ImGui::CollapsingHeader(this == cameraNode?"Camera": "Node")){
            ImGui::DragFloat3("Local Position",&position.x);
            ImGui::DragFloat3("Local Rotation",&rotationEuler.x);
            ImGui::DragFloat3("Local Scale",&scale.x);
            auto globalPos = localToWorld() * glm::vec4(0,0,0,1); // transform 0,0,0 (pivot point) from local coordinate frame to global coordinate frame
            bool changed = ImGui::DragFloat3("Global Position",&globalPos.x);
            if (changed){
                if (parent){
                    position = glm::inverse(parent->localToWorld()) * globalPos;
                }
                else {
                    position = globalPos;
                }

            }
            if (ImGui::Button("Add child")){
                children.emplace_back(this);
            }
            if (ImGui::Button("Make camera")){
                cameraNode = this;
            }
            for (auto & n : children){
                n.gui(level+1);
            }
        }
        ImGui::Unindent(level*20);
        ImGui::PopID();
    }
};
{'fraction_non_alphanumeric': 0.14029328080542788, 'fraction_numerical': 0.015101772816808929, 'mean_word_length': 2.3455344070278183, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4857284', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1444, 'n_words': 271}