6 #include <glm/gtc/matrix_transform.hpp>
13 , block_transform(1.0f)
14 , block_visible(false)
16 , crosshair_transform(1.0f)
19 , projection(glm::ortho(0.0f, 1.0f, 1.0f, 0.0f, near, far))
20 , view(glm::translate(glm::mat4(1.0f), glm::vec3(-0.5f, -0.5f, 0))) {
21 block_transform = glm::translate(block_transform, glm::vec3(50.0f, 50.0f, 0.0f));
22 block_transform = glm::scale(block_transform, glm::vec3(50.0f));
23 block_transform = glm::rotate(block_transform, 3.5f, glm::vec3(1.0f, 0.0f, 0.0f));
24 block_transform = glm::rotate(block_transform, 0.85f, glm::vec3(0.0f, 1.0f, 0.0f));
26 crosshair.vertices = std::vector<glm::vec3>({
27 { -10.0f, 0.0f, 0.0f }, { 10.0f, 0.0f, 0.0f },
28 { 0.0f, -10.0f, 0.0f }, { 0.0f, 10.0f, 0.0f },
30 crosshair.indices = std::vector<OutlineModel::Index>({
33 crosshair.colors.resize(4, { 10.0f, 10.0f, 10.0f });
34 crosshair.Invalidate();
38 void HUD::Viewport(float width, float height) {
39 Viewport(0, 0, width, height);
42 void HUD::Viewport(float x, float y, float width, float height) {
43 projection = glm::ortho(x, width, height, y, near, far);
44 crosshair_transform = glm::translate(glm::mat4(1.0f), glm::vec3(width * 0.5f, height * 0.5f, 0.0f));
48 void HUD::Display(const BlockType &type) {
50 type.FillModel(block);
51 block_visible = type.visible;
55 void HUD::Render(DirectionalLighting &program) {
57 program.SetLightDirection({ 1.0f, 3.0f, 5.0f });
58 GLContext::ClearDepthBuffer();
59 program.SetMVP(block_transform, view, projection);
61 program.SetM(crosshair_transform);