Block rotation profiles
This commit is contained in:
parent
9ded9b63f8
commit
8bc8eb14bd
@ -7,5 +7,5 @@
|
|||||||
"wood",
|
"wood",
|
||||||
"wood"
|
"wood"
|
||||||
],
|
],
|
||||||
"rotatable": true
|
"rotation": "pipe"
|
||||||
}
|
}
|
||||||
@ -52,6 +52,17 @@ Block* ContentLoader::loadBlock(string name, path file) {
|
|||||||
cerr << "unknown model " << model << endl;
|
cerr << "unknown model " << model << endl;
|
||||||
def->model = BlockModel::none;
|
def->model = BlockModel::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rotation profile
|
||||||
|
string profile = "none";
|
||||||
|
root->str("rotation", profile);
|
||||||
|
def->rotatable = profile != "none";
|
||||||
|
if (profile == "pipe") {
|
||||||
|
def->rotations = BlockRotProfile::PIPE;
|
||||||
|
} else if (profile != "none") {
|
||||||
|
cerr << "unknown rotation profile " << profile << endl;
|
||||||
|
def->rotatable = false;
|
||||||
|
}
|
||||||
|
|
||||||
// block hitbox AABB [x, y, z, width, height, depth]
|
// block hitbox AABB [x, y, z, width, height, depth]
|
||||||
json::JArray* hitboxobj = root->arr("hitbox");
|
json::JArray* hitboxobj = root->arr("hitbox");
|
||||||
@ -76,7 +87,6 @@ Block* ContentLoader::loadBlock(string name, path file) {
|
|||||||
root->flag("light-passing", def->lightPassing);
|
root->flag("light-passing", def->lightPassing);
|
||||||
root->flag("breakable", def->breakable);
|
root->flag("breakable", def->breakable);
|
||||||
root->flag("selectable", def->selectable);
|
root->flag("selectable", def->selectable);
|
||||||
root->flag("rotatable", def->rotatable);
|
|
||||||
root->flag("sky-light-passing", def->skyLightPassing);
|
root->flag("sky-light-passing", def->skyLightPassing);
|
||||||
root->num("draw-group", def->drawGroup);
|
root->num("draw-group", def->drawGroup);
|
||||||
|
|
||||||
|
|||||||
@ -279,17 +279,13 @@ void BlocksRenderer::blockCubeShaded(int x, int y, int z, const UVRegion(&texfac
|
|||||||
ivec3 loff(0);
|
ivec3 loff(0);
|
||||||
ivec3 coord(x, y, z);
|
ivec3 coord(x, y, z);
|
||||||
if (block->rotatable) {
|
if (block->rotatable) {
|
||||||
if (states == BLOCK_DIR_X) {
|
auto& rotations = block->rotations;
|
||||||
Y = {1, 0, 0};
|
auto& orient = rotations.variants[states & BLOCK_ROT_MASK];
|
||||||
X = {0, -1, 0};
|
X = orient.axisX;
|
||||||
coord.y++;
|
Y = orient.axisY;
|
||||||
loff.y--;
|
Z = orient.axisZ;
|
||||||
} else if (states == BLOCK_DIR_Z) {
|
coord += orient.fix;
|
||||||
Y = {0, 0, 1};
|
loff -= orient.fix;
|
||||||
Z = {0, -1, 0};
|
|
||||||
coord.z--;
|
|
||||||
loff.z++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOpen(x+Z.x, y+Z.y, z+Z.z, group)) {
|
if (isOpen(x+Z.x, y+Z.y, z+Z.z, group)) {
|
||||||
|
|||||||
@ -1,10 +1,19 @@
|
|||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
|
|
||||||
|
BlockRotProfile BlockRotProfile::PIPE {{
|
||||||
|
// Vertical
|
||||||
|
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}},
|
||||||
|
// X-Aligned
|
||||||
|
{{0, -1, 0}, {1, 0, 0}, {0, 0, 1}, {0, 1, 0}},
|
||||||
|
// Z-Aligned
|
||||||
|
{{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {0, 0, -1}},
|
||||||
|
}};
|
||||||
|
|
||||||
Block::Block(std::string name)
|
Block::Block(std::string name)
|
||||||
: name(name),
|
: name(name),
|
||||||
textureFaces {"notfound","notfound","notfound",
|
textureFaces {"notfound","notfound","notfound",
|
||||||
"notfound","notfound","notfound",} {
|
"notfound","notfound","notfound",} {
|
||||||
|
rotations = BlockRotProfile::PIPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block::Block(std::string name, std::string texture) : name(name),
|
Block::Block(std::string name, std::string texture) : name(name),
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#define VOXELS_BLOCK_H_
|
#define VOXELS_BLOCK_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "../maths/aabb.h"
|
#include "../maths/aabb.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
@ -15,6 +16,23 @@
|
|||||||
|
|
||||||
#define BLOCK_AABB_GRID 16
|
#define BLOCK_AABB_GRID 16
|
||||||
|
|
||||||
|
struct CoordSystem {
|
||||||
|
glm::ivec3 axisX;
|
||||||
|
glm::ivec3 axisY;
|
||||||
|
glm::ivec3 axisZ;
|
||||||
|
// Grid 3d position fix offset (for negative vectors)
|
||||||
|
glm::ivec3 fix;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BlockRotProfile {
|
||||||
|
CoordSystem variants[16];
|
||||||
|
|
||||||
|
/* Wood logs, pillars, pipes
|
||||||
|
3 orientations supported
|
||||||
|
*/
|
||||||
|
static BlockRotProfile PIPE;
|
||||||
|
};
|
||||||
|
|
||||||
enum class BlockModel {
|
enum class BlockModel {
|
||||||
none, // invisible
|
none, // invisible
|
||||||
block, // default shape
|
block, // default shape
|
||||||
@ -38,6 +56,7 @@ public:
|
|||||||
bool breakable = true;
|
bool breakable = true;
|
||||||
bool rotatable = false;
|
bool rotatable = false;
|
||||||
AABB hitbox;
|
AABB hitbox;
|
||||||
|
BlockRotProfile rotations;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
blockid_t id;
|
blockid_t id;
|
||||||
|
|||||||
@ -4,8 +4,11 @@
|
|||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
#define BLOCK_DIR_X 0x1
|
#define BLOCK_DIR_X 0x1
|
||||||
#define BLOCK_DIR_Y 0x2
|
#define BLOCK_DIR_Y 0x0
|
||||||
#define BLOCK_DIR_Z 0x3
|
#define BLOCK_DIR_Z 0x2
|
||||||
|
|
||||||
|
// limited to 16 block orientations
|
||||||
|
#define BLOCK_ROT_MASK 0xF
|
||||||
|
|
||||||
struct voxel {
|
struct voxel {
|
||||||
blockid_t id;
|
blockid_t id;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user