Remove redundant SelectionBox::Face class.

master
aurailus 2019-06-21 14:29:13 -07:00
parent dcb5a75e6f
commit d25299b9ba
11 changed files with 40 additions and 44 deletions

View File

@ -11,14 +11,10 @@
#include <vec3.hpp>
#include <glm.hpp>
#include "../../util/Util.h"
#include "../../util/Dir.h"
class SelectionBox {
public:
enum Face {
NONE,
TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT
};
SelectionBox() {
set({0, 0, 0}, {1, 1, 1});
}
@ -45,7 +41,7 @@ public:
this->b = b;
}
Face intersects(glm::vec3 vec, glm::vec3 blockOffset) {
Dir intersects(glm::vec3 vec, glm::vec3 blockOffset) {
const float THRESH = 0.02f;
vec -= blockOffset; //Normalize Vector Position
@ -60,7 +56,7 @@ public:
return NONE;
}
static glm::vec3 faceToOffset(SelectionBox::Face f) {
static glm::vec3 faceToOffset(Dir f) {
static const glm::vec3 positionOffsets[6] {
{0, 1, 0},
{0, -1, 0},
@ -70,7 +66,7 @@ public:
{-1, 0, 0}
};
return positionOffsets[f - 1];
return positionOffsets[f];
}
glm::vec3 a {}, b {};

View File

@ -6,12 +6,12 @@
#define GLPROJECT_MESHMOD_H
enum ShaderMod {
NONE = 0,
ROTATE_X,
ROTATE_Y,
ROTATE_Z,
SWAY_ATTACHED,
SWAY_FULL_BLOCK
MOD_NONE = 0,
MOD_ROTATE_X,
MOD_ROTATE_Y,
MOD_ROTATE_Z,
MOD_SWAY_ATTACHED,
MOD_SWAY_FULL_BLOCK
};
#endif //GLPROJECT_MESHMOD_H

View File

@ -67,26 +67,26 @@ LocalBlockModel LocalBlockModel::create(sol::table model, std::vector<std::strin
std::string shaderMod = (*shaderModTable).get_or<std::string>("type", "none");
if (shaderMod == "none") {
meshPart.shaderMod = NONE;
meshPart.shaderMod = MOD_NONE;
}
else if (shaderMod == "rotate_x") {
meshPart.shaderMod = ROTATE_X;
meshPart.shaderMod = MOD_ROTATE_X;
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
}
else if (shaderMod == "rotate_y") {
meshPart.shaderMod = ROTATE_Y;
meshPart.shaderMod = MOD_ROTATE_Y;
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
}
else if (shaderMod == "rotate_z") {
meshPart.shaderMod = ROTATE_Z;
meshPart.shaderMod = MOD_ROTATE_Z;
meshPart.modValue = (*shaderModTable).get_or<float>("speed", 1);
}
else if (shaderMod == "sway_attached") {
meshPart.shaderMod = SWAY_ATTACHED;
meshPart.shaderMod = MOD_SWAY_ATTACHED;
meshPart.modValue = (*shaderModTable).get_or<float>("amplitude", 1);
}
else if (shaderMod == "sway_full_block") {
meshPart.shaderMod = SWAY_FULL_BLOCK;
meshPart.shaderMod = MOD_SWAY_FULL_BLOCK;
meshPart.modValue = (*shaderModTable).get_or<float>("amplitude", 1);
}
}

View File

@ -9,7 +9,7 @@ LocalMeshPart::LocalMeshPart(std::vector<MeshVertex> vertices, std::vector<unsig
this->vertices = std::move(vertices);
this->indices = std::move(indices);
this->shaderMod = NONE;
this->shaderMod = MOD_NONE;
this->modValue = 0;
//These vertex structs do (should) not have normals, so we will generate them here from the triangle information

View File

@ -9,7 +9,7 @@ ServerMeshPart::ServerMeshPart(std::vector<MeshVertex> vertices, std::vector<uns
this->vertices = std::move(vertices);
this->indices = std::move(indices);
this->meshMod = NONE;
this->meshMod = MOD_NONE;
this->modValue = 0;
//These vertex structs do (should) not have normals, so we will generate them here from the triangle information

View File

@ -110,12 +110,12 @@ void DebugGui::update(Player& player, LocalWorld& world, LocalDefs& defs, double
glm::vec3 regionCoordinate = TransPos::Dimension::regionFromVec(chunkPos);
auto thing = player.getPointedThing();
std::string face = (thing.face == SelectionBox::TOP) ? "TOP" :
(thing.face == SelectionBox::BOTTOM) ? "BOTTOM" :
(thing.face == SelectionBox::LEFT) ? "LEFT" :
(thing.face == SelectionBox::RIGHT) ? "RIGHT" :
(thing.face == SelectionBox::FRONT) ? "FRONT" :
(thing.face == SelectionBox::BACK) ? "BACK" :
std::string face = (thing.face == TOP) ? "TOP" :
(thing.face == BOTTOM) ? "BOTTOM" :
(thing.face == LEFT) ? "LEFT" :
(thing.face == RIGHT) ? "RIGHT" :
(thing.face == FRONT) ? "FRONT" :
(thing.face == BACK) ? "BACK" :
"NONE";
std::ostringstream str;

View File

@ -107,9 +107,9 @@ void Player::pointerUpdate(InputManager &input, double delta) {
auto blockID = world.getBlock(rayEnd);
if (blockID > 0) {
auto sBox = defs.blocks().fromIndex(blockID).getSelectionBox();
SelectionBox::Face intersects = sBox.intersects(*ray.getEnd(), pointedPos);
auto intersects = sBox.intersects(*ray.getEnd(), pointedPos);
if (intersects != SelectionBox::NONE) {
if (intersects != NONE) {
pointedThing.blockID = static_cast<unsigned int>(blockID);
pointedThing.blockDef = &defs.blocks().fromIndex(blockID);
pointedThing.pos = pointedPos;

View File

@ -97,11 +97,11 @@ void MeshGenerator::addFaces(const glm::vec3 &offset, const vector<LocalMeshPart
switch (mp.shaderMod) {
default: break;
case ROTATE_X:
case ROTATE_Y:
case ROTATE_Z:
case SWAY_ATTACHED:
case SWAY_FULL_BLOCK: {
case MOD_ROTATE_X:
case MOD_ROTATE_Y:
case MOD_ROTATE_Z:
case MOD_SWAY_ATTACHED:
case MOD_SWAY_FULL_BLOCK: {
modData = {Util::packFloat((offset - 8.f) / 8), mp.modValue, 0};
break;
}

View File

@ -9,7 +9,7 @@ enum Dir {
LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3, FRONT = 4, BACK = 5,
XNEG = 0, XPOS = 1, YPOS = 2, YNEG = 3, ZPOS = 4, ZNEG = 5,
INVALID = -1,
INVALID = -1, NONE = -1,
NO_CULL = 6,
};

View File

@ -32,7 +32,7 @@ public:
LocalBlockDef* blockDef = nullptr;
glm::vec3 pos {};
SelectionBox::Face face = SelectionBox::NONE;
Dir face = NONE;
};
#endif //ZEUS_POSBLOCK_H

View File

@ -9,14 +9,14 @@
TEST_CASE("Test Intersection", "math") {
SelectionBox s({0, 0, 0}, {1, 1, 1});
REQUIRE(s.intersects({0.5, 1, 0.5}) == 1);
REQUIRE(s.intersects({0.5, 0, 0.5}) == 2);
REQUIRE(s.intersects({0.5, 1, 0.5}, {}) == 1);
REQUIRE(s.intersects({0.5, 0, 0.5}, {}) == 2);
REQUIRE(s.intersects({0.5, 0.5, 0}) == 3);
REQUIRE(s.intersects({0.5, 0.5, 1}) == 4);
REQUIRE(s.intersects({0.5, 0.5, 0}, {}) == 3);
REQUIRE(s.intersects({0.5, 0.5, 1}, {}) == 4);
REQUIRE(s.intersects({0, 0.5, 0.5}) == 5);
REQUIRE(s.intersects({1, 0.5, 0.5}) == 6);
REQUIRE(s.intersects({0, 0.5, 0.5}, {}) == 5);
REQUIRE(s.intersects({1, 0.5, 0.5}, {}) == 6);
REQUIRE(s.intersects({2, 2, 2}) == 0);
REQUIRE(s.intersects({2, 2, 2}, {}) == 0);
}