Maths functions scripting api

This commit is contained in:
antopilo
2021-09-13 06:47:05 -04:00
parent 4f93cb4395
commit a047032f86
5 changed files with 108 additions and 13 deletions

View File

@@ -10,11 +10,16 @@ class Math {
return Vector3.new(result[0], result[1], result[2])
}
static Dot(vec1, vec2) {
return this.Dot_(vec1.x, vec1.y, vec1.z, vec2.x, vec2.y, vec2.z)
}
foreign static Dot_(x, y, z, x1, y2, z2)
foreign static Cross_(x, y, z, x1, y2, z2)
foreign static Length_(x, y, z)
}
class Vector3 {
x {_x}
y {_y}
z {_z}
@@ -113,7 +118,11 @@ class Vector3 {
this.Normalize() * vec.Normalize()
}
Dot(vec) {
return Math.Dot(this, vec)
}
Length() {
this.Sqrt()
return Math.Length_(_x, _y, _z)
}
}

View File

@@ -24,7 +24,6 @@ namespace Nuake {
{
}
void FileSystemUI::EditorInterfaceDrawFiletree(Ref<Directory> dir)
{
ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth;
@@ -53,7 +52,7 @@ namespace Nuake {
void FileSystemUI::DrawDirectory(Ref<Directory> directory)
{
ImGui::PushFont(EditorInterface::bigIconFont);
std::string id = ICON_FA_FOLDER + std::string("##") + directory->name;
std::string id = directory->name;
if (ImGui::Button(id.c_str(), ImVec2(100, 100)))
m_CurrentDirectory = directory;
@@ -131,9 +130,9 @@ namespace Nuake {
ImGui::EndDragDropSource();
}
}
ImGui::Text(file->name.c_str());
ImGui::PopFont();
}
bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f)
@@ -147,6 +146,7 @@ namespace Nuake {
bb.Max = bb.Min + CalcItemSize(split_vertically ? ImVec2(thickness, splitter_long_axis_size) : ImVec2(splitter_long_axis_size, thickness), 0.0f, 0.0f);
return SplitterBehavior(bb, id, split_vertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, min_size1, min_size2, 0.0f);
}
float h = 200;
static float sz1 = 300;
static float sz2 = 300;
@@ -168,17 +168,19 @@ namespace Nuake {
bool is_selected = m_CurrentDirectory == FileSystem::RootDirectory;
if (is_selected)
base_flags |= ImGuiTreeNodeFlags_Selected;
std::string icon = ICON_FA_FOLDER;
std::string icon = ICON_FA_FOLDER;
bool open = ImGui::TreeNodeEx((icon + " " + "Project files").c_str(), base_flags);
if (ImGui::IsItemClicked())
{
m_CurrentDirectory = FileSystem::RootDirectory;
}
if (open)
{
for(auto& d : rootDirectory->Directories)
EditorInterfaceDrawFiletree(d);
ImGui::TreePop();
}
@@ -192,6 +194,7 @@ namespace Nuake {
Ref<Directory> currentParent = m_CurrentDirectory;
paths.push_back(m_CurrentDirectory);
while (currentParent != nullptr)
{
paths.push_back(currentParent);
@@ -206,14 +209,19 @@ namespace Nuake {
if (ImGui::BeginChild("Path", avail))
{
if (ImGui::Button("Refresh"))
{
FileSystem::Scan();
m_CurrentDirectory = FileSystem::RootDirectory;
}
ImGui::SameLine();
for (int i = paths.size() - 1; i > 0; i--) {
for (int i = paths.size() - 1; i > 0; i--)
{
if (i != paths.size())
ImGui::SameLine();
if (ImGui::Button(paths[i]->name.c_str())) {
if (ImGui::Button(paths[i]->name.c_str()))
m_CurrentDirectory = paths[i];
}
ImGui::SameLine();
ImGui::Text("/");
@@ -226,9 +234,9 @@ namespace Nuake {
if (ImGui::BeginChild("Content", avail))
{
int width = ImGui::GetWindowWidth() * 0.8f;
int width = avail.x;
ImVec2 buttonSize = ImVec2(80, 80);
int amount = (int)(width / 100);
int amount = (int)(width / 200);
if (amount <= 0) amount = 1;
int i = 1; // current amount of item per row.
@@ -246,13 +254,15 @@ namespace Nuake {
if (m_CurrentDirectory && m_CurrentDirectory->Directories.size() > 0)
{
for (auto d : m_CurrentDirectory->Directories)
for (Ref<Directory>& d : m_CurrentDirectory->Directories)
{
DrawDirectory(d);
if (i - 1 % amount != 0)
if (i + 1 % amount != 0)
ImGui::TableNextColumn();
else
ImGui::TableNextRow();
i++;
}
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "src/Core/Core.h"
#include "src/Rendering/Materials/Material.h"
#include <vector>
namespace Nuake {
class MaterialCollection
{
private:
std::vector<Ref<Material>> m_Materials;
public:
std::string Path;
MaterialCollection(const std::string path)
{
}
};
}

View File

@@ -26,6 +26,8 @@ namespace Nuake {
RegisterMethod("Radians(_)", (void*)Radians);
RegisterMethod("Degrees(_)", (void*)Degrees);
RegisterMethod("Cross_(_,_,_,_,_,_)", (void*)Cross);
RegisterMethod("Dot_(_,_,_,_,_,_)", (void*)Dot);
RegisterMethod("Length_(_,_,_)", (void*)Length);
}
static void Sqrt(WrenVM* vm)
@@ -85,6 +87,28 @@ namespace Nuake {
wrenInsertInList(vm, 0, -1, 2);
wrenInsertInList(vm, 0, -1, 3);
}
static void Dot(WrenVM* vm)
{
Vector3 v1 = Vector3(wrenGetSlotDouble(vm, 1),
wrenGetSlotDouble(vm, 2),
wrenGetSlotDouble(vm, 3));
Vector3 v2 = Vector3(wrenGetSlotDouble(vm, 4),
wrenGetSlotDouble(vm, 5),
wrenGetSlotDouble(vm, 6));
float dot = glm::dot(v1, v2);
wrenSetSlotDouble(vm, 0, dot);
}
static void Length(WrenVM* vm)
{
Vector3 v1 = Vector3(wrenGetSlotDouble(vm, 1),
wrenGetSlotDouble(vm, 2),
wrenGetSlotDouble(vm, 3));
wrenSetSlotDouble(vm, 0, v1.length());
}
};
}
}

View File

@@ -0,0 +1,31 @@
#include <string>
#include "Node.h"
namespace Nuake
{
namespace UI
{
class TextInput : public Node
{
private:
std::string content = "";
bool IsFocus = false;
Ref<Node> Background;
public:
TextInput()
{
Background = CreateRef<Node>();
Background->NormalStyle.MinWidth = {200, Layout::Unit::PIXEL };
Background->NormalStyle.MinHeight = { 30, Layout::Unit::PIXEL };
Childrens.push_back(Background);
}
void Draw()
{
Renderer2D::DrawRect()
}
};
}
}