Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
34fed06
foundation for physics plugin interface
Pheubel Feb 1, 2023
b07c2ff
Added bodytype enum
Pheubel Feb 2, 2023
8473d38
reverted use of weak_ptr
Pheubel Feb 2, 2023
3e3ba43
reverted use of weak_ptr
Pheubel Feb 2, 2023
db86b0c
Merge branch 'main' into feature/physics
Pheubel Feb 2, 2023
af3dd29
dev checkpoint
Pheubel Feb 2, 2023
9e86a57
dev checkpoint
Pheubel Feb 4, 2023
471b460
changed body definition around
Pheubel Feb 6, 2023
e487d89
added API for adding joints
Pheubel Feb 6, 2023
7e692dc
joint base type seems finalised
Pheubel Feb 6, 2023
2e4ece8
updated physics header with new types
Pheubel Feb 6, 2023
a043abc
Create DistanceJointDefinition2D.h
Pheubel Feb 6, 2023
fcf3384
expanded physics header
Pheubel Feb 6, 2023
686ddc2
expanded joint2d base
Pheubel Feb 6, 2023
f2932ac
changed naming
Pheubel Feb 6, 2023
4a6ccf4
renamed to be more clear
Pheubel Feb 6, 2023
e09b384
added springjoint definition
Pheubel Feb 6, 2023
4f7cae5
added body for spring joint definition
Pheubel Feb 6, 2023
9c6f02a
added gear joint definition
Pheubel Feb 6, 2023
a3a3148
Merge branch 'main' into feature/physics
Pheubel Feb 6, 2023
1df17b5
set up shells for spring joint
Pheubel Feb 7, 2023
fcd73b6
Update DistanceJoint2D.h
Pheubel Feb 7, 2023
a65b377
added shell for sliding joint
Pheubel Feb 7, 2023
639081b
separated physics in 2d and 3d domains
Pheubel Feb 7, 2023
ccf01ff
created shell for hinge joint 2d
Pheubel Feb 7, 2023
1f1b9fb
Merge branch 'main' into feature/physics
Pheubel Feb 12, 2023
e38f342
changed name
Pheubel Feb 12, 2023
e18eda2
removed redundant const modifier
Pheubel Feb 12, 2023
1db75a0
fixed spelling mistake
Pheubel Feb 12, 2023
7fee078
Removed redundant joint type
Pheubel Feb 12, 2023
9fa81bd
Removed redundant joint type
Pheubel Feb 12, 2023
41917bb
made base joint definition abstract
Pheubel Feb 12, 2023
8317f88
Added missing definition fields for sliding joint
Pheubel Feb 13, 2023
51846ba
expanded on sliding joint documentation
Pheubel Feb 13, 2023
1429669
added getters an setters for joints
Pheubel Feb 22, 2023
677e01a
added various collision fixtures
Pheubel Mar 15, 2023
57ef0d2
added missing preprocessor guard
Pheubel Mar 15, 2023
353deb3
corrected mistakes related to misspelling and wrong typing
Pheubel Mar 15, 2023
695ee9e
expanded on rigidbody
Pheubel Mar 16, 2023
e9122e0
fixed up code
Pheubel Mar 16, 2023
395515a
added missing public
Pheubel Mar 16, 2023
7ac9a01
added collision fixtures
Pheubel Mar 16, 2023
647bbe3
added fixture adding and removing
Pheubel Mar 17, 2023
2b9873d
added missing [[nodiscard]]
Pheubel Mar 17, 2023
ccdc05e
added more collision related stuff
Pheubel Mar 17, 2023
98a0cd4
wrap up API part of proposal
Pheubel Mar 18, 2023
a417e71
applied format patch
Pheubel Mar 18, 2023
ef901e0
Merge branch 'main' into feature/physics
Pheubel Jul 1, 2023
ba8e610
renamed header files to be more in line with future standards
Pheubel Jul 1, 2023
a219405
replaced ifndef guards with pragma onces
Pheubel Jul 1, 2023
7271139
changed define guard to match file name patern
Pheubel Jul 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/NovelRT/NovelRT.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
// Persistence types
#include <NovelRT/Persistence/Persistence.h>

// Physics types
#include <NovelRT/Physics/Physics.hpp>

//Misc types
#include <NovelRT/LoggingService.h>
#include <NovelRT/Timing/StepTimer.h>
Expand Down
30 changes: 30 additions & 0 deletions include/NovelRT/Physics/2D/BodyDefinition2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
struct BodyDefinition2D final
{
std::optional<OnCollisionEnterCallbackDelegate2D> OnCollisionEnter;
std::optional<OnCollisionExitCallbackDelegate2D> OnCollisionExit;
std::optional<OnTriggerEnterCallbackDelegate2D> OnTriggerEnter;
std::optional<OnTriggerExitCallbackDelegate2D> OnTriggerExit;
NovelRT::Maths::GeoVector2F Position;
NovelRT::Maths::GeoVector2F LinearVelocity;
NovelRT::Maths::GeoVector2F AngularVelocity;
NovelRT::Maths::GeoVector2F Gravity;
float RotationAngle;
float LinearDamping;
float AngularDamping;
RigidBodyFlags2D Flags;
};
}

// TODO: when implementing box2d, instead of relying on gravity scale, set it to 1 or 0 (depending on
// BodyFlags::UseWorldGravity) and apply a constant force during the world step.
16 changes: 16 additions & 0 deletions include/NovelRT/Physics/2D/BoxCollisionFixture2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
class BoxCollisionFixture2D : public CollisionFixture2D
{
public:
[[nodiscard]] virtual NovelRT::Maths::GeoVector2F GetHalfSize() = 0;

virtual void SetHalfSize(NovelRT::Maths::GeoVector2F halfSize) = 0;
};
}
15 changes: 15 additions & 0 deletions include/NovelRT/Physics/2D/BoxCollisionFixtureDefinition2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
struct BoxCollisionFixtureDefinition2D final : public CollisionFixtureDefinition2D
{
NovelRT::Maths::GeoVector2F HalfSize;

~BoxCollisionFixtureDefinition2D() = default;
};
}
20 changes: 20 additions & 0 deletions include/NovelRT/Physics/2D/CapsuleCollisionFixture2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
class CapsuleCollisionFixture2D : public CollisionFixture2D
{
public:
[[nodiscard]] virtual float GetHeight() = 0;

[[nodiscard]] virtual float GetRadius() = 0;

virtual void SetHeight(float height) = 0;

virtual void SetRadius(float radius) = 0;
};
}
16 changes: 16 additions & 0 deletions include/NovelRT/Physics/2D/CapsuleCollisionFixtureDefinition2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
struct CapsuleCollisionFixtureDefinition2D final : public CollisionFixtureDefinition2D
{
float Height;
float Radius;

~CapsuleCollisionFixtureDefinition2D() = default;
};
}
16 changes: 16 additions & 0 deletions include/NovelRT/Physics/2D/CircleCollisionFixture2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
class CircleCollisionFixture2D : public CollisionFixture2D
{
[[nodiscard]] virtual float GetRadius() = 0;

virtual void SetRadius() = 0;
};

} // namespace NovelRT::Physics::Physics2D
16 changes: 16 additions & 0 deletions include/NovelRT/Physics/2D/CircleCollisionFixtureDefinition2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
struct CircleCollisionFixtureDefinition2D final : public CollisionFixtureDefinition2D
{
float Radius;

~CircleCollisionFixtureDefinition2D() = default;
};

} // namespace NovelRT::Physics::Physics2D
15 changes: 15 additions & 0 deletions include/NovelRT/Physics/2D/CollisionCallbackArgument2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
struct CollisionCallBackArgument2D final
{
const RigidBody2D* const RigidBody;
const CollisionFixture2D* const CollisionFixture;
};

} // namespace NovelRT::Physics::Physics2D
37 changes: 37 additions & 0 deletions include/NovelRT/Physics/2D/CollisionFixture2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
class CollisionFixture2D
{
public:
[[nodiscard]] virtual NovelRT::Maths::GeoVector2F GetOffset() = 0;

[[nodiscard]] virtual float GetFriction() = 0;

[[nodiscard]] virtual float GetRestitution() = 0;

[[nodiscard]] virtual float GetRestitutionThreshold() = 0;

[[nodiscard]] virtual float GetDensity() = 0;

[[nodiscard]] virtual bool IsSensor() = 0;

virtual void SetOffset(NovelRT::Maths::GeoVector2F offset) = 0;

virtual void SetFriction(float friction) = 0;

virtual void SetRestitution(float restitution) = 0;

virtual void SetRestitutionThreshold(float restitutionThreshold) = 0;

virtual void SetDensity(float density) = 0;

virtual void SetIsSensor(bool isSensor) = 0;
};

} // namespace NovelRT::Physics::Physics2D
21 changes: 21 additions & 0 deletions include/NovelRT/Physics/2D/CollisionFixtureDefinition2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
struct CollisionFixtureDefinition2D
{
NovelRT::Maths::GeoVector2F Offset;
float Friction;
float Restitution;
float RestitutionThreshold;
float Density;
bool IsSensor;

virtual ~CollisionFixtureDefinition2D() = 0;
};

} // namespace NovelRT::Physics::Physics2D
45 changes: 45 additions & 0 deletions include/NovelRT/Physics/2D/DistanceJoint2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
/**
* @brief
* A joint that keeps the anchors of the attached bodies within a certain range of distance.
*/
class DistanceJoint2D : public Joint2D
{
protected:
float _minLength;
float _maxLength;
float _restLength;

public:
[[nodiscard]] inline float GetMinLength() const noexcept
{
return _minLength;
}

[[nodiscard]] inline float GetMaxLength() const noexcept
{
return _minLength;
}

[[nodiscard]] inline float GetRestLength() const noexcept
{
return _minLength;
}

virtual void SetMinLength(float minLength) = 0;

virtual void SetMaxLength(float maxLength) = 0;

virtual void SetRestLength(float restLength) = 0;
};
}
20 changes: 20 additions & 0 deletions include/NovelRT/Physics/2D/DistanceJointDefinition2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
struct DistanceJointDefinition2D final : public JointDefinition2D
{
float MinLength;
float MaxLength;
float RestLength;

~DistanceJointDefinition2D() = default;
};
}
17 changes: 17 additions & 0 deletions include/NovelRT/Physics/2D/EdgeCollisionFixture2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
class EdgeCollisionFixture2D : public CollisionFixture2D
{
public:
[[nodiscard]] virtual NovelRT::Utilities::Misc::Span<const NovelRT::Maths::GeoVector2F> GetVertices() = 0;

virtual void SetVertices(NovelRT::Utilities::Misc::Span<const NovelRT::Maths::GeoVector2F> vertices) = 0;
};

} // namespace NovelRT::Physics::Physics2D
16 changes: 16 additions & 0 deletions include/NovelRT/Physics/2D/EdgeCollisionFixtureDefinition2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
struct EdgeCollisionFixtureDefinition2D final : public CollisionFixtureDefinition2D
{
std::vector<NovelRT::Maths::GeoVector2F> Vertices;

~EdgeCollisionFixtureDefinition2D() = default;
};

} // namespace NovelRT::Physics::Physics2D
37 changes: 37 additions & 0 deletions include/NovelRT/Physics/2D/FixedDistanceJoint2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
/**
* @brief
* A joint that keeps the anchors of the attached bodies at a set distance.
*/
class FixedDistanceJoint2D : public Joint2D
{
protected:
float _restLength;
bool _isOnlyMaxLengthEnforced;

public:
[[nodiscard]] inline float GetRestLength() const noexcept
{
return _restLength;
}

[[nodiscard]] inline bool GetIsOnlyMaxLengthEnforced() const noexcept
{
return _isOnlyMaxLengthEnforced;
}

virtual void SetRestLength(float restLength) = 0;

virtual void SetIsOnlyMaxLengthEnforced(bool isOnlyMaxLengthEnforced) = 0;
};
}
19 changes: 19 additions & 0 deletions include/NovelRT/Physics/2D/FixedDistanceJointDefinition2D.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#pragma once

#ifndef NOVELRT_PHYSICS_HPP
#error NovelRT does not support including types explicitly by default. Please include Physics.h instead for the Physics namespace subset.
#endif

namespace NovelRT::Physics::Physics2D
{
struct FixedJointDefinition2D final : public JointDefinition2D
{
float RestLength;
bool IsOnlyMaxLengthEnforced;

~FixedJointDefinition2D() = default;
};
}
Loading