8 #include <glm/gtc/matrix_transform.hpp>
13 HUD::HUD(const BlockTypeRegistry &types)
17 , block_transform(1.0f)
18 , block_visible(false)
20 , crosshair_transform(1.0f)
23 , projection(glm::ortho(0.0f, 1.0f, 1.0f, 0.0f, near, far))
24 , view(glm::translate(glm::mat4(1.0f), glm::vec3(-0.5f, -0.5f, 0))) {
25 block_transform = glm::translate(block_transform, glm::vec3(50.0f, 50.0f, 0.0f));
26 block_transform = glm::scale(block_transform, glm::vec3(50.0f));
27 block_transform = glm::rotate(block_transform, 3.5f, glm::vec3(1.0f, 0.0f, 0.0f));
28 block_transform = glm::rotate(block_transform, 0.35f, glm::vec3(0.0f, 1.0f, 0.0f));
30 crosshair.vertices = std::vector<glm::vec3>({
31 { -10.0f, 0.0f, 0.0f }, { 10.0f, 0.0f, 0.0f },
32 { 0.0f, -10.0f, 0.0f }, { 0.0f, 10.0f, 0.0f },
34 crosshair.indices = std::vector<OutlineModel::Index>({
37 crosshair.colors.resize(4, { 10.0f, 10.0f, 10.0f });
38 crosshair.Invalidate();
42 void HUD::Viewport(float width, float height) {
43 Viewport(0, 0, width, height);
46 void HUD::Viewport(float x, float y, float width, float height) {
47 projection = glm::ortho(x, width, height, y, near, far);
48 crosshair_transform = glm::translate(glm::mat4(1.0f), glm::vec3(width * 0.5f, height * 0.5f, 0.0f));
52 void HUD::Display(const Block &b) {
53 const BlockType &type = *types.Get(b.type);
56 type.FillModel(block_buf, b.Transform());
57 block.Update(block_buf);
58 block_visible = type.visible;
62 void HUD::Render(DirectionalLighting &program) {
64 program.SetLightDirection({ 1.0f, 3.0f, 5.0f });
65 // disable distance fog
66 program.SetFogDensity(0.0f);
67 GLContext::ClearDepthBuffer();
68 program.SetMVP(block_transform, view, projection);
70 program.SetM(crosshair_transform);