Skip to content

Commit

Permalink
Merge pull request #42 from A-lex-Ra/main
Browse files Browse the repository at this point in the history
Реализация рэйкастинга для AABB в произвольной позиции
  • Loading branch information
MihailRis authored Dec 9, 2023
2 parents 8e7f6e2 + 616057b commit 545057e
Show file tree
Hide file tree
Showing 10 changed files with 516 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Debug/src/**/*.o
Debug/voxel_engine

/build
/screenshots

/world
/worlds/**/*
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/gui/panels.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ namespace gui {
void back();
void clearHistory();
void reset();


//FIXME "gui::PagesControl::current() returns Page by-value! (can initiate unexpected behaviour)")
Page current();
};
}
Expand Down
19 changes: 10 additions & 9 deletions src/logic/PlayerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void CameraControl::update(PlayerInput& input, float delta) {

vec3 PlayerController::selectedBlockPosition;
vec3 PlayerController::selectedPointPosition;
vec3 PlayerController::selectedBlockNormal;
ivec3 PlayerController::selectedBlockNormal;
int PlayerController::selectedBlockId = -1;
int PlayerController::selectedBlockStates = 0;

Expand Down Expand Up @@ -192,7 +192,8 @@ void PlayerController::updateInteraction(){
Lighting* lighting = level->lighting;
Camera* camera = player->camera;
vec3 end;
vec3 norm;
ivec3 iend;
ivec3 norm;

bool xkey = Events::pressed(keycode::X);
bool lclick = Events::jactive(BIND_PLAYER_ATTACK) ||
Expand All @@ -203,7 +204,7 @@ void PlayerController::updateInteraction(){
if (xkey) {
maxDistance *= 20.0f;
}
vec3 iend;

voxel* vox = chunks->rayCast(camera->position,
camera->front,
maxDistance,
Expand All @@ -215,9 +216,9 @@ void PlayerController::updateInteraction(){
selectedBlockPosition = iend;
selectedPointPosition = end;
selectedBlockNormal = norm;
int x = (int)iend.x;
int y = (int)iend.y;
int z = (int)iend.z;
int x = iend.x;
int y = iend.y;
int z = iend.z;
uint8_t states = 0;

Block* def = contentIds->getBlockDef(player->choosenBlock);
Expand Down Expand Up @@ -250,9 +251,9 @@ void PlayerController::updateInteraction(){
}
if (rclick){
if (block->model != BlockModel::xsprite){
x = (int)(iend.x)+(int)(norm.x);
y = (int)(iend.y)+(int)(norm.y);
z = (int)(iend.z)+(int)(norm.z);
x = (iend.x)+(norm.x);
y = (iend.y)+(norm.y);
z = (iend.z)+(norm.z);
}
vox = chunks->get(x, y, z);
if (vox && (block = contentIds->getBlockDef(vox->id))->replaceable) {
Expand Down
2 changes: 1 addition & 1 deletion src/logic/PlayerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PlayerController {
void updateInteraction();
public:
static glm::vec3 selectedBlockPosition;
static glm::vec3 selectedBlockNormal;
static glm::ivec3 selectedBlockNormal;
static glm::vec3 selectedPointPosition;
static int selectedBlockId;
static int selectedBlockStates;
Expand Down
Loading

0 comments on commit 545057e

Please sign in to comment.