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

View File

@ -189,6 +189,8 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
Block* block = contentIds->getBlockDef(id);
assert(block != nullptr);
const vec3 pos = PlayerController::selectedBlockPosition;
const vec3 point = PlayerController::selectedPointPosition;
const vec3 norm = PlayerController::selectedBlockNormal;
const AABB& hitbox = block->hitbox;
const vec3 center = pos + hitbox.center();
const vec3 size = hitbox.size();
@ -196,6 +198,8 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
linesShader->uniformMatrix("u_projview", camera->getProjView());
lineBatch->lineWidth(2.0f);
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();
}
skybox->unbind();
@ -206,6 +210,7 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
ctx.depthTest(true);
linesShader->use();
if (settings.debug.showChunkBorders){
linesShader->uniformMatrix("u_projview", camera->getProjView());
vec3 coord = level->player->camera->position;

View File

@ -15,13 +15,16 @@ public:
LineBatch(size_t capacity=4096);
~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,
float r, float g, float b, float a);
void box(float x, float y, float z, float w, float h, float d,
float r, float g, float b, float a);
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);
}

View File

@ -107,6 +107,8 @@ void CameraControl::update(PlayerInput& input, float delta) {
}
vec3 PlayerController::selectedBlockPosition;
vec3 PlayerController::selectedPointPosition;
vec3 PlayerController::selectedBlockNormal;
int PlayerController::selectedBlockId = -1;
PlayerController::PlayerController(Level* level, const EngineSettings& settings)
@ -179,6 +181,7 @@ void PlayerController::updateControls(float delta){
player->update(level, input, delta);
}
#include <iostream>
void PlayerController::updateInteraction(){
auto contentIds = level->content->indices;
Chunks* chunks = level->chunks;
@ -206,6 +209,8 @@ void PlayerController::updateInteraction(){
player->selectedVoxel = *vox;
selectedBlockId = vox->id;
selectedBlockPosition = iend;
selectedPointPosition = end;
selectedBlockNormal = norm;
int x = (int)iend.x;
int y = (int)iend.y;
int z = (int)iend.z;

View File

@ -37,6 +37,8 @@ class PlayerController {
void updateInteraction();
public:
static glm::vec3 selectedBlockPosition;
static glm::vec3 selectedBlockNormal;
static glm::vec3 selectedPointPosition;
static int selectedBlockId;
PlayerController(Level* level, const EngineSettings& settings);

View File

@ -230,6 +230,7 @@ voxel* Chunks::rayCast(vec3 start,
end.y += dy / float(subs);
end.z += dz / float(subs);
if (box.inside(end)) {
end += iend;
norm.x = norm.y = norm.z = 0.0f;
if (steppedIndex == 0) norm.x = -stepx;
if (steppedIndex == 1) norm.y = -stepy;