modelling
|
@ -0,0 +1,3 @@
|
|||
[lfs]
|
||||
url = https://git.onewaycoding.com/jay/fast-nuclear-sim.git/info/lfs
|
||||
|
BIN
assets/scene.blend (Stored with Git LFS)
BIN
assets/scene.glb (Stored with Git LFS)
|
@ -6,13 +6,12 @@ layout (triangle_strip, max_vertices=18) out;
|
|||
|
||||
uniform mat4 shadow_mats[6];
|
||||
|
||||
in float emissive[];
|
||||
in float base_transparency[];
|
||||
in flat int should_ignore[];
|
||||
out vec3 frag_pos;
|
||||
|
||||
void main()
|
||||
{
|
||||
if(emissive[0] > 0 || base_transparency[0] > 0) return;
|
||||
if(should_ignore[0] != 0) return;
|
||||
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
|
|
|
@ -4,17 +4,16 @@
|
|||
layout (location = 2) in vec4 aPos;
|
||||
layout (location = 4) in vec4 aColour;
|
||||
layout (location = 5) in vec3 aMaterial;
|
||||
layout (location = 6) in float aTransformIndex;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 camera;
|
||||
|
||||
out float emissive;
|
||||
out float base_transparency;
|
||||
out flat int should_ignore;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = camera * model * aPos;
|
||||
base_transparency = 1.f - aColour.a;
|
||||
emissive = aMaterial[2];
|
||||
should_ignore = int(aTransformIndex >= 0.f || aMaterial[2] > 0.f || aColour.a < 1.f);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@ struct Light
|
|||
vec4 colour;
|
||||
};
|
||||
|
||||
layout(std140, binding = 1) buffer ssbo_lights
|
||||
layout(std140, binding = 1) readonly buffer LightBuffer
|
||||
{
|
||||
Light lights[];
|
||||
};
|
||||
|
||||
layout(std430, binding = 2) buffer ssbo_shadow_maps
|
||||
layout(std430, binding = 2) readonly buffer ShadowMapBuffer
|
||||
{
|
||||
samplerCube shadow_maps[];
|
||||
};
|
||||
|
@ -97,10 +97,11 @@ vec3 sRGB_To_LinRGB(vec3 c)
|
|||
|
||||
void main()
|
||||
{
|
||||
vec4 albedo = texture2D(frag_tex, vin.tex_pos) * vin.colour;
|
||||
vec4 albedo = texture2D(frag_tex, vin.tex_pos);
|
||||
if(albedo.a == 0.f) discard;
|
||||
|
||||
vec3 albedo_lin = sRGB_To_LinRGB(albedo.rgb);
|
||||
vec3 albedo_lin = sRGB_To_LinRGB(albedo.rgb) * vin.colour.rgb;
|
||||
albedo *= vin.colour;
|
||||
|
||||
float roughness = vin.material[0];
|
||||
float metalness = vin.material[1];
|
||||
|
@ -163,6 +164,5 @@ void main()
|
|||
|
||||
light = mix(light, albedo.rgb, luminance);
|
||||
frag_colour = vec4(light, albedo.a);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,17 @@ layout (location = 2) in vec4 aPos;
|
|||
layout (location = 3) in vec3 aNormal;
|
||||
layout (location = 4) in vec4 aColour;
|
||||
layout (location = 5) in vec3 aMaterial;
|
||||
layout (location = 6) in float aTransformIndex;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 camera;
|
||||
uniform mat4 projection;
|
||||
|
||||
layout (binding = 3) readonly buffer TransformBuffer
|
||||
{
|
||||
mat4 transforms[];
|
||||
};
|
||||
|
||||
out VS_OUT {
|
||||
vec3 normal;
|
||||
vec4 colour;
|
||||
|
@ -25,11 +31,12 @@ out flat sampler2D frag_tex;
|
|||
|
||||
void main()
|
||||
{
|
||||
mat4 mvp = camera * model;
|
||||
mat4 m = (aTransformIndex >= 0.f ? transforms[int(aTransformIndex)] : mat4(1.f)) * model;
|
||||
mat4 mvp = camera * m;
|
||||
vec4 pos = mvp * aPos;
|
||||
|
||||
vout.normal = mat3(model) * aNormal;
|
||||
vout.pos = (model * aPos).xyz;
|
||||
vout.normal = mat3(m) * aNormal;
|
||||
vout.pos = (m * aPos).xyz;
|
||||
vout.colour = aColour;
|
||||
vout.tex_pos = aTexPos;
|
||||
vout.material = aMaterial;
|
||||
|
|
Before Width: | Height: | Size: 132 B After Width: | Height: | Size: 3.6 MiB |
Before Width: | Height: | Size: 132 B After Width: | Height: | Size: 2.8 MiB |
After Width: | Height: | Size: 137 KiB |
After Width: | Height: | Size: 181 KiB |
Before Width: | Height: | Size: 130 B After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 130 B After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 130 B After Width: | Height: | Size: 71 KiB |
Before Width: | Height: | Size: 130 B After Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 130 B After Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 131 B After Width: | Height: | Size: 215 KiB |
Before Width: | Height: | Size: 131 B After Width: | Height: | Size: 305 KiB |
|
@ -9,16 +9,34 @@
|
|||
|
||||
using namespace Sim::Graphics::Equipment;
|
||||
|
||||
Reactor::Reactor(const Model& model, Mesh& rmesh)
|
||||
Reactor::Reactor(const Model& model)
|
||||
{
|
||||
g_control_rod = model.load("visual_control_rod");
|
||||
}
|
||||
|
||||
void Reactor::update(double dt)
|
||||
void Reactor::remesh_static(Mesh& rmesh)
|
||||
{
|
||||
Sim::System& sys = *Sim::System::active;
|
||||
|
||||
for(int i = 0; i < sys.reactor.size; i++)
|
||||
{
|
||||
Sim::Reactor::Rod* r = sys.reactor.rods[i].get();
|
||||
|
||||
if(!r->should_display())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(r->get_colour()[3] != 0)
|
||||
{
|
||||
Mesh m = g_control_rod;
|
||||
m.set_transform_id();
|
||||
rmesh.add(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Reactor::remesh_slow(Mesh& rmesh)
|
||||
void Reactor::get_static_transforms(std::vector<glm::mat4>& transforms)
|
||||
{
|
||||
Sim::System& sys = *Sim::System::active;
|
||||
|
||||
|
@ -42,17 +60,8 @@ void Reactor::remesh_slow(Mesh& rmesh)
|
|||
|
||||
if(r->get_colour()[3] != 0)
|
||||
{
|
||||
rmesh.add(g_control_rod, glm::translate(glm::mat4(1), glm::vec3(ox, oy, (1 - r->get_colour().r) * sys.reactor.cell_height)));
|
||||
transforms.push_back(glm::translate(glm::mat4(1), glm::vec3(ox, oy, (1 - r->get_colour().r) * sys.reactor.cell_height)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Reactor::remesh_fast(Mesh& rmesh)
|
||||
{
|
||||
}
|
||||
|
||||
void Reactor::render()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,11 +12,9 @@ class Reactor : public MeshGen
|
|||
|
||||
public:
|
||||
|
||||
Reactor(const Model& model, Mesh& rmesh);
|
||||
virtual void update(double dt);
|
||||
virtual void remesh_slow(Mesh& rmesh);
|
||||
virtual void remesh_fast(Mesh& rmesh);
|
||||
virtual void render();
|
||||
Reactor(const Model& model);
|
||||
virtual void get_static_transforms(std::vector<glm::mat4>& transforms);
|
||||
virtual void remesh_static(Mesh& rmesh);
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -36,5 +36,8 @@ void Arrays::vertex_attrib_pointers()
|
|||
|
||||
glVertexAttribPointer(5, 3, GL_FLOAT, false, sizeof(v), ptr_diff(&v.material, &v));
|
||||
glEnableVertexAttribArray(5);
|
||||
|
||||
glVertexAttribPointer(6, 1, GL_FLOAT, false, sizeof(v), ptr_diff(&v.transform_id, &v));
|
||||
glEnableVertexAttribArray(6);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ struct Vertex
|
|||
glm::vec3 normal = {0, 0, 0};
|
||||
glm::vec4 colour = {1, 1, 1, 1};
|
||||
glm::vec3 material = {0, 0, 0};
|
||||
float transform_id = -1;
|
||||
|
||||
constexpr bool operator==(const Vertex&) const = default;
|
||||
|
||||
|
|
|
@ -15,11 +15,22 @@ Mesh::Mesh()
|
|||
|
||||
}
|
||||
|
||||
void Mesh::set_transform_id()
|
||||
{
|
||||
for(unsigned int i = 0; i < vertices.size(); i++)
|
||||
{
|
||||
vertices[i].transform_id = 0;
|
||||
}
|
||||
|
||||
max_transform_id = 0;
|
||||
}
|
||||
|
||||
void Mesh::add(const Mesh& o, glm::mat4 mat)
|
||||
{
|
||||
unsigned int off = vertices.size();
|
||||
glm::mat3 mat3(mat);
|
||||
float t_off = max_transform_id + 1;
|
||||
|
||||
glm::mat3 mat3(mat);
|
||||
vertices.reserve(vertices.size() + o.vertices.size());
|
||||
indices.reserve(indices.size() + o.indices.size());
|
||||
|
||||
|
@ -28,6 +39,13 @@ void Mesh::add(const Mesh& o, glm::mat4 mat)
|
|||
Arrays::Vertex v = o.vertices[i];
|
||||
v.normal = mat3 * v.normal;
|
||||
v.pos = mat * v.pos;
|
||||
|
||||
if(v.transform_id >= 0)
|
||||
{
|
||||
v.transform_id += t_off;
|
||||
max_transform_id = std::max(max_transform_id, v.transform_id);
|
||||
}
|
||||
|
||||
vertices.push_back(v);
|
||||
}
|
||||
|
||||
|
@ -192,40 +210,29 @@ vec3 Mesh::calc_intersect(vec3 pos, vec3 path) const
|
|||
}
|
||||
|
||||
vec3 path_n = path / l;
|
||||
unsigned int i_found = 0;
|
||||
bool changing = true;
|
||||
|
||||
for(unsigned int i = 0; i < indices.size(); i += 3)
|
||||
while(changing)
|
||||
{
|
||||
vec3 v[3] = {
|
||||
vec3(this->vertices[indices[i]].pos),
|
||||
vec3(this->vertices[indices[i + 1]].pos),
|
||||
vec3(this->vertices[indices[i + 2]].pos)
|
||||
};
|
||||
changing = false;
|
||||
|
||||
if(calc_intercept_vert(v, pos, path, path_n, l))
|
||||
for(unsigned int i = 0; i < indices.size(); i += 3)
|
||||
{
|
||||
i_found = i;
|
||||
}
|
||||
vec3 v[3] = {
|
||||
vec3(this->vertices[indices[i]].pos),
|
||||
vec3(this->vertices[indices[i + 1]].pos),
|
||||
vec3(this->vertices[indices[i + 2]].pos)
|
||||
};
|
||||
|
||||
if(l == 0)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
if(calc_intercept_vert(v, pos, path, path_n, l))
|
||||
{
|
||||
changing = true;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < i_found; i += 3)
|
||||
{
|
||||
vec3 v[3] = {
|
||||
vec3(this->vertices[indices[i]].pos),
|
||||
vec3(this->vertices[indices[i + 1]].pos),
|
||||
vec3(this->vertices[indices[i + 2]].pos)
|
||||
};
|
||||
|
||||
calc_intercept_vert(v, pos, path, path_n, l);
|
||||
|
||||
if(l == 0)
|
||||
{
|
||||
return path;
|
||||
if(l == 0)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,11 @@ struct Mesh
|
|||
{
|
||||
std::vector<Arrays::Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
float max_transform_id = -1;
|
||||
|
||||
Mesh();
|
||||
|
||||
void set_transform_id();
|
||||
void set_vertices(const Arrays::Vertex* data, size_t size);
|
||||
void set_indices(const unsigned int* data, size_t size);
|
||||
void load_text(const char* text, double size);
|
||||
|
|
|
@ -10,10 +10,10 @@ class MeshGen
|
|||
{
|
||||
public:
|
||||
virtual ~MeshGen() {}
|
||||
virtual void update(double dt) = 0;
|
||||
virtual void remesh_slow(Mesh& rmesh) = 0;
|
||||
virtual void remesh_fast(Mesh& rmesh) = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void update(double dt) {};
|
||||
virtual void get_static_transforms(std::vector<glm::mat4>& transforms) {};
|
||||
virtual void remesh_static(Mesh& rmesh) {};
|
||||
virtual void remesh_slow(Mesh& rmesh) {};
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -116,14 +116,9 @@ struct CoreJoystick : public Focus::FocusType
|
|||
}
|
||||
};
|
||||
|
||||
Core::Core(const Model& model, Mesh& rmesh)
|
||||
Core::Core(const Model& model)
|
||||
{
|
||||
Mesh mesh = model.load("translation_monitor_3");
|
||||
mat = Locations::monitors[2];
|
||||
|
||||
mesh.load_text("Reactor Core", 0.04);
|
||||
rmesh.add(mesh, mat);
|
||||
|
||||
m_buttons[0] = model.load("click_numpad_1");
|
||||
m_buttons[1] = model.load("click_numpad_2");
|
||||
m_buttons[2] = model.load("click_numpad_3");
|
||||
|
@ -138,6 +133,13 @@ Core::Core(const Model& model, Mesh& rmesh)
|
|||
m_scram = model.load("click_scram");
|
||||
}
|
||||
|
||||
void Core::remesh_static(Mesh& rmesh)
|
||||
{
|
||||
Mesh mesh;
|
||||
mesh.load_text("Reactor Core", 0.04);
|
||||
rmesh.add(mesh, mat);
|
||||
}
|
||||
|
||||
static Mesh add_dot(glm::mat4 model_mat, glm::vec4 colour)
|
||||
{
|
||||
unsigned int indices[] = {0, 1, 3, 0, 3, 2};
|
||||
|
@ -183,16 +185,6 @@ void Core::update(double dt)
|
|||
}
|
||||
|
||||
void Core::remesh_slow(Mesh& rmesh)
|
||||
{
|
||||
remesh(rmesh, false);
|
||||
}
|
||||
|
||||
void Core::remesh_fast(Mesh& rmesh)
|
||||
{
|
||||
remesh(rmesh, true);
|
||||
}
|
||||
|
||||
void Core::remesh(Mesh& rmesh, bool fast)
|
||||
{
|
||||
Sim::System& sys = *System::active;
|
||||
Sim::Graphics::Mesh mesh;
|
||||
|
@ -221,43 +213,32 @@ void Core::remesh(Mesh& rmesh, bool fast)
|
|||
}
|
||||
|
||||
glm::mat4 mat = glm::translate(glm::mat4(1), glm::vec3(ox, oy, 0)) * mat_scale;
|
||||
glm::vec4 colour_heat = r->get_heat_colour() * glm::vec4(glm::vec3(1), 1);
|
||||
glm::vec4 colour_spec = r->get_colour();
|
||||
|
||||
if(!fast)
|
||||
if(colour_heat[3] == 0)
|
||||
{
|
||||
glm::vec4 colour_heat = r->get_heat_colour() * glm::vec4(glm::vec3(1), 1);
|
||||
glm::vec4 colour_spec = r->get_colour();
|
||||
|
||||
if(colour_heat[3] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mesh.add(add_dot(mat, colour_heat));
|
||||
|
||||
if(colour_spec[3] != 0)
|
||||
{
|
||||
mesh.add(add_dot(mat * mat_spec, colour_spec));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if(sys.reactor.cursor == i)
|
||||
{
|
||||
mesh.add(add_dot(mat * mat_cursor, {1, 0, 0, 1}));
|
||||
}
|
||||
mesh.add(add_dot(mat, colour_heat));
|
||||
|
||||
if(r->selected)
|
||||
{
|
||||
mesh.add(add_dot(mat * mat_select, {1, 1, 0, 1}));
|
||||
}
|
||||
if(colour_spec[3] != 0)
|
||||
{
|
||||
mesh.add(add_dot(mat * mat_spec, colour_spec));
|
||||
}
|
||||
|
||||
if(sys.reactor.cursor == i)
|
||||
{
|
||||
mesh.add(add_dot(mat * mat_cursor, {1, 0, 0, 1}));
|
||||
}
|
||||
|
||||
if(r->selected)
|
||||
{
|
||||
mesh.add(add_dot(mat * mat_select, {1, 1, 0, 1}));
|
||||
}
|
||||
}
|
||||
|
||||
rmesh.add(mesh, mat);
|
||||
}
|
||||
|
||||
void Core::render()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,10 @@ class Core : public MeshGen
|
|||
|
||||
public:
|
||||
|
||||
Core(const Model& model, Mesh& rmesh);
|
||||
void remesh(Mesh& rmesh, bool fast);
|
||||
Core(const Model& model);
|
||||
virtual void update(double dt);
|
||||
virtual void remesh_static(Mesh& rmesh);
|
||||
virtual void remesh_slow(Mesh& rmesh);
|
||||
virtual void remesh_fast(Mesh& rmesh);
|
||||
virtual void render();
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -49,12 +49,29 @@ struct ValveJoystick : public Focus::FocusType
|
|||
}
|
||||
};
|
||||
|
||||
PrimaryLoop::PrimaryLoop(const Model& model, Mesh& rmesh)
|
||||
PrimaryLoop::PrimaryLoop(const Model& model)
|
||||
{
|
||||
mat = Locations::monitors[3];
|
||||
|
||||
g_switch_pump = model.load("visual_pump_switch_1");
|
||||
g_switch_bypass = model.load("visual_bypass_switch");
|
||||
g_switch_inlet = model.load("visual_inlet_switch");
|
||||
|
||||
m_joystick_turbine_bypass = model.load("click_bypass_joystick");
|
||||
m_joystick_turbine_inlet = model.load("click_inlet_joystick");
|
||||
m_switch_pump = model.load("click_pump_switch_1");
|
||||
m_switch_bypass = model.load("click_bypass_switch");
|
||||
m_switch_inlet = model.load("click_inlet_switch");
|
||||
|
||||
g_switch_pump.set_transform_id();
|
||||
g_switch_bypass.set_transform_id();
|
||||
g_switch_inlet.set_transform_id();
|
||||
}
|
||||
|
||||
void PrimaryLoop::remesh_static(Mesh& rmesh)
|
||||
{
|
||||
std::stringstream ss;
|
||||
Sim::Graphics::Mesh mesh;
|
||||
Mesh mesh;
|
||||
|
||||
ss << "Turbine Bypass Valve\n\n";
|
||||
ss << "Opened\nFlow\nSetpoint\n\n";
|
||||
|
@ -71,15 +88,9 @@ PrimaryLoop::PrimaryLoop(const Model& model, Mesh& rmesh)
|
|||
mesh.load_text(ss.str().c_str(), 0.04);
|
||||
rmesh.add(mesh, mat);
|
||||
|
||||
g_switch_pump = model.load("visual_pump_switch_1");
|
||||
g_switch_bypass = model.load("visual_bypass_switch");
|
||||
g_switch_inlet = model.load("visual_inlet_switch");
|
||||
|
||||
m_joystick_turbine_bypass = model.load("click_bypass_joystick");
|
||||
m_joystick_turbine_inlet = model.load("click_inlet_joystick");
|
||||
m_switch_pump = model.load("click_pump_switch_1");
|
||||
m_switch_bypass = model.load("click_bypass_switch");
|
||||
m_switch_inlet = model.load("click_inlet_switch");
|
||||
rmesh.add(g_switch_pump);
|
||||
rmesh.add(g_switch_bypass);
|
||||
rmesh.add(g_switch_inlet);
|
||||
}
|
||||
|
||||
void PrimaryLoop::update(double dt)
|
||||
|
@ -146,7 +157,7 @@ void PrimaryLoop::remesh_slow(Mesh& rmesh)
|
|||
rmesh.add(mesh, glm::translate(mat, glm::vec3(0.5, 0, 0)));
|
||||
}
|
||||
|
||||
void PrimaryLoop::remesh_fast(Mesh& rmesh)
|
||||
void PrimaryLoop::get_static_transforms(std::vector<glm::mat4>& transforms)
|
||||
{
|
||||
System& sys = *System::active;
|
||||
|
||||
|
@ -154,12 +165,8 @@ void PrimaryLoop::remesh_fast(Mesh& rmesh)
|
|||
float off2 = sys.loop.turbine_bypass_valve.get_auto() ? 0.07 : 0;
|
||||
float off3 = sys.loop.turbine_inlet_valve.get_auto() ? 0.07 : 0;
|
||||
|
||||
rmesh.add(g_switch_pump, glm::translate(glm::mat4(1), glm::vec3(0, off1, 0)));
|
||||
rmesh.add(g_switch_bypass, glm::translate(glm::mat4(1), glm::vec3(0, off2, 0)));
|
||||
rmesh.add(g_switch_inlet, glm::translate(glm::mat4(1), glm::vec3(0, off3, 0)));
|
||||
}
|
||||
|
||||
void PrimaryLoop::render()
|
||||
{
|
||||
transforms.push_back(glm::translate(glm::mat4(1), glm::vec3(0, off1, 0)));
|
||||
transforms.push_back(glm::translate(glm::mat4(1), glm::vec3(0, off2, 0)));
|
||||
transforms.push_back(glm::translate(glm::mat4(1), glm::vec3(0, off3, 0)));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,11 @@ class PrimaryLoop : public MeshGen
|
|||
|
||||
public:
|
||||
|
||||
PrimaryLoop(const Model& model, Mesh& rmesh);
|
||||
PrimaryLoop(const Model& model);
|
||||
virtual void update(double dt);
|
||||
virtual void get_static_transforms(std::vector<glm::mat4>& transforms);
|
||||
virtual void remesh_static(Mesh& rmesh);
|
||||
virtual void remesh_slow(Mesh& rmesh);
|
||||
virtual void remesh_fast(Mesh& rmesh);
|
||||
virtual void render();
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -17,23 +17,10 @@ using namespace Sim::Graphics::Monitor;
|
|||
using namespace Sim::Util::Streams;
|
||||
|
||||
|
||||
SecondaryLoop::SecondaryLoop(const Model& model, Mesh& rmesh)
|
||||
SecondaryLoop::SecondaryLoop(const Model& model)
|
||||
{
|
||||
mat = Locations::monitors[5];
|
||||
|
||||
std::stringstream ss;
|
||||
Sim::Graphics::Mesh mesh;
|
||||
|
||||
ss << "Cooling Tower\n\n";
|
||||
ss << "Heat\nSteam\nPressure\nLevel\n\n";
|
||||
ss << "Secondary Pump\n\n";
|
||||
ss << "Power\nSpeed\nFlow\n\n";
|
||||
ss << "Freight Pump\n\n";
|
||||
ss << "Power\nSpeed\nFlow\n\n";
|
||||
|
||||
mesh.load_text(ss.str().c_str(), 0.04);
|
||||
rmesh.add(mesh, mat);
|
||||
|
||||
g_switch_2 = model.load("visual_pump_switch_2");
|
||||
g_switch_3 = model.load("visual_pump_switch_3");
|
||||
|
||||
|
@ -41,6 +28,9 @@ SecondaryLoop::SecondaryLoop(const Model& model, Mesh& rmesh)
|
|||
m_joystick_turbine_inlet = model.load("click_inlet_joystick");
|
||||
m_switch_2 = model.load("click_pump_switch_2");
|
||||
m_switch_3 = model.load("click_pump_switch_3");
|
||||
|
||||
g_switch_2.set_transform_id();
|
||||
g_switch_3.set_transform_id();
|
||||
}
|
||||
|
||||
void SecondaryLoop::update(double dt)
|
||||
|
@ -53,6 +43,24 @@ void SecondaryLoop::update(double dt)
|
|||
sys.freight_pump.powered = !sys.freight_pump.powered;
|
||||
}
|
||||
|
||||
void SecondaryLoop::remesh_static(Mesh& rmesh)
|
||||
{
|
||||
std::stringstream ss;
|
||||
Mesh mesh;
|
||||
|
||||
ss << "Cooling Tower\n\n";
|
||||
ss << "Heat\nSteam\nPressure\nLevel\n\n";
|
||||
ss << "Secondary Pump\n\n";
|
||||
ss << "Power\nSpeed\nFlow\n\n";
|
||||
ss << "Freight Pump\n\n";
|
||||
ss << "Power\nSpeed\nFlow\n\n";
|
||||
|
||||
mesh.load_text(ss.str().c_str(), 0.04);
|
||||
rmesh.add(mesh, mat);
|
||||
rmesh.add(g_switch_2);
|
||||
rmesh.add(g_switch_3);
|
||||
}
|
||||
|
||||
void SecondaryLoop::remesh_slow(Mesh& rmesh)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
@ -77,19 +85,14 @@ void SecondaryLoop::remesh_slow(Mesh& rmesh)
|
|||
rmesh.add(mesh, glm::translate(mat, glm::vec3(0.5, 0, 0)));
|
||||
}
|
||||
|
||||
void SecondaryLoop::remesh_fast(Mesh& rmesh)
|
||||
void SecondaryLoop::get_static_transforms(std::vector<glm::mat4>& transforms)
|
||||
{
|
||||
System& sys = *System::active;
|
||||
|
||||
float off2 = sys.loop.secondary_pump.powered ? 0.07 : 0;
|
||||
float off3 = sys.freight_pump.powered ? 0.07 : 0;
|
||||
|
||||
rmesh.add(g_switch_2, glm::translate(glm::mat4(1), glm::vec3(0, off2, 0)));
|
||||
rmesh.add(g_switch_3, glm::translate(glm::mat4(1), glm::vec3(0, off3, 0)));
|
||||
transforms.push_back(glm::translate(glm::mat4(1), glm::vec3(0, off2, 0)));
|
||||
transforms.push_back(glm::translate(glm::mat4(1), glm::vec3(0, off3, 0)));
|
||||
}
|
||||
|
||||
void SecondaryLoop::render()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@ class SecondaryLoop : public MeshGen
|
|||
|
||||
public:
|
||||
|
||||
SecondaryLoop(const Model& model, Mesh& rmesh);
|
||||
SecondaryLoop(const Model& model);
|
||||
virtual void update(double dt);
|
||||
virtual void get_static_transforms(std::vector<glm::mat4>& transforms);
|
||||
virtual void remesh_static(Mesh& rmesh);
|
||||
virtual void remesh_slow(Mesh& rmesh);
|
||||
virtual void remesh_fast(Mesh& rmesh);
|
||||
virtual void render();
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -16,10 +16,47 @@ using namespace Sim::Graphics;
|
|||
using namespace Sim::Graphics::Monitor;
|
||||
using namespace Sim::Util::Streams;
|
||||
|
||||
Turbine::Turbine(const Model& model, Mesh& rmesh)
|
||||
Turbine::Turbine(const Model& model)
|
||||
{
|
||||
mat = Locations::monitors[4];
|
||||
|
||||
g_synchroscope_dial = model.load("visual_synchroscope_dial");
|
||||
g_switch_breaker = model.load("visual_breaker_switch");
|
||||
m_switch_breaker = model.load("click_breaker_switch");
|
||||
|
||||
g_synchroscope_dial.set_transform_id();
|
||||
g_switch_breaker.set_transform_id();
|
||||
}
|
||||
|
||||
void Turbine::update(double dt)
|
||||
{
|
||||
System& sys = *System::active;
|
||||
|
||||
if(m_switch_breaker.check_focus())
|
||||
sys.loop.generator.breaker_closed = !sys.loop.generator.breaker_closed;
|
||||
}
|
||||
|
||||
void Turbine::get_static_transforms(std::vector<glm::mat4>& transforms)
|
||||
{
|
||||
System& sys = *System::active;
|
||||
double rpm = sys.loop.generator.get_rpm();
|
||||
glm::mat4 mat(1);
|
||||
|
||||
if(rpm > 3570 && rpm < 3630)
|
||||
{
|
||||
mat = glm::translate(mat, glm::vec3(6.35, 3.949, 1.35));
|
||||
mat = glm::rotate(mat, float(sys.loop.generator.get_phase_diff()), glm::vec3(0, 1, 0));
|
||||
mat = glm::translate(mat, glm::vec3(-6.35, -3.949, -1.35));
|
||||
}
|
||||
|
||||
float off1 = sys.loop.generator.breaker_closed ? 0.07 : 0;
|
||||
|
||||
transforms.push_back(mat);
|
||||
transforms.push_back(glm::translate(glm::mat4(1), glm::vec3(0, off1, 0)));
|
||||
}
|
||||
|
||||
void Turbine::remesh_static(Mesh& rmesh)
|
||||
{
|
||||
std::stringstream ss;
|
||||
Sim::Graphics::Mesh mesh;
|
||||
|
||||
|
@ -32,30 +69,8 @@ Turbine::Turbine(const Model& model, Mesh& rmesh)
|
|||
mesh.load_text("Synchroscope", 0.04);
|
||||
rmesh.add(mesh, glm::translate(mat, glm::vec3(0, 0.6, 0)));
|
||||
|
||||
mesh = model.load("visual_synchroscope_dial");
|
||||
gm_synchroscope_dial.bind();
|
||||
gm_synchroscope_dial.set(mesh, GL_STATIC_DRAW);
|
||||
|
||||
g_switch_breaker = model.load("visual_breaker_switch");
|
||||
m_switch_breaker = model.load("click_breaker_switch");
|
||||
}
|
||||
|
||||
void Turbine::update(double dt)
|
||||
{
|
||||
System& sys = *System::active;
|
||||
double rpm = sys.loop.generator.get_rpm();
|
||||
|
||||
if(rpm > 3570 && rpm < 3630)
|
||||
{
|
||||
glm::mat4 mat = glm::mat4(1);
|
||||
mat = glm::translate(mat, glm::vec3(6.35, 3.949, 1.35));
|
||||
mat = glm::rotate(mat, float(sys.loop.generator.get_phase_diff()), glm::vec3(0, 1, 0));
|
||||
mat = glm::translate(mat, glm::vec3(-6.35, -3.949, -1.35));
|
||||
gm_synchroscope_dial.model_matrix = mat;
|
||||
}
|
||||
|
||||
if(m_switch_breaker.check_focus())
|
||||
sys.loop.generator.breaker_closed = !sys.loop.generator.breaker_closed;
|
||||
rmesh.add(g_synchroscope_dial);
|
||||
rmesh.add(g_switch_breaker);
|
||||
}
|
||||
|
||||
void Turbine::remesh_slow(Mesh& rmesh)
|
||||
|
@ -93,19 +108,5 @@ void Turbine::remesh_slow(Mesh& rmesh)
|
|||
void Turbine::remesh_fast(Mesh& rmesh)
|
||||
{
|
||||
System& sys = *System::active;
|
||||
float off1 = sys.loop.generator.breaker_closed ? 0.07 : 0;
|
||||
rmesh.add(g_switch_breaker, glm::translate(glm::mat4(1), glm::vec3(0, off1, 0)));
|
||||
}
|
||||
|
||||
void Turbine::render()
|
||||
{
|
||||
double rpm = System::active->loop.generator.get_rpm();
|
||||
|
||||
if(rpm > 3570 && rpm < 3630)
|
||||
{
|
||||
gm_synchroscope_dial.bind();
|
||||
gm_synchroscope_dial.uniform();
|
||||
gm_synchroscope_dial.render();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,17 +12,18 @@ class Turbine : public MeshGen
|
|||
{
|
||||
glm::mat4 mat;
|
||||
|
||||
GLMesh gm_synchroscope_dial;
|
||||
Mesh g_synchroscope_dial;
|
||||
Mesh g_switch_breaker;
|
||||
Mesh m_switch_breaker;
|
||||
|
||||
public:
|
||||
|
||||
Turbine(const Model& model, Mesh& rmesh);
|
||||
Turbine(const Model& model);
|
||||
virtual void update(double dt);
|
||||
virtual void get_static_transforms(std::vector<glm::mat4>& transforms);
|
||||
virtual void remesh_static(Mesh& rmesh);
|
||||
virtual void remesh_slow(Mesh& rmesh);
|
||||
virtual void remesh_fast(Mesh& rmesh);
|
||||
virtual void render();
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -15,10 +15,13 @@
|
|||
using namespace Sim::Graphics::Monitor;
|
||||
using namespace Sim::Util::Streams;
|
||||
|
||||
Vessel::Vessel(const Model& model, Mesh& rmesh)
|
||||
Vessel::Vessel(const Model& model)
|
||||
{
|
||||
mat = Locations::monitors[1];
|
||||
}
|
||||
|
||||
void Vessel::remesh_static(Mesh& rmesh)
|
||||
{
|
||||
std::stringstream ss;
|
||||
Sim::Graphics::Mesh mesh;
|
||||
|
||||
|
@ -38,10 +41,6 @@ Vessel::Vessel(const Model& model, Mesh& rmesh)
|
|||
rmesh.add(mesh, mat);
|
||||
}
|
||||
|
||||
void Vessel::update(double dt)
|
||||
{
|
||||
}
|
||||
|
||||
void Vessel::remesh_slow(Mesh& rmesh)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
@ -97,11 +96,3 @@ void Vessel::remesh_slow(Mesh& rmesh)
|
|||
rmesh.add(mesh, glm::translate(mat, glm::vec3(0.5, 0, 0)));
|
||||
}
|
||||
|
||||
void Vessel::remesh_fast(Mesh& rmesh)
|
||||
{
|
||||
}
|
||||
|
||||
void Vessel::render()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,9 @@ class Vessel : public MeshGen
|
|||
|
||||
public:
|
||||
|
||||
Vessel(const Model& model, Mesh& rmesh);
|
||||
virtual void update(double dt);
|
||||
Vessel(const Model& model);
|
||||
virtual void remesh_static(Mesh& rmesh);
|
||||
virtual void remesh_slow(Mesh& rmesh);
|
||||
virtual void remesh_fast(Mesh& rmesh);
|
||||
virtual void render();
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -121,6 +121,11 @@ void Shader::use()
|
|||
ACTIVE = this;
|
||||
}
|
||||
|
||||
void Shader::block_binding(const char* name, unsigned int binding)
|
||||
{
|
||||
glUniformBlockBinding(prog_id, get_block_index(name), binding);
|
||||
}
|
||||
|
||||
unsigned int Shader::operator [](const char* pos)
|
||||
{
|
||||
auto it = uniform_locations.find(pos);
|
||||
|
@ -133,6 +138,18 @@ unsigned int Shader::operator [](const char* pos)
|
|||
return uniform_locations[pos] = glGetUniformLocation(prog_id, pos);
|
||||
}
|
||||
|
||||
unsigned int Shader::get_block_index(const char* pos)
|
||||
{
|
||||
auto it = uniform_block_indices.find(pos);
|
||||
|
||||
if(it != uniform_block_indices.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return uniform_block_indices[pos] = glGetUniformBlockIndex(prog_id, pos);
|
||||
}
|
||||
|
||||
unsigned int Shader::get(const char* pos)
|
||||
{
|
||||
return operator[](pos);
|
||||
|
|
|
@ -11,6 +11,7 @@ class Shader
|
|||
unsigned int prog_id = 0;
|
||||
|
||||
std::unordered_map<const char*, unsigned int> uniform_locations;
|
||||
std::unordered_map<const char*, unsigned int> uniform_block_indices;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -27,9 +28,11 @@ public:
|
|||
|
||||
void load(const char* path, const char* file_vsh, const char* file_gsh, const char* file_fsh);
|
||||
void load(const char* path, const char* file_vsh, const char* file_fsh);
|
||||
void block_binding(const char* name, unsigned int index);
|
||||
void use();
|
||||
|
||||
unsigned int operator[](const char* pos);
|
||||
unsigned int get_block_index(const char* pos);
|
||||
unsigned int get(const char* pos);
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ void Clock::remesh_slow(Mesh& rmesh)
|
|||
int t_m = std::fmod(at / 60, 60);
|
||||
int t_h = std::fmod(at / 3600, 24);
|
||||
|
||||
// ss << "FPS: " << (1.0 / dt) << "\n";
|
||||
ss << "FPS: " << (1.0 / dt) << "\n";
|
||||
ss << "Time: " << std::setfill('0') << std::setw(2) << t_h << ":";
|
||||
ss << std::setfill('0') << std::setw(2) << t_m << ":";
|
||||
ss << std::setfill('0') << std::setw(2) << t_s << "\n";
|
||||
|
|
|
@ -37,20 +37,22 @@
|
|||
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
constexpr int SSBO_TRANSFORMS_LEN = 2;
|
||||
|
||||
static GLFWwindow* win;
|
||||
static bool win_should_close = false;
|
||||
static unsigned int ssbo_lights;
|
||||
static unsigned int ssbo_shadow_maps;
|
||||
static unsigned int ssbo_transforms[SSBO_TRANSFORMS_LEN];
|
||||
static double secs_wait_at = 0;
|
||||
static double secs_wait_now = 0;
|
||||
|
||||
static int gm_dynamic_slow_at = 0;
|
||||
static int ssbo_transforms_at = 0;
|
||||
|
||||
static GLMesh gm_scene;
|
||||
static GLMesh gm_transparent;
|
||||
static GLMesh gm_dynamic_slow[2];
|
||||
static GLMesh gm_dynamic_fast;
|
||||
static Mesh m_dynamic_fast;
|
||||
|
||||
static std::vector<GLLight> lights;
|
||||
static std::vector<std::unique_ptr<MeshGen>> monitors;
|
||||
|
@ -149,13 +151,22 @@ void Window::create()
|
|||
|
||||
glUniform1i(Shader::MAIN["lights_count"], model.lights.size());
|
||||
|
||||
monitors.push_back(std::make_unique<Monitor::Core>(model, m_scene));
|
||||
monitors.push_back(std::make_unique<Monitor::Vessel>(model, m_scene));
|
||||
monitors.push_back(std::make_unique<Monitor::PrimaryLoop>(model, m_scene));
|
||||
monitors.push_back(std::make_unique<Monitor::SecondaryLoop>(model, m_scene));
|
||||
monitors.push_back(std::make_unique<Monitor::Turbine>(model, m_scene));
|
||||
monitors.push_back(std::make_unique<Monitor::Core>(model));
|
||||
monitors.push_back(std::make_unique<Monitor::Vessel>(model));
|
||||
monitors.push_back(std::make_unique<Monitor::PrimaryLoop>(model));
|
||||
monitors.push_back(std::make_unique<Monitor::SecondaryLoop>(model));
|
||||
monitors.push_back(std::make_unique<Monitor::Turbine>(model));
|
||||
equipment.push_back(std::make_unique<Equipment::Reactor>(model));
|
||||
|
||||
equipment.push_back(std::make_unique<Equipment::Reactor>(model, m_scene));
|
||||
for(auto& monitor : monitors)
|
||||
{
|
||||
monitor->remesh_static(m_scene);
|
||||
}
|
||||
|
||||
for(auto& equipment : equipment)
|
||||
{
|
||||
equipment->remesh_static(m_scene);
|
||||
}
|
||||
|
||||
gm_scene.bind();
|
||||
gm_scene.set(m_scene, GL_STATIC_DRAW);
|
||||
|
@ -190,6 +201,28 @@ void Window::create()
|
|||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo_shadow_maps);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, light_handles.size() * sizeof(light_handles[0]), &light_handles[0], GL_STATIC_DRAW);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, ssbo_shadow_maps);
|
||||
|
||||
// setup the transforms ssbos and their initial values
|
||||
|
||||
std::vector<glm::mat4> transforms;
|
||||
|
||||
for(auto& monitor : monitors)
|
||||
{
|
||||
monitor->get_static_transforms(transforms);
|
||||
}
|
||||
|
||||
for(auto& equipment : equipment)
|
||||
{
|
||||
equipment->get_static_transforms(transforms);
|
||||
}
|
||||
|
||||
glGenBuffers(SSBO_TRANSFORMS_LEN, ssbo_transforms);
|
||||
|
||||
for(int i = 0; i < SSBO_TRANSFORMS_LEN; i++)
|
||||
{
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo_transforms[i]);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, transforms.size() * sizeof(transforms[0]), &transforms[0], GL_DYNAMIC_DRAW);
|
||||
}
|
||||
}
|
||||
|
||||
void update_slow()
|
||||
|
@ -216,37 +249,28 @@ void update_slow()
|
|||
void Window::update(double dt)
|
||||
{
|
||||
Mesh mesh;
|
||||
std::vector<glm::mat4> transforms;
|
||||
|
||||
glfwPollEvents();
|
||||
|
||||
for(auto& monitor : monitors)
|
||||
{
|
||||
monitor->update(dt);
|
||||
monitor->get_static_transforms(transforms);
|
||||
}
|
||||
|
||||
for(auto& equipment : equipment)
|
||||
{
|
||||
equipment->update(dt);
|
||||
equipment->get_static_transforms(transforms);
|
||||
}
|
||||
|
||||
UI::update(dt);
|
||||
|
||||
for(auto& monitor : monitors)
|
||||
{
|
||||
monitor->remesh_fast(mesh);
|
||||
}
|
||||
|
||||
for(auto& equipment : equipment)
|
||||
{
|
||||
equipment->remesh_fast(mesh);
|
||||
}
|
||||
|
||||
if(mesh != m_dynamic_fast)
|
||||
{
|
||||
gm_dynamic_fast.bind();
|
||||
gm_dynamic_fast.set(mesh, GL_DYNAMIC_DRAW);
|
||||
m_dynamic_fast = std::move(mesh);
|
||||
}
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, ssbo_transforms[ssbo_transforms_at]);
|
||||
ssbo_transforms_at = (ssbo_transforms_at + 1) % SSBO_TRANSFORMS_LEN;
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo_transforms[ssbo_transforms_at]);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, transforms.size() * sizeof(transforms[0]), &transforms[0], GL_DYNAMIC_DRAW);
|
||||
|
||||
secs_wait_now += dt;
|
||||
if(secs_wait_now > secs_wait_at + 1.0/30.0)
|
||||
|
@ -266,20 +290,6 @@ void Window::render_scene()
|
|||
gm_dynamic_slow[gm_dynamic_slow_at].uniform();
|
||||
gm_dynamic_slow[gm_dynamic_slow_at].render();
|
||||
|
||||
gm_dynamic_fast.bind();
|
||||
gm_dynamic_fast.uniform();
|
||||
gm_dynamic_fast.render();
|
||||
|
||||
for(auto& monitor : monitors)
|
||||
{
|
||||
monitor->render();
|
||||
}
|
||||
|
||||
for(auto& equipment : equipment)
|
||||
{
|
||||
equipment->render();
|
||||
}
|
||||
|
||||
gm_transparent.bind();
|
||||
gm_transparent.uniform();
|
||||
gm_transparent.render();
|
||||
|
@ -303,6 +313,7 @@ void Window::render()
|
|||
glUniformMatrix4fv(Shader::MAIN["camera"], 1, false, &mat_camera[0][0]);
|
||||
glUniform3fv(Shader::MAIN["camera_pos"], 1, &camera_pos[0]);
|
||||
glUniform3fv(Shader::MAIN["brightness"], 1, &brightness[0]);
|
||||
projection_matrix = mat_projection;
|
||||
|
||||
glFrontFace(GL_CCW);
|
||||
glClearColor(0, 0, 0, 1.0f);
|
||||
|
|
|
@ -13,6 +13,7 @@ extern glm::mat4 projection_matrix;
|
|||
|
||||
bool should_close();
|
||||
void create();
|
||||
void remesh();
|
||||
void update(double dt);
|
||||
void render();
|
||||
void render_scene();
|
||||
|
|