selection normal vector debug

This commit is contained in:
MihailRis
2023-11-30 15:04:20 +03:00
parent 0c35eeb072
commit cee0214ac5
5 changed files with 17 additions and 1 deletions
+5
View File
@@ -189,6 +189,8 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
Block* block = contentIds->getBlockDef(id); Block* block = contentIds->getBlockDef(id);
assert(block != nullptr); assert(block != nullptr);
const vec3 pos = PlayerController::selectedBlockPosition; const vec3 pos = PlayerController::selectedBlockPosition;
const vec3 point = PlayerController::selectedPointPosition;
const vec3 norm = PlayerController::selectedBlockNormal;
const AABB& hitbox = block->hitbox; const AABB& hitbox = block->hitbox;
const vec3 center = pos + hitbox.center(); const vec3 center = pos + hitbox.center();
const vec3 size = hitbox.size(); const vec3 size = hitbox.size();
@@ -196,6 +198,8 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
linesShader->uniformMatrix("u_projview", camera->getProjView()); linesShader->uniformMatrix("u_projview", camera->getProjView());
lineBatch->lineWidth(2.0f); lineBatch->lineWidth(2.0f);
lineBatch->box(center, size + vec3(0.02), vec4(0.f, 0.f, 0.f, 0.5f)); lineBatch->box(center, size + vec3(0.02), vec4(0.f, 0.f, 0.f, 0.5f));
if (level->player->debug)
lineBatch->line(point, point+norm*0.5f, vec4(1.0f, 0.0f, 1.0f, 1.0f));
lineBatch->render(); lineBatch->render();
} }
skybox->unbind(); skybox->unbind();
@@ -206,6 +210,7 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
ctx.depthTest(true); ctx.depthTest(true);
linesShader->use(); linesShader->use();
if (settings.debug.showChunkBorders){ if (settings.debug.showChunkBorders){
linesShader->uniformMatrix("u_projview", camera->getProjView()); linesShader->uniformMatrix("u_projview", camera->getProjView());
vec3 coord = level->player->camera->position; vec3 coord = level->player->camera->position;
+4 -1
View File
@@ -15,13 +15,16 @@ public:
LineBatch(size_t capacity=4096); LineBatch(size_t capacity=4096);
~LineBatch(); ~LineBatch();
inline void line(const glm::vec3 a, const glm::vec3 b, const glm::vec4 color) {
line(a.x, a.y, a.z, b.x, b.y, b.z, color.r, color.g, color.b, color.a);
}
void line(float x1, float y1, float z1, float x2, float y2, float z2, void line(float x1, float y1, float z1, float x2, float y2, float z2,
float r, float g, float b, float a); float r, float g, float b, float a);
void box(float x, float y, float z, float w, float h, float d, void box(float x, float y, float z, float w, float h, float d,
float r, float g, float b, float a); float r, float g, float b, float a);
inline void box(glm::vec3 xyz, glm::vec3 whd, glm::vec4 rgba) { inline void box(glm::vec3 xyz, glm::vec3 whd, glm::vec4 rgba) {
return box(xyz.x, xyz.y, xyz.z, whd.x, whd.y, whd.z, box(xyz.x, xyz.y, xyz.z, whd.x, whd.y, whd.z,
rgba.r, rgba.g, rgba.b, rgba.a); rgba.r, rgba.g, rgba.b, rgba.a);
} }
+5
View File
@@ -107,6 +107,8 @@ void CameraControl::update(PlayerInput& input, float delta) {
} }
vec3 PlayerController::selectedBlockPosition; vec3 PlayerController::selectedBlockPosition;
vec3 PlayerController::selectedPointPosition;
vec3 PlayerController::selectedBlockNormal;
int PlayerController::selectedBlockId = -1; int PlayerController::selectedBlockId = -1;
PlayerController::PlayerController(Level* level, const EngineSettings& settings) PlayerController::PlayerController(Level* level, const EngineSettings& settings)
@@ -179,6 +181,7 @@ void PlayerController::updateControls(float delta){
player->update(level, input, delta); player->update(level, input, delta);
} }
#include <iostream>
void PlayerController::updateInteraction(){ void PlayerController::updateInteraction(){
auto contentIds = level->content->indices; auto contentIds = level->content->indices;
Chunks* chunks = level->chunks; Chunks* chunks = level->chunks;
@@ -206,6 +209,8 @@ void PlayerController::updateInteraction(){
player->selectedVoxel = *vox; player->selectedVoxel = *vox;
selectedBlockId = vox->id; selectedBlockId = vox->id;
selectedBlockPosition = iend; selectedBlockPosition = iend;
selectedPointPosition = end;
selectedBlockNormal = norm;
int x = (int)iend.x; int x = (int)iend.x;
int y = (int)iend.y; int y = (int)iend.y;
int z = (int)iend.z; int z = (int)iend.z;
+2
View File
@@ -37,6 +37,8 @@ class PlayerController {
void updateInteraction(); void updateInteraction();
public: public:
static glm::vec3 selectedBlockPosition; static glm::vec3 selectedBlockPosition;
static glm::vec3 selectedBlockNormal;
static glm::vec3 selectedPointPosition;
static int selectedBlockId; static int selectedBlockId;
PlayerController(Level* level, const EngineSettings& settings); PlayerController(Level* level, const EngineSettings& settings);
+1
View File
@@ -230,6 +230,7 @@ voxel* Chunks::rayCast(vec3 start,
end.y += dy / float(subs); end.y += dy / float(subs);
end.z += dz / float(subs); end.z += dz / float(subs);
if (box.inside(end)) { if (box.inside(end)) {
end += iend;
norm.x = norm.y = norm.z = 0.0f; norm.x = norm.y = norm.z = 0.0f;
if (steppedIndex == 0) norm.x = -stepx; if (steppedIndex == 0) norm.x = -stepx;
if (steppedIndex == 1) norm.y = -stepy; if (steppedIndex == 1) norm.y = -stepy;