Using HUD from motor to show the people online
This commit is contained in:
parent
a236d2c1fc
commit
d399c201eb
2 changed files with 20 additions and 18 deletions
|
@ -89,6 +89,8 @@ void GameRenderer::draw(Client const & client){
|
||||||
moggle::gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
moggle::gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
gl::disable(GL_DEPTH_TEST);
|
gl::disable(GL_DEPTH_TEST);
|
||||||
gl::disable(GL_CULL_FACE);
|
gl::disable(GL_CULL_FACE);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
auto projectionMatrix = projection_matrices::orthographic(client.sim.bounds.xmin, client.sim.bounds.xmax, client.sim.bounds.ymax, client.sim.bounds.ymin, -100.0f, 100.0f);
|
auto projectionMatrix = projection_matrices::orthographic(client.sim.bounds.xmin, client.sim.bounds.xmax, client.sim.bounds.ymax, client.sim.bounds.ymin, -100.0f, 100.0f);
|
||||||
auto modelViewProjectionMatrix = projectionMatrix;
|
auto modelViewProjectionMatrix = projectionMatrix;
|
||||||
|
|
|
@ -36,6 +36,9 @@ namespace games {
|
||||||
auto l = from_json<cheap_line_type>(js);
|
auto l = from_json<cheap_line_type>(js);
|
||||||
current_client->add_line(l);
|
current_client->add_line(l);
|
||||||
}
|
}
|
||||||
|
} else if (command == "peeps"){
|
||||||
|
auto str = from_json<std::string>(object["data"]);
|
||||||
|
current_client->update_peeps(str);
|
||||||
}
|
}
|
||||||
} catch(std::exception& e){
|
} catch(std::exception& e){
|
||||||
throw websockets::runtime_error(e.what());
|
throw websockets::runtime_error(e.what());
|
||||||
|
@ -194,21 +197,9 @@ namespace games {
|
||||||
if(!wsi) throw std::runtime_error("socket could not be created.");
|
if(!wsi) throw std::runtime_error("socket could not be created.");
|
||||||
|
|
||||||
// motor
|
// motor
|
||||||
{
|
|
||||||
motor::DirectionalLight p{motor::Position{0, 0, 20}, 1.0f, motor::Color{1, 1, 1, 1}};
|
|
||||||
scene->add(std::make_shared<motor::DirectionalLight>(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// peeps_lbl = std::make_shared<motor::TextureLabel>("Peeps:", motor::bundle.get_font_path() + "VeraMoBd.ttf", 72);
|
|
||||||
// peeps_lbl->get_mesh()->material->diffuse_color = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
||||||
// scene->add(peeps_lbl);
|
|
||||||
} catch (std::exception & e) {
|
|
||||||
CERR << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
world.physics.set_gravity({0.0, 0.0, 0.0});
|
world.physics.set_gravity({0.0, 0.0, 0.0});
|
||||||
scene->camera.set_perspective(80.0f, 4.0f/3.0f, .5f, 50.0f);
|
hud->camera.set_orthographic(-100, 100, -100, 100, 1, -1);
|
||||||
|
update_peeps("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::handle_input(float dt, Input input){
|
void Client::handle_input(float dt, Input input){
|
||||||
|
@ -277,7 +268,7 @@ namespace games {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(input.keys_went_down[SDLK_s]){
|
if(input.keys_went_down[SDLK_s]){
|
||||||
scene->update_shader_pipeline();
|
hud->update_shader_pipeline();
|
||||||
game_renderer.load_shaders();
|
game_renderer.load_shaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +290,18 @@ namespace games {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::update_peeps(std::string peeps){
|
void Client::update_peeps(std::string peeps){
|
||||||
assert(peeps_lbl);
|
if(!peeps_lbl){
|
||||||
|
try {
|
||||||
|
peeps_lbl = std::make_shared<motor::TextureLabel>("Peeps:", motor::bundle.get_font_path() + "VeraMoBd.ttf", 72);
|
||||||
|
peeps_lbl->get_mesh()->material->diffuse_color = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
|
peeps_lbl->set_position({-95.0, -90.0, 0.0});
|
||||||
|
peeps_lbl->set_scale(motor::scale(0.05));
|
||||||
|
peeps_lbl->set_rotation(motor::lookat_rotation({0, 0, -1}, {0, 1, 0}));
|
||||||
|
hud->add(peeps_lbl);
|
||||||
|
} catch (std::exception & e) {
|
||||||
|
CERR << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
peeps_lbl->set_text("Peeps: " + peeps);
|
peeps_lbl->set_text("Peeps: " + peeps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,8 +310,6 @@ namespace games {
|
||||||
Base::update(dt, input);
|
Base::update(dt, input);
|
||||||
handle_input(dt, input);
|
handle_input(dt, input);
|
||||||
|
|
||||||
scene->camera.set_position({0, 0, 20});
|
|
||||||
|
|
||||||
float dt2 = dt;
|
float dt2 = dt;
|
||||||
if(dt2 > 1.0/70.0 && dt2 < 1.0/55.0) dt2 = 1.0/60.0;
|
if(dt2 > 1.0/70.0 && dt2 < 1.0/55.0) dt2 = 1.0/60.0;
|
||||||
if(pause) dt2 = 0.0;
|
if(pause) dt2 = 0.0;
|
||||||
|
|
Reference in a new issue