Also display oriented block in HUD.
Use Q for face, E for turn.
Told you I'd reassign them ;)
And I'll do it again, no worries.
const glm::mat4 &Transform() const;
+ Face GetFace() const { return Face(orient / 4); }
+ void SetFace(Face face) { orient = face * TURN_COUNT + GetTurn(); }
+ Turn GetTurn() const { return Turn(orient % 4); }
+ void SetTurn(Turn turn) { orient = GetFace() * TURN_COUNT + turn; }
+
};
#include "hud.hpp"
+#include "block.hpp"
#include "init.hpp"
+#include "shader.hpp"
#include "shape.hpp"
#include <glm/gtc/matrix_transform.hpp>
namespace blank {
-HUD::HUD()
-: block()
+HUD::HUD(const BlockTypeRegistry &types)
+: types(types)
+, block()
, block_buf()
, block_transform(1.0f)
, block_visible(false)
block_transform = glm::translate(block_transform, glm::vec3(50.0f, 50.0f, 0.0f));
block_transform = glm::scale(block_transform, glm::vec3(50.0f));
block_transform = glm::rotate(block_transform, 3.5f, glm::vec3(1.0f, 0.0f, 0.0f));
- block_transform = glm::rotate(block_transform, 0.85f, glm::vec3(0.0f, 1.0f, 0.0f));
+ block_transform = glm::rotate(block_transform, 0.35f, glm::vec3(0.0f, 1.0f, 0.0f));
crosshair.vertices = std::vector<glm::vec3>({
{ -10.0f, 0.0f, 0.0f }, { 10.0f, 0.0f, 0.0f },
}
-void HUD::Display(const BlockType &type) {
+void HUD::Display(const Block &b) {
+ const BlockType &type = *types.Get(b.type);
+
block_buf.Clear();
- type.FillModel(block_buf);
+ type.FillModel(block_buf, b.Transform());
block.Update(block_buf);
block_visible = type.visible;
}
#define BLANK_HUD_H_
#include "model.hpp"
-#include "shader.hpp"
#include "world.hpp"
#include <glm/glm.hpp>
namespace blank {
+class BlockTypeRegistry;
+class DirectionalLighting;
+
class HUD {
public:
- HUD();
+ explicit HUD(const BlockTypeRegistry &);
HUD(const HUD &) = delete;
HUD &operator =(const HUD &) = delete;
void Viewport(float width, float height);
void Viewport(float x, float y, float width, float height);
- void Display(const BlockType &);
+ void Display(const Block &);
void Render(DirectionalLighting &);
private:
+ const BlockTypeRegistry &types;
+
Model block;
Model::Buffer block_buf;
glm::mat4 block_transform;
Interface::Interface(World &world)
: world(world)
, ctrl(world.Player())
-, hud()
+, hud(world.BlockTypes())
, aim_chunk(nullptr)
, aim_block(0)
, aim_normal()
, up(false)
, down(false) {
hud.Viewport(960, 600);
- hud.Display(*world.BlockTypes()[selection.type]);
+ hud.Display(selection);
}
case SDLK_d:
right = event.state == SDL_PRESSED;
break;
- case SDLK_q:
case SDLK_SPACE:
up = event.state == SDL_PRESSED;
break;
- case SDLK_e:
case SDLK_LSHIFT:
down = event.state == SDL_PRESSED;
break;
+
+ case SDLK_q:
+ if (event.state == SDL_PRESSED) {
+ FaceBlock();
+ }
+ break;
+ case SDLK_e:
+ if (event.state == SDL_PRESSED) {
+ TurnBlock();
+ }
+ break;
}
}
+void Interface::FaceBlock() {
+ selection.SetFace(Block::Face((selection.GetFace() + 1) % Block::FACE_COUNT));
+ hud.Display(selection);
+}
+
+void Interface::TurnBlock() {
+ selection.SetTurn(Block::Turn((selection.GetTurn() + 1) % Block::TURN_COUNT));
+ hud.Display(selection);
+}
+
+
void Interface::Handle(const SDL_MouseMotionEvent &event) {
ctrl.RotateYaw(event.xrel * yaw_sensitivity);
ctrl.RotatePitch(event.yrel * pitch_sensitivity);
void Interface::PickBlock() {
if (!aim_chunk) return;
selection = aim_chunk->BlockAt(aim_block);
- hud.Display(*world.BlockTypes()[selection.type]);
+ hud.Display(selection);
}
void Interface::PlaceBlock() {
if (size_t(selection.type) >= world.BlockTypes().Size()) {
selection.type = 1;
}
- hud.Display(*world.BlockTypes()[selection.type]);
+ hud.Display(selection);
}
void Interface::SelectPrevious() {
if (selection.type <= 0) {
selection.type = world.BlockTypes().Size() - 1;
}
- hud.Display(*world.BlockTypes()[selection.type]);
+ hud.Display(selection);
}
void Interface::Handle(const SDL_WindowEvent &event) {
void Handle(const SDL_MouseWheelEvent &);
void Handle(const SDL_WindowEvent &);
+ void FaceBlock();
+ void TurnBlock();
+
void PickBlock();
void PlaceBlock();
void RemoveBlock();