summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-02-06 17:36:03 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-02-06 17:46:17 +0100
commitb118fc208028cd1deed8b735d18096e090d546b6 (patch)
tree46c2619ed22e58a78928f570176422392ef1ff49 /src
parentSimplified raycast (diff)
downloadAltCraft-b118fc208028cd1deed8b735d18096e090d546b6.tar
AltCraft-b118fc208028cd1deed8b735d18096e090d546b6.tar.gz
AltCraft-b118fc208028cd1deed8b735d18096e090d546b6.tar.bz2
AltCraft-b118fc208028cd1deed8b735d18096e090d546b6.tar.lz
AltCraft-b118fc208028cd1deed8b735d18096e090d546b6.tar.xz
AltCraft-b118fc208028cd1deed8b735d18096e090d546b6.tar.zst
AltCraft-b118fc208028cd1deed8b735d18096e090d546b6.zip
Diffstat (limited to 'src')
-rw-r--r--src/GameState.cpp1
-rw-r--r--src/GameState.hpp1
-rw-r--r--src/RendererWorld.cpp22
3 files changed, 24 insertions, 0 deletions
diff --git a/src/GameState.cpp b/src/GameState.cpp
index 180db98..28e8007 100644
--- a/src/GameState.cpp
+++ b/src/GameState.cpp
@@ -39,6 +39,7 @@ void GameState::Update(float deltaTime) {
RaycastResult raycast = world.Raycast(player->pos + player->EyeOffset, direction);
selectedBlock = raycast.isHit ? raycast.hitBlock : Vector(0,0,0);
distanceToSelectedBlock = raycast.isHit ? (player->pos - raycast.hitPos).GetLength() : 0.0f;
+ raycastHit = raycast.hitPos;
}
}
diff --git a/src/GameState.hpp b/src/GameState.hpp
index 5d3d36a..fac9923 100644
--- a/src/GameState.hpp
+++ b/src/GameState.hpp
@@ -63,4 +63,5 @@ public:
Vector selectedBlock;
float distanceToSelectedBlock;
+ VectorF raycastHit;
};
diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp
index 895661f..8390de7 100644
--- a/src/RendererWorld.cpp
+++ b/src/RendererWorld.cpp
@@ -268,6 +268,28 @@ void RendererWorld::Render(RenderState & renderState) {
glCheckError();
}
+ //Render raycast hit
+ bool renderHit = false;
+ if (renderHit) {
+ VectorF hit = gs->raycastHit;
+ glLineWidth(2.0f);
+ {
+ glm::mat4 model;
+ model = glm::translate(model, hit.glm());
+ model = glm::scale(model,glm::vec3(0.3f,0.3f,0.3f));
+ glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
+ if (selectedBlock == Vector())
+ glUniform3f(colorLoc,0.7,0.0,0.0);
+ else
+ glUniform3f(colorLoc, 0.0, 0.0, 0.7);
+ glCheckError();
+ glDrawArrays(GL_LINE_STRIP, 0, 36);
+ }
+ glLineWidth(1.0f);
+ glCheckError();
+ }
+
+
//Render sections
renderState.SetActiveShader(blockShader->Program);
projectionLoc = glGetUniformLocation(blockShader->Program, "projection");