Skip to content

Commit

Permalink
Physics :D
Browse files Browse the repository at this point in the history
  • Loading branch information
Jukitsu committed Nov 26, 2023
1 parent 3ee3588 commit 2ca21a7
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 64 deletions.
25 changes: 13 additions & 12 deletions Jukcraft/Jukcraft.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>..\bin\Debug-windowsJukcraft\</OutDir>
<IntDir>..\bin-int\Debug-windowsJukcraft\</IntDir>
<OutDir>..\bin\Debug-windows-Jukcraft\</OutDir>
<IntDir>..\bin-int\Debug-windows-Jukcraft\</IntDir>
<TargetName>Jukcraft</TargetName>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Beta|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\bin\Beta-windowsJukcraft\</OutDir>
<IntDir>..\bin-int\Beta-windowsJukcraft\</IntDir>
<OutDir>..\bin\Beta-windows-Jukcraft\</OutDir>
<IntDir>..\bin-int\Beta-windows-Jukcraft\</IntDir>
<TargetName>Jukcraft</TargetName>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\bin\Release-windowsJukcraft\</OutDir>
<IntDir>..\bin-int\Release-windowsJukcraft\</IntDir>
<OutDir>..\bin\Release-windows-Jukcraft\</OutDir>
<IntDir>..\bin-int\Release-windows-Jukcraft\</IntDir>
<TargetName>Jukcraft</TargetName>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
Expand Down Expand Up @@ -154,23 +154,24 @@
<ClInclude Include="src\core\App.h" />
<ClInclude Include="src\core\Camera.h" />
<ClInclude Include="src\core\Game.h" />
<ClInclude Include="src\core\HitRay.h" />
<ClInclude Include="src\core\Log.h" />
<ClInclude Include="src\core\Window.h" />
<ClInclude Include="src\core\util.h" />
<ClInclude Include="src\entity\BipedEntity.h" />
<ClInclude Include="src\entity\Entity.h" />
<ClInclude Include="src\entity\HitRay.h" />
<ClInclude Include="src\entity\LivingEntity.h" />
<ClInclude Include="src\entity\BipedEntity.h" />
<ClInclude Include="src\entity\player\Player.h" />
<ClInclude Include="src\models\Collider.h" />
<ClInclude Include="src\models\Model.h" />
<ClInclude Include="src\pch.h" />
<ClInclude Include="src\renderer\gfx\buffers\StagingBuffer.h" />
<ClInclude Include="src\physics\constants.h" />
<ClInclude Include="src\renderer\Renderer.h" />
<ClInclude Include="src\renderer\gfx\buffers\DynamicBuffer.h" />
<ClInclude Include="src\renderer\gfx\buffers\StagingBuffer.h" />
<ClInclude Include="src\renderer\gfx\objects\Buffer.h" />
<ClInclude Include="src\renderer\gfx\objects\Shader.h" />
<ClInclude Include="src\renderer\gfx\objects\VertexArray.h" />
<ClInclude Include="src\models\Model.h" />
<ClInclude Include="src\renderer\texture\TextureManager.h" />
<ClInclude Include="src\world\LightEngine.h" />
<ClInclude Include="src\world\World.h" />
Expand All @@ -182,11 +183,11 @@
<ClCompile Include="src\core\App.cpp" />
<ClCompile Include="src\core\Camera.cpp" />
<ClCompile Include="src\core\Game.cpp" />
<ClCompile Include="src\core\HitRay.cpp" />
<ClCompile Include="src\core\Log.cpp" />
<ClCompile Include="src\core\Window.cpp" />
<ClCompile Include="src\entity\LivingEntity.cpp" />
<ClCompile Include="src\entity\BipedEntity.cpp" />
<ClCompile Include="src\entity\HitRay.cpp" />
<ClCompile Include="src\entity\LivingEntity.cpp" />
<ClCompile Include="src\entity\player\Player.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\pch.cpp">
Expand Down
76 changes: 54 additions & 22 deletions Jukcraft/Jukcraft.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<Filter Include="core">
<UniqueIdentifier>{4E40957C-3A77-960D-E363-7C10CF79120F}</UniqueIdentifier>
</Filter>
<Filter Include="entity">
<UniqueIdentifier>{C2FD7FFB-AE9F-AAD1-975A-BE25839B3122}</UniqueIdentifier>
</Filter>
<Filter Include="entity\player">
<UniqueIdentifier>{BE34F17E-2AF5-6CB5-F32F-B6325FAFB191}</UniqueIdentifier>
</Filter>
<Filter Include="models">
<UniqueIdentifier>{2983320E-1525-5DE4-FEDF-7038EA20E434}</UniqueIdentifier>
</Filter>
<Filter Include="physics">
<UniqueIdentifier>{A823A1AC-1403-2048-1D1B-AB1E897986A9}</UniqueIdentifier>
</Filter>
<Filter Include="renderer">
<UniqueIdentifier>{9C6AA017-8837-FB22-B150-E9CA9D7C30B1}</UniqueIdentifier>
</Filter>
Expand All @@ -19,9 +31,6 @@
<Filter Include="renderer\gfx\objects">
<UniqueIdentifier>{0949E6C7-F5D7-6F91-9EF6-838C8A648037}</UniqueIdentifier>
</Filter>
<Filter Include="renderer\models">
<UniqueIdentifier>{EF8827A6-5B14-956A-6425-185FD02FF16A}</UniqueIdentifier>
</Filter>
<Filter Include="renderer\texture">
<UniqueIdentifier>{1C040F70-08FD-2DC2-312F-13471D870DCE}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -51,9 +60,6 @@
<ClInclude Include="src\core\Game.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="src\core\HitRay.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="src\core\Log.h">
<Filter>core</Filter>
</ClInclude>
Expand All @@ -63,13 +69,40 @@
<ClInclude Include="src\core\util.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="src\entity\BipedEntity.h">
<Filter>entity</Filter>
</ClInclude>
<ClInclude Include="src\entity\Entity.h">
<Filter>entity</Filter>
</ClInclude>
<ClInclude Include="src\entity\HitRay.h">
<Filter>entity</Filter>
</ClInclude>
<ClInclude Include="src\entity\LivingEntity.h">
<Filter>entity</Filter>
</ClInclude>
<ClInclude Include="src\entity\player\Player.h">
<Filter>entity\player</Filter>
</ClInclude>
<ClInclude Include="src\models\Collider.h">
<Filter>models</Filter>
</ClInclude>
<ClInclude Include="src\models\Model.h">
<Filter>models</Filter>
</ClInclude>
<ClInclude Include="src\pch.h" />
<ClInclude Include="src\physics\constants.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="src\renderer\Renderer.h">
<Filter>renderer</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\buffers\DynamicBuffer.h">
<Filter>renderer\gfx\buffers</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\buffers\StagingBuffer.h">
<Filter>renderer\gfx\buffers</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\objects\Buffer.h">
<Filter>renderer\gfx\objects</Filter>
</ClInclude>
Expand All @@ -79,9 +112,6 @@
<ClInclude Include="src\renderer\gfx\objects\VertexArray.h">
<Filter>renderer\gfx\objects</Filter>
</ClInclude>
<ClInclude Include="src\models\Model.h">
<Filter>renderer\models</Filter>
</ClInclude>
<ClInclude Include="src\renderer\texture\TextureManager.h">
<Filter>renderer\texture</Filter>
</ClInclude>
Expand All @@ -100,12 +130,6 @@
<ClInclude Include="src\world\chunk\util.h">
<Filter>world\chunk</Filter>
</ClInclude>
<ClInclude Include="src\renderer\gfx\buffers\StagingBuffer.h" />
<ClInclude Include="src\entity\Entity.h" />
<ClInclude Include="src\entity\player\Player.h" />
<ClInclude Include="src\entity\BipedEntity.h" />
<ClInclude Include="src\models\Collider.h" />
<ClInclude Include="src\entity\LivingEntity.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\core\App.cpp">
Expand All @@ -117,17 +141,29 @@
<ClCompile Include="src\core\Game.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="src\core\HitRay.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="src\core\Log.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="src\core\Window.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="src\entity\BipedEntity.cpp">
<Filter>entity</Filter>
</ClCompile>
<ClCompile Include="src\entity\HitRay.cpp">
<Filter>entity</Filter>
</ClCompile>
<ClCompile Include="src\entity\LivingEntity.cpp">
<Filter>entity</Filter>
</ClCompile>
<ClCompile Include="src\entity\player\Player.cpp">
<Filter>entity\player</Filter>
</ClCompile>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\pch.cpp" />
<ClCompile Include="src\renderer\gfx\buffers\DynamicBuffer.cpp">
<Filter>renderer\gfx\buffers</Filter>
</ClCompile>
<ClCompile Include="src\vendor\stb\stb_build.cpp">
<Filter>vendor\stb</Filter>
</ClCompile>
Expand All @@ -143,9 +179,5 @@
<ClCompile Include="src\world\chunk\ChunkManager.cpp">
<Filter>world\chunk</Filter>
</ClCompile>
<ClCompile Include="src\renderer\gfx\buffers\DynamicBuffer.cpp" />
<ClCompile Include="src\entity\player\Player.cpp" />
<ClCompile Include="src\entity\BipedEntity.cpp" />
<ClCompile Include="src\entity\LivingEntity.cpp" />
</ItemGroup>
</Project>
36 changes: 26 additions & 10 deletions Jukcraft/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ endif

ifeq ($(config),debug)
RESCOMP = windres
TARGETDIR = ../bin/Debug-windowsJukcraft
TARGETDIR = ../bin/Debug-windows-Jukcraft
TARGET = $(TARGETDIR)/Jukcraft.exe
OBJDIR = ../bin-int/Debug-windowsJukcraft
OBJDIR = ../bin-int/Debug-windows-Jukcraft
PCH = src/pch.h
GCH = $(OBJDIR)/$(notdir $(PCH)).gch
DEFINES += -DGLFW_INCLUDE_NONE
Expand All @@ -41,9 +41,9 @@ endif

ifeq ($(config),beta)
RESCOMP = windres
TARGETDIR = ../bin/Beta-windowsJukcraft
TARGETDIR = ../bin/Beta-windows-Jukcraft
TARGET = $(TARGETDIR)/Jukcraft.exe
OBJDIR = ../bin-int/Beta-windowsJukcraft
OBJDIR = ../bin-int/Beta-windows-Jukcraft
PCH = src/pch.h
GCH = $(OBJDIR)/$(notdir $(PCH)).gch
DEFINES += -DGLFW_INCLUDE_NONE -DGLM_FORCE_INLINE
Expand All @@ -70,9 +70,9 @@ endif

ifeq ($(config),release)
RESCOMP = windres
TARGETDIR = ../bin/Release-windowsJukcraft
TARGETDIR = ../bin/Release-windows-Jukcraft
TARGET = $(TARGETDIR)/Jukcraft.exe
OBJDIR = ../bin-int/Release-windowsJukcraft
OBJDIR = ../bin-int/Release-windows-Jukcraft
PCH = src/pch.h
GCH = $(OBJDIR)/$(notdir $(PCH)).gch
DEFINES += -DGLFW_INCLUDE_NONE -DGLM_FORCE_INLINE -DSPDLOG_NO_EXCEPTIONS
Expand Down Expand Up @@ -101,11 +101,15 @@ OBJECTS := \
$(OBJDIR)/App.o \
$(OBJDIR)/Camera.o \
$(OBJDIR)/Game.o \
$(OBJDIR)/HitRay.o \
$(OBJDIR)/Log.o \
$(OBJDIR)/Window.o \
$(OBJDIR)/BipedEntity.o \
$(OBJDIR)/HitRay.o \
$(OBJDIR)/LivingEntity.o \
$(OBJDIR)/Player.o \
$(OBJDIR)/main.o \
$(OBJDIR)/pch.o \
$(OBJDIR)/DynamicBuffer.o \
$(OBJDIR)/stb_build.o \
$(OBJDIR)/LightEngine.o \
$(OBJDIR)/World.o \
Expand Down Expand Up @@ -178,21 +182,33 @@ $(OBJDIR)/Camera.o: src/core/Camera.cpp
$(OBJDIR)/Game.o: src/core/Game.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/HitRay.o: src/core/HitRay.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/Log.o: src/core/Log.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/Window.o: src/core/Window.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/BipedEntity.o: src/entity/BipedEntity.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/HitRay.o: src/entity/HitRay.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/LivingEntity.o: src/entity/LivingEntity.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/Player.o: src/entity/player/Player.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/main.o: src/main.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/pch.o: src/pch.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/DynamicBuffer.o: src/renderer/gfx/buffers/DynamicBuffer.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/stb_build.o: src/vendor/stb/stb_build.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
Expand Down
2 changes: 1 addition & 1 deletion Jukcraft/src/core/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace Jukcraft {

if (glfwGetTime() - timer > 1.0) {
timer++;
LOG_TRACE("FPS: {}, Updates: {}", frames, updates);
LOG_TRACE("FPS: {}, TPS: {}", frames, updates);
updates = 0, frames = 0;
}

Expand Down
21 changes: 11 additions & 10 deletions Jukcraft/src/core/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#include <GLFW/glfw3.h>
#include "core/App.h"

static constexpr float WALKING_SPEED = 4.317f;
#include "physics/constants.h"

static constexpr float sensitivity = 0.005f;

namespace Jukcraft {
Camera::Camera(gfx::Shader& shader, std::unique_ptr<Player>& player)
:shader(shader), player(player), speed(WALKING_SPEED) {
:shader(shader), player(player), speed(WALK_SPEED) {
ubo.allocate(sizeof(ShaderCameraData), nullptr, true);
mappedUbo = reinterpret_cast<ShaderCameraData*>(ubo.map(0, sizeof(ShaderCameraData)));

Expand Down Expand Up @@ -43,18 +44,18 @@ namespace Jukcraft {
if (App::GetWindow().isKeyPressed(GLFW_KEY_LEFT_SHIFT)) input.y += -1;
if (App::GetWindow().isKeyPressed(GLFW_KEY_SPACE)) input.y += 1;

if (deltaTime * 20.0f > 1.0f) speed = WALKING_SPEED;

if (deltaTime * 20.0f > 1.0f)
speed = WALK_SPEED;
else
speed += (WALKING_SPEED - speed) * deltaTime * 20;
speed += (WALK_SPEED - speed) * deltaTime * 20;


const float multiplier = speed;
if (input.y) {
player->velocity.y = input.y * multiplier;
if (input.y > 0) {
player->jump();
} if (input.x || input.z) {
const float angle = player->yaw - glm::atan<float>((float)input.z, (float)input.x) + glm::pi<float>() / 2;
player->velocity.x = glm::cos(angle) * multiplier;
player->velocity.z = glm::sin(angle) * multiplier;
player->acceleration.x = glm::cos(angle) * speed;
player->acceleration.z = glm::sin(angle) * speed;
}


Expand Down
2 changes: 1 addition & 1 deletion Jukcraft/src/core/Game.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pch.h"
#include "core/Game.h"
#include <GLFW/glfw3.h>
#include "core/HitRay.h"
#include "entity/HitRay.h"

namespace Jukcraft {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "pch.h"
#include "core/HitRay.h"
#include "entity/HitRay.h"


namespace Jukcraft {
Expand Down
File renamed without changes.
Loading

0 comments on commit 2ca21a7

Please sign in to comment.