TerraForge3D  2.3.1
3D Terrain And Landscape Generator
CosNode.cpp
1#include "Generators/CPUNodeEditor/Nodes/CosNode.h"
2#include "Base/ImGuiShapes.h"
3#include "Generators/CPUNodeEditor/CPUNodeEditor.h"
4#include <iostream>
5
6#include <mutex>
7
8
9NodeOutput CosNode::Evaluate(NodeInputParam input, NodeEditorPin *pin)
10{
11 float x = 1;
12
13 if (inputPins[0]->IsLinked())
14 {
15 x = inputPins[0]->other->Evaluate(input).value;
16 }
17
18 else
19 {
20 x = value1;
21 }
22
23 if (inputPins[1]->IsLinked())
24 {
25 x *= inputPins[1]->other->Evaluate(input).value;
26 }
27
28 else
29 {
30 x *= value2;
31 }
32
33 return NodeOutput({ cos(x) });
34}
35
36void CosNode::Load(nlohmann::json data)
37{
38 value1 = data["value1"];
39 value2 = data["value2"];
40}
41
42nlohmann::json CosNode::Save()
43{
44 nlohmann::json data;
45 data["type"] = MeshNodeEditor::MeshNodeType::Cos;
46 data["value1"] = value1;
47 data["value2"] = value2;
48 return data;
49}
50
51void CosNode::OnRender()
52{
53 DrawHeader("Cos");
54 inputPins[0]->Render();
55
56 if (inputPins[0]->IsLinked())
57 {
58 ImGui::Text("X");
59 }
60
61 else
62 {
63 ImGui::PushItemWidth(100);
64 ImGui::DragFloat(("##" + std::to_string(inputPins[0]->id)).c_str(), &value1, 0.01f);
65 ImGui::PopItemWidth();
66 }
67
68 ImGui::SameLine();
69 ImGui::Text("Out");
70 outputPins[0]->Render();
71 inputPins[1]->Render();
72
73 if (inputPins[1]->IsLinked())
74 {
75 ImGui::Text("k");
76 }
77
78 else
79 {
80 ImGui::PushItemWidth(100);
81 ImGui::DragFloat(("##" + std::to_string(inputPins[1]->id)).c_str(), &value2, 0.01f);
82 ImGui::PopItemWidth();
83 }
84
85 ImGui::Text("Calculates cos(kX)");
86}
87
88CosNode::CosNode()
89{
90 inputPins.push_back(new NodeEditorPin());
91 inputPins.push_back(new NodeEditorPin());
92 outputPins.push_back(new NodeEditorPin(NodeEditorPinType::Output));
93 headerColor = ImColor(MATH_NODE_COLOR);
94 value1 = (0.0f);
95 value2 = (1.0f);
96}
a class to store JSON values
Definition: json.hpp:17860