Skip to content

Commit 0af85cd

Browse files
authored
Merge pull request #47 from CapsCollective/feature/math-overhaul
Re-implemented math classes to enable raycasting and improve precision
2 parents 049e838 + b3bf6d0 commit 0af85cd

File tree

133 files changed

+14020
-7842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+14020
-7842
lines changed

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: windows-latest
1515
defaults:
1616
run:
17-
shell: PowerShell
17+
shell: pwsh
1818

1919
steps:
2020
- uses: actions/checkout@v2

engine/core/TransitionAdapter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define SIEGE_ENGINE_TRANSITIONADAPTER_H
1111

1212
#include <utils/math/Maths.h>
13+
#include <utils/math/vec/Vec3.h>
1314

1415
#include <raylib/Vector3.hpp>
1516

engine/core/entity/Entity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Entity
4343
* @param name - a const reference to the name of the
4444
* entity as a string
4545
*/
46-
Entity(const String& name) : Entity(name, {Vec3::Zero, 0.f}) {};
46+
Entity(const String& name) : Entity(name, {Vec3::Zero(), 0.f}) {};
4747

4848
/**
4949
* Delegate constructor for Entity, initialises

engine/core/render/Camera.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ static Vec3 pos {0.f, 10.f, 10.f};
1919
static raylib::Camera3D& GetCamera()
2020
{
2121
static raylib::Camera3D camera(FromVec3(pos),
22-
FromVec3(Vec3::Zero),
23-
FromVec3(Vec3::Up),
22+
FromVec3(Vec3::Zero()),
23+
FromVec3(Vec3::Up()),
2424
45.f,
2525
CAMERA_PERSPECTIVE);
2626
return camera;

engine/core/render/Camera.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ class Cam
3737
};
3838
} // namespace Siege
3939

40-
#endif // SIEGE_ENGINE_CAMERA_H
40+
#endif // SIEGE_ENGINE_FPSCAMERA_H

engine/core/render/RenderSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ void RenderSystem::DrawFrame()
4343
// Draw the model
4444
DrawModelEx(model,
4545
FromVec3(item.transform.GetPosition()),
46-
FromVec3(Vec3::Up),
46+
FromVec3(Vec3::Up()),
4747
item.transform.GetRotation().y,
4848
FromVec3(item.transform.GetScale()),
4949
WHITE);
5050
DrawModelWiresEx(model,
5151
FromVec3(item.transform.GetPosition()),
52-
FromVec3(Vec3::Up),
52+
FromVec3(Vec3::Up()),
5353
item.transform.GetRotation().y,
5454
FromVec3(item.transform.GetScale()),
5555
PINK);

engine/core/scene/SceneFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ String SceneFile::SerialiseToString(const std::vector<Entity*>& entities)
4343

4444
// Serialise the general entity information
4545
fileData += (entity->GetName() + SEP);
46-
fileData += DefineField("POSITION", entity->GetPosition().ToString());
46+
fileData += DefineField("POSITION", ToString(entity->GetPosition()));
4747
fileData += DefineField("ROTATION", String::FromFloat(entity->GetRotation()));
4848
fileData += DefineField("Z-INDEX", String::FromInt(entity->GetZIndex()));
4949

@@ -78,7 +78,7 @@ void SceneFile::DeserialiseLines(const std::vector<String>& lines, std::vector<E
7878
EntityData data;
7979
if (!(args.size() >= 4 && args[ENTITY_ROT].GetFloat(data.rotation) &&
8080
args[ENTITY_Z_IDX].GetInt(data.zIndex) &&
81-
Vec3::FromString(data.position, args[ENTITY_POS])))
81+
FromString(data.position, args[ENTITY_POS])))
8282
{
8383
CC_LOG_WARNING("Failed to deserialise fields for entity \"{}\"", args[ENTITY_NAME]);
8484
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
3+
//
4+
// This code is released under an unmodified zlib license.
5+
// For conditions of distribution and use, please see:
6+
// https://opensource.org/licenses/Zlib
7+
//
8+
9+
#version 450
10+
11+
layout (location = 0) in vec4 fragColour;
12+
layout (location = 1) in vec2 uv;
13+
layout (location = 2) in flat uint texId;
14+
15+
layout (location = 0) out vec4 outColour;
16+
17+
layout(binding = 1) uniform sampler2D tex[16];
18+
19+
void main() {
20+
vec4 sampled = texture(tex[texId], vec2(uv.x, -uv.y));
21+
outColour = sampled * fragColour;
22+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#version 450
2+
3+
//
4+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
5+
//
6+
// This code is released under an unmodified zlib license.
7+
// For conditions of distribution and use, please see:
8+
// https://opensource.org/licenses/Zlib
9+
//
10+
11+
// Per instance data
12+
layout (location = 0) in vec3 inPosition;
13+
layout (location = 1) in vec3 inScale;
14+
layout (location = 2) in vec4 inColour;
15+
layout (location = 3) in vec4 inUv;
16+
17+
layout (location = 0) out vec4 outColour;
18+
layout (location = 1) out vec2 outUv;
19+
layout (location = 2) out flat uint outTexId;
20+
21+
layout (push_constant) uniform PushConstant {
22+
uint textureIndex;
23+
} pushConstant;
24+
25+
vec3 quadVertices[4] = {
26+
vec3(1.0, 1.0, 0),
27+
vec3(1.0, -1.0, 0),
28+
vec3(-1.0, -1.0, 0),
29+
vec3(-1.0, 1.0, 0)
30+
};
31+
32+
struct CameraData
33+
{
34+
mat4 projectionMatrix;
35+
mat4 viewMatrix;
36+
};
37+
38+
layout (binding = 0) uniform GlobalData {
39+
CameraData cameraData;
40+
} globalData;
41+
42+
CameraData camera = globalData.cameraData;
43+
44+
void main() {
45+
vec4 quadInCameraSpace = camera.viewMatrix * vec4(inPosition, 1.0);
46+
47+
vec4 positionInCameraSpace = quadInCameraSpace + vec4(quadVertices[gl_VertexIndex].xy * (inScale.xy * 0.5), 0.0, 0.0);
48+
49+
gl_Position = camera.projectionMatrix * positionInCameraSpace;
50+
51+
float uvx = (float(gl_VertexIndex == 0 || gl_VertexIndex == 1) * (inUv.x + inUv.z))
52+
+ (float(gl_VertexIndex == 2 || gl_VertexIndex == 3) * (inUv.x));
53+
float uvy = (float(gl_VertexIndex == 0 || gl_VertexIndex == 3) * (inUv.y + inUv.w))
54+
+ (float(gl_VertexIndex == 1 || gl_VertexIndex == 2) * (inUv.y));
55+
56+
outColour = inColour;
57+
outUv = vec2(uvx, uvy);
58+
outTexId = pushConstant.textureIndex;
59+
}
File renamed without changes.

0 commit comments

Comments
 (0)