-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
259 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#version 330 core | ||
out vec4 FragColor; | ||
|
||
uniform vec3 rayColor = vec3(0,1,0); | ||
|
||
void main() { | ||
FragColor = vec4(rayColor, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#version 330 core | ||
layout (location = 0) in vec3 aPos; | ||
|
||
uniform mat4 view; | ||
uniform mat4 projection; | ||
|
||
void main() { | ||
gl_Position = projection * view * vec4(aPos, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "Target.h" | ||
#include "pch.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
class Target | ||
{ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "Collider.h" | ||
#include "pch.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
class SphereCollider; | ||
class RectangleCollider; | ||
|
||
class Collider | ||
{ | ||
public: | ||
virtual ~Collider() = default; | ||
virtual bool checkCollision(const Collider& other) const = 0; | ||
virtual bool checkCollisionWith(const SphereCollider& other) const = 0; | ||
virtual bool checkCollisionWith(const RectangleCollider& other) const = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
bool checkSphereRectangleCollision(const SphereCollider& sphere, const RectangleCollider& rectangle) | ||
{ | ||
glm::vec3 closestPoint = glm::clamp(sphere.center, aabb.min, aabb.max); | ||
float distanceSquared = glm::distance2(sphere.center, closestPoint); | ||
return distanceSquared < (sphere.radius * sphere.radius); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "Ray.h" | ||
#include "pch.h" | ||
|
||
#include <Renderer/Renderer.h> | ||
|
||
Ray::Ray(const glm::vec3& origin, const glm::vec3& direction, float length) | ||
: mOrigin(origin) | ||
, mDirection(glm::normalize(direction)) | ||
, mLength(length) | ||
, mShader{{ShaderType::VertexShader, "resources/Shaders/Graphics/Physics/Ray.vs"}, | ||
{ShaderType::FragmentShader, "resources/Shaders/Graphics/Physics/Ray.fs"}} | ||
{ | ||
glm::vec3 endPoint = mOrigin + mDirection * mLength; | ||
|
||
std::vector<float> vertices = {mOrigin.x, mOrigin.y, mOrigin.z, | ||
endPoint.x, endPoint.y, endPoint.z}; | ||
mBufferLayout.push<float>(3); | ||
|
||
mVBO.setBuffer(vertices); | ||
mVAO.setBuffer(mVBO, mBufferLayout); | ||
} | ||
|
||
void Ray::draw(const Renderer& target, const Camera& camera) const | ||
{ | ||
constexpr auto numberOfVertices = 6; | ||
target.draw3D(mVAO, numberOfVertices, mShader, camera, Renderer::DrawMode::Lines); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
#include "Renderer/Core/Buffers/BufferLayout.h" | ||
#include "Renderer/Core/Buffers/VertexBuffer.h" | ||
#include "Renderer/Core/VertexArray.h" | ||
|
||
#include <Renderer/Core/Shader.h> | ||
|
||
class Camera; | ||
class Renderer; | ||
|
||
class Ray | ||
{ | ||
public: | ||
Ray(const glm::vec3& origin, const glm::vec3& direction, float length = 100); | ||
|
||
/** | ||
* \brief Draws a model for a given target | ||
* \param target The target to which the model is drawn | ||
* \param camera A camera in 3D space that looks at this object | ||
*/ | ||
void draw(const Renderer& target, const Camera& camera) const; | ||
|
||
|
||
/** | ||
* Updates the Player logic dependent, or independent of time, every rendered frame. | ||
* \param deltaTime the time that has passed since the game was last updated. | ||
*/ | ||
void update(const float& deltaTime); | ||
|
||
private: | ||
VertexArray mVAO; | ||
VertexBuffer mVBO; | ||
BufferLayout mBufferLayout; | ||
glm::vec3 mOrigin; | ||
glm::vec3 mDirection; | ||
float mLength; | ||
Shader mShader; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "RectangleCollider.h" | ||
#include "pch.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
class RectangleCollider : public Collider | ||
{ | ||
public: | ||
glm::vec3 min;// Minimum point | ||
glm::vec3 max;// Maximum point | ||
|
||
RectangleCollider(const glm::vec3& min, const glm::vec3& max) | ||
: min(min) | ||
, max(max) | ||
{ | ||
} | ||
|
||
bool checkCollision(const Collider& other) const override | ||
{ | ||
return other.checkCollisionWith(*this); | ||
} | ||
|
||
bool checkCollisionWith(const SphereCollider& other) const override | ||
{ | ||
return checkSphereRectangleCollision(other, *this); | ||
} | ||
|
||
bool checkCollisionWith(const RectangleCollider& other) const override | ||
{ | ||
return (min.x <= other.max.x && max.x >= other.min.x) && | ||
(min.y <= other.max.y && max.y >= other.min.y) && | ||
(min.z <= other.max.z && max.z >= other.min.z); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "SphereCollider.h" | ||
#include "pch.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
class SphereCollider : public Collider | ||
{ | ||
public: | ||
glm::vec3 center; | ||
float radius; | ||
|
||
SphereCollider(const glm::vec3& center, float radius) | ||
: center(center) | ||
, radius(radius) | ||
{ | ||
} | ||
|
||
bool checkCollision(const Collider& other) const override | ||
{ | ||
return other.checkCollisionWith(*this); | ||
} | ||
|
||
bool checkCollisionWith(const SphereCollider& other) const override | ||
{ | ||
float distanceSquared = glm::distance2(center, other.center); | ||
float radiusSum = radius + other.radius; | ||
return distanceSquared < (radiusSum * radiusSum); | ||
} | ||
|
||
bool checkCollisionWith(const RectangleCollider& other) const override | ||
{ | ||
return checkSphereRectangleCollision(*this, other); | ||
} | ||
}; |
Oops, something went wrong.