more dials, better models
This commit is contained in:
parent
a270d3d601
commit
1b317e9ff6
BIN
assets/scene.blend (Stored with Git LFS)
BIN
assets/scene.blend (Stored with Git LFS)
Binary file not shown.
BIN
assets/scene.glb (Stored with Git LFS)
BIN
assets/scene.glb (Stored with Git LFS)
Binary file not shown.
|
@ -33,9 +33,9 @@ out vec4 frag_colour;
|
|||
|
||||
uniform vec3 brightness;
|
||||
uniform vec3 camera_pos;
|
||||
uniform int lights_count;
|
||||
uniform float far_plane;
|
||||
uniform bool shadows_enabled;
|
||||
uniform int lights_count;
|
||||
|
||||
vec3 FresnelSchlick(float cosTheta, vec3 F0)
|
||||
{
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
|
@ -121,6 +121,22 @@ double Generator::get_phase_diff() const
|
|||
return Util::Math::mod(phase - grid->get_phase() + M_PI, 2*M_PI) - M_PI;
|
||||
}
|
||||
|
||||
double Generator::get_frequency() const
|
||||
{
|
||||
return get_rpm() / 60;
|
||||
}
|
||||
|
||||
double Generator::get_power() const
|
||||
{
|
||||
return energy_generated;
|
||||
}
|
||||
|
||||
double Generator::get_voltage() const
|
||||
{
|
||||
// TODO: implement this
|
||||
return get_frequency() / 60 * 20e3;
|
||||
}
|
||||
|
||||
Generator::operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
|
|
|
@ -34,11 +34,13 @@ public:
|
|||
void update(double dt);
|
||||
|
||||
double get_rpm() const;
|
||||
double get_frequency() const;
|
||||
double get_power() const;
|
||||
double get_voltage() const;
|
||||
double get_phase_diff() const;
|
||||
|
||||
operator Json::Value() const;
|
||||
|
||||
constexpr double get_energy_generated() const { return energy_generated; }
|
||||
constexpr double get_phase() const { return phase; }
|
||||
};
|
||||
|
||||
|
|
|
@ -11,35 +11,14 @@ using namespace Sim::Graphics::Equipment;
|
|||
|
||||
Reactor::Reactor(const Model& model)
|
||||
{
|
||||
g_control_rod = model.load("visual_control_rod");
|
||||
g_control_rod = model.load("visual_control_rod_lift");
|
||||
g_control_rod.set_transform_id();
|
||||
g_control_rod.add(model.load("visual_control_rod_base"));
|
||||
}
|
||||
|
||||
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::get_static_transforms(std::vector<glm::mat4>& transforms)
|
||||
{
|
||||
Sim::System& sys = *Sim::System::active;
|
||||
|
||||
double t_step = sys.reactor.cell_width;
|
||||
double t_sx = -(sys.reactor.width - 1) * t_step / 2.0;
|
||||
double t_sy = -(sys.reactor.height - 1) * t_step / 2.0;
|
||||
|
@ -60,7 +39,27 @@ void Reactor::get_static_transforms(std::vector<glm::mat4>& transforms)
|
|||
|
||||
if(r->get_colour()[3] != 0)
|
||||
{
|
||||
transforms.push_back(glm::translate(glm::mat4(1), glm::vec3(ox, oy, (1 - r->get_colour().r) * sys.reactor.cell_height)));
|
||||
rmesh.add(g_control_rod, glm::translate(glm::mat4(1), glm::vec3(ox, oy, 0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Reactor::get_static_transforms(std::vector<glm::mat4>& transforms)
|
||||
{
|
||||
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)
|
||||
{
|
||||
transforms.push_back(glm::translate(glm::mat4(1), glm::vec3(0, 0, (1 - r->get_colour().r) * sys.reactor.cell_height)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,14 @@ void Mesh::set_transform_id()
|
|||
max_transform_id = 0;
|
||||
}
|
||||
|
||||
void Mesh::set_texture_id(unsigned int id)
|
||||
{
|
||||
for(unsigned int i = 0; i < vertices.size(); i++)
|
||||
{
|
||||
vertices[i].texid = id;
|
||||
}
|
||||
}
|
||||
|
||||
void Mesh::add(const Mesh& o, glm::mat4 mat)
|
||||
{
|
||||
unsigned int off = vertices.size();
|
||||
|
|
|
@ -24,6 +24,7 @@ struct Mesh
|
|||
Mesh();
|
||||
|
||||
void set_transform_id();
|
||||
void set_texture_id(unsigned int 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);
|
||||
|
|
|
@ -189,7 +189,7 @@ void Core::remesh_slow(Mesh& rmesh)
|
|||
Sim::System& sys = *System::active;
|
||||
Sim::Graphics::Mesh mesh;
|
||||
|
||||
double step = 1 / (sys.vessel.diameter / sys.reactor.cell_width * 0.8);
|
||||
double step = sys.reactor.cell_width / sys.vessel.diameter * 0.8;
|
||||
double sx = 0.5 - (sys.reactor.width - 1) * step / 2.0;
|
||||
double sy = 0.5 - (sys.reactor.height - 1) * step / 2.0;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "../../coolant/valve.hpp"
|
||||
#include "../input/focus.hpp"
|
||||
#include "../../util/streams.hpp"
|
||||
#include "../../util/math.hpp"
|
||||
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <iostream>
|
||||
|
@ -20,11 +21,18 @@ Turbine::Turbine(const Model& model)
|
|||
{
|
||||
mat = Locations::monitors[4];
|
||||
|
||||
g_synchroscope_dial = model.load("visual_synchroscope_dial");
|
||||
g_dial_phase = model.load("visual_dial_phase");
|
||||
g_dial_voltage = model.load("visual_dial_voltage");
|
||||
g_dial_power = model.load("visual_dial_power");
|
||||
g_dial_frequency = model.load("visual_dial_frequency");
|
||||
|
||||
g_switch_breaker = model.load("visual_breaker_switch");
|
||||
m_switch_breaker = model.load("click_breaker_switch");
|
||||
|
||||
g_synchroscope_dial.set_transform_id();
|
||||
g_dial_phase.set_transform_id();
|
||||
g_dial_voltage.set_transform_id();
|
||||
g_dial_power.set_transform_id();
|
||||
g_dial_frequency.set_transform_id();
|
||||
g_switch_breaker.set_transform_id();
|
||||
}
|
||||
|
||||
|
@ -40,18 +48,37 @@ 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);
|
||||
glm::mat4 mat_phase(1);
|
||||
glm::mat4 mat_voltage(1);
|
||||
glm::mat4 mat_power(1);
|
||||
glm::mat4 mat_frequency(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));
|
||||
mat_phase = glm::translate(mat_phase, glm::vec3(6.35, 3.949, 1.35));
|
||||
mat_phase = glm::rotate(mat_phase, float(sys.loop.generator.get_phase_diff()), glm::vec3(0, 1, 0));
|
||||
mat_phase = glm::translate(mat_phase, glm::vec3(-6.35, -3.949, -1.35));
|
||||
}
|
||||
|
||||
mat_voltage = glm::translate(mat_voltage, glm::vec3(6.95, 3.949, 1.95));
|
||||
mat_voltage = glm::rotate(mat_voltage, float(Util::Math::map(sys.loop.generator.get_voltage(), 0, 24e3, 0, M_PI)), glm::vec3(0, 1, 0));
|
||||
mat_voltage = glm::translate(mat_voltage, glm::vec3(-6.95, -3.949, -1.95));
|
||||
|
||||
mat_power = glm::translate(mat_power, glm::vec3(6.35, 3.949, 1.95));
|
||||
mat_power = glm::rotate(mat_power, float(Util::Math::map(sys.loop.generator.get_power(), 0, 600e6, 0, M_PI)), glm::vec3(0, 1, 0));
|
||||
mat_power = glm::translate(mat_power, glm::vec3(-6.35, -3.949, -1.95));
|
||||
|
||||
mat_frequency = glm::translate(mat_frequency, glm::vec3(6.95, 3.949, 1.35));
|
||||
mat_frequency = glm::rotate(mat_frequency, float(Util::Math::map(sys.loop.generator.get_frequency(), 0, 120, 0, M_PI)), glm::vec3(0, 1, 0));
|
||||
mat_frequency = glm::translate(mat_frequency, glm::vec3(-6.95, -3.949, -1.35));
|
||||
|
||||
transforms.push_back(mat_phase);
|
||||
transforms.push_back(mat_voltage);
|
||||
transforms.push_back(mat_power);
|
||||
transforms.push_back(mat_frequency);
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
|
@ -66,7 +93,10 @@ void Turbine::remesh_static(Mesh& rmesh)
|
|||
mesh.load_text(ss.str().c_str(), 0.04);
|
||||
rmesh.add(mesh, mat);
|
||||
|
||||
rmesh.add(g_synchroscope_dial);
|
||||
rmesh.add(g_dial_phase);
|
||||
rmesh.add(g_dial_voltage);
|
||||
rmesh.add(g_dial_power);
|
||||
rmesh.add(g_dial_frequency);
|
||||
rmesh.add(g_switch_breaker);
|
||||
}
|
||||
|
||||
|
@ -83,22 +113,5 @@ void Turbine::remesh_slow(Mesh& rmesh)
|
|||
|
||||
mesh.load_text(ss.str().c_str(), 0.04);
|
||||
rmesh.add(mesh, glm::translate(mat, glm::vec3(0.5, 0, 0)));
|
||||
|
||||
ss = std::stringstream();
|
||||
|
||||
ss << "Local\n\n";
|
||||
ss << show( sys.loop.generator.get_rpm() / 60 ) << " Hz\n";
|
||||
Util::Streams::show_units( ss, sys.loop.generator.get_energy_generated() ) << "W\n";
|
||||
|
||||
mesh.load_text(ss.str().c_str(), 0.04);
|
||||
rmesh.add(mesh, glm::translate(mat, glm::vec3(0.4, 0.75, 0)));
|
||||
|
||||
ss = std::stringstream();
|
||||
|
||||
ss << "Grid\n\n";
|
||||
ss << show( sys.grid.frequency ) << " Hz\n";
|
||||
|
||||
mesh.load_text(ss.str().c_str(), 0.04);
|
||||
rmesh.add(mesh, glm::translate(mat, glm::vec3(0.7, 0.75, 0)));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,10 @@ class Turbine : public MeshGen
|
|||
{
|
||||
glm::mat4 mat;
|
||||
|
||||
Mesh g_synchroscope_dial;
|
||||
Mesh g_dial_phase;
|
||||
Mesh g_dial_voltage;
|
||||
Mesh g_dial_power;
|
||||
Mesh g_dial_frequency;
|
||||
Mesh g_switch_breaker;
|
||||
Mesh m_switch_breaker;
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@ static double secs_wait_now = 0;
|
|||
static int gm_dynamic_slow_at = 0;
|
||||
static int ssbo_transforms_at = 0;
|
||||
|
||||
static Mesh g_scene;
|
||||
|
||||
static GLMesh gm_scene;
|
||||
static GLMesh gm_transparent;
|
||||
static GLMesh gm_dynamic_slow[2];
|
||||
|
@ -73,6 +75,36 @@ static void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, G
|
|||
}
|
||||
}
|
||||
|
||||
void remesh_static()
|
||||
{
|
||||
Mesh mesh(g_scene);
|
||||
|
||||
for(auto& monitor : monitors)
|
||||
{
|
||||
monitor->remesh_static(mesh);
|
||||
}
|
||||
|
||||
for(auto& equipment : equipment)
|
||||
{
|
||||
equipment->remesh_static(mesh);
|
||||
}
|
||||
|
||||
gm_scene.bind();
|
||||
gm_scene.set(mesh, GL_STATIC_DRAW);
|
||||
|
||||
std::cout << "Remeshed static\n";
|
||||
}
|
||||
|
||||
void render_shadow_map()
|
||||
{
|
||||
Shader::LIGHT.use();
|
||||
|
||||
for(auto& light : lights)
|
||||
{
|
||||
light.render();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::create()
|
||||
{
|
||||
glfwInit();
|
||||
|
@ -135,11 +167,14 @@ void Window::create()
|
|||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
Sim::System& sys = *System::active;
|
||||
Mesh m_scene, m_transparent;
|
||||
Mesh m_transparent;
|
||||
|
||||
Model model("../assets", "scene.glb");
|
||||
m_transparent = model.load("visual_water");
|
||||
m_scene = model.load("scene");
|
||||
|
||||
g_scene.add(model.load("cr"));
|
||||
g_scene.add(model.load("cb"));
|
||||
g_scene.add(model.load("hw"));
|
||||
|
||||
Camera::init(model);
|
||||
|
||||
|
@ -158,18 +193,7 @@ void Window::create()
|
|||
monitors.push_back(std::make_unique<Monitor::Turbine>(model));
|
||||
equipment.push_back(std::make_unique<Equipment::Reactor>(model));
|
||||
|
||||
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);
|
||||
remesh_static();
|
||||
|
||||
gm_transparent.bind();
|
||||
gm_transparent.set(m_transparent, GL_STATIC_DRAW);
|
||||
|
@ -246,6 +270,12 @@ void update_slow()
|
|||
UI::update_slow();
|
||||
}
|
||||
|
||||
void Window::reload()
|
||||
{
|
||||
remesh_static();
|
||||
render_shadow_map();
|
||||
}
|
||||
|
||||
void Window::update(double dt)
|
||||
{
|
||||
Mesh mesh;
|
||||
|
|
|
@ -13,7 +13,7 @@ extern glm::mat4 projection_matrix;
|
|||
|
||||
bool should_close();
|
||||
void create();
|
||||
void remesh();
|
||||
void reload();
|
||||
void update(double dt);
|
||||
void render();
|
||||
void render_scene();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "reactor/coolant/pipe.hpp"
|
||||
#include "reactor/coolant/heater.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/window.hpp"
|
||||
|
||||
using namespace Sim;
|
||||
|
||||
|
@ -38,7 +39,7 @@ const char* CORE_LAYOUT[] = {
|
|||
|
||||
System::System() :
|
||||
vessel(Coolant::WATER, 8, 10, 6e6, 5e5, 10),
|
||||
reactor(Reactor::Builder(19, 19, 1.0 / 4.0, 4, Reactor::Fuel::FuelRod(0.5), &vessel, CORE_LAYOUT)),
|
||||
reactor(Reactor::Builder(19, 19, 0.4, 4, Reactor::Fuel::FuelRod(0.5), &vessel, CORE_LAYOUT)),
|
||||
evaporator(Coolant::WATER, 2, 30, 0, 1000),
|
||||
sink(Coolant::WATER, 11, 0, 0),
|
||||
grid(),
|
||||
|
@ -113,6 +114,8 @@ void System::load(const char* path)
|
|||
Graphics::Camera::load(root["camera"]);
|
||||
std::unique_ptr<System> sys = std::make_unique<System>(root);
|
||||
active = std::move(sys);
|
||||
|
||||
Graphics::Window::reload();
|
||||
}
|
||||
|
||||
void System::save()
|
||||
|
|
Loading…
Reference in New Issue