Rename ChipmunkPhysics2D and JoltPhysics3D to Physics[2D|3D]
This commit is contained in:
parent
139bed2b0a
commit
e336c8a514
|
|
@ -2,7 +2,7 @@
|
|||
#include <Nazara/Platform.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Math/PidController.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D.hpp>
|
||||
#include <Nazara/Physics2D.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <Nazara/Widgets.hpp>
|
||||
|
|
@ -21,14 +21,14 @@ int main(int argc, char* argv[])
|
|||
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
|
||||
resourceDir = "../.." / resourceDir;
|
||||
|
||||
Nz::Application<Nz::Graphics, Nz::ChipmunkPhysics2D> app(argc, argv);
|
||||
Nz::Application<Nz::Graphics, Nz::Physics2D> app(argc, argv);
|
||||
|
||||
auto& windowing = app.AddComponent<Nz::WindowingAppComponent>();
|
||||
|
||||
auto& ecs = app.AddComponent<Nz::EntitySystemAppComponent>();
|
||||
|
||||
auto& world = ecs.AddWorld<Nz::EnttWorld>();
|
||||
Nz::ChipmunkPhysics2DSystem& physSytem = world.AddSystem<Nz::ChipmunkPhysics2DSystem>();
|
||||
Nz::Physics2DSystem& physSytem = world.AddSystem<Nz::Physics2DSystem>();
|
||||
Nz::RenderSystem& renderSystem = world.AddSystem<Nz::RenderSystem>();
|
||||
|
||||
std::string windowTitle = "Physics 2D";
|
||||
|
|
@ -59,9 +59,9 @@ int main(int argc, char* argv[])
|
|||
std::shared_ptr<Nz::MaterialInstance> spriteMaterial = Nz::MaterialInstance::Instantiate(Nz::MaterialType::Phong);
|
||||
spriteMaterial->SetTextureProperty("BaseColorMap", Nz::Texture::LoadFromFile(resourceDir / "box.png", texParams));
|
||||
|
||||
Nz::ChipmunkRigidBody2DComponent::DynamicSettings boxSettings;
|
||||
Nz::RigidBody2DComponent::DynamicSettings boxSettings;
|
||||
boxSettings.mass = 50.f;
|
||||
boxSettings.geom = std::make_shared<Nz::ChipmunkBoxCollider2D>(Nz::Vector2f(32.f, 32.f));
|
||||
boxSettings.geom = std::make_shared<Nz::BoxCollider2D>(Nz::Vector2f(32.f, 32.f));
|
||||
|
||||
std::shared_ptr<Nz::Sprite> boxSprite = std::make_shared<Nz::Sprite>(spriteMaterial);
|
||||
boxSprite->SetSize({ 32.f, 32.f });
|
||||
|
|
@ -76,7 +76,7 @@ int main(int argc, char* argv[])
|
|||
spriteEntity.emplace<Nz::NodeComponent>(Nz::Vector2f(windowSize.x * 0.5f + x * 32.f - 15.f * 32.f, windowSize.y / 2 + y * 48.f));
|
||||
spriteEntity.emplace<Nz::GraphicsComponent>(boxSprite, 1);
|
||||
|
||||
auto& rigidBody = spriteEntity.emplace<Nz::ChipmunkRigidBody2DComponent>(boxSettings);
|
||||
auto& rigidBody = spriteEntity.emplace<Nz::RigidBody2DComponent>(boxSettings);
|
||||
rigidBody.SetFriction(0.9f);
|
||||
//rigidBody.SetElasticity(0.99f);
|
||||
}
|
||||
|
|
@ -102,12 +102,12 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
Nz::ChipmunkRigidBody2DComponent::StaticSettings groundSettings;
|
||||
groundSettings.geom = std::make_shared<Nz::ChipmunkBoxCollider2D>(tilemap->GetSize());
|
||||
Nz::RigidBody2DComponent::StaticSettings groundSettings;
|
||||
groundSettings.geom = std::make_shared<Nz::BoxCollider2D>(tilemap->GetSize());
|
||||
|
||||
groundEntity.emplace<Nz::NodeComponent>().SetPosition(windowSize.x * 0.5f, -windowSize.y * 0.2f);
|
||||
groundEntity.emplace<Nz::GraphicsComponent>().AttachRenderable(tilemap, 1);
|
||||
auto& rigidBody = groundEntity.emplace<Nz::ChipmunkRigidBody2DComponent>(groundSettings);
|
||||
auto& rigidBody = groundEntity.emplace<Nz::RigidBody2DComponent>(groundSettings);
|
||||
rigidBody.SetFriction(0.9f);
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ int main(int argc, char* argv[])
|
|||
Nz::PidController<Nz::Vector3f> headingController(0.5f, 0.f, 0.05f);
|
||||
Nz::PidController<Nz::Vector3f> upController(1.f, 0.f, 0.1f);
|
||||
|
||||
std::optional<Nz::ChipmunkPivotConstraint2D> grabConstraint;
|
||||
std::optional<Nz::PhysPivotConstraint2D> grabConstraint;
|
||||
NazaraSlot(Nz::WindowEventHandler, OnMouseMoved, grabbedObjectMove);
|
||||
|
||||
Nz::WindowEventHandler& eventHandler = window.GetEventHandler();
|
||||
|
|
@ -139,14 +139,14 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
if (nearestEntity && nearestEntity != groundEntity)
|
||||
{
|
||||
grabConstraint.emplace(nearestEntity.get<Nz::ChipmunkRigidBody2DComponent>(), worldPos);
|
||||
grabConstraint.emplace(nearestEntity.get<Nz::RigidBody2DComponent>(), worldPos);
|
||||
|
||||
grabbedObjectMove.Connect(eventHandler.OnMouseMoved, [&, nearestEntity, viewer](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||
{
|
||||
auto& viewerComponent = viewer.get<Nz::CameraComponent>();
|
||||
Nz::Vector2f worldPos = Nz::Vector2f(viewerComponent.Unproject(Nz::Vector3f(event.x, event.y, 0.f)));
|
||||
|
||||
auto& rigidBody = nearestEntity.get<Nz::ChipmunkRigidBody2DComponent>();
|
||||
auto& rigidBody = nearestEntity.get<Nz::RigidBody2DComponent>();
|
||||
|
||||
grabConstraint->SetFirstAnchor(worldPos);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
target("Physics2DDemo")
|
||||
add_deps("NazaraGraphics", "NazaraChipmunkPhysics2D")
|
||||
add_deps("NazaraGraphics", "NazaraPhysics2D")
|
||||
add_packages("entt")
|
||||
add_files("main.cpp")
|
||||
add_defines("NAZARA_ENTT")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <Nazara/Platform.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Math/PidController.hpp>
|
||||
#include <Nazara/JoltPhysics3D.hpp>
|
||||
#include <Nazara/Physics3D.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
|
|
@ -20,14 +20,14 @@ int main(int argc, char* argv[])
|
|||
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
|
||||
resourceDir = "../.." / resourceDir;
|
||||
|
||||
Nz::Application<Nz::Graphics, Nz::JoltPhysics3D> app(argc, argv);
|
||||
Nz::Application<Nz::Graphics, Nz::Physics3D> app(argc, argv);
|
||||
|
||||
auto& windowing = app.AddComponent<Nz::WindowingAppComponent>();
|
||||
|
||||
auto& ecs = app.AddComponent<Nz::EntitySystemAppComponent>();
|
||||
|
||||
auto& world = ecs.AddWorld<Nz::EnttWorld>();
|
||||
Nz::JoltPhysics3DSystem& physSytem = world.AddSystem<Nz::JoltPhysics3DSystem>();
|
||||
Nz::Physics3DSystem& physSytem = world.AddSystem<Nz::Physics3DSystem>();
|
||||
physSytem.GetPhysWorld().SetGravity(Nz::Vector3f::Zero());
|
||||
|
||||
Nz::RenderSystem& renderSystem = world.AddSystem<Nz::RenderSystem>();
|
||||
|
|
@ -101,7 +101,7 @@ int main(int argc, char* argv[])
|
|||
cameraComponent.UpdateClearColor(Nz::Color(0.5f, 0.5f, 0.5f));
|
||||
}
|
||||
|
||||
auto shipCollider = std::make_shared<Nz::JoltConvexHullCollider3D>(vertices, vertexMapper.GetVertexCount());
|
||||
auto shipCollider = std::make_shared<Nz::ConvexHullCollider3D>(vertices, vertexMapper.GetVertexCount());
|
||||
|
||||
std::shared_ptr<Nz::MaterialInstance> colliderMat = Nz::MaterialInstance::Instantiate(Nz::MaterialType::Basic);
|
||||
colliderMat->SetValueProperty("BaseColor", Nz::Color::Green());
|
||||
|
|
@ -139,11 +139,11 @@ int main(int argc, char* argv[])
|
|||
auto& entityNode = playerEntity.emplace<Nz::NodeComponent>();
|
||||
entityNode.SetPosition(Nz::Vector3f(12.5f, 0.f, 25.f));
|
||||
|
||||
Nz::JoltRigidBody3D::DynamicSettings settings;
|
||||
Nz::RigidBody3D::DynamicSettings settings;
|
||||
settings.geom = shipCollider;
|
||||
settings.mass = 100.f;
|
||||
|
||||
auto& entityPhys = playerEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
|
||||
auto& entityPhys = playerEntity.emplace<Nz::RigidBody3DComponent>(settings);
|
||||
entityPhys.SetMass(50.f);
|
||||
entityPhys.SetAngularDamping(0.1f);
|
||||
entityPhys.SetLinearDamping(0.5f);
|
||||
|
|
@ -182,11 +182,11 @@ int main(int argc, char* argv[])
|
|||
entityNode.SetPosition(Nz::Vector3f(x * 2.f, y * 1.5f, z * 2.f));
|
||||
entityNode.SetRotation(Nz::EulerAnglesf(0.f, Nz::TurnAnglef(0.5f), 0.f));
|
||||
|
||||
Nz::JoltRigidBody3D::DynamicSettings settings;
|
||||
Nz::RigidBody3D::DynamicSettings settings;
|
||||
settings.geom = shipCollider;
|
||||
settings.mass = 100.f;
|
||||
|
||||
auto& entityPhys = entity.emplace<Nz::JoltRigidBody3DComponent>(settings);
|
||||
auto& entityPhys = entity.emplace<Nz::RigidBody3DComponent>(settings);
|
||||
entityPhys.SetMass(1.f);
|
||||
entityPhys.SetAngularDamping(0.f);
|
||||
entityPhys.SetLinearDamping(0.f);
|
||||
|
|
@ -221,13 +221,13 @@ int main(int argc, char* argv[])
|
|||
showColliders = !showColliders;
|
||||
if (showColliders)
|
||||
{
|
||||
auto view = world.GetRegistry().view<Nz::GraphicsComponent, Nz::JoltRigidBody3DComponent>();
|
||||
auto view = world.GetRegistry().view<Nz::GraphicsComponent, Nz::RigidBody3DComponent>();
|
||||
for (auto [entity, gfxComponent, _] : view.each())
|
||||
gfxComponent.AttachRenderable(colliderModel, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto view = world.GetRegistry().view<Nz::GraphicsComponent, Nz::JoltRigidBody3DComponent>();
|
||||
auto view = world.GetRegistry().view<Nz::GraphicsComponent, Nz::RigidBody3DComponent>();
|
||||
for (auto [entity, gfxComponent, _] : view.each())
|
||||
gfxComponent.DetachRenderable(colliderModel);
|
||||
}
|
||||
|
|
@ -242,11 +242,11 @@ int main(int argc, char* argv[])
|
|||
|
||||
entity.emplace<Nz::NodeComponent>();
|
||||
|
||||
Nz::JoltRigidBody3D::DynamicSettings settings;
|
||||
Nz::RigidBody3D::DynamicSettings settings;
|
||||
settings.geom = shipCollider;
|
||||
settings.mass = 100.f;
|
||||
|
||||
auto& entityPhys = entity.emplace<Nz::JoltRigidBody3DComponent>(settings);
|
||||
auto& entityPhys = entity.emplace<Nz::RigidBody3DComponent>(settings);
|
||||
entityPhys.SetMass(1.f);
|
||||
entityPhys.SetAngularDamping(0.f);
|
||||
entityPhys.SetLinearDamping(0.f);
|
||||
|
|
@ -273,7 +273,7 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
float elapsedTime = deltaTime->AsSeconds();
|
||||
|
||||
auto spaceshipView = world.GetRegistry().view<Nz::NodeComponent, Nz::JoltRigidBody3DComponent>();
|
||||
auto spaceshipView = world.GetRegistry().view<Nz::NodeComponent, Nz::RigidBody3DComponent>();
|
||||
for (auto&& [entity, node, _] : spaceshipView.each())
|
||||
{
|
||||
if (entity == playerEntity)
|
||||
|
|
@ -284,7 +284,7 @@ int main(int argc, char* argv[])
|
|||
world.GetRegistry().destroy(entity);
|
||||
}
|
||||
|
||||
Nz::JoltRigidBody3DComponent& playerShipBody = playerEntity.get<Nz::JoltRigidBody3DComponent>();
|
||||
Nz::RigidBody3DComponent& playerShipBody = playerEntity.get<Nz::RigidBody3DComponent>();
|
||||
Nz::Quaternionf currentRotation = playerShipBody.GetRotation();
|
||||
|
||||
Nz::Vector3f desiredHeading = headingEntity.get<Nz::NodeComponent>().GetForward();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
target("PhysicsDemo")
|
||||
add_deps("NazaraGraphics", "NazaraJoltPhysics3D")
|
||||
add_deps("NazaraGraphics", "NazaraPhysics3D")
|
||||
add_packages("entt")
|
||||
add_files("main.cpp")
|
||||
add_defines("NAZARA_ENTT")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Platform/WindowingAppComponent.hpp>
|
||||
#include <Nazara/JoltPhysics3D.hpp>
|
||||
#include <Nazara/Physics3D.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <iostream>
|
||||
|
|
@ -16,7 +16,7 @@ int main(int argc, char* argv[])
|
|||
Nz::Renderer::Config renderConfig;
|
||||
renderConfig.validationLevel = Nz::RenderAPIValidationLevel::None;
|
||||
|
||||
Nz::Application<Nz::Graphics, Nz::JoltPhysics3D> app(argc, argv, renderConfig);
|
||||
Nz::Application<Nz::Graphics, Nz::Physics3D> app(argc, argv, renderConfig);
|
||||
|
||||
auto& windowing = app.AddComponent<Nz::WindowingAppComponent>();
|
||||
Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1280, 720), "Physics playground");
|
||||
|
|
@ -33,7 +33,7 @@ int main(int argc, char* argv[])
|
|||
auto& ecs = app.AddComponent<Nz::EntitySystemAppComponent>();
|
||||
auto& world = ecs.AddWorld<Nz::EnttWorld>();
|
||||
|
||||
auto& physSystem = world.AddSystem<Nz::JoltPhysics3DSystem>();
|
||||
auto& physSystem = world.AddSystem<Nz::Physics3DSystem>();
|
||||
physSystem.GetPhysWorld().SetMaxStepCount(1);
|
||||
physSystem.GetPhysWorld().SetStepSize(Nz::Time::TickDuration(30));
|
||||
physSystem.GetPhysWorld().SetGravity(Nz::Vector3f::Down() * 9.81f);
|
||||
|
|
@ -81,9 +81,9 @@ int main(int argc, char* argv[])
|
|||
boxColliderEntity.emplace<Nz::NodeComponent>();
|
||||
|
||||
float thickness = 1.f;
|
||||
std::shared_ptr<Nz::JoltBoxCollider3D> wallCollider = std::make_shared<Nz::JoltBoxCollider3D>(Nz::Vector3f(BoxDims + thickness * 2.f, BoxDims + thickness * 2.f, thickness));
|
||||
std::shared_ptr<Nz::BoxCollider3D> wallCollider = std::make_shared<Nz::BoxCollider3D>(Nz::Vector3f(BoxDims + thickness * 2.f, BoxDims + thickness * 2.f, thickness));
|
||||
|
||||
std::vector<Nz::JoltCompoundCollider3D::ChildCollider> colliders;
|
||||
std::vector<Nz::CompoundCollider3D::ChildCollider> colliders;
|
||||
for (Nz::Vector3f normal : { Nz::Vector3f::Forward(), Nz::Vector3f::Backward(), Nz::Vector3f::Left(), Nz::Vector3f::Right(), Nz::Vector3f::Up(), Nz::Vector3f::Down() })
|
||||
{
|
||||
auto& colliderEntry = colliders.emplace_back();
|
||||
|
|
@ -92,12 +92,12 @@ int main(int argc, char* argv[])
|
|||
colliderEntry.offset = normal * BoxDims * 0.5f + normal * 0.5f;
|
||||
}
|
||||
|
||||
std::shared_ptr<Nz::JoltCompoundCollider3D> boxCollider = std::make_shared<Nz::JoltCompoundCollider3D>(std::move(colliders));
|
||||
std::shared_ptr<Nz::CompoundCollider3D> boxCollider = std::make_shared<Nz::CompoundCollider3D>(std::move(colliders));
|
||||
|
||||
Nz::JoltRigidBody3D::StaticSettings settings;
|
||||
Nz::RigidBody3D::StaticSettings settings;
|
||||
settings.geom = boxCollider;
|
||||
|
||||
boxColliderEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
|
||||
boxColliderEntity.emplace<Nz::RigidBody3DComponent>(settings);
|
||||
|
||||
std::shared_ptr<Nz::Model> colliderModel;
|
||||
{
|
||||
|
|
@ -125,7 +125,7 @@ int main(int argc, char* argv[])
|
|||
float radius = radiusDis(rd);
|
||||
std::uniform_real_distribution<float> positionRandom(-BoxDims * 0.5f + radius, BoxDims * 0.5f - radius);
|
||||
|
||||
std::shared_ptr<Nz::JoltSphereCollider3D> sphereCollider = std::make_shared<Nz::JoltSphereCollider3D>(radius);
|
||||
std::shared_ptr<Nz::SphereCollider3D> sphereCollider = std::make_shared<Nz::SphereCollider3D>(radius);
|
||||
|
||||
entt::handle ballEntity = world.CreateEntity();
|
||||
|
||||
|
|
@ -142,11 +142,11 @@ int main(int argc, char* argv[])
|
|||
ballNode.SetPosition(positionRandom(rd), positionRandom(rd), positionRandom(rd));
|
||||
ballNode.SetScale(radius);
|
||||
|
||||
Nz::JoltRigidBody3D::DynamicSettings settings;
|
||||
Nz::RigidBody3D::DynamicSettings settings;
|
||||
settings.geom = sphereCollider;
|
||||
settings.mass = 4.f / 3.f * Nz::Pi<float> * Nz::IntegralPow(radius, 3);
|
||||
|
||||
ballEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
|
||||
ballEntity.emplace<Nz::RigidBody3DComponent>(settings);
|
||||
}
|
||||
|
||||
std::uniform_real_distribution<float> lengthDis(0.2f, 1.5f);
|
||||
|
|
@ -177,13 +177,13 @@ int main(int argc, char* argv[])
|
|||
ballNode.SetPosition(xRandom(rd), yRandom(rd), zRandom(rd));
|
||||
ballNode.SetScale(width, height, depth);
|
||||
|
||||
std::shared_ptr<Nz::JoltBoxCollider3D> boxCollider = std::make_shared<Nz::JoltBoxCollider3D>(Nz::Vector3f(width, height, depth));
|
||||
std::shared_ptr<Nz::BoxCollider3D> boxCollider = std::make_shared<Nz::BoxCollider3D>(Nz::Vector3f(width, height, depth));
|
||||
|
||||
Nz::JoltRigidBody3D::DynamicSettings settings;
|
||||
Nz::RigidBody3D::DynamicSettings settings;
|
||||
settings.geom = boxCollider;
|
||||
settings.mass = width * height * depth;
|
||||
|
||||
boxEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
|
||||
boxEntity.emplace<Nz::RigidBody3DComponent>(settings);
|
||||
}
|
||||
|
||||
// Spaceships
|
||||
|
|
@ -227,7 +227,7 @@ int main(int argc, char* argv[])
|
|||
Nz::VertexMapper vertexMapper(*spaceshipMesh->GetSubMesh(0));
|
||||
Nz::SparsePtr<Nz::Vector3f> vertices = vertexMapper.GetComponentPtr<Nz::Vector3f>(Nz::VertexComponent::Position);
|
||||
|
||||
auto shipCollider = std::make_shared<Nz::JoltConvexHullCollider3D>(vertices, vertexMapper.GetVertexCount(), 0.1f);
|
||||
auto shipCollider = std::make_shared<Nz::ConvexHullCollider3D>(vertices, vertexMapper.GetVertexCount(), 0.1f);
|
||||
|
||||
std::shared_ptr<Nz::Model> colliderModel;
|
||||
{
|
||||
|
|
@ -249,11 +249,11 @@ int main(int argc, char* argv[])
|
|||
auto& shipNode = shipEntity.emplace<Nz::NodeComponent>();
|
||||
shipNode.SetPosition(xRandom(rd), yRandom(rd), zRandom(rd));
|
||||
|
||||
Nz::JoltRigidBody3D::DynamicSettings settings;
|
||||
Nz::RigidBody3D::DynamicSettings settings;
|
||||
settings.geom = shipCollider;
|
||||
settings.mass = 100.f;
|
||||
|
||||
shipEntity.emplace<Nz::JoltRigidBody3DComponent>(settings);
|
||||
shipEntity.emplace<Nz::RigidBody3DComponent>(settings);
|
||||
|
||||
//shipEntity.get<Nz::GraphicsComponent>().AttachRenderable(colliderModel);
|
||||
}
|
||||
|
|
@ -304,7 +304,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
struct GrabConstraint
|
||||
{
|
||||
GrabConstraint(Nz::JoltRigidBody3D& body, const Nz::Vector3f& grabPos) :
|
||||
GrabConstraint(Nz::RigidBody3D& body, const Nz::Vector3f& grabPos) :
|
||||
grabBody(body.GetWorld(), BodySettings(grabPos)),
|
||||
grabConstraint(body, grabBody, grabPos)
|
||||
{
|
||||
|
|
@ -324,9 +324,9 @@ int main(int argc, char* argv[])
|
|||
grabBody.SetPosition(pos);
|
||||
}
|
||||
|
||||
static Nz::JoltRigidBody3D::DynamicSettings BodySettings(const Nz::Vector3f& pos)
|
||||
static Nz::RigidBody3D::DynamicSettings BodySettings(const Nz::Vector3f& pos)
|
||||
{
|
||||
Nz::JoltRigidBody3D::DynamicSettings settings;
|
||||
Nz::RigidBody3D::DynamicSettings settings;
|
||||
settings.mass = 0.f; //< kinematic
|
||||
settings.isSimulationEnabled = false;
|
||||
settings.position = pos;
|
||||
|
|
@ -334,8 +334,8 @@ int main(int argc, char* argv[])
|
|||
return settings;
|
||||
}
|
||||
|
||||
Nz::JoltRigidBody3D grabBody;
|
||||
Nz::JoltDistanceConstraint3D grabConstraint;
|
||||
Nz::RigidBody3D grabBody;
|
||||
Nz::PhysDistanceConstraint3D grabConstraint;
|
||||
};
|
||||
|
||||
std::optional<GrabConstraint> grabConstraint;
|
||||
|
|
@ -365,7 +365,7 @@ int main(int argc, char* argv[])
|
|||
Nz::Vector3f from = cameraComponent.Unproject({ float(event.x), float(event.y), 0.f });
|
||||
Nz::Vector3f to = cameraComponent.Unproject({ float(event.x), float(event.y), 1.f });
|
||||
|
||||
Nz::JoltPhysics3DSystem::RaycastHit lastHitInfo;
|
||||
Nz::Physics3DSystem::RaycastHit lastHitInfo;
|
||||
auto callback = [&](const decltype(lastHitInfo)& hitInfo) -> std::optional<float>
|
||||
{
|
||||
if (hitInfo.hitEntity == boxColliderEntity)
|
||||
|
|
@ -386,7 +386,7 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
if (lastHitInfo.hitBody && lastHitInfo.hitEntity != boxColliderEntity)
|
||||
{
|
||||
grabConstraint.emplace(static_cast<Nz::JoltRigidBody3D&>(*lastHitInfo.hitBody), lastHitInfo.hitPosition);
|
||||
grabConstraint.emplace(static_cast<Nz::RigidBody3D&>(*lastHitInfo.hitBody), lastHitInfo.hitPosition);
|
||||
|
||||
grabbedObjectMove.Connect(eventHandler.OnMouseMoved, [&, distance = Nz::Vector3f::Distance(from, lastHitInfo.hitPosition)](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
target("PhysicsPlayground")
|
||||
add_deps("NazaraGraphics", "NazaraJoltPhysics3D")
|
||||
add_deps("NazaraGraphics", "NazaraPhysics3D")
|
||||
add_packages("entt")
|
||||
add_files("main.cpp")
|
||||
add_defines("NAZARA_ENTT")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <Nazara/Platform.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Math/PidController.hpp>
|
||||
#include <Nazara/JoltPhysics3D.hpp>
|
||||
#include <Nazara/Physics3D.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <Nazara/Utility/Plugins/AssimpPlugin.hpp>
|
||||
|
|
@ -18,7 +18,7 @@ NAZARA_REQUEST_DEDICATED_GPU()
|
|||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Nz::Application<Nz::Graphics, Nz::JoltPhysics3D> app(argc, argv);
|
||||
Nz::Application<Nz::Graphics, Nz::Physics3D> app(argc, argv);
|
||||
|
||||
Nz::PluginLoader loader;
|
||||
Nz::Plugin<Nz::AssimpPlugin> assimp = loader.Load<Nz::AssimpPlugin>();
|
||||
|
|
@ -30,7 +30,7 @@ int main(int argc, char* argv[])
|
|||
auto& world = ecs.AddWorld<Nz::EnttWorld>();
|
||||
world.AddSystem<Nz::SkeletonSystem>();
|
||||
|
||||
Nz::JoltPhysics3DSystem& physSytem = world.AddSystem<Nz::JoltPhysics3DSystem>();
|
||||
Nz::Physics3DSystem& physSytem = world.AddSystem<Nz::Physics3DSystem>();
|
||||
physSytem.GetPhysWorld().SetGravity(Nz::Vector3f::Zero());
|
||||
Nz::RenderSystem& renderSystem = world.AddSystem<Nz::RenderSystem>();
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
physSytem.GetPhysWorld().SetGravity({ 0.f, -9.81f, 0.f });
|
||||
|
||||
std::optional<Nz::JoltCharacter> character;
|
||||
std::optional<Nz::PhysCharacter3D> character;
|
||||
|
||||
entt::handle playerEntity = world.CreateEntity();
|
||||
entt::handle playerRotation = world.CreateEntity();
|
||||
|
|
@ -60,12 +60,12 @@ int main(int argc, char* argv[])
|
|||
auto& playerNode = playerEntity.emplace<Nz::NodeComponent>();
|
||||
playerNode.SetPosition(0.f, 1.8f, 1.f);
|
||||
|
||||
auto playerCollider = std::make_shared<Nz::JoltBoxCollider3D>(Nz::Vector3f(0.2f, 1.8f, 0.2f));
|
||||
auto playerCollider = std::make_shared<Nz::BoxCollider3D>(Nz::Vector3f(0.2f, 1.8f, 0.2f));
|
||||
|
||||
//auto& playerBody = playerEntity.emplace<Nz::JoltRigidBody3DComponent>(physSytem.CreateRigidBody(playerCollider));
|
||||
//auto& playerBody = playerEntity.emplace<Nz::RigidBody3DComponent>(physSytem.CreateRigidBody(playerCollider));
|
||||
//playerBody.SetMass(42.f);
|
||||
|
||||
Nz::JoltCharacter::Settings characterSettings;
|
||||
Nz::PhysCharacter3D::Settings characterSettings;
|
||||
characterSettings.collider = playerCollider;
|
||||
characterSettings.position = Nz::Vector3f::Up() * 5.f;
|
||||
|
||||
|
|
@ -363,13 +363,13 @@ int main(int argc, char* argv[])
|
|||
|
||||
floorEntity.emplace<Nz::NodeComponent>();
|
||||
|
||||
auto floorCollider = std::make_shared<Nz::JoltBoxCollider3D>(Nz::Vector3f(planeSize.x, 1.f, planeSize.y));
|
||||
auto translatedFloorCollider = std::make_shared<Nz::JoltTranslatedRotatedCollider3D>(std::move(floorCollider), Nz::Vector3f::Down() * 0.5f);
|
||||
auto floorCollider = std::make_shared<Nz::BoxCollider3D>(Nz::Vector3f(planeSize.x, 1.f, planeSize.y));
|
||||
auto translatedFloorCollider = std::make_shared<Nz::TranslatedRotatedCollider3D>(std::move(floorCollider), Nz::Vector3f::Down() * 0.5f);
|
||||
|
||||
Nz::JoltRigidBody3D::StaticSettings floorSettings;
|
||||
Nz::RigidBody3D::StaticSettings floorSettings;
|
||||
floorSettings.geom = translatedFloorCollider;
|
||||
|
||||
floorEntity.emplace<Nz::JoltRigidBody3DComponent>(floorSettings);
|
||||
floorEntity.emplace<Nz::RigidBody3DComponent>(floorSettings);
|
||||
|
||||
std::shared_ptr<Nz::GraphicalMesh> boxMeshGfx = Nz::GraphicalMesh::Build(Nz::Primitive::Box(Nz::Vector3f(0.5f, 0.5f, 0.5f)), meshPrimitiveParams);
|
||||
|
||||
|
|
@ -529,7 +529,7 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
float updateTime = deltaTime->AsSeconds();
|
||||
|
||||
//auto& playerBody = playerEntity.get<Nz::JoltRigidBody3DComponent>();
|
||||
//auto& playerBody = playerEntity.get<Nz::RigidBody3DComponent>();
|
||||
//playerBody.SetAngularDamping(std::numeric_limits<float>::max());
|
||||
|
||||
Nz::Vector3f velocity = character->GetLinearVelocity();
|
||||
|
|
@ -596,7 +596,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
//renderBuffer->Fill(skeletalBufferMem.data(), 0, skeletalBufferMem.size());
|
||||
|
||||
/*auto spaceshipView = registry.view<Nz::NodeComponent, Nz::JoltRigidBody3DComponent>();
|
||||
/*auto spaceshipView = registry.view<Nz::NodeComponent, Nz::RigidBody3DComponent>();
|
||||
for (auto&& [entity, node, _] : spaceshipView.each())
|
||||
{
|
||||
if (entity == playerEntity)
|
||||
|
|
@ -607,7 +607,7 @@ int main(int argc, char* argv[])
|
|||
registry.destroy(entity);
|
||||
}
|
||||
|
||||
Nz::JoltRigidBody3DComponent& playerShipBody = registry.get<Nz::JoltRigidBody3DComponent>(playerEntity);
|
||||
Nz::RigidBody3DComponent& playerShipBody = registry.get<Nz::RigidBody3DComponent>(playerEntity);
|
||||
Nz::Quaternionf currentRotation = playerShipBody.GetRotation();
|
||||
|
||||
Nz::Vector3f desiredHeading = registry.get<Nz::NodeComponent>(headingEntity).GetForward();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ end
|
|||
target("Showcase")
|
||||
set_group("Examples")
|
||||
set_kind("binary")
|
||||
add_deps("NazaraAudio", "NazaraGraphics", "NazaraChipmunkPhysics2D", "NazaraJoltPhysics3D", "NazaraWidgets")
|
||||
add_deps("NazaraAudio", "NazaraGraphics", "NazaraPhysics2D", "NazaraPhysics3D", "NazaraWidgets")
|
||||
if has_config("embed_plugins", "static") then
|
||||
add_deps("PluginAssimp")
|
||||
else
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Network.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D.hpp>
|
||||
#include <Nazara/Physics3D.hpp>
|
||||
#include <Nazara/Physics2D.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <iostream>
|
||||
|
|
@ -11,7 +12,7 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
// This "example" has only one purpose: Giving an empty project for you to test whatever you want
|
||||
// If you wish to have multiple test projects, you only have to copy/paste this directory and change the name in the xmake.lua
|
||||
Nz::Application<Nz::Audio, Nz::Core, Nz::Graphics, Nz::Network, Nz::ChipmunkPhysics2D, Nz::Renderer, Nz::Utility> app(argc, argv);
|
||||
Nz::Application<Nz::Audio, Nz::Core, Nz::Graphics, Nz::Network, Nz::Physics2D, Nz::Physics3D, Nz::Renderer, Nz::Utility> app(argc, argv);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
target("Tut00_EmptyProject")
|
||||
add_deps("NazaraAudio", "NazaraGraphics", "NazaraNetwork", "NazaraChipmunkPhysics2D", "NazaraRenderer", "NazaraUtility")
|
||||
add_deps("NazaraAudio", "NazaraGraphics", "NazaraNetwork", "NazaraPhysics2D", "NazaraPhysics3D", "NazaraRenderer", "NazaraUtility")
|
||||
add_files("main.cpp")
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - ChipmunkPhysics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GLOBAL_CHIPMUNKPHYSICS2D_HPP
|
||||
#define NAZARA_GLOBAL_CHIPMUNKPHYSICS2D_HPP
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkConstraint2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysics2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Enums.hpp>
|
||||
|
||||
#ifdef NAZARA_ENTT
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Components.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Systems.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_GLOBAL_CHIPMUNKPHYSICS2D_HPP
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkArbiter2D::ChipmunkArbiter2D(cpArbiter* arbiter) :
|
||||
m_arbiter(arbiter)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
|
|
@ -1,196 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkCollider2D::ChipmunkCollider2D() :
|
||||
m_categoryMask(0xFFFFFFFF),
|
||||
m_collisionGroup(0),
|
||||
m_collisionMask(0xFFFFFFFF),
|
||||
m_surfaceVelocity(Vector2f::Zero()),
|
||||
m_trigger(false),
|
||||
m_elasticity(0.f),
|
||||
m_friction(0.f),
|
||||
m_collisionId(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline UInt32 ChipmunkCollider2D::GetCategoryMask() const
|
||||
{
|
||||
return m_categoryMask;
|
||||
}
|
||||
|
||||
inline UInt32 ChipmunkCollider2D::GetCollisionGroup() const
|
||||
{
|
||||
return m_collisionGroup;
|
||||
}
|
||||
|
||||
inline unsigned int ChipmunkCollider2D::GetCollisionId() const
|
||||
{
|
||||
return m_collisionId;
|
||||
}
|
||||
|
||||
inline UInt32 ChipmunkCollider2D::GetCollisionMask() const
|
||||
{
|
||||
return m_collisionMask;
|
||||
}
|
||||
|
||||
inline float ChipmunkCollider2D::GetElasticity() const
|
||||
{
|
||||
return m_elasticity;
|
||||
}
|
||||
|
||||
inline float ChipmunkCollider2D::GetFriction() const
|
||||
{
|
||||
return m_friction;
|
||||
}
|
||||
|
||||
inline Vector2f ChipmunkCollider2D::GetSurfaceVelocity() const
|
||||
{
|
||||
return m_surfaceVelocity;
|
||||
}
|
||||
|
||||
inline bool ChipmunkCollider2D::IsTrigger() const
|
||||
{
|
||||
return m_trigger;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetCategoryMask(UInt32 categoryMask)
|
||||
{
|
||||
m_categoryMask = categoryMask;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetCollisionGroup(UInt32 groupId)
|
||||
{
|
||||
m_collisionGroup = groupId;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetCollisionId(unsigned int typeId)
|
||||
{
|
||||
m_collisionId = typeId;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetCollisionMask(UInt32 mask)
|
||||
{
|
||||
m_collisionMask = mask;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetElasticity(float elasticity)
|
||||
{
|
||||
m_elasticity = elasticity;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetFriction(float friction)
|
||||
{
|
||||
m_friction = friction;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||
{
|
||||
m_surfaceVelocity = surfaceVelocity;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetTrigger(bool trigger)
|
||||
{
|
||||
m_trigger = trigger;
|
||||
}
|
||||
|
||||
inline float ChipmunkBoxCollider2D::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
inline const Rectf& ChipmunkBoxCollider2D::GetRect() const
|
||||
{
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
inline Vector2f ChipmunkBoxCollider2D::GetSize() const
|
||||
{
|
||||
return m_rect.GetLengths();
|
||||
}
|
||||
|
||||
|
||||
inline const Vector2f& ChipmunkCircleCollider2D::GetOffset() const
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
inline float ChipmunkCircleCollider2D::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
|
||||
inline bool Nz::ChipmunkCompoundCollider2D::DoesOverrideCollisionProperties() const
|
||||
{
|
||||
return m_doesOverrideCollisionProperties;
|
||||
}
|
||||
|
||||
inline const std::vector<std::shared_ptr<ChipmunkCollider2D>>& ChipmunkCompoundCollider2D::GetGeoms() const
|
||||
{
|
||||
return m_geoms;
|
||||
}
|
||||
|
||||
inline void Nz::ChipmunkCompoundCollider2D::OverridesCollisionProperties(bool shouldOverride)
|
||||
{
|
||||
m_doesOverrideCollisionProperties = shouldOverride;
|
||||
}
|
||||
|
||||
|
||||
inline const std::vector<Vector2d>& ChipmunkConvexCollider2D::GetVertices() const
|
||||
{
|
||||
return m_vertices;
|
||||
}
|
||||
|
||||
|
||||
ChipmunkSegmentCollider2D::ChipmunkSegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness) :
|
||||
ChipmunkSegmentCollider2D(first, first, second, second, thickness)
|
||||
{
|
||||
}
|
||||
|
||||
inline ChipmunkSegmentCollider2D::ChipmunkSegmentCollider2D(const Vector2f& first, const Vector2f& firstNeighbor, const Vector2f& second, const Vector2f& secondNeighbor, float thickness) :
|
||||
m_first(first),
|
||||
m_firstNeighbor(firstNeighbor),
|
||||
m_second(second),
|
||||
m_secondNeighbor(secondNeighbor),
|
||||
m_thickness(thickness)
|
||||
{
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkSegmentCollider2D::GetFirstPoint() const
|
||||
{
|
||||
return m_first;
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkSegmentCollider2D::GetFirstPointNeighbor() const
|
||||
{
|
||||
return m_firstNeighbor;
|
||||
}
|
||||
|
||||
inline float ChipmunkSegmentCollider2D::GetLength() const
|
||||
{
|
||||
return m_first.Distance(m_second);
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkSegmentCollider2D::GetSecondPoint() const
|
||||
{
|
||||
return m_second;
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkSegmentCollider2D::GetSecondPointNeighbor() const
|
||||
{
|
||||
return m_secondNeighbor;
|
||||
}
|
||||
|
||||
inline float ChipmunkSegmentCollider2D::GetThickness() const
|
||||
{
|
||||
return m_thickness;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCONSTRAINT2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCONSTRAINT2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
struct cpConstraint;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkConstraint2D;
|
||||
|
||||
using ChipmunkConstraint2DHandle = ObjectHandle<ChipmunkConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkConstraint2D : public HandledObject<ChipmunkConstraint2D>
|
||||
{
|
||||
public:
|
||||
ChipmunkConstraint2D(const ChipmunkConstraint2D&) = delete;
|
||||
ChipmunkConstraint2D(ChipmunkConstraint2D&& constraint) noexcept;
|
||||
virtual ~ChipmunkConstraint2D();
|
||||
|
||||
void EnableBodyCollision(bool enable);
|
||||
|
||||
ChipmunkRigidBody2D& GetBodyA();
|
||||
const ChipmunkRigidBody2D& GetBodyA() const;
|
||||
ChipmunkRigidBody2D& GetBodyB();
|
||||
const ChipmunkRigidBody2D& GetBodyB() const;
|
||||
float GetErrorBias() const;
|
||||
float GetLastImpulse() const;
|
||||
float GetMaxBias() const;
|
||||
float GetMaxForce() const;
|
||||
ChipmunkPhysWorld2D& GetWorld();
|
||||
const ChipmunkPhysWorld2D& GetWorld() const;
|
||||
|
||||
bool IsBodyCollisionEnabled() const;
|
||||
bool IsSingleBody() const;
|
||||
|
||||
void SetErrorBias(float bias);
|
||||
void SetMaxBias(float bias);
|
||||
void SetMaxForce(float force);
|
||||
|
||||
ChipmunkConstraint2D& operator=(const ChipmunkConstraint2D&) = delete;
|
||||
ChipmunkConstraint2D& operator=(ChipmunkConstraint2D&& constraint) noexcept;
|
||||
|
||||
protected:
|
||||
ChipmunkConstraint2D(ChipmunkPhysWorld2D* world, cpConstraint* constraint);
|
||||
|
||||
MovablePtr<cpConstraint> m_constraint;
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
};
|
||||
|
||||
class ChipmunkDampedSpringConstraint2D;
|
||||
|
||||
using ChipmunkDampedSpringConstraint2DHandle = ObjectHandle<ChipmunkDampedSpringConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkDampedSpringConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkDampedSpringConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping);
|
||||
~ChipmunkDampedSpringConstraint2D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
Vector2f GetFirstAnchor() const;
|
||||
float GetRestLength() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
float GetStiffness() const;
|
||||
|
||||
void SetDamping(float newDamping);
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetRestLength(float newLength);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
void SetStiffness(float newStiffness);
|
||||
};
|
||||
|
||||
class ChipmunkDampedRotarySpringConstraint2D;
|
||||
|
||||
using ChipmunkDampedRotarySpringConstraint2DHandle = ObjectHandle<ChipmunkDampedRotarySpringConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkDampedRotarySpringConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkDampedRotarySpringConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const RadianAnglef& restAngle, float stiffness, float damping);
|
||||
~ChipmunkDampedRotarySpringConstraint2D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
RadianAnglef GetRestAngle() const;
|
||||
float GetStiffness() const;
|
||||
|
||||
void SetDamping(float newDamping);
|
||||
void SetRestAngle(const RadianAnglef& newAngle);
|
||||
void SetStiffness(float newStiffness);
|
||||
};
|
||||
|
||||
class ChipmunkGearConstraint2D;
|
||||
|
||||
using ChipmunkGearConstraint2DHandle = ObjectHandle<ChipmunkGearConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkGearConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkGearConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, float phase, float ratio);
|
||||
~ChipmunkGearConstraint2D() = default;
|
||||
|
||||
float GetPhase() const;
|
||||
float GetRatio() const;
|
||||
|
||||
void SetPhase(float phase);
|
||||
void SetRatio(float ratio);
|
||||
};
|
||||
|
||||
class ChipmunkMotorConstraint2D;
|
||||
|
||||
using ChipmunkMotorConstraint2DHandle = ObjectHandle<ChipmunkMotorConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkMotorConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkMotorConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, float rate);
|
||||
~ChipmunkMotorConstraint2D() = default;
|
||||
|
||||
float GetRate() const;
|
||||
void SetRate(float rate);
|
||||
};
|
||||
|
||||
class ChipmunkPinConstraint2D;
|
||||
|
||||
using ChipmunkPinConstraint2DHandle = ObjectHandle<ChipmunkPinConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPinConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkPinConstraint2D(ChipmunkRigidBody2D& body, const Vector2f& anchor);
|
||||
ChipmunkPinConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
|
||||
~ChipmunkPinConstraint2D() = default;
|
||||
|
||||
float GetDistance() const;
|
||||
Vector2f GetFirstAnchor() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetDistance(float newDistance);
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
|
||||
class ChipmunkPivotConstraint2D;
|
||||
|
||||
using ChipmunkPivotConstraint2DHandle = ObjectHandle<ChipmunkPivotConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPivotConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkPivotConstraint2D(ChipmunkRigidBody2D& body, const Vector2f& anchor);
|
||||
ChipmunkPivotConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& anchor);
|
||||
ChipmunkPivotConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
|
||||
~ChipmunkPivotConstraint2D() = default;
|
||||
|
||||
Vector2f GetFirstAnchor() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
|
||||
class ChipmunkRatchetConstraint2D;
|
||||
|
||||
using ChipmunkRatchetConstraint2DHandle = ObjectHandle<ChipmunkRatchetConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRatchetConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkRatchetConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, float phase, float ratchet);
|
||||
~ChipmunkRatchetConstraint2D() = default;
|
||||
|
||||
RadianAnglef GetAngle() const;
|
||||
float GetPhase() const;
|
||||
float GetRatchet() const;
|
||||
|
||||
void SetAngle(const RadianAnglef& angle);
|
||||
void SetPhase(float phase);
|
||||
void SetRatchet(float ratchet);
|
||||
};
|
||||
|
||||
class ChipmunkRotaryLimitConstraint2D;
|
||||
|
||||
using ChipmunkRotaryLimitConstraint2DHandle = ObjectHandle<ChipmunkRotaryLimitConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRotaryLimitConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkRotaryLimitConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const RadianAnglef& minAngle, const RadianAnglef& maxAngle);
|
||||
~ChipmunkRotaryLimitConstraint2D() = default;
|
||||
|
||||
RadianAnglef GetMaxAngle() const;
|
||||
RadianAnglef GetMinAngle() const;
|
||||
|
||||
void SetMaxAngle(const RadianAnglef& maxAngle);
|
||||
void SetMinAngle(const RadianAnglef& minAngle);
|
||||
};
|
||||
|
||||
class ChipmunkSlideConstraint2D;
|
||||
|
||||
using ChipmunkSlideConstraint2DHandle = ObjectHandle<ChipmunkSlideConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkSlideConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkSlideConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max);
|
||||
~ChipmunkSlideConstraint2D() = default;
|
||||
|
||||
Vector2f GetFirstAnchor() const;
|
||||
float GetMaxDistance() const;
|
||||
float GetMinDistance() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetMaxDistance(float newMaxDistance);
|
||||
void SetMinDistance(float newMinDistance);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkConstraint2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCONSTRAINT2D_HPP
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPhysics2D : public ModuleBase<ChipmunkPhysics2D>
|
||||
{
|
||||
friend ModuleBase;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
struct Config {};
|
||||
|
||||
ChipmunkPhysics2D(Config /*config*/);
|
||||
~ChipmunkPhysics2D() = default;
|
||||
|
||||
private:
|
||||
static ChipmunkPhysics2D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_HPP
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkRigidBody2D::ChipmunkRigidBody2D(ChipmunkPhysWorld2D& world, const DynamicSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline ChipmunkRigidBody2D::ChipmunkRigidBody2D(ChipmunkPhysWorld2D& world, const StaticSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline ChipmunkRigidBody2D::~ChipmunkRigidBody2D()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline void ChipmunkRigidBody2D::AddForce(const Vector2f& force, CoordSys coordSys)
|
||||
{
|
||||
return AddForce(force, GetMassCenter(coordSys), coordSys);
|
||||
}
|
||||
|
||||
inline void ChipmunkRigidBody2D::AddImpulse(const Vector2f& impulse, CoordSys coordSys)
|
||||
{
|
||||
return AddImpulse(impulse, GetMassCenter(coordSys), coordSys);
|
||||
}
|
||||
|
||||
inline UInt32 ChipmunkRigidBody2D::GetBodyIndex() const
|
||||
{
|
||||
return m_bodyIndex;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<ChipmunkCollider2D>& ChipmunkRigidBody2D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline cpBody* ChipmunkRigidBody2D::GetHandle() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
inline float ChipmunkRigidBody2D::GetMass() const
|
||||
{
|
||||
return m_mass;
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkRigidBody2D::GetPositionOffset() const
|
||||
{
|
||||
return m_positionOffset;
|
||||
}
|
||||
|
||||
inline std::size_t ChipmunkRigidBody2D::GetShapeIndex(cpShape* shape) const
|
||||
{
|
||||
auto it = std::find(m_shapes.begin(), m_shapes.end(), shape);
|
||||
if (it == m_shapes.end())
|
||||
return InvalidShapeIndex;
|
||||
|
||||
return std::distance(m_shapes.begin(), it);
|
||||
}
|
||||
|
||||
inline std::size_t ChipmunkRigidBody2D::GetShapeCount() const
|
||||
{
|
||||
return m_shapes.size();
|
||||
}
|
||||
|
||||
inline const ChipmunkRigidBody2D::VelocityFunc& ChipmunkRigidBody2D::GetVelocityFunction() const
|
||||
{
|
||||
return m_velocityFunc;
|
||||
}
|
||||
|
||||
inline ChipmunkPhysWorld2D* ChipmunkRigidBody2D::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
|
||||
inline bool ChipmunkRigidBody2D::IsKinematic() const
|
||||
{
|
||||
return m_mass <= 0.f;
|
||||
}
|
||||
|
||||
inline bool ChipmunkRigidBody2D::IsSimulationEnabled() const
|
||||
{
|
||||
return m_isSimulationEnabled;
|
||||
}
|
||||
|
||||
inline bool ChipmunkRigidBody2D::IsStatic() const
|
||||
{
|
||||
return m_isStatic;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_CHIPMUNKRIGIDBODY2DCOMPONENT_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_CHIPMUNKRIGIDBODY2DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRigidBody2DComponent : public ChipmunkRigidBody2D
|
||||
{
|
||||
friend class ChipmunkPhysics2DSystem;
|
||||
|
||||
public:
|
||||
inline ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2D::DynamicSettings& settings);
|
||||
inline ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2D::StaticSettings& settings);
|
||||
ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2DComponent&) = delete;
|
||||
ChipmunkRigidBody2DComponent(ChipmunkRigidBody2DComponent&&) noexcept = default;
|
||||
~ChipmunkRigidBody2DComponent() = default;
|
||||
|
||||
ChipmunkRigidBody2DComponent& operator=(const ChipmunkRigidBody2DComponent&) = delete;
|
||||
ChipmunkRigidBody2DComponent& operator=(ChipmunkRigidBody2DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(ChipmunkPhysWorld2D& world);
|
||||
|
||||
using Setting = std::variant<ChipmunkRigidBody2D::DynamicSettings, ChipmunkRigidBody2D::StaticSettings>;
|
||||
std::unique_ptr<Setting> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Components/ChipmunkRigidBody2DComponent.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_CHIPMUNKRIGIDBODY2DCOMPONENT_HPP
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkRigidBody2DComponent::ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2D::DynamicSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline ChipmunkRigidBody2DComponent::ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2D::StaticSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline void ChipmunkRigidBody2DComponent::Construct(ChipmunkPhysWorld2D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Create(world, arg);
|
||||
}, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - JoltPhysics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GLOBAL_JOLTPHYSICS3D_HPP
|
||||
#define NAZARA_GLOBAL_JOLTPHYSICS3D_HPP
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Enums.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltAbstractBody.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltCharacter.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltCollider3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltConstraint3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysics3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysicsStepListener.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.hpp>
|
||||
|
||||
#ifdef NAZARA_ENTT
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Components.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Systems.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_GLOBAL_JOLTPHYSICS3D_HPP
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTCHARACTERCOMPONENT_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTCHARACTERCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltCharacter.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCharacterComponent : public JoltCharacter
|
||||
{
|
||||
friend class JoltPhysics3DSystem;
|
||||
|
||||
public:
|
||||
inline JoltCharacterComponent(const JoltCharacter::Settings& settings);
|
||||
JoltCharacterComponent(const JoltCharacterComponent&) = default;
|
||||
JoltCharacterComponent(JoltCharacterComponent&&) noexcept = default;
|
||||
~JoltCharacterComponent() = default;
|
||||
|
||||
JoltCharacterComponent& operator=(const JoltCharacterComponent&) = default;
|
||||
JoltCharacterComponent& operator=(JoltCharacterComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(JoltPhysWorld3D& world);
|
||||
|
||||
std::unique_ptr<JoltCharacter::Settings> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltCharacterComponent.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTCHARACTERCOMPONENT_HPP
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltCharacterComponent::JoltCharacterComponent(const JoltCharacter::Settings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<JoltCharacter::Settings>(settings);
|
||||
}
|
||||
|
||||
inline void JoltCharacterComponent::Construct(JoltPhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
Create(world, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTRIGIDBODY3DCOMPONENT_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTRIGIDBODY3DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltRigidBody3DComponent : public JoltRigidBody3D
|
||||
{
|
||||
friend class JoltPhysics3DSystem;
|
||||
|
||||
public:
|
||||
inline JoltRigidBody3DComponent(const JoltRigidBody3D::DynamicSettings& settings);
|
||||
inline JoltRigidBody3DComponent(const JoltRigidBody3D::StaticSettings& settings);
|
||||
JoltRigidBody3DComponent(const JoltRigidBody3DComponent&) = default;
|
||||
JoltRigidBody3DComponent(JoltRigidBody3DComponent&&) noexcept = default;
|
||||
~JoltRigidBody3DComponent() = default;
|
||||
|
||||
JoltRigidBody3DComponent& operator=(const JoltRigidBody3DComponent&) = default;
|
||||
JoltRigidBody3DComponent& operator=(JoltRigidBody3DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(JoltPhysWorld3D& world);
|
||||
|
||||
using Setting = std::variant<JoltRigidBody3D::DynamicSettings, JoltRigidBody3D::StaticSettings>;
|
||||
std::unique_ptr<Setting> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTRIGIDBODY3DCOMPONENT_HPP
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <cassert>
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltRigidBody3DComponent::JoltRigidBody3DComponent(const JoltRigidBody3D::DynamicSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline JoltRigidBody3DComponent::JoltRigidBody3DComponent(const JoltRigidBody3D::StaticSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline void JoltRigidBody3DComponent::Construct(JoltPhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Create(world, arg);
|
||||
}, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_CONFIGCHECK_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_CONFIGCHECK_HPP
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_CONFIGCHECK_HPP
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTABSTRACTBODY_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTABSTRACTBODY_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltAbstractBody
|
||||
{
|
||||
public:
|
||||
JoltAbstractBody() = default;
|
||||
JoltAbstractBody(const JoltAbstractBody&) = delete;
|
||||
JoltAbstractBody(JoltAbstractBody&&) = delete;
|
||||
virtual ~JoltAbstractBody();
|
||||
|
||||
virtual UInt32 GetBodyIndex() const = 0;
|
||||
|
||||
JoltAbstractBody& operator=(const JoltAbstractBody&) = delete;
|
||||
JoltAbstractBody& operator=(JoltAbstractBody&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltAbstractBody.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTABSTRACTBODY_HPP
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTCHARACTER_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTCHARACTER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltAbstractBody.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysicsStepListener.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class Character;
|
||||
class Body;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class JoltCharacterImpl;
|
||||
class JoltCollider3D;
|
||||
class JoltPhysWorld3D;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCharacter : public JoltAbstractBody, public JoltPhysicsStepListener
|
||||
{
|
||||
friend JoltPhysWorld3D;
|
||||
|
||||
public:
|
||||
struct Settings;
|
||||
|
||||
JoltCharacter(JoltPhysWorld3D& physWorld, const Settings& settings);
|
||||
JoltCharacter(const JoltCharacter&) = delete;
|
||||
JoltCharacter(JoltCharacter&& character) noexcept;
|
||||
~JoltCharacter();
|
||||
|
||||
inline void DisableSleeping();
|
||||
void EnableSleeping(bool enable);
|
||||
|
||||
UInt32 GetBodyIndex() const override;
|
||||
inline const std::shared_ptr<JoltCollider3D>& GetCollider() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
inline JoltPhysWorld3D& GetPhysWorld();
|
||||
inline const JoltPhysWorld3D& GetPhysWorld() const;
|
||||
Vector3f GetPosition() const;
|
||||
std::pair<Vector3f, Quaternionf> GetPositionAndRotation() const;
|
||||
Quaternionf GetRotation() const;
|
||||
Vector3f GetUp() const;
|
||||
|
||||
bool IsOnGround() const;
|
||||
|
||||
void SetFriction(float friction);
|
||||
inline void SetImpl(std::shared_ptr<JoltCharacterImpl> characterImpl);
|
||||
void SetLinearVelocity(const Vector3f& linearVel);
|
||||
void SetRotation(const Quaternionf& rotation);
|
||||
void SetUp(const Vector3f& up);
|
||||
|
||||
void TeleportTo(const Vector3f& position, const Quaternionf& rotation);
|
||||
|
||||
void WakeUp();
|
||||
|
||||
JoltCharacter& operator=(const JoltCharacter&) = delete;
|
||||
JoltCharacter& operator=(JoltCharacter&& character) noexcept;
|
||||
|
||||
struct Settings
|
||||
{
|
||||
std::shared_ptr<JoltCollider3D> collider;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
};
|
||||
|
||||
protected:
|
||||
JoltCharacter();
|
||||
|
||||
void Create(JoltPhysWorld3D& physWorld, const Settings& settings);
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
void PostSimulate(float elapsedTime) override;
|
||||
void PreSimulate(float elapsedTime) override;
|
||||
|
||||
std::shared_ptr<JoltCharacterImpl> m_impl;
|
||||
std::shared_ptr<JoltCollider3D> m_collider;
|
||||
std::unique_ptr<JPH::Character> m_character;
|
||||
MovablePtr<JoltPhysWorld3D> m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCharacterImpl
|
||||
{
|
||||
public:
|
||||
JoltCharacterImpl() = default;
|
||||
JoltCharacterImpl(const JoltCharacterImpl&) = delete;
|
||||
JoltCharacterImpl(JoltCharacterImpl&&) = delete;
|
||||
virtual ~JoltCharacterImpl();
|
||||
|
||||
virtual void PostSimulate(JoltCharacter& character, float elapsedTime);
|
||||
virtual void PreSimulate(JoltCharacter& character, float elapsedTime);
|
||||
|
||||
JoltCharacterImpl& operator=(const JoltCharacterImpl&) = delete;
|
||||
JoltCharacterImpl& operator=(JoltCharacterImpl&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltCharacter.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTCHARACTER_HPP
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void JoltCharacter::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<JoltCollider3D>& JoltCharacter::GetCollider() const
|
||||
{
|
||||
return m_collider;
|
||||
}
|
||||
|
||||
inline JoltPhysWorld3D& JoltCharacter::GetPhysWorld()
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline const JoltPhysWorld3D& JoltCharacter::GetPhysWorld() const
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline void JoltCharacter::SetImpl(std::shared_ptr<JoltCharacterImpl> characterImpl)
|
||||
{
|
||||
m_impl = std::move(characterImpl);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTCOLLIDER3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTCOLLIDER3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Enums.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class ShapeSettings;
|
||||
class BoxShapeSettings;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PrimitiveList;
|
||||
class StaticMesh;
|
||||
struct Primitive;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltCollider3D();
|
||||
JoltCollider3D(const JoltCollider3D&) = delete;
|
||||
JoltCollider3D(JoltCollider3D&&) = delete;
|
||||
virtual ~JoltCollider3D();
|
||||
|
||||
virtual void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix = Matrix4f::Identity()) const = 0;
|
||||
|
||||
virtual std::shared_ptr<StaticMesh> GenerateDebugMesh() const;
|
||||
|
||||
inline JPH::ShapeSettings* GetShapeSettings() const;
|
||||
virtual JoltColliderType3D GetType() const = 0;
|
||||
|
||||
JoltCollider3D& operator=(const JoltCollider3D&) = delete;
|
||||
JoltCollider3D& operator=(JoltCollider3D&&) = delete;
|
||||
|
||||
static std::shared_ptr<JoltCollider3D> Build(const PrimitiveList& list);
|
||||
|
||||
protected:
|
||||
template<typename T> const T* GetShapeSettingsAs() const;
|
||||
void ResetShapeSettings();
|
||||
void SetupShapeSettings(std::unique_ptr<JPH::ShapeSettings>&& shapeSettings);
|
||||
|
||||
private:
|
||||
static std::shared_ptr<JoltCollider3D> CreateGeomFromPrimitive(const Primitive& primitive);
|
||||
|
||||
std::unique_ptr<JPH::ShapeSettings> m_shapeSettings;
|
||||
};
|
||||
|
||||
/*********************************** Shapes ******************************************/
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltBoxCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltBoxCollider3D(const Vector3f& lengths, float convexRadius = 0.01f);
|
||||
~JoltBoxCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
Vector3f GetLengths() const;
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCapsuleCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltCapsuleCollider3D(float height, float radius);
|
||||
~JoltCapsuleCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetHeight() const;
|
||||
float GetRadius() const;
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCompoundCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
struct ChildCollider;
|
||||
|
||||
JoltCompoundCollider3D(std::vector<ChildCollider> childs);
|
||||
~JoltCompoundCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
const std::vector<ChildCollider>& GetGeoms() const;
|
||||
JoltColliderType3D GetType() const override;
|
||||
|
||||
struct ChildCollider
|
||||
{
|
||||
std::shared_ptr<JoltCollider3D> collider;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f offset = Vector3f::Zero();
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<ChildCollider> m_childs;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltConvexHullCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltConvexHullCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, float hullTolerance = 0.001f, float convexRadius = 0.f, float maxErrorConvexRadius = 0.05f);
|
||||
~JoltConvexHullCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltMeshCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltMeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt16> indices, std::size_t indexCount);
|
||||
JoltMeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt32> indices, std::size_t indexCount);
|
||||
~JoltMeshCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltSphereCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltSphereCollider3D(float radius);
|
||||
~JoltSphereCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetRadius() const;
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
/*********************************** Decorated ******************************************/
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltTranslatedRotatedCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
inline JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Vector3f& translation);
|
||||
inline JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Quaternionf& rotation);
|
||||
JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Vector3f& translation, const Quaternionf& rotation);
|
||||
~JoltTranslatedRotatedCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
JoltColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<JoltCollider3D> m_collider;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltCollider3D.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTCOLLIDER3D_HPP
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <NazaraUtils/Algorithm.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JPH::ShapeSettings* JoltCollider3D::GetShapeSettings() const
|
||||
{
|
||||
return m_shapeSettings.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* JoltCollider3D::GetShapeSettingsAs() const
|
||||
{
|
||||
return SafeCast<T*>(m_shapeSettings.get());
|
||||
}
|
||||
|
||||
|
||||
inline JoltTranslatedRotatedCollider3D::JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Vector3f& translation) :
|
||||
JoltTranslatedRotatedCollider3D(std::move(collider), translation, Quaternionf::Identity())
|
||||
{
|
||||
}
|
||||
|
||||
inline JoltTranslatedRotatedCollider3D::JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Quaternionf& rotation) :
|
||||
JoltTranslatedRotatedCollider3D(std::move(collider), Vector3f::Zero(), rotation)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTCONSTRAINT3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTCONSTRAINT3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.hpp>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class TwoBodyConstraint;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class JoltConstraint3D;
|
||||
|
||||
using JoltConstraint3DHandle = ObjectHandle<JoltConstraint3D>;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltConstraint3D : public HandledObject<JoltConstraint3D>
|
||||
{
|
||||
public:
|
||||
JoltConstraint3D(const JoltConstraint3D&) = delete;
|
||||
JoltConstraint3D(JoltConstraint3D&& constraint) noexcept;
|
||||
virtual ~JoltConstraint3D();
|
||||
|
||||
JoltRigidBody3D& GetBodyA();
|
||||
const JoltRigidBody3D& GetBodyA() const;
|
||||
JoltRigidBody3D& GetBodyB();
|
||||
const JoltRigidBody3D& GetBodyB() const;
|
||||
JoltPhysWorld3D& GetWorld();
|
||||
const JoltPhysWorld3D& GetWorld() const;
|
||||
|
||||
bool IsSingleBody() const;
|
||||
|
||||
JoltConstraint3D& operator=(const JoltConstraint3D&) = delete;
|
||||
JoltConstraint3D& operator=(JoltConstraint3D&& constraint) noexcept;
|
||||
|
||||
protected:
|
||||
JoltConstraint3D();
|
||||
|
||||
template<typename T> T* GetConstraint();
|
||||
template<typename T> const T* GetConstraint() const;
|
||||
|
||||
void SetupConstraint(std::unique_ptr<JPH::TwoBodyConstraint> constraint);
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
|
||||
std::unique_ptr<JPH::TwoBodyConstraint> m_constraint;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltDistanceConstraint3D : public JoltConstraint3D
|
||||
{
|
||||
public:
|
||||
JoltDistanceConstraint3D(JoltRigidBody3D& first, const Vector3f& pivot, float maxDist = -1.f, float minDist = -1.f);
|
||||
JoltDistanceConstraint3D(JoltRigidBody3D& first, JoltRigidBody3D& second, const Vector3f& pivot, float maxDist = -1.f, float minDist = -1.f);
|
||||
JoltDistanceConstraint3D(JoltRigidBody3D& first, JoltRigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor, float maxDist = -1.f, float minDist = -1.f);
|
||||
~JoltDistanceConstraint3D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
float GetFrequency() const;
|
||||
float GetMaxDistance() const;
|
||||
float GetMinDistance() const;
|
||||
|
||||
void SetDamping(float damping);
|
||||
void SetDistance(float minDist, float maxDist);
|
||||
void SetFrequency(float frequency);
|
||||
void SetMaxDistance(float maxDist);
|
||||
void SetMinDistance(float minDist);
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPivotConstraint3D : public JoltConstraint3D
|
||||
{
|
||||
public:
|
||||
JoltPivotConstraint3D(JoltRigidBody3D& first, const Vector3f& pivot);
|
||||
JoltPivotConstraint3D(JoltRigidBody3D& first, JoltRigidBody3D& second, const Vector3f& pivot);
|
||||
JoltPivotConstraint3D(JoltRigidBody3D& first, JoltRigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor);
|
||||
~JoltPivotConstraint3D() = default;
|
||||
|
||||
Vector3f GetFirstAnchor() const;
|
||||
Vector3f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector3f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector3f& secondAnchor);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltConstraint3D.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTCONSTRAINT3D_HPP
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTPHYSICSSTEPLISTENER_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTPHYSICSSTEPLISTENER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPhysicsStepListener
|
||||
{
|
||||
public:
|
||||
JoltPhysicsStepListener() = default;
|
||||
JoltPhysicsStepListener(const JoltPhysicsStepListener&) = delete;
|
||||
JoltPhysicsStepListener(JoltPhysicsStepListener&&) = delete;
|
||||
virtual ~JoltPhysicsStepListener();
|
||||
|
||||
virtual void PostSimulate(float elapsedTime);
|
||||
virtual void PreSimulate(float elapsedTime);
|
||||
|
||||
JoltPhysicsStepListener& operator=(const JoltPhysicsStepListener&) = delete;
|
||||
JoltPhysicsStepListener& operator=(JoltPhysicsStepListener&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysicsStepListener.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTPHYSICSSTEPLISTENER_HPP
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltRigidBody3D::JoltRigidBody3D(JoltPhysWorld3D& world, const DynamicSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline JoltRigidBody3D::JoltRigidBody3D(JoltPhysWorld3D& world, const StaticSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline void JoltRigidBody3D::DisableSimulation()
|
||||
{
|
||||
return EnableSimulation(false);
|
||||
}
|
||||
|
||||
inline void JoltRigidBody3D::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline JPH::Body* JoltRigidBody3D::GetBody()
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline const JPH::Body* JoltRigidBody3D::GetBody() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<JoltCollider3D>& JoltRigidBody3D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline JoltPhysWorld3D& JoltRigidBody3D::GetWorld() const
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline bool JoltRigidBody3D::IsSimulationEnabled() const
|
||||
{
|
||||
return m_isSimulationEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltPhysWorld3D& JoltPhysics3DSystem::GetPhysWorld()
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline const JoltPhysWorld3D& JoltPhysics3DSystem::GetPhysWorld() const
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline entt::handle JoltPhysics3DSystem::GetRigidBodyEntity(UInt32 bodyIndex) const
|
||||
{
|
||||
return entt::handle(m_registry, m_bodyIndicesToEntity[bodyIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GLOBAL_PHYSICS2D_HPP
|
||||
#define NAZARA_GLOBAL_PHYSICS2D_HPP
|
||||
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/Enums.hpp>
|
||||
#include <Nazara/Physics2D/PhysArbiter2D.hpp>
|
||||
#include <Nazara/Physics2D/PhysConstraint2D.hpp>
|
||||
#include <Nazara/Physics2D/Physics2D.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
|
||||
#ifdef NAZARA_ENTT
|
||||
|
||||
#include <Nazara/Physics2D/Components.hpp>
|
||||
#include <Nazara/Physics2D/Systems.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_GLOBAL_PHYSICS2D_HPP
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCOLLIDER2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCOLLIDER2D_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_COLLIDER2D_HPP
|
||||
#define NAZARA_PHYSICS2D_COLLIDER2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Enums.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/Enums.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
|
|
@ -23,18 +23,18 @@ struct cpShape;
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkRigidBody2D;
|
||||
class RigidBody2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API Collider2D
|
||||
{
|
||||
friend ChipmunkRigidBody2D;
|
||||
friend class ChipmunkCompoundCollider2D; //< See CompoundCollider2D::CreateShapes
|
||||
friend RigidBody2D;
|
||||
friend class CompoundCollider2D; //< See CompoundCollider2D::CreateShapes
|
||||
|
||||
public:
|
||||
inline ChipmunkCollider2D();
|
||||
ChipmunkCollider2D(const ChipmunkCollider2D&) = delete;
|
||||
ChipmunkCollider2D(ChipmunkCollider2D&&) = delete;
|
||||
virtual ~ChipmunkCollider2D();
|
||||
inline Collider2D();
|
||||
Collider2D(const Collider2D&) = delete;
|
||||
Collider2D(Collider2D&&) = delete;
|
||||
virtual ~Collider2D();
|
||||
|
||||
virtual Vector2f ComputeCenterOfMass() const = 0;
|
||||
virtual float ComputeMomentOfInertia(float mass) const = 0;
|
||||
|
|
@ -49,7 +49,7 @@ namespace Nz
|
|||
inline float GetFriction() const;
|
||||
inline Vector2f GetSurfaceVelocity() const;
|
||||
|
||||
virtual ChipmunkColliderType2D GetType() const = 0;
|
||||
virtual ColliderType2D GetType() const = 0;
|
||||
|
||||
inline bool IsTrigger() const;
|
||||
|
||||
|
|
@ -62,11 +62,11 @@ namespace Nz
|
|||
inline void SetSurfaceVelocity(const Vector2f& surfaceVelocity);
|
||||
inline void SetTrigger(bool trigger);
|
||||
|
||||
ChipmunkCollider2D& operator=(const ChipmunkCollider2D&) = delete;
|
||||
ChipmunkCollider2D& operator=(ChipmunkCollider2D&&) = delete;
|
||||
Collider2D& operator=(const Collider2D&) = delete;
|
||||
Collider2D& operator=(Collider2D&&) = delete;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnColliderRelease, const ChipmunkCollider2D* /*collider*/);
|
||||
NazaraSignal(OnColliderRelease, const Collider2D* /*collider*/);
|
||||
|
||||
protected:
|
||||
virtual std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const = 0;
|
||||
|
|
@ -84,11 +84,11 @@ namespace Nz
|
|||
virtual std::size_t GenerateShapes(cpBody* body, std::vector<cpShape*>* shapes) const;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkBoxCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API BoxCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkBoxCollider2D(const Vector2f& size, float radius = 0.f);
|
||||
ChipmunkBoxCollider2D(const Rectf& rect, float radius = 0.f);
|
||||
BoxCollider2D(const Vector2f& size, float radius = 0.f);
|
||||
BoxCollider2D(const Rectf& rect, float radius = 0.f);
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
|
@ -96,7 +96,7 @@ namespace Nz
|
|||
inline float GetRadius() const;
|
||||
inline const Rectf& GetRect() const;
|
||||
inline Vector2f GetSize() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
|
|
@ -105,17 +105,17 @@ namespace Nz
|
|||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkCircleCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API CircleCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkCircleCollider2D(float radius, const Vector2f& offset = Vector2f::Zero());
|
||||
CircleCollider2D(float radius, const Vector2f& offset = Vector2f::Zero());
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
inline const Vector2f& GetOffset() const;
|
||||
inline float GetRadius() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
|
|
@ -124,18 +124,18 @@ namespace Nz
|
|||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkCompoundCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API CompoundCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkCompoundCollider2D(std::vector<std::shared_ptr<ChipmunkCollider2D>> geoms);
|
||||
CompoundCollider2D(std::vector<std::shared_ptr<Collider2D>> geoms);
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
inline bool DoesOverrideCollisionProperties() const;
|
||||
|
||||
inline const std::vector<std::shared_ptr<ChipmunkCollider2D>>& GetGeoms() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
inline const std::vector<std::shared_ptr<Collider2D>>& GetGeoms() const;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
inline void OverridesCollisionProperties(bool shouldOverride);
|
||||
|
||||
|
|
@ -143,19 +143,19 @@ namespace Nz
|
|||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
std::size_t GenerateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
|
||||
std::vector<std::shared_ptr<ChipmunkCollider2D>> m_geoms;
|
||||
std::vector<std::shared_ptr<Collider2D>> m_geoms;
|
||||
bool m_doesOverrideCollisionProperties;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkConvexCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API ConvexCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkConvexCollider2D(SparsePtr<const Vector2f> vertices, std::size_t vertexCount, float radius = 0.f);
|
||||
ConvexCollider2D(SparsePtr<const Vector2f> vertices, std::size_t vertexCount, float radius = 0.f);
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
ColliderType2D GetType() const override;
|
||||
inline const std::vector<Vector2d>& GetVertices() const;
|
||||
|
||||
private:
|
||||
|
|
@ -165,25 +165,25 @@ namespace Nz
|
|||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkNullCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API NullCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkNullCollider2D() = default;
|
||||
NullCollider2D() = default;
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkSegmentCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API SegmentCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
inline ChipmunkSegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness = 1.f);
|
||||
inline ChipmunkSegmentCollider2D(const Vector2f& first, const Vector2f& firstNeighbor, const Vector2f& second, const Vector2f& secondNeighbor, float thickness = 1.f);
|
||||
inline SegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness = 1.f);
|
||||
inline SegmentCollider2D(const Vector2f& first, const Vector2f& firstNeighbor, const Vector2f& second, const Vector2f& secondNeighbor, float thickness = 1.f);
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
|
@ -194,7 +194,7 @@ namespace Nz
|
|||
inline const Vector2f& GetSecondPoint() const;
|
||||
inline const Vector2f& GetSecondPointNeighbor() const;
|
||||
inline float GetThickness() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
|
|
@ -207,6 +207,6 @@ namespace Nz
|
|||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.inl>
|
||||
#include <Nazara/Physics2D/Collider2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCOLLIDER2D_HPP
|
||||
#endif // NAZARA_PHYSICS2D_COLLIDER2D_HPP
|
||||
|
|
@ -0,0 +1,196 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Collider2D::Collider2D() :
|
||||
m_categoryMask(0xFFFFFFFF),
|
||||
m_collisionGroup(0),
|
||||
m_collisionMask(0xFFFFFFFF),
|
||||
m_surfaceVelocity(Vector2f::Zero()),
|
||||
m_trigger(false),
|
||||
m_elasticity(0.f),
|
||||
m_friction(0.f),
|
||||
m_collisionId(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline UInt32 Collider2D::GetCategoryMask() const
|
||||
{
|
||||
return m_categoryMask;
|
||||
}
|
||||
|
||||
inline UInt32 Collider2D::GetCollisionGroup() const
|
||||
{
|
||||
return m_collisionGroup;
|
||||
}
|
||||
|
||||
inline unsigned int Collider2D::GetCollisionId() const
|
||||
{
|
||||
return m_collisionId;
|
||||
}
|
||||
|
||||
inline UInt32 Collider2D::GetCollisionMask() const
|
||||
{
|
||||
return m_collisionMask;
|
||||
}
|
||||
|
||||
inline float Collider2D::GetElasticity() const
|
||||
{
|
||||
return m_elasticity;
|
||||
}
|
||||
|
||||
inline float Collider2D::GetFriction() const
|
||||
{
|
||||
return m_friction;
|
||||
}
|
||||
|
||||
inline Vector2f Collider2D::GetSurfaceVelocity() const
|
||||
{
|
||||
return m_surfaceVelocity;
|
||||
}
|
||||
|
||||
inline bool Collider2D::IsTrigger() const
|
||||
{
|
||||
return m_trigger;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCategoryMask(UInt32 categoryMask)
|
||||
{
|
||||
m_categoryMask = categoryMask;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionGroup(UInt32 groupId)
|
||||
{
|
||||
m_collisionGroup = groupId;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionId(unsigned int typeId)
|
||||
{
|
||||
m_collisionId = typeId;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionMask(UInt32 mask)
|
||||
{
|
||||
m_collisionMask = mask;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetElasticity(float elasticity)
|
||||
{
|
||||
m_elasticity = elasticity;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetFriction(float friction)
|
||||
{
|
||||
m_friction = friction;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||
{
|
||||
m_surfaceVelocity = surfaceVelocity;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetTrigger(bool trigger)
|
||||
{
|
||||
m_trigger = trigger;
|
||||
}
|
||||
|
||||
inline float BoxCollider2D::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
inline const Rectf& BoxCollider2D::GetRect() const
|
||||
{
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
inline Vector2f BoxCollider2D::GetSize() const
|
||||
{
|
||||
return m_rect.GetLengths();
|
||||
}
|
||||
|
||||
|
||||
inline const Vector2f& CircleCollider2D::GetOffset() const
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
inline float CircleCollider2D::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
|
||||
inline bool Nz::CompoundCollider2D::DoesOverrideCollisionProperties() const
|
||||
{
|
||||
return m_doesOverrideCollisionProperties;
|
||||
}
|
||||
|
||||
inline const std::vector<std::shared_ptr<Collider2D>>& CompoundCollider2D::GetGeoms() const
|
||||
{
|
||||
return m_geoms;
|
||||
}
|
||||
|
||||
inline void Nz::CompoundCollider2D::OverridesCollisionProperties(bool shouldOverride)
|
||||
{
|
||||
m_doesOverrideCollisionProperties = shouldOverride;
|
||||
}
|
||||
|
||||
|
||||
inline const std::vector<Vector2d>& ConvexCollider2D::GetVertices() const
|
||||
{
|
||||
return m_vertices;
|
||||
}
|
||||
|
||||
|
||||
SegmentCollider2D::SegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness) :
|
||||
SegmentCollider2D(first, first, second, second, thickness)
|
||||
{
|
||||
}
|
||||
|
||||
inline SegmentCollider2D::SegmentCollider2D(const Vector2f& first, const Vector2f& firstNeighbor, const Vector2f& second, const Vector2f& secondNeighbor, float thickness) :
|
||||
m_first(first),
|
||||
m_firstNeighbor(firstNeighbor),
|
||||
m_second(second),
|
||||
m_secondNeighbor(secondNeighbor),
|
||||
m_thickness(thickness)
|
||||
{
|
||||
}
|
||||
|
||||
inline const Vector2f& SegmentCollider2D::GetFirstPoint() const
|
||||
{
|
||||
return m_first;
|
||||
}
|
||||
|
||||
inline const Vector2f& SegmentCollider2D::GetFirstPointNeighbor() const
|
||||
{
|
||||
return m_firstNeighbor;
|
||||
}
|
||||
|
||||
inline float SegmentCollider2D::GetLength() const
|
||||
{
|
||||
return m_first.Distance(m_second);
|
||||
}
|
||||
|
||||
inline const Vector2f& SegmentCollider2D::GetSecondPoint() const
|
||||
{
|
||||
return m_second;
|
||||
}
|
||||
|
||||
inline const Vector2f& SegmentCollider2D::GetSecondPointNeighbor() const
|
||||
{
|
||||
return m_secondNeighbor;
|
||||
}
|
||||
|
||||
inline float SegmentCollider2D::GetThickness() const
|
||||
{
|
||||
return m_thickness;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - ChipmunkPhysics2D module
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
|
|
@ -26,9 +26,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_COMPONENTS_HPP
|
||||
#define NAZARA_PHYSICS2D_COMPONENTS_HPP
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Components/ChipmunkRigidBody2DComponent.hpp>
|
||||
#include <Nazara/Physics2D/Components/RigidBody2DComponent.hpp>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_HPP
|
||||
#endif // NAZARA_PHYSICS2D_COMPONENTS_HPP
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
|
||||
#define NAZARA_PHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS2D_API RigidBody2DComponent : public RigidBody2D
|
||||
{
|
||||
friend class Physics2DSystem;
|
||||
|
||||
public:
|
||||
inline RigidBody2DComponent(const RigidBody2D::DynamicSettings& settings);
|
||||
inline RigidBody2DComponent(const RigidBody2D::StaticSettings& settings);
|
||||
RigidBody2DComponent(const RigidBody2DComponent&) = delete;
|
||||
RigidBody2DComponent(RigidBody2DComponent&&) noexcept = default;
|
||||
~RigidBody2DComponent() = default;
|
||||
|
||||
RigidBody2DComponent& operator=(const RigidBody2DComponent&) = delete;
|
||||
RigidBody2DComponent& operator=(RigidBody2DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(PhysWorld2D& world);
|
||||
|
||||
using Setting = std::variant<RigidBody2D::DynamicSettings, RigidBody2D::StaticSettings>;
|
||||
std::unique_ptr<Setting> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/Components/RigidBody2DComponent.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RigidBody2DComponent::RigidBody2DComponent(const RigidBody2D::DynamicSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline RigidBody2DComponent::RigidBody2DComponent(const RigidBody2D::StaticSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline void RigidBody2DComponent::Construct(PhysWorld2D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Create(world, arg);
|
||||
}, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Nazara Engine - JoltPhysics3D module
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
|
|
@ -24,25 +24,25 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_CONFIG_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_CONFIG_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_CONFIG_HPP
|
||||
#define NAZARA_PHYSICS2D_CONFIG_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_JOLTPHYSICS3D_SAFE 1
|
||||
#define NAZARA_PHYSICS2D_SAFE 1
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/JoltPhysics3D/ConfigCheck.hpp>
|
||||
#include <Nazara/Physics2D/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_JOLTPHYSICS3D_API
|
||||
#define NAZARA_PHYSICS2D_API
|
||||
#else
|
||||
#ifdef NAZARA_JOLTPHYSICS3D_BUILD
|
||||
#define NAZARA_JOLTPHYSICS3D_API NAZARA_EXPORT
|
||||
#ifdef NAZARA_PHYSICS2D_BUILD
|
||||
#define NAZARA_PHYSICS2D_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_JOLTPHYSICS3D_API NAZARA_IMPORT
|
||||
#define NAZARA_PHYSICS2D_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_CONFIG_HPP
|
||||
#endif // NAZARA_PHYSICS2D_CONFIG_HPP
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CONFIGCHECK_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CONFIGCHECK_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_CONFIGCHECK_HPP
|
||||
#define NAZARA_PHYSICS2D_CONFIGCHECK_HPP
|
||||
|
||||
/// This file is used to check the constant values defined in Config.hpp
|
||||
|
||||
|
|
@ -16,4 +16,4 @@
|
|||
|
||||
#undef NazaraCheckTypeAndVal
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CONFIGCHECK_HPP
|
||||
#endif // NAZARA_PHYSICS2D_CONFIGCHECK_HPP
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_ENUMS_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_ENUMS_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_ENUMS_HPP
|
||||
#define NAZARA_PHYSICS2D_ENUMS_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum class ChipmunkColliderType2D
|
||||
enum class ColliderType2D
|
||||
{
|
||||
Box,
|
||||
Compound,
|
||||
|
|
@ -22,4 +22,4 @@ namespace Nz
|
|||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_ENUMS_HPP
|
||||
#endif // NAZARA_PHYSICS2D_ENUMS_HPP
|
||||
|
|
@ -1,35 +1,35 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKARBITER2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKARBITER2D_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_PHYSARBITER2D_HPP
|
||||
#define NAZARA_PHYSICS2D_PHYSARBITER2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
struct cpArbiter;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkRigidBody2D;
|
||||
class RigidBody2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkArbiter2D
|
||||
class NAZARA_PHYSICS2D_API PhysArbiter2D
|
||||
{
|
||||
public:
|
||||
inline ChipmunkArbiter2D(cpArbiter* arbiter);
|
||||
ChipmunkArbiter2D(const ChipmunkArbiter2D&) = delete;
|
||||
ChipmunkArbiter2D(ChipmunkArbiter2D&&) = default;
|
||||
~ChipmunkArbiter2D() = default;
|
||||
inline PhysArbiter2D(cpArbiter* arbiter);
|
||||
PhysArbiter2D(const PhysArbiter2D&) = delete;
|
||||
PhysArbiter2D(PhysArbiter2D&&) = default;
|
||||
~PhysArbiter2D() = default;
|
||||
|
||||
float ComputeTotalKinematicEnergy() const;
|
||||
Nz::Vector2f ComputeTotalImpulse() const;
|
||||
|
||||
std::pair<ChipmunkRigidBody2D*, ChipmunkRigidBody2D*> GetBodies() const;
|
||||
std::pair<RigidBody2D*, RigidBody2D*> GetBodies() const;
|
||||
|
||||
std::size_t GetContactCount() const;
|
||||
float GetContactDepth(std::size_t i) const;
|
||||
|
|
@ -48,14 +48,14 @@ namespace Nz
|
|||
void SetFriction(float friction);
|
||||
void SetSurfaceVelocity(const Vector2f& surfaceVelocity);
|
||||
|
||||
ChipmunkArbiter2D& operator=(const ChipmunkArbiter2D&) = delete;
|
||||
ChipmunkArbiter2D& operator=(ChipmunkArbiter2D&&) = default;
|
||||
PhysArbiter2D& operator=(const PhysArbiter2D&) = delete;
|
||||
PhysArbiter2D& operator=(PhysArbiter2D&&) = default;
|
||||
|
||||
private:
|
||||
MovablePtr<cpArbiter> m_arbiter;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.inl>
|
||||
#include <Nazara/Physics2D/PhysArbiter2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKARBITER2D_HPP
|
||||
#endif // NAZARA_PHYSICS2D_PHYSARBITER2D_HPP
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline PhysArbiter2D::PhysArbiter2D(cpArbiter* arbiter) :
|
||||
m_arbiter(arbiter)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,238 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS2D_PHYSCONSTRAINT2D_HPP
|
||||
#define NAZARA_PHYSICS2D_PHYSCONSTRAINT2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
struct cpConstraint;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PhysConstraint2D;
|
||||
|
||||
using PhysConstraint2DHandle = ObjectHandle<PhysConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysConstraint2D : public HandledObject<PhysConstraint2D>
|
||||
{
|
||||
public:
|
||||
PhysConstraint2D(const PhysConstraint2D&) = delete;
|
||||
PhysConstraint2D(PhysConstraint2D&& constraint) noexcept;
|
||||
virtual ~PhysConstraint2D();
|
||||
|
||||
void EnableBodyCollision(bool enable);
|
||||
|
||||
RigidBody2D& GetBodyA();
|
||||
const RigidBody2D& GetBodyA() const;
|
||||
RigidBody2D& GetBodyB();
|
||||
const RigidBody2D& GetBodyB() const;
|
||||
float GetErrorBias() const;
|
||||
float GetLastImpulse() const;
|
||||
float GetMaxBias() const;
|
||||
float GetMaxForce() const;
|
||||
PhysWorld2D& GetWorld();
|
||||
const PhysWorld2D& GetWorld() const;
|
||||
|
||||
bool IsBodyCollisionEnabled() const;
|
||||
bool IsSingleBody() const;
|
||||
|
||||
void SetErrorBias(float bias);
|
||||
void SetMaxBias(float bias);
|
||||
void SetMaxForce(float force);
|
||||
|
||||
PhysConstraint2D& operator=(const PhysConstraint2D&) = delete;
|
||||
PhysConstraint2D& operator=(PhysConstraint2D&& constraint) noexcept;
|
||||
|
||||
protected:
|
||||
PhysConstraint2D(PhysWorld2D* world, cpConstraint* constraint);
|
||||
|
||||
MovablePtr<cpConstraint> m_constraint;
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
};
|
||||
|
||||
class PhysDampedSpringConstraint2D;
|
||||
|
||||
using PhysDampedSpringConstraint2DHandle = ObjectHandle<PhysDampedSpringConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysDampedSpringConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysDampedSpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping);
|
||||
~PhysDampedSpringConstraint2D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
Vector2f GetFirstAnchor() const;
|
||||
float GetRestLength() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
float GetStiffness() const;
|
||||
|
||||
void SetDamping(float newDamping);
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetRestLength(float newLength);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
void SetStiffness(float newStiffness);
|
||||
};
|
||||
|
||||
class PhysDampedRotarySpringConstraint2D;
|
||||
|
||||
using PhysDampedRotarySpringConstraint2DHandle = ObjectHandle<PhysDampedRotarySpringConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysDampedRotarySpringConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysDampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& restAngle, float stiffness, float damping);
|
||||
~PhysDampedRotarySpringConstraint2D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
RadianAnglef GetRestAngle() const;
|
||||
float GetStiffness() const;
|
||||
|
||||
void SetDamping(float newDamping);
|
||||
void SetRestAngle(const RadianAnglef& newAngle);
|
||||
void SetStiffness(float newStiffness);
|
||||
};
|
||||
|
||||
class PhysGearConstraint2D;
|
||||
|
||||
using PhysGearConstraint2DHandle = ObjectHandle<PhysGearConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysGearConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysGearConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratio);
|
||||
~PhysGearConstraint2D() = default;
|
||||
|
||||
float GetPhase() const;
|
||||
float GetRatio() const;
|
||||
|
||||
void SetPhase(float phase);
|
||||
void SetRatio(float ratio);
|
||||
};
|
||||
|
||||
class PhysMotorConstraint2D;
|
||||
|
||||
using PhysMotorConstraint2DHandle = ObjectHandle<PhysMotorConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysMotorConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysMotorConstraint2D(RigidBody2D& first, RigidBody2D& second, float rate);
|
||||
~PhysMotorConstraint2D() = default;
|
||||
|
||||
float GetRate() const;
|
||||
void SetRate(float rate);
|
||||
};
|
||||
|
||||
class PhysPinConstraint2D;
|
||||
|
||||
using PhysPinConstraint2DHandle = ObjectHandle<PhysPinConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysPinConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysPinConstraint2D(RigidBody2D& body, const Vector2f& anchor);
|
||||
PhysPinConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
|
||||
~PhysPinConstraint2D() = default;
|
||||
|
||||
float GetDistance() const;
|
||||
Vector2f GetFirstAnchor() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetDistance(float newDistance);
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
|
||||
class PhysPivotConstraint2D;
|
||||
|
||||
using PhysPivotConstraint2DHandle = ObjectHandle<PhysPivotConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysPivotConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysPivotConstraint2D(RigidBody2D& body, const Vector2f& anchor);
|
||||
PhysPivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor);
|
||||
PhysPivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
|
||||
~PhysPivotConstraint2D() = default;
|
||||
|
||||
Vector2f GetFirstAnchor() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
|
||||
class PhysRatchetConstraint2D;
|
||||
|
||||
using PhysRatchetConstraint2DHandle = ObjectHandle<PhysRatchetConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysRatchetConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysRatchetConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratchet);
|
||||
~PhysRatchetConstraint2D() = default;
|
||||
|
||||
RadianAnglef GetAngle() const;
|
||||
float GetPhase() const;
|
||||
float GetRatchet() const;
|
||||
|
||||
void SetAngle(const RadianAnglef& angle);
|
||||
void SetPhase(float phase);
|
||||
void SetRatchet(float ratchet);
|
||||
};
|
||||
|
||||
class PhysRotaryLimitConstraint2D;
|
||||
|
||||
using PhysRotaryLimitConstraint2DHandle = ObjectHandle<PhysRotaryLimitConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysRotaryLimitConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysRotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& minAngle, const RadianAnglef& maxAngle);
|
||||
~PhysRotaryLimitConstraint2D() = default;
|
||||
|
||||
RadianAnglef GetMaxAngle() const;
|
||||
RadianAnglef GetMinAngle() const;
|
||||
|
||||
void SetMaxAngle(const RadianAnglef& maxAngle);
|
||||
void SetMinAngle(const RadianAnglef& minAngle);
|
||||
};
|
||||
|
||||
class PhysSlideConstraint2D;
|
||||
|
||||
using PhysSlideConstraint2DHandle = ObjectHandle<PhysSlideConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysSlideConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysSlideConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max);
|
||||
~PhysSlideConstraint2D() = default;
|
||||
|
||||
Vector2f GetFirstAnchor() const;
|
||||
float GetMaxDistance() const;
|
||||
float GetMinDistance() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetMaxDistance(float newMaxDistance);
|
||||
void SetMinDistance(float newMinDistance);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/PhysConstraint2D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS2D_PHYSCONSTRAINT2D_HPP
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKPHYSWORLD2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKPHYSWORLD2D_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_PHYSWORLD2D_HPP
|
||||
#define NAZARA_PHYSICS2D_PHYSWORLD2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <NazaraUtils/Bitset.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
|
|
@ -27,23 +27,23 @@ struct cpSpace;
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkArbiter2D;
|
||||
class PhysArbiter2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPhysWorld2D
|
||||
class NAZARA_PHYSICS2D_API PhysWorld2D
|
||||
{
|
||||
friend ChipmunkRigidBody2D;
|
||||
friend RigidBody2D;
|
||||
|
||||
using ContactEndCallback = std::function<void(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPostSolveCallback = std::function<void(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactStartCallback = std::function<bool(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactEndCallback = std::function<void(PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPostSolveCallback = std::function<void(PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactStartCallback = std::function<bool(PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
|
||||
using DebugDrawCircleCallback = std::function<void(const Vector2f& origin, const RadianAnglef& rotation, float radius, const Color& outlineColor, const Color& fillColor, void* userdata)>;
|
||||
using DebugDrawDotCallback = std::function<void(const Vector2f& origin, float radius, const Color& color, void* userdata)>;
|
||||
using DebugDrawPolygonCallback = std::function<void(const Vector2f* vertices, std::size_t vertexCount, float radius, const Color& outlineColor, const Color& fillColor, void* userdata)>;
|
||||
using DebugDrawSegmentCallback = std::function<void(const Vector2f& first, const Vector2f& second, const Color& color, void* userdata)>;
|
||||
using DebugDrawTickSegmentCallback = std::function<void(const Vector2f& first, const Vector2f& second, float thickness, const Color& outlineColor, const Color& fillColor, void* userdata)>;
|
||||
using DebugDrawGetColorCallback = std::function<Color(ChipmunkRigidBody2D& body, std::size_t shapeIndex, void* userdata)>;
|
||||
using DebugDrawGetColorCallback = std::function<Color(RigidBody2D& body, std::size_t shapeIndex, void* userdata)>;
|
||||
|
||||
public:
|
||||
struct ContactCallbacks;
|
||||
|
|
@ -51,10 +51,10 @@ namespace Nz
|
|||
struct NearestQueryResult;
|
||||
struct RaycastHit;
|
||||
|
||||
ChipmunkPhysWorld2D();
|
||||
ChipmunkPhysWorld2D(const ChipmunkPhysWorld2D&) = delete;
|
||||
ChipmunkPhysWorld2D(ChipmunkPhysWorld2D&&) = delete;
|
||||
~ChipmunkPhysWorld2D();
|
||||
PhysWorld2D();
|
||||
PhysWorld2D(const PhysWorld2D&) = delete;
|
||||
PhysWorld2D(PhysWorld2D&&) = delete;
|
||||
~PhysWorld2D();
|
||||
|
||||
void DebugDraw(const DebugDrawOptions& options, bool drawShapes = true, bool drawConstraints = true, bool drawCollisions = true) const;
|
||||
|
||||
|
|
@ -65,15 +65,15 @@ namespace Nz
|
|||
std::size_t GetMaxStepCount() const;
|
||||
Time GetStepSize() const;
|
||||
|
||||
bool NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, ChipmunkRigidBody2D** nearestBody = nullptr);
|
||||
bool NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RigidBody2D** nearestBody = nullptr);
|
||||
bool NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, NearestQueryResult* result);
|
||||
|
||||
void RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(const RaycastHit&)>& callback);
|
||||
bool RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RaycastHit>* hitInfos);
|
||||
bool RaycastQueryFirst(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RaycastHit* hitInfo = nullptr);
|
||||
|
||||
void RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(ChipmunkRigidBody2D*)>& callback);
|
||||
void RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<ChipmunkRigidBody2D*>* bodies);
|
||||
void RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(RigidBody2D*)>& callback);
|
||||
void RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RigidBody2D*>* bodies);
|
||||
|
||||
void RegisterCallbacks(unsigned int collisionId, ContactCallbacks callbacks);
|
||||
void RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, ContactCallbacks callbacks);
|
||||
|
|
@ -89,8 +89,8 @@ namespace Nz
|
|||
|
||||
void UseSpatialHash(float cellSize, std::size_t entityCount);
|
||||
|
||||
ChipmunkPhysWorld2D& operator=(const ChipmunkPhysWorld2D&) = delete;
|
||||
ChipmunkPhysWorld2D& operator=(ChipmunkPhysWorld2D&&) = delete;
|
||||
PhysWorld2D& operator=(const PhysWorld2D&) = delete;
|
||||
PhysWorld2D& operator=(PhysWorld2D&&) = delete;
|
||||
|
||||
struct ContactCallbacks
|
||||
{
|
||||
|
|
@ -119,7 +119,7 @@ namespace Nz
|
|||
|
||||
struct NearestQueryResult
|
||||
{
|
||||
ChipmunkRigidBody2D* nearestBody;
|
||||
RigidBody2D* nearestBody;
|
||||
Vector2f closestPoint;
|
||||
Vector2f fraction;
|
||||
float distance;
|
||||
|
|
@ -127,30 +127,30 @@ namespace Nz
|
|||
|
||||
struct RaycastHit
|
||||
{
|
||||
ChipmunkRigidBody2D* nearestBody;
|
||||
RigidBody2D* nearestBody;
|
||||
Vector2f hitPos;
|
||||
Vector2f hitNormal;
|
||||
float fraction;
|
||||
};
|
||||
|
||||
NazaraSignal(OnPhysWorld2DPreStep, const ChipmunkPhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
NazaraSignal(OnPhysWorld2DPostStep, const ChipmunkPhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
NazaraSignal(OnPhysWorld2DPreStep, const PhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
NazaraSignal(OnPhysWorld2DPostStep, const PhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
|
||||
private:
|
||||
using PostStep = std::function<void(ChipmunkRigidBody2D* body)>;
|
||||
using PostStep = std::function<void(RigidBody2D* body)>;
|
||||
|
||||
static constexpr std::size_t FreeBodyIdGrowRate = 256;
|
||||
|
||||
void DeferBodyAction(ChipmunkRigidBody2D& rigidBody, PostStep&& func);
|
||||
void DeferBodyAction(RigidBody2D& rigidBody, PostStep&& func);
|
||||
void InitCallbacks(cpCollisionHandler* handler, ContactCallbacks callbacks);
|
||||
inline UInt32 RegisterBody(ChipmunkRigidBody2D& rigidBody);
|
||||
inline UInt32 RegisterBody(RigidBody2D& rigidBody);
|
||||
inline void UnregisterBody(UInt32 bodyIndex);
|
||||
inline void UpdateBodyPointer(ChipmunkRigidBody2D& rigidBody);
|
||||
inline void UpdateBodyPointer(RigidBody2D& rigidBody);
|
||||
|
||||
std::size_t m_maxStepCount;
|
||||
std::unordered_map<cpCollisionHandler*, std::unique_ptr<ContactCallbacks>> m_callbacks;
|
||||
std::unordered_map<UInt32, std::vector<PostStep>> m_rigidBodyPostSteps;
|
||||
std::vector<ChipmunkRigidBody2D*> m_bodies;
|
||||
std::vector<RigidBody2D*> m_bodies;
|
||||
cpSpace* m_handle;
|
||||
Bitset<UInt64> m_freeBodyIndices;
|
||||
Time m_stepSize;
|
||||
|
|
@ -158,6 +158,6 @@ namespace Nz
|
|||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.inl>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKPHYSWORLD2D_HPP
|
||||
#endif // NAZARA_PHYSICS2D_PHYSWORLD2D_HPP
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <cassert>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline UInt32 ChipmunkPhysWorld2D::RegisterBody(ChipmunkRigidBody2D& rigidBody)
|
||||
inline UInt32 PhysWorld2D::RegisterBody(RigidBody2D& rigidBody)
|
||||
{
|
||||
std::size_t bodyIndex = m_freeBodyIndices.FindFirst();
|
||||
if (bodyIndex == m_freeBodyIndices.npos)
|
||||
|
|
@ -26,7 +26,7 @@ namespace Nz
|
|||
return SafeCast<UInt32>(bodyIndex);
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysWorld2D::UnregisterBody(UInt32 bodyIndex)
|
||||
inline void PhysWorld2D::UnregisterBody(UInt32 bodyIndex)
|
||||
{
|
||||
assert(!m_freeBodyIndices.Test(bodyIndex));
|
||||
m_freeBodyIndices.Set(bodyIndex, true);
|
||||
|
|
@ -36,7 +36,7 @@ namespace Nz
|
|||
m_rigidBodyPostSteps.erase(bodyIndex);
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysWorld2D::UpdateBodyPointer(ChipmunkRigidBody2D& rigidBody)
|
||||
inline void PhysWorld2D::UpdateBodyPointer(RigidBody2D& rigidBody)
|
||||
{
|
||||
UInt32 bodyIndex = rigidBody.GetBodyIndex();
|
||||
assert(m_bodies[bodyIndex]);
|
||||
|
|
@ -44,4 +44,4 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS2D_HPP
|
||||
#define NAZARA_PHYSICS2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS2D_API Physics2D : public ModuleBase<Physics2D>
|
||||
{
|
||||
friend ModuleBase;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
struct Config {};
|
||||
|
||||
Physics2D(Config /*config*/);
|
||||
~Physics2D() = default;
|
||||
|
||||
private:
|
||||
static Physics2D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PHYSICS2D_HPP
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKRIGIDBODY2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKRIGIDBODY2D_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_RIGIDBODY2D_HPP
|
||||
#define NAZARA_PHYSICS2D_RIGIDBODY2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
|
@ -21,22 +21,22 @@ struct cpBody;
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkArbiter2D;
|
||||
class ChipmunkPhysWorld2D;
|
||||
class PhysArbiter2D;
|
||||
class PhysWorld2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRigidBody2D
|
||||
class NAZARA_PHYSICS2D_API RigidBody2D
|
||||
{
|
||||
public:
|
||||
struct DynamicSettings;
|
||||
struct StaticSettings;
|
||||
|
||||
using VelocityFunc = std::function<void(ChipmunkRigidBody2D& body2D, const Vector2f& gravity, float damping, float deltaTime)>;
|
||||
using VelocityFunc = std::function<void(RigidBody2D& body2D, const Vector2f& gravity, float damping, float deltaTime)>;
|
||||
|
||||
inline ChipmunkRigidBody2D(ChipmunkPhysWorld2D& world, const DynamicSettings& settings);
|
||||
inline ChipmunkRigidBody2D(ChipmunkPhysWorld2D& world, const StaticSettings& settings);
|
||||
ChipmunkRigidBody2D(const ChipmunkRigidBody2D& object);
|
||||
ChipmunkRigidBody2D(ChipmunkRigidBody2D&& object) noexcept;
|
||||
inline ~ChipmunkRigidBody2D();
|
||||
inline RigidBody2D(PhysWorld2D& world, const DynamicSettings& settings);
|
||||
inline RigidBody2D(PhysWorld2D& world, const StaticSettings& settings);
|
||||
RigidBody2D(const RigidBody2D& object);
|
||||
RigidBody2D(RigidBody2D&& object) noexcept;
|
||||
inline ~RigidBody2D();
|
||||
|
||||
inline void AddForce(const Vector2f& force, CoordSys coordSys = CoordSys::Global);
|
||||
void AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys = CoordSys::Global);
|
||||
|
|
@ -48,7 +48,7 @@ namespace Nz
|
|||
|
||||
void EnableSimulation(bool simulation);
|
||||
|
||||
void ForEachArbiter(const FunctionRef<void(ChipmunkArbiter2D& /*arbiter*/)>& callback);
|
||||
void ForEachArbiter(const FunctionRef<void(PhysArbiter2D& /*arbiter*/)>& callback);
|
||||
void ForceSleep();
|
||||
|
||||
Rectf GetAABB() const;
|
||||
|
|
@ -56,7 +56,7 @@ namespace Nz
|
|||
inline UInt32 GetBodyIndex() const;
|
||||
float GetElasticity(std::size_t shapeIndex = 0) const;
|
||||
float GetFriction(std::size_t shapeIndex = 0) const;
|
||||
inline const std::shared_ptr<ChipmunkCollider2D>& GetGeom() const;
|
||||
inline const std::shared_ptr<Collider2D>& GetGeom() const;
|
||||
inline cpBody* GetHandle() const;
|
||||
inline float GetMass() const;
|
||||
Vector2f GetMassCenter(CoordSys coordSys = CoordSys::Local) const;
|
||||
|
|
@ -69,7 +69,7 @@ namespace Nz
|
|||
Vector2f GetSurfaceVelocity(std::size_t shapeIndex = 0) const;
|
||||
Vector2f GetVelocity() const;
|
||||
inline const VelocityFunc& GetVelocityFunction() const;
|
||||
inline ChipmunkPhysWorld2D* GetWorld() const;
|
||||
inline PhysWorld2D* GetWorld() const;
|
||||
|
||||
inline bool IsKinematic() const;
|
||||
inline bool IsSimulationEnabled() const;
|
||||
|
|
@ -83,7 +83,7 @@ namespace Nz
|
|||
void SetElasticity(std::size_t shapeIndex, float elasticity);
|
||||
void SetFriction(float friction);
|
||||
void SetFriction(std::size_t shapeIndex, float friction);
|
||||
void SetGeom(std::shared_ptr<ChipmunkCollider2D> geom, bool recomputeMoment = true, bool recomputeMassCenter = true);
|
||||
void SetGeom(std::shared_ptr<Collider2D> geom, bool recomputeMoment = true, bool recomputeMassCenter = true);
|
||||
void SetMass(float mass, bool recomputeMoment = true);
|
||||
void SetMassCenter(const Vector2f& center, CoordSys coordSys = CoordSys::Local);
|
||||
void SetMomentOfInertia(float moment);
|
||||
|
|
@ -107,15 +107,15 @@ namespace Nz
|
|||
|
||||
void Wakeup();
|
||||
|
||||
ChipmunkRigidBody2D& operator=(const ChipmunkRigidBody2D& object);
|
||||
ChipmunkRigidBody2D& operator=(ChipmunkRigidBody2D&& object) noexcept;
|
||||
RigidBody2D& operator=(const RigidBody2D& object);
|
||||
RigidBody2D& operator=(RigidBody2D&& object) noexcept;
|
||||
|
||||
static constexpr UInt32 InvalidBodyIndex = std::numeric_limits<UInt32>::max();
|
||||
static constexpr std::size_t InvalidShapeIndex = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
struct CommonSettings
|
||||
{
|
||||
std::shared_ptr<ChipmunkCollider2D> geom;
|
||||
std::shared_ptr<Collider2D> geom;
|
||||
RadianAnglef rotation = RadianAnglef::Zero();
|
||||
Vector2f position = Vector2f::Zero();
|
||||
bool initiallySleeping = false;
|
||||
|
|
@ -125,7 +125,7 @@ namespace Nz
|
|||
struct DynamicSettings : CommonSettings
|
||||
{
|
||||
DynamicSettings() = default;
|
||||
DynamicSettings(std::shared_ptr<ChipmunkCollider2D> collider, float mass_) :
|
||||
DynamicSettings(std::shared_ptr<Collider2D> collider, float mass_) :
|
||||
mass(mass_)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
|
|
@ -140,16 +140,16 @@ namespace Nz
|
|||
struct StaticSettings : CommonSettings
|
||||
{
|
||||
StaticSettings() = default;
|
||||
StaticSettings(std::shared_ptr<ChipmunkCollider2D> collider)
|
||||
StaticSettings(std::shared_ptr<Collider2D> collider)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
ChipmunkRigidBody2D() = default;
|
||||
void Create(ChipmunkPhysWorld2D& world, const DynamicSettings& settings);
|
||||
void Create(ChipmunkPhysWorld2D& world, const StaticSettings& settings);
|
||||
RigidBody2D() = default;
|
||||
void Create(PhysWorld2D& world, const DynamicSettings& settings);
|
||||
void Create(PhysWorld2D& world, const StaticSettings& settings);
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
|
|
@ -161,9 +161,9 @@ namespace Nz
|
|||
static void CopyShapeData(cpShape* from, cpShape* to);
|
||||
|
||||
std::vector<cpShape*> m_shapes;
|
||||
std::shared_ptr<ChipmunkCollider2D> m_geom;
|
||||
std::shared_ptr<Collider2D> m_geom;
|
||||
MovablePtr<cpBody> m_handle;
|
||||
MovablePtr<ChipmunkPhysWorld2D> m_world;
|
||||
MovablePtr<PhysWorld2D> m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
Vector2f m_positionOffset;
|
||||
VelocityFunc m_velocityFunc;
|
||||
|
|
@ -175,6 +175,6 @@ namespace Nz
|
|||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.inl>
|
||||
#include <Nazara/Physics2D/RigidBody2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKRIGIDBODY2D_HPP
|
||||
#endif // NAZARA_PHYSICS2D_RIGIDBODY2D_HPP
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RigidBody2D::RigidBody2D(PhysWorld2D& world, const DynamicSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline RigidBody2D::RigidBody2D(PhysWorld2D& world, const StaticSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline RigidBody2D::~RigidBody2D()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline void RigidBody2D::AddForce(const Vector2f& force, CoordSys coordSys)
|
||||
{
|
||||
return AddForce(force, GetMassCenter(coordSys), coordSys);
|
||||
}
|
||||
|
||||
inline void RigidBody2D::AddImpulse(const Vector2f& impulse, CoordSys coordSys)
|
||||
{
|
||||
return AddImpulse(impulse, GetMassCenter(coordSys), coordSys);
|
||||
}
|
||||
|
||||
inline UInt32 RigidBody2D::GetBodyIndex() const
|
||||
{
|
||||
return m_bodyIndex;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Collider2D>& RigidBody2D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline cpBody* RigidBody2D::GetHandle() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
inline float RigidBody2D::GetMass() const
|
||||
{
|
||||
return m_mass;
|
||||
}
|
||||
|
||||
inline const Vector2f& RigidBody2D::GetPositionOffset() const
|
||||
{
|
||||
return m_positionOffset;
|
||||
}
|
||||
|
||||
inline std::size_t RigidBody2D::GetShapeIndex(cpShape* shape) const
|
||||
{
|
||||
auto it = std::find(m_shapes.begin(), m_shapes.end(), shape);
|
||||
if (it == m_shapes.end())
|
||||
return InvalidShapeIndex;
|
||||
|
||||
return std::distance(m_shapes.begin(), it);
|
||||
}
|
||||
|
||||
inline std::size_t RigidBody2D::GetShapeCount() const
|
||||
{
|
||||
return m_shapes.size();
|
||||
}
|
||||
|
||||
inline const RigidBody2D::VelocityFunc& RigidBody2D::GetVelocityFunction() const
|
||||
{
|
||||
return m_velocityFunc;
|
||||
}
|
||||
|
||||
inline PhysWorld2D* RigidBody2D::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
|
||||
inline bool RigidBody2D::IsKinematic() const
|
||||
{
|
||||
return m_mass <= 0.f;
|
||||
}
|
||||
|
||||
inline bool RigidBody2D::IsSimulationEnabled() const
|
||||
{
|
||||
return m_isSimulationEnabled;
|
||||
}
|
||||
|
||||
inline bool RigidBody2D::IsStatic() const
|
||||
{
|
||||
return m_isStatic;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - JoltPhysics3D module
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
|
|
@ -26,9 +26,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_SYSTEMS_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_SYSTEMS_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_SYSTEMS_HPP
|
||||
#define NAZARA_PHYSICS2D_SYSTEMS_HPP
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.hpp>
|
||||
#include <Nazara/Physics2D/Systems/Physics2DSystem.hpp>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_SYSTEMS_HPP
|
||||
#endif // NAZARA_PHYSICS2D_SYSTEMS_HPP
|
||||
|
|
@ -1,43 +1,43 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_CHIPMUNKPHYSICS2DSYSTEM_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_CHIPMUNKPHYSICS2DSYSTEM_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
|
||||
#define NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Components/ChipmunkRigidBody2DComponent.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/Components/RigidBody2DComponent.hpp>
|
||||
#include <NazaraUtils/TypeList.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPhysics2DSystem
|
||||
class NAZARA_PHYSICS2D_API Physics2DSystem
|
||||
{
|
||||
using ContactEndCallback = std::function<void(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactPostSolveCallback = std::function<void(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactStartCallback = std::function<bool(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactEndCallback = std::function<void(PhysWorld2D& world, PhysArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactPostSolveCallback = std::function<void(PhysWorld2D& world, PhysArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(PhysWorld2D& world, PhysArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactStartCallback = std::function<bool(PhysWorld2D& world, PhysArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
|
||||
public:
|
||||
static constexpr Int64 ExecutionOrder = 0;
|
||||
using Components = TypeList<ChipmunkRigidBody2DComponent, class NodeComponent>;
|
||||
using Components = TypeList<RigidBody2DComponent, class NodeComponent>;
|
||||
|
||||
struct ContactCallbacks;
|
||||
struct NearestQueryResult;
|
||||
struct RaycastHit;
|
||||
|
||||
ChipmunkPhysics2DSystem(entt::registry& registry);
|
||||
ChipmunkPhysics2DSystem(const ChipmunkPhysics2DSystem&) = delete;
|
||||
ChipmunkPhysics2DSystem(ChipmunkPhysics2DSystem&&) = delete;
|
||||
~ChipmunkPhysics2DSystem();
|
||||
Physics2DSystem(entt::registry& registry);
|
||||
Physics2DSystem(const Physics2DSystem&) = delete;
|
||||
Physics2DSystem(Physics2DSystem&&) = delete;
|
||||
~Physics2DSystem();
|
||||
|
||||
inline ChipmunkPhysWorld2D& GetPhysWorld();
|
||||
inline const ChipmunkPhysWorld2D& GetPhysWorld() const;
|
||||
inline PhysWorld2D& GetPhysWorld();
|
||||
inline const PhysWorld2D& GetPhysWorld() const;
|
||||
inline entt::handle GetRigidBodyEntity(UInt32 bodyIndex) const;
|
||||
|
||||
inline bool NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, entt::handle* nearestEntity = nullptr);
|
||||
|
|
@ -55,8 +55,8 @@ namespace Nz
|
|||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
ChipmunkPhysics2DSystem& operator=(const ChipmunkPhysics2DSystem&) = delete;
|
||||
ChipmunkPhysics2DSystem& operator=(ChipmunkPhysics2DSystem&&) = delete;
|
||||
Physics2DSystem& operator=(const Physics2DSystem&) = delete;
|
||||
Physics2DSystem& operator=(Physics2DSystem&&) = delete;
|
||||
|
||||
struct ContactCallbacks
|
||||
{
|
||||
|
|
@ -67,12 +67,12 @@ namespace Nz
|
|||
void* userdata = nullptr;
|
||||
};
|
||||
|
||||
struct NearestQueryResult : ChipmunkPhysWorld2D::NearestQueryResult
|
||||
struct NearestQueryResult : PhysWorld2D::NearestQueryResult
|
||||
{
|
||||
entt::handle nearestEntity;
|
||||
};
|
||||
|
||||
struct RaycastHit : ChipmunkPhysWorld2D::RaycastHit
|
||||
struct RaycastHit : PhysWorld2D::RaycastHit
|
||||
{
|
||||
entt::handle nearestEntity;
|
||||
};
|
||||
|
|
@ -80,17 +80,17 @@ namespace Nz
|
|||
private:
|
||||
void OnBodyConstruct(entt::registry& registry, entt::entity entity);
|
||||
void OnBodyDestruct(entt::registry& registry, entt::entity entity);
|
||||
ChipmunkPhysWorld2D::ContactCallbacks SetupContactCallbacks(ContactCallbacks callbacks);
|
||||
PhysWorld2D::ContactCallbacks SetupContactCallbacks(ContactCallbacks callbacks);
|
||||
|
||||
std::vector<entt::entity> m_bodyIndicesToEntity;
|
||||
entt::registry& m_registry;
|
||||
entt::observer m_physicsConstructObserver;
|
||||
entt::scoped_connection m_bodyConstructConnection;
|
||||
entt::scoped_connection m_bodyDestructConnection;
|
||||
ChipmunkPhysWorld2D m_physWorld;
|
||||
PhysWorld2D m_physWorld;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.inl>
|
||||
#include <Nazara/Physics2D/Systems/Physics2DSystem.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_CHIPMUNKPHYSICS2DSYSTEM_HPP
|
||||
#endif // NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
|
||||
|
|
@ -1,29 +1,29 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkPhysWorld2D& ChipmunkPhysics2DSystem::GetPhysWorld()
|
||||
inline PhysWorld2D& Physics2DSystem::GetPhysWorld()
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline const ChipmunkPhysWorld2D& ChipmunkPhysics2DSystem::GetPhysWorld() const
|
||||
inline const PhysWorld2D& Physics2DSystem::GetPhysWorld() const
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline entt::handle ChipmunkPhysics2DSystem::GetRigidBodyEntity(UInt32 bodyIndex) const
|
||||
inline entt::handle Physics2DSystem::GetRigidBodyEntity(UInt32 bodyIndex) const
|
||||
{
|
||||
return entt::handle(m_registry, m_bodyIndicesToEntity[bodyIndex]);
|
||||
}
|
||||
|
||||
inline bool ChipmunkPhysics2DSystem::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, entt::handle* nearestEntity)
|
||||
inline bool Physics2DSystem::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, entt::handle* nearestEntity)
|
||||
{
|
||||
ChipmunkRigidBody2D* nearestBody;
|
||||
RigidBody2D* nearestBody;
|
||||
if (!m_physWorld.NearestBodyQuery(from, maxDistance, collisionGroup, categoryMask, collisionMask, &nearestBody))
|
||||
return false;
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
inline bool ChipmunkPhysics2DSystem::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, NearestQueryResult* result)
|
||||
inline bool Physics2DSystem::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, NearestQueryResult* result)
|
||||
{
|
||||
if (!m_physWorld.NearestBodyQuery(from, maxDistance, collisionGroup, categoryMask, collisionMask, result))
|
||||
return false;
|
||||
|
|
@ -54,12 +54,12 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(const RaycastHit&)>& callback)
|
||||
inline void Physics2DSystem::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(const RaycastHit&)>& callback)
|
||||
{
|
||||
return m_physWorld.RaycastQuery(from, to, radius, collisionGroup, categoryMask, collisionMask, [&](const ChipmunkPhysWorld2D::RaycastHit& hitInfo)
|
||||
return m_physWorld.RaycastQuery(from, to, radius, collisionGroup, categoryMask, collisionMask, [&](const PhysWorld2D::RaycastHit& hitInfo)
|
||||
{
|
||||
RaycastHit extendedHitInfo;
|
||||
static_cast<ChipmunkPhysWorld2D::RaycastHit&>(extendedHitInfo) = hitInfo;
|
||||
static_cast<PhysWorld2D::RaycastHit&>(extendedHitInfo) = hitInfo;
|
||||
|
||||
if (extendedHitInfo.nearestBody)
|
||||
extendedHitInfo.nearestEntity = GetRigidBodyEntity(extendedHitInfo.nearestBody->GetBodyIndex());
|
||||
|
|
@ -68,7 +68,7 @@ namespace Nz
|
|||
});
|
||||
}
|
||||
|
||||
inline bool ChipmunkPhysics2DSystem::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RaycastHit>* hitInfos)
|
||||
inline bool Physics2DSystem::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RaycastHit>* hitInfos)
|
||||
{
|
||||
NazaraAssert(hitInfos, "invalid output pointer");
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ namespace Nz
|
|||
return hitInfos->size() != originalSize;
|
||||
}
|
||||
|
||||
inline bool ChipmunkPhysics2DSystem::RaycastQueryFirst(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RaycastHit* hitInfo)
|
||||
inline bool Physics2DSystem::RaycastQueryFirst(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RaycastHit* hitInfo)
|
||||
{
|
||||
if (!m_physWorld.RaycastQueryFirst(from, to, radius, collisionGroup, categoryMask, collisionMask, hitInfo))
|
||||
return false;
|
||||
|
|
@ -98,33 +98,33 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(entt::handle)>& callback)
|
||||
inline void Physics2DSystem::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(entt::handle)>& callback)
|
||||
{
|
||||
return m_physWorld.RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, [&](ChipmunkRigidBody2D* body)
|
||||
return m_physWorld.RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, [&](RigidBody2D* body)
|
||||
{
|
||||
callback(GetRigidBodyEntity(body->GetBodyIndex()));
|
||||
});
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<entt::handle>* bodies)
|
||||
inline void Physics2DSystem::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<entt::handle>* bodies)
|
||||
{
|
||||
NazaraAssert(bodies, "invalid output pointer");
|
||||
|
||||
return m_physWorld.RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, [&](ChipmunkRigidBody2D* body)
|
||||
return m_physWorld.RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, [&](RigidBody2D* body)
|
||||
{
|
||||
bodies->emplace_back(GetRigidBodyEntity(body->GetBodyIndex()));
|
||||
});
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RegisterCallbacks(unsigned int collisionId, ContactCallbacks callbacks)
|
||||
inline void Physics2DSystem::RegisterCallbacks(unsigned int collisionId, ContactCallbacks callbacks)
|
||||
{
|
||||
return m_physWorld.RegisterCallbacks(collisionId, SetupContactCallbacks(std::move(callbacks)));
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, ContactCallbacks callbacks)
|
||||
inline void Physics2DSystem::RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, ContactCallbacks callbacks)
|
||||
{
|
||||
return m_physWorld.RegisterCallbacks(collisionIdA, collisionIdB, SetupContactCallbacks(std::move(callbacks)));
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - Physics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GLOBAL_PHYSICS3D_HPP
|
||||
#define NAZARA_GLOBAL_PHYSICS3D_HPP
|
||||
|
||||
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Enums.hpp>
|
||||
#include <Nazara/Physics3D/PhysCharacter3D.hpp>
|
||||
#include <Nazara/Physics3D/PhysConstraint3D.hpp>
|
||||
#include <Nazara/Physics3D/Physics3D.hpp>
|
||||
#include <Nazara/Physics3D/Physics3DBody.hpp>
|
||||
#include <Nazara/Physics3D/Physiscs3DStepListener.hpp>
|
||||
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
|
||||
#ifdef NAZARA_ENTT
|
||||
|
||||
#include <Nazara/Physics3D/Components.hpp>
|
||||
#include <Nazara/Physics3D/Systems.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_GLOBAL_PHYSICS3D_HPP
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_COLLIDER3D_HPP
|
||||
#define NAZARA_PHYSICS3D_COLLIDER3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Enums.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class ShapeSettings;
|
||||
class BoxShapeSettings;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PrimitiveList;
|
||||
class StaticMesh;
|
||||
struct Primitive;
|
||||
|
||||
class NAZARA_PHYSICS3D_API Collider3D
|
||||
{
|
||||
public:
|
||||
Collider3D();
|
||||
Collider3D(const Collider3D&) = delete;
|
||||
Collider3D(Collider3D&&) = delete;
|
||||
virtual ~Collider3D();
|
||||
|
||||
virtual void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix = Matrix4f::Identity()) const = 0;
|
||||
|
||||
virtual std::shared_ptr<StaticMesh> GenerateDebugMesh() const;
|
||||
|
||||
inline JPH::ShapeSettings* GetShapeSettings() const;
|
||||
virtual ColliderType3D GetType() const = 0;
|
||||
|
||||
Collider3D& operator=(const Collider3D&) = delete;
|
||||
Collider3D& operator=(Collider3D&&) = delete;
|
||||
|
||||
static std::shared_ptr<Collider3D> Build(const PrimitiveList& list);
|
||||
|
||||
protected:
|
||||
template<typename T> const T* GetShapeSettingsAs() const;
|
||||
void ResetShapeSettings();
|
||||
void SetupShapeSettings(std::unique_ptr<JPH::ShapeSettings>&& shapeSettings);
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Collider3D> CreateGeomFromPrimitive(const Primitive& primitive);
|
||||
|
||||
std::unique_ptr<JPH::ShapeSettings> m_shapeSettings;
|
||||
};
|
||||
|
||||
/*********************************** Shapes ******************************************/
|
||||
|
||||
class NAZARA_PHYSICS3D_API BoxCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
BoxCollider3D(const Vector3f& lengths, float convexRadius = 0.01f);
|
||||
~BoxCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
Vector3f GetLengths() const;
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API CapsuleCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
CapsuleCollider3D(float height, float radius);
|
||||
~CapsuleCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetHeight() const;
|
||||
float GetRadius() const;
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API CompoundCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
struct ChildCollider;
|
||||
|
||||
CompoundCollider3D(std::vector<ChildCollider> childs);
|
||||
~CompoundCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
const std::vector<ChildCollider>& GetGeoms() const;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
struct ChildCollider
|
||||
{
|
||||
std::shared_ptr<Collider3D> collider;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f offset = Vector3f::Zero();
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<ChildCollider> m_childs;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API ConvexHullCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
ConvexHullCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, float hullTolerance = 0.001f, float convexRadius = 0.f, float maxErrorConvexRadius = 0.05f);
|
||||
~ConvexHullCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API MeshCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
MeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt16> indices, std::size_t indexCount);
|
||||
MeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt32> indices, std::size_t indexCount);
|
||||
~MeshCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API SphereCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
SphereCollider3D(float radius);
|
||||
~SphereCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetRadius() const;
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
/*********************************** Decorated ******************************************/
|
||||
|
||||
class NAZARA_PHYSICS3D_API TranslatedRotatedCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
inline TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Vector3f& translation);
|
||||
inline TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Quaternionf& rotation);
|
||||
TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Vector3f& translation, const Quaternionf& rotation);
|
||||
~TranslatedRotatedCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Collider3D> m_collider;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Collider3D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_COLLIDER3D_HPP
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <NazaraUtils/Algorithm.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JPH::ShapeSettings* Collider3D::GetShapeSettings() const
|
||||
{
|
||||
return m_shapeSettings.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* Collider3D::GetShapeSettingsAs() const
|
||||
{
|
||||
return SafeCast<T*>(m_shapeSettings.get());
|
||||
}
|
||||
|
||||
|
||||
inline TranslatedRotatedCollider3D::TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Vector3f& translation) :
|
||||
TranslatedRotatedCollider3D(std::move(collider), translation, Quaternionf::Identity())
|
||||
{
|
||||
}
|
||||
|
||||
inline TranslatedRotatedCollider3D::TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Quaternionf& rotation) :
|
||||
TranslatedRotatedCollider3D(std::move(collider), Vector3f::Zero(), rotation)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - JoltPhysics3D module
|
||||
Nazara Engine - Physics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
|
|
@ -26,10 +26,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_COMPONENTS_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_COMPONENTS_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_COMPONENTS_HPP
|
||||
#define NAZARA_PHYSICS3D_COMPONENTS_HPP
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltCharacterComponent.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.hpp>
|
||||
#include <Nazara/Physics3D/Components/PhysCharacter3DComponent.hpp>
|
||||
#include <Nazara/Physics3D/Components/RigidBody3DComponent.hpp>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_COMPONENTS_HPP
|
||||
#endif // NAZARA_PHYSICS3D_COMPONENTS_HPP
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_COMPONENTS_PHYSCHARACTER3DCOMPONENT_HPP
|
||||
#define NAZARA_PHYSICS3D_COMPONENTS_PHYSCHARACTER3DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics3D/PhysCharacter3D.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API PhysCharacter3DComponent : public PhysCharacter3D
|
||||
{
|
||||
friend class Physics3DSystem;
|
||||
|
||||
public:
|
||||
inline PhysCharacter3DComponent(const PhysCharacter3D::Settings& settings);
|
||||
PhysCharacter3DComponent(const PhysCharacter3DComponent&) = default;
|
||||
PhysCharacter3DComponent(PhysCharacter3DComponent&&) noexcept = default;
|
||||
~PhysCharacter3DComponent() = default;
|
||||
|
||||
PhysCharacter3DComponent& operator=(const PhysCharacter3DComponent&) = default;
|
||||
PhysCharacter3DComponent& operator=(PhysCharacter3DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(PhysWorld3D& world);
|
||||
|
||||
std::unique_ptr<PhysCharacter3D::Settings> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Components/PhysCharacter3DComponent.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_COMPONENTS_PHYSCHARACTER3DCOMPONENT_HPP
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline PhysCharacter3DComponent::PhysCharacter3DComponent(const PhysCharacter3D::Settings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<PhysCharacter3D::Settings>(settings);
|
||||
}
|
||||
|
||||
inline void PhysCharacter3DComponent::Construct(PhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
Create(world, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_COMPONENTS_RIGIDBODY3DCOMPONENT_HPP
|
||||
#define NAZARA_PHYSICS3D_COMPONENTS_RIGIDBODY3DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API RigidBody3DComponent : public RigidBody3D
|
||||
{
|
||||
friend class Physics3DSystem;
|
||||
|
||||
public:
|
||||
inline RigidBody3DComponent(const RigidBody3D::DynamicSettings& settings);
|
||||
inline RigidBody3DComponent(const RigidBody3D::StaticSettings& settings);
|
||||
RigidBody3DComponent(const RigidBody3DComponent&) = default;
|
||||
RigidBody3DComponent(RigidBody3DComponent&&) noexcept = default;
|
||||
~RigidBody3DComponent() = default;
|
||||
|
||||
RigidBody3DComponent& operator=(const RigidBody3DComponent&) = default;
|
||||
RigidBody3DComponent& operator=(RigidBody3DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(PhysWorld3D& world);
|
||||
|
||||
using Setting = std::variant<RigidBody3D::DynamicSettings, RigidBody3D::StaticSettings>;
|
||||
std::unique_ptr<Setting> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Components/RigidBody3DComponent.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_COMPONENTS_RIGIDBODY3DCOMPONENT_HPP
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <cassert>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RigidBody3DComponent::RigidBody3DComponent(const RigidBody3D::DynamicSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline RigidBody3DComponent::RigidBody3DComponent(const RigidBody3D::StaticSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline void RigidBody3DComponent::Construct(PhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Create(world, arg);
|
||||
}, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Nazara Engine - ChipmunkPhysics2D module
|
||||
Nazara Engine - Physics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
|
|
@ -24,25 +24,25 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CONFIG_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CONFIG_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_CONFIG_HPP
|
||||
#define NAZARA_PHYSICS3D_CONFIG_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_SAFE 1
|
||||
#define NAZARA_PHYSICS3D_SAFE 1
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/ChipmunkPhysics2D/ConfigCheck.hpp>
|
||||
#include <Nazara/Physics3D/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_API
|
||||
#define NAZARA_PHYSICS3D_API
|
||||
#else
|
||||
#ifdef NAZARA_CHIPMUNKPHYSICS2D_BUILD
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_API NAZARA_EXPORT
|
||||
#ifdef NAZARA_PHYSICS3D_BUILD
|
||||
#define NAZARA_PHYSICS3D_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_API NAZARA_IMPORT
|
||||
#define NAZARA_PHYSICS3D_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CONFIG_HPP
|
||||
#endif // NAZARA_PHYSICS3D_CONFIG_HPP
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_CONFIGCHECK_HPP
|
||||
#define NAZARA_PHYSICS3D_CONFIGCHECK_HPP
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_CONFIGCHECK_HPP
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_ENUMS_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_ENUMS_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_ENUMS_HPP
|
||||
#define NAZARA_PHYSICS3D_ENUMS_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum class JoltColliderType3D
|
||||
enum class ColliderType3D
|
||||
{
|
||||
Box,
|
||||
Capsule,
|
||||
|
|
@ -24,11 +24,11 @@ namespace Nz
|
|||
Max = TranslatedRotatedDecoration
|
||||
};
|
||||
|
||||
enum class JoltMotionQuality
|
||||
enum class PhysMotionQuality3D
|
||||
{
|
||||
Discrete,
|
||||
LinearCast
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_ENUMS_HPP
|
||||
#endif // NAZARA_PHYSICS3D_ENUMS_HPP
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSCHARACTER3D_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSCHARACTER3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Physics3DBody.hpp>
|
||||
#include <Nazara/Physics3D/Physiscs3DStepListener.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class Character;
|
||||
class Body;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PhysCharacter3DImpl;
|
||||
class Collider3D;
|
||||
class PhysWorld3D;
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysCharacter3D : public Physics3DBody, public Physiscs3DStepListener
|
||||
{
|
||||
friend PhysWorld3D;
|
||||
|
||||
public:
|
||||
struct Settings;
|
||||
|
||||
PhysCharacter3D(PhysWorld3D& physWorld, const Settings& settings);
|
||||
PhysCharacter3D(const PhysCharacter3D&) = delete;
|
||||
PhysCharacter3D(PhysCharacter3D&& character) noexcept;
|
||||
~PhysCharacter3D();
|
||||
|
||||
inline void DisableSleeping();
|
||||
void EnableSleeping(bool enable);
|
||||
|
||||
UInt32 GetBodyIndex() const override;
|
||||
inline const std::shared_ptr<Collider3D>& GetCollider() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
inline PhysWorld3D& GetPhysWorld();
|
||||
inline const PhysWorld3D& GetPhysWorld() const;
|
||||
Vector3f GetPosition() const;
|
||||
std::pair<Vector3f, Quaternionf> GetPositionAndRotation() const;
|
||||
Quaternionf GetRotation() const;
|
||||
Vector3f GetUp() const;
|
||||
|
||||
bool IsOnGround() const;
|
||||
|
||||
void SetFriction(float friction);
|
||||
inline void SetImpl(std::shared_ptr<PhysCharacter3DImpl> characterImpl);
|
||||
void SetLinearVelocity(const Vector3f& linearVel);
|
||||
void SetRotation(const Quaternionf& rotation);
|
||||
void SetUp(const Vector3f& up);
|
||||
|
||||
void TeleportTo(const Vector3f& position, const Quaternionf& rotation);
|
||||
|
||||
void WakeUp();
|
||||
|
||||
PhysCharacter3D& operator=(const PhysCharacter3D&) = delete;
|
||||
PhysCharacter3D& operator=(PhysCharacter3D&& character) noexcept;
|
||||
|
||||
struct Settings
|
||||
{
|
||||
std::shared_ptr<Collider3D> collider;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
};
|
||||
|
||||
protected:
|
||||
PhysCharacter3D();
|
||||
|
||||
void Create(PhysWorld3D& physWorld, const Settings& settings);
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
void PostSimulate(float elapsedTime) override;
|
||||
void PreSimulate(float elapsedTime) override;
|
||||
|
||||
std::shared_ptr<PhysCharacter3DImpl> m_impl;
|
||||
std::shared_ptr<Collider3D> m_collider;
|
||||
std::unique_ptr<JPH::Character> m_character;
|
||||
MovablePtr<PhysWorld3D> m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysCharacter3DImpl
|
||||
{
|
||||
public:
|
||||
PhysCharacter3DImpl() = default;
|
||||
PhysCharacter3DImpl(const PhysCharacter3DImpl&) = delete;
|
||||
PhysCharacter3DImpl(PhysCharacter3DImpl&&) = delete;
|
||||
virtual ~PhysCharacter3DImpl();
|
||||
|
||||
virtual void PostSimulate(PhysCharacter3D& character, float elapsedTime);
|
||||
virtual void PreSimulate(PhysCharacter3D& character, float elapsedTime);
|
||||
|
||||
PhysCharacter3DImpl& operator=(const PhysCharacter3DImpl&) = delete;
|
||||
PhysCharacter3DImpl& operator=(PhysCharacter3DImpl&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/PhysCharacter3D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_PHYSCHARACTER3D_HPP
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void PhysCharacter3D::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Collider3D>& PhysCharacter3D::GetCollider() const
|
||||
{
|
||||
return m_collider;
|
||||
}
|
||||
|
||||
inline PhysWorld3D& PhysCharacter3D::GetPhysWorld()
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline const PhysWorld3D& PhysCharacter3D::GetPhysWorld() const
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline void PhysCharacter3D::SetImpl(std::shared_ptr<PhysCharacter3DImpl> characterImpl)
|
||||
{
|
||||
m_impl = std::move(characterImpl);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSCONSTRAINT3D_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSCONSTRAINT3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class TwoBodyConstraint;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PhysConstraint3D;
|
||||
|
||||
using PhysConstraint3DHandle = ObjectHandle<PhysConstraint3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysConstraint3D : public HandledObject<PhysConstraint3D>
|
||||
{
|
||||
public:
|
||||
PhysConstraint3D(const PhysConstraint3D&) = delete;
|
||||
PhysConstraint3D(PhysConstraint3D&& constraint) noexcept;
|
||||
virtual ~PhysConstraint3D();
|
||||
|
||||
RigidBody3D& GetBodyA();
|
||||
const RigidBody3D& GetBodyA() const;
|
||||
RigidBody3D& GetBodyB();
|
||||
const RigidBody3D& GetBodyB() const;
|
||||
PhysWorld3D& GetWorld();
|
||||
const PhysWorld3D& GetWorld() const;
|
||||
|
||||
bool IsSingleBody() const;
|
||||
|
||||
PhysConstraint3D& operator=(const PhysConstraint3D&) = delete;
|
||||
PhysConstraint3D& operator=(PhysConstraint3D&& constraint) noexcept;
|
||||
|
||||
protected:
|
||||
PhysConstraint3D();
|
||||
|
||||
template<typename T> T* GetConstraint();
|
||||
template<typename T> const T* GetConstraint() const;
|
||||
|
||||
void SetupConstraint(std::unique_ptr<JPH::TwoBodyConstraint> constraint);
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
|
||||
std::unique_ptr<JPH::TwoBodyConstraint> m_constraint;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysDistanceConstraint3D : public PhysConstraint3D
|
||||
{
|
||||
public:
|
||||
PhysDistanceConstraint3D(RigidBody3D& first, const Vector3f& pivot, float maxDist = -1.f, float minDist = -1.f);
|
||||
PhysDistanceConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& pivot, float maxDist = -1.f, float minDist = -1.f);
|
||||
PhysDistanceConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor, float maxDist = -1.f, float minDist = -1.f);
|
||||
~PhysDistanceConstraint3D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
float GetFrequency() const;
|
||||
float GetMaxDistance() const;
|
||||
float GetMinDistance() const;
|
||||
|
||||
void SetDamping(float damping);
|
||||
void SetDistance(float minDist, float maxDist);
|
||||
void SetFrequency(float frequency);
|
||||
void SetMaxDistance(float maxDist);
|
||||
void SetMinDistance(float minDist);
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysPivotConstraint3D : public PhysConstraint3D
|
||||
{
|
||||
public:
|
||||
PhysPivotConstraint3D(RigidBody3D& first, const Vector3f& pivot);
|
||||
PhysPivotConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& pivot);
|
||||
PhysPivotConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor);
|
||||
~PhysPivotConstraint3D() = default;
|
||||
|
||||
Vector3f GetFirstAnchor() const;
|
||||
Vector3f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector3f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector3f& secondAnchor);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/PhysConstraint3D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_PHYSCONSTRAINT3D_HPP
|
||||
|
|
@ -1,22 +1,22 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T>
|
||||
T* JoltConstraint3D::GetConstraint()
|
||||
T* PhysConstraint3D::GetConstraint()
|
||||
{
|
||||
return SafeCast<T*>(m_constraint.get());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* JoltConstraint3D::GetConstraint() const
|
||||
const T* PhysConstraint3D::GetConstraint() const
|
||||
{
|
||||
return SafeCast<const T*>(m_constraint.get());
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSWORLD3D_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSWORLD3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <atomic>
|
||||
|
|
@ -27,31 +27,31 @@ namespace JPH
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class JoltAbstractBody;
|
||||
class JoltCharacter;
|
||||
class JoltCharacterImpl;
|
||||
class JoltCollider3D;
|
||||
class JoltPhysicsStepListener;
|
||||
class JoltRigidBody3D;
|
||||
class Physics3DBody;
|
||||
class PhysCharacter3D;
|
||||
class PhysCharacter3DImpl;
|
||||
class Collider3D;
|
||||
class Physiscs3DStepListener;
|
||||
class RigidBody3D;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPhysWorld3D
|
||||
class NAZARA_PHYSICS3D_API PhysWorld3D
|
||||
{
|
||||
friend JoltCharacter;
|
||||
friend JoltRigidBody3D;
|
||||
friend PhysCharacter3D;
|
||||
friend RigidBody3D;
|
||||
|
||||
public:
|
||||
struct PointCollisionInfo;
|
||||
struct RaycastHit;
|
||||
struct ShapeCollisionInfo;
|
||||
|
||||
JoltPhysWorld3D();
|
||||
JoltPhysWorld3D(const JoltPhysWorld3D&) = delete;
|
||||
JoltPhysWorld3D(JoltPhysWorld3D&& ph) = delete;
|
||||
~JoltPhysWorld3D();
|
||||
PhysWorld3D();
|
||||
PhysWorld3D(const PhysWorld3D&) = delete;
|
||||
PhysWorld3D(PhysWorld3D&& ph) = delete;
|
||||
~PhysWorld3D();
|
||||
|
||||
bool CollisionQuery(const Vector3f& point, const FunctionRef<std::optional<float>(const PointCollisionInfo& collisionInfo)>& callback);
|
||||
bool CollisionQuery(const JoltCollider3D& collider, const Matrix4f& colliderTransform, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const JoltCollider3D& collider, const Matrix4f& colliderTransform, const Vector3f& colliderScale, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const Collider3D& collider, const Matrix4f& colliderTransform, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const Collider3D& collider, const Matrix4f& colliderTransform, const Vector3f& colliderScale, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
|
||||
UInt32 GetActiveBodyCount() const;
|
||||
Vector3f GetGravity() const;
|
||||
|
|
@ -67,7 +67,7 @@ namespace Nz
|
|||
|
||||
void RefreshBodies();
|
||||
|
||||
inline void RegisterStepListener(JoltPhysicsStepListener* stepListener);
|
||||
inline void RegisterStepListener(Physiscs3DStepListener* stepListener);
|
||||
|
||||
void SetGravity(const Vector3f& gravity);
|
||||
void SetMaxStepCount(std::size_t maxStepCount);
|
||||
|
|
@ -75,27 +75,27 @@ namespace Nz
|
|||
|
||||
bool Step(Time timestep);
|
||||
|
||||
inline void UnregisterStepListener(JoltPhysicsStepListener* stepListener);
|
||||
inline void UnregisterStepListener(Physiscs3DStepListener* stepListener);
|
||||
|
||||
JoltPhysWorld3D& operator=(const JoltPhysWorld3D&) = delete;
|
||||
JoltPhysWorld3D& operator=(JoltPhysWorld3D&&) = delete;
|
||||
PhysWorld3D& operator=(const PhysWorld3D&) = delete;
|
||||
PhysWorld3D& operator=(PhysWorld3D&&) = delete;
|
||||
|
||||
struct PointCollisionInfo
|
||||
{
|
||||
JoltAbstractBody* hitBody = nullptr;
|
||||
Physics3DBody* hitBody = nullptr;
|
||||
};
|
||||
|
||||
struct RaycastHit
|
||||
{
|
||||
float fraction;
|
||||
JoltAbstractBody* hitBody = nullptr;
|
||||
Physics3DBody* hitBody = nullptr;
|
||||
Vector3f hitNormal;
|
||||
Vector3f hitPosition;
|
||||
};
|
||||
|
||||
struct ShapeCollisionInfo
|
||||
{
|
||||
JoltAbstractBody* hitBody = nullptr;
|
||||
Physics3DBody* hitBody = nullptr;
|
||||
Vector3f collisionPosition1;
|
||||
Vector3f collisionPosition2;
|
||||
Vector3f penetrationAxis;
|
||||
|
|
@ -111,7 +111,7 @@ namespace Nz
|
|||
|
||||
struct JoltWorld;
|
||||
|
||||
std::shared_ptr<JoltCharacterImpl> GetDefaultCharacterImpl();
|
||||
std::shared_ptr<PhysCharacter3DImpl> GetDefaultCharacterImpl();
|
||||
const JPH::Shape* GetNullShape() const;
|
||||
|
||||
void OnPreStep(float deltatime);
|
||||
|
|
@ -121,17 +121,17 @@ namespace Nz
|
|||
void UnregisterBody(const JPH::BodyID& bodyID, bool destroy, bool removeFromRegisterList);
|
||||
|
||||
std::size_t m_maxStepCount;
|
||||
std::shared_ptr<JoltCharacterImpl> m_defaultCharacterImpl;
|
||||
std::shared_ptr<PhysCharacter3DImpl> m_defaultCharacterImpl;
|
||||
std::unique_ptr<std::atomic_uint64_t[]> m_activeBodies;
|
||||
std::unique_ptr<std::uint64_t[]> m_registeredBodies;
|
||||
std::unique_ptr<JoltWorld> m_world;
|
||||
std::vector<JoltPhysicsStepListener*> m_stepListeners;
|
||||
std::vector<Physiscs3DStepListener*> m_stepListeners;
|
||||
Vector3f m_gravity;
|
||||
Time m_stepSize;
|
||||
Time m_timestepAccumulator;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysWorld3D.inl>
|
||||
#include <Nazara/Physics3D/PhysWorld3D.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP
|
||||
#endif // NAZARA_PHYSICS3D_PHYSWORLD3D_HPP
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline bool JoltPhysWorld3D::IsBodyActive(UInt32 bodyIndex) const
|
||||
inline bool PhysWorld3D::IsBodyActive(UInt32 bodyIndex) const
|
||||
{
|
||||
UInt32 blockIndex = bodyIndex / 64;
|
||||
UInt32 localIndex = bodyIndex % 64;
|
||||
|
|
@ -14,7 +14,7 @@ namespace Nz
|
|||
return m_activeBodies[blockIndex] & (UInt64(1u) << localIndex);
|
||||
}
|
||||
|
||||
inline bool JoltPhysWorld3D::IsBodyRegistered(UInt32 bodyIndex) const
|
||||
inline bool PhysWorld3D::IsBodyRegistered(UInt32 bodyIndex) const
|
||||
{
|
||||
UInt32 blockIndex = bodyIndex / 64;
|
||||
UInt32 localIndex = bodyIndex % 64;
|
||||
|
|
@ -22,13 +22,13 @@ namespace Nz
|
|||
return m_registeredBodies[blockIndex] & (UInt64(1u) << localIndex);
|
||||
}
|
||||
|
||||
inline void JoltPhysWorld3D::RegisterStepListener(JoltPhysicsStepListener* stepListener)
|
||||
inline void PhysWorld3D::RegisterStepListener(Physiscs3DStepListener* stepListener)
|
||||
{
|
||||
auto it = std::lower_bound(m_stepListeners.begin(), m_stepListeners.end(), stepListener);
|
||||
m_stepListeners.insert(it, stepListener);
|
||||
}
|
||||
|
||||
inline void JoltPhysWorld3D::UnregisterStepListener(JoltPhysicsStepListener* stepListener)
|
||||
inline void PhysWorld3D::UnregisterStepListener(Physiscs3DStepListener* stepListener)
|
||||
{
|
||||
auto it = std::lower_bound(m_stepListeners.begin(), m_stepListeners.end(), stepListener);
|
||||
assert(*it == stepListener);
|
||||
|
|
@ -36,4 +36,4 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_HPP
|
||||
#define NAZARA_PHYSICS3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
|
|
@ -20,7 +20,7 @@ namespace JPH
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPhysics3D : public ModuleBase<JoltPhysics3D>
|
||||
class NAZARA_PHYSICS3D_API Physics3D : public ModuleBase<Physics3D>
|
||||
{
|
||||
friend ModuleBase;
|
||||
|
||||
|
|
@ -29,16 +29,16 @@ namespace Nz
|
|||
|
||||
struct Config {};
|
||||
|
||||
JoltPhysics3D(Config /*config*/);
|
||||
~JoltPhysics3D();
|
||||
Physics3D(Config /*config*/);
|
||||
~Physics3D();
|
||||
|
||||
JPH::JobSystem& GetThreadPool();
|
||||
|
||||
private:
|
||||
std::unique_ptr<JPH::JobSystemThreadPool> m_threadPool;
|
||||
|
||||
static JoltPhysics3D* s_instance;
|
||||
static Physics3D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_HPP
|
||||
#endif // NAZARA_PHYSICS3D_HPP
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSICS3DBODY_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSICS3DBODY_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API Physics3DBody
|
||||
{
|
||||
public:
|
||||
Physics3DBody() = default;
|
||||
Physics3DBody(const Physics3DBody&) = delete;
|
||||
Physics3DBody(Physics3DBody&&) = delete;
|
||||
virtual ~Physics3DBody();
|
||||
|
||||
virtual UInt32 GetBodyIndex() const = 0;
|
||||
|
||||
Physics3DBody& operator=(const Physics3DBody&) = delete;
|
||||
Physics3DBody& operator=(Physics3DBody&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Physics3DBody.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_PHYSICS3DBODY_HPP
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSISCS3DSTEPLISTENER_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSISCS3DSTEPLISTENER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API Physiscs3DStepListener
|
||||
{
|
||||
public:
|
||||
Physiscs3DStepListener() = default;
|
||||
Physiscs3DStepListener(const Physiscs3DStepListener&) = delete;
|
||||
Physiscs3DStepListener(Physiscs3DStepListener&&) = delete;
|
||||
virtual ~Physiscs3DStepListener();
|
||||
|
||||
virtual void PostSimulate(float elapsedTime);
|
||||
virtual void PreSimulate(float elapsedTime);
|
||||
|
||||
Physiscs3DStepListener& operator=(const Physiscs3DStepListener&) = delete;
|
||||
Physiscs3DStepListener& operator=(Physiscs3DStepListener&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Physiscs3DStepListener.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_PHYSISCS3DSTEPLISTENER_HPP
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTRIGIDBODY3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTRIGIDBODY3D_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_RIGIDBODY3D_HPP
|
||||
#define NAZARA_PHYSICS3D_RIGIDBODY3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltAbstractBody.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltCollider3D.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Physics3DBody.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
namespace JPH
|
||||
|
|
@ -25,19 +25,19 @@ namespace JPH
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class JoltPhysWorld3D;
|
||||
class PhysWorld3D;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltRigidBody3D : public JoltAbstractBody
|
||||
class NAZARA_PHYSICS3D_API RigidBody3D : public Physics3DBody
|
||||
{
|
||||
public:
|
||||
struct DynamicSettings;
|
||||
struct StaticSettings;
|
||||
|
||||
inline JoltRigidBody3D(JoltPhysWorld3D& world, const DynamicSettings& settings);
|
||||
inline JoltRigidBody3D(JoltPhysWorld3D& world, const StaticSettings& settings);
|
||||
JoltRigidBody3D(const JoltRigidBody3D& object) = delete;
|
||||
JoltRigidBody3D(JoltRigidBody3D&& object) noexcept;
|
||||
~JoltRigidBody3D();
|
||||
inline RigidBody3D(PhysWorld3D& world, const DynamicSettings& settings);
|
||||
inline RigidBody3D(PhysWorld3D& world, const StaticSettings& settings);
|
||||
RigidBody3D(const RigidBody3D& object) = delete;
|
||||
RigidBody3D(RigidBody3D&& object) noexcept;
|
||||
~RigidBody3D();
|
||||
|
||||
void AddForce(const Vector3f& force, CoordSys coordSys = CoordSys::Global);
|
||||
void AddForce(const Vector3f& force, const Vector3f& point, CoordSys coordSys = CoordSys::Global);
|
||||
|
|
@ -56,7 +56,7 @@ namespace Nz
|
|||
inline JPH::Body* GetBody();
|
||||
inline const JPH::Body* GetBody() const;
|
||||
UInt32 GetBodyIndex() const override;
|
||||
inline const std::shared_ptr<JoltCollider3D>& GetGeom() const;
|
||||
inline const std::shared_ptr<Collider3D>& GetGeom() const;
|
||||
float GetLinearDamping() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
float GetMass() const;
|
||||
|
|
@ -64,7 +64,7 @@ namespace Nz
|
|||
Vector3f GetPosition() const;
|
||||
std::pair<Vector3f, Quaternionf> GetPositionAndRotation() const;
|
||||
Quaternionf GetRotation() const;
|
||||
inline JoltPhysWorld3D& GetWorld() const;
|
||||
inline PhysWorld3D& GetWorld() const;
|
||||
|
||||
inline bool IsSimulationEnabled() const;
|
||||
bool IsSleeping() const;
|
||||
|
|
@ -73,7 +73,7 @@ namespace Nz
|
|||
|
||||
void SetAngularDamping(float angularDamping);
|
||||
void SetAngularVelocity(const Vector3f& angularVelocity);
|
||||
void SetGeom(std::shared_ptr<JoltCollider3D> geom, bool recomputeInertia = true);
|
||||
void SetGeom(std::shared_ptr<Collider3D> geom, bool recomputeInertia = true);
|
||||
void SetLinearDamping(float damping);
|
||||
void SetLinearVelocity(const Vector3f& velocity);
|
||||
void SetMass(float mass, bool recomputeInertia = true);
|
||||
|
|
@ -89,12 +89,12 @@ namespace Nz
|
|||
|
||||
void WakeUp();
|
||||
|
||||
JoltRigidBody3D& operator=(const JoltRigidBody3D& object) = delete;
|
||||
JoltRigidBody3D& operator=(JoltRigidBody3D&& object) noexcept;
|
||||
RigidBody3D& operator=(const RigidBody3D& object) = delete;
|
||||
RigidBody3D& operator=(RigidBody3D&& object) noexcept;
|
||||
|
||||
struct CommonSettings
|
||||
{
|
||||
std::shared_ptr<JoltCollider3D> geom;
|
||||
std::shared_ptr<Collider3D> geom;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
bool initiallySleeping = false;
|
||||
|
|
@ -105,14 +105,14 @@ namespace Nz
|
|||
struct DynamicSettings : CommonSettings
|
||||
{
|
||||
DynamicSettings() = default;
|
||||
DynamicSettings(std::shared_ptr<JoltCollider3D> collider, float mass_) :
|
||||
DynamicSettings(std::shared_ptr<Collider3D> collider, float mass_) :
|
||||
mass(mass_)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
}
|
||||
|
||||
// Default values from Jolt
|
||||
JoltMotionQuality motionQuality = JoltMotionQuality::Discrete;
|
||||
PhysMotionQuality3D motionQuality = PhysMotionQuality3D::Discrete;
|
||||
Vector3f angularVelocity = Vector3f::Zero();
|
||||
Vector3f linearVelocity = Vector3f::Zero();
|
||||
bool allowSleeping = true;
|
||||
|
|
@ -129,16 +129,16 @@ namespace Nz
|
|||
struct StaticSettings : CommonSettings
|
||||
{
|
||||
StaticSettings() = default;
|
||||
StaticSettings(std::shared_ptr<JoltCollider3D> collider)
|
||||
StaticSettings(std::shared_ptr<Collider3D> collider)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
JoltRigidBody3D() = default;
|
||||
void Create(JoltPhysWorld3D& world, const DynamicSettings& settings);
|
||||
void Create(JoltPhysWorld3D& world, const StaticSettings& settings);
|
||||
RigidBody3D() = default;
|
||||
void Create(PhysWorld3D& world, const DynamicSettings& settings);
|
||||
void Create(PhysWorld3D& world, const StaticSettings& settings);
|
||||
void Destroy(bool worldDestruction = false);
|
||||
|
||||
private:
|
||||
|
|
@ -148,15 +148,15 @@ namespace Nz
|
|||
|
||||
bool ShouldActivate() const;
|
||||
|
||||
std::shared_ptr<JoltCollider3D> m_geom;
|
||||
std::shared_ptr<Collider3D> m_geom;
|
||||
MovablePtr<JPH::Body> m_body;
|
||||
MovablePtr<JoltPhysWorld3D> m_world;
|
||||
MovablePtr<PhysWorld3D> m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
bool m_isSimulationEnabled;
|
||||
bool m_isTrigger;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.inl>
|
||||
#include <Nazara/Physics3D/RigidBody3D.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTRIGIDBODY3D_HPP
|
||||
#endif // NAZARA_PHYSICS3D_RIGIDBODY3D_HPP
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RigidBody3D::RigidBody3D(PhysWorld3D& world, const DynamicSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline RigidBody3D::RigidBody3D(PhysWorld3D& world, const StaticSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline void RigidBody3D::DisableSimulation()
|
||||
{
|
||||
return EnableSimulation(false);
|
||||
}
|
||||
|
||||
inline void RigidBody3D::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline JPH::Body* RigidBody3D::GetBody()
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline const JPH::Body* RigidBody3D::GetBody() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Collider3D>& RigidBody3D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline PhysWorld3D& RigidBody3D::GetWorld() const
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline bool RigidBody3D::IsSimulationEnabled() const
|
||||
{
|
||||
return m_isSimulationEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - ChipmunkPhysics2D module
|
||||
Nazara Engine - Physics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
|
|
@ -26,9 +26,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_SYSTEMS_HPP
|
||||
#define NAZARA_PHYSICS3D_SYSTEMS_HPP
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.hpp>
|
||||
#include <Nazara/Physics3D/Systems/Physics3DSystem.hpp>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_HPP
|
||||
#endif // NAZARA_PHYSICS3D_SYSTEMS_HPP
|
||||
|
|
@ -1,45 +1,45 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_SYSTEMS_JOLTPHYSICS3DSYSTEM_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_SYSTEMS_JOLTPHYSICS3DSYSTEM_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_SYSTEMS_PHYSICS3DSYSTEM_HPP
|
||||
#define NAZARA_PHYSICS3D_SYSTEMS_PHYSICS3DSYSTEM_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltCharacterComponent.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.hpp>
|
||||
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
||||
#include <Nazara/Physics3D/Components/PhysCharacter3DComponent.hpp>
|
||||
#include <Nazara/Physics3D/Components/RigidBody3DComponent.hpp>
|
||||
#include <NazaraUtils/TypeList.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPhysics3DSystem
|
||||
class NAZARA_PHYSICS3D_API Physics3DSystem
|
||||
{
|
||||
public:
|
||||
static constexpr Int64 ExecutionOrder = 0;
|
||||
using Components = TypeList<JoltCharacterComponent, JoltRigidBody3DComponent, class NodeComponent>;
|
||||
using Components = TypeList<PhysCharacter3DComponent, RigidBody3DComponent, class NodeComponent>;
|
||||
|
||||
struct PointCollisionInfo;
|
||||
struct RaycastHit;
|
||||
struct ShapeCollisionInfo;
|
||||
|
||||
JoltPhysics3DSystem(entt::registry& registry);
|
||||
JoltPhysics3DSystem(const JoltPhysics3DSystem&) = delete;
|
||||
JoltPhysics3DSystem(JoltPhysics3DSystem&&) = delete;
|
||||
~JoltPhysics3DSystem();
|
||||
Physics3DSystem(entt::registry& registry);
|
||||
Physics3DSystem(const Physics3DSystem&) = delete;
|
||||
Physics3DSystem(Physics3DSystem&&) = delete;
|
||||
~Physics3DSystem();
|
||||
|
||||
bool CollisionQuery(const Vector3f& point, const FunctionRef<std::optional<float>(const PointCollisionInfo& collisionInfo)>& callback);
|
||||
bool CollisionQuery(const JoltCollider3D& collider, const Matrix4f& colliderTransform, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const JoltCollider3D& collider, const Matrix4f& colliderTransform, const Vector3f& colliderScale, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const Collider3D& collider, const Matrix4f& colliderTransform, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const Collider3D& collider, const Matrix4f& colliderTransform, const Vector3f& colliderScale, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
|
||||
inline JoltPhysWorld3D& GetPhysWorld();
|
||||
inline const JoltPhysWorld3D& GetPhysWorld() const;
|
||||
inline PhysWorld3D& GetPhysWorld();
|
||||
inline const PhysWorld3D& GetPhysWorld() const;
|
||||
inline entt::handle GetRigidBodyEntity(UInt32 bodyIndex) const;
|
||||
|
||||
bool RaycastQuery(const Vector3f& from, const Vector3f& to, const FunctionRef<std::optional<float>(const RaycastHit& hitInfo)>& callback);
|
||||
|
|
@ -47,20 +47,20 @@ namespace Nz
|
|||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
JoltPhysics3DSystem& operator=(const JoltPhysics3DSystem&) = delete;
|
||||
JoltPhysics3DSystem& operator=(JoltPhysics3DSystem&&) = delete;
|
||||
Physics3DSystem& operator=(const Physics3DSystem&) = delete;
|
||||
Physics3DSystem& operator=(Physics3DSystem&&) = delete;
|
||||
|
||||
struct PointCollisionInfo : JoltPhysWorld3D::PointCollisionInfo
|
||||
struct PointCollisionInfo : PhysWorld3D::PointCollisionInfo
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
|
||||
struct RaycastHit : JoltPhysWorld3D::RaycastHit
|
||||
struct RaycastHit : PhysWorld3D::RaycastHit
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
|
||||
struct ShapeCollisionInfo : JoltPhysWorld3D::ShapeCollisionInfo
|
||||
struct ShapeCollisionInfo : PhysWorld3D::ShapeCollisionInfo
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
|
|
@ -80,10 +80,10 @@ namespace Nz
|
|||
entt::scoped_connection m_bodyDestructConnection;
|
||||
entt::scoped_connection m_characterConstructConnection;
|
||||
entt::scoped_connection m_characterDestructConnection;
|
||||
JoltPhysWorld3D m_physWorld;
|
||||
PhysWorld3D m_physWorld;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.inl>
|
||||
#include <Nazara/Physics3D/Systems/Physics3DSystem.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_SYSTEMS_JOLTPHYSICS3DSYSTEM_HPP
|
||||
#endif // NAZARA_PHYSICS3D_SYSTEMS_PHYSICS3DSYSTEM_HPP
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline PhysWorld3D& Physics3DSystem::GetPhysWorld()
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline const PhysWorld3D& Physics3DSystem::GetPhysWorld() const
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline entt::handle Physics3DSystem::GetRigidBodyEntity(UInt32 bodyIndex) const
|
||||
{
|
||||
return entt::handle(m_registry, m_bodyIndicesToEntity[bodyIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
|
@ -1,457 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkConstraint2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkHelper.hpp>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
ChipmunkConstraint2D::ChipmunkConstraint2D(ChipmunkPhysWorld2D* world, cpConstraint* constraint) :
|
||||
m_constraint(constraint)
|
||||
{
|
||||
cpConstraintSetUserData(m_constraint, this);
|
||||
cpSpaceAddConstraint(world->GetHandle(), m_constraint);
|
||||
}
|
||||
|
||||
ChipmunkConstraint2D::ChipmunkConstraint2D(ChipmunkConstraint2D&& constraint) noexcept :
|
||||
m_constraint(std::move(constraint.m_constraint))
|
||||
{
|
||||
if (m_constraint)
|
||||
cpConstraintSetUserData(m_constraint, this);
|
||||
}
|
||||
|
||||
ChipmunkConstraint2D::~ChipmunkConstraint2D()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void ChipmunkConstraint2D::EnableBodyCollision(bool enable)
|
||||
{
|
||||
cpConstraintSetCollideBodies(m_constraint, (enable) ? cpTrue : cpFalse);
|
||||
}
|
||||
|
||||
ChipmunkRigidBody2D& ChipmunkConstraint2D::GetBodyA()
|
||||
{
|
||||
return *static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(cpConstraintGetBodyA(m_constraint)));
|
||||
}
|
||||
|
||||
const ChipmunkRigidBody2D& ChipmunkConstraint2D::GetBodyA() const
|
||||
{
|
||||
return *static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(cpConstraintGetBodyA(m_constraint)));
|
||||
}
|
||||
|
||||
ChipmunkRigidBody2D& ChipmunkConstraint2D::GetBodyB()
|
||||
{
|
||||
NazaraAssert(!IsSingleBody(), "constraint is not attached to a second body");
|
||||
return *static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(cpConstraintGetBodyB(m_constraint)));
|
||||
}
|
||||
|
||||
const ChipmunkRigidBody2D& ChipmunkConstraint2D::GetBodyB() const
|
||||
{
|
||||
NazaraAssert(!IsSingleBody(), "constraint is not attached to a second body");
|
||||
return *static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(cpConstraintGetBodyB(m_constraint)));
|
||||
}
|
||||
|
||||
float ChipmunkConstraint2D::GetErrorBias() const
|
||||
{
|
||||
return float(cpConstraintGetErrorBias(m_constraint));
|
||||
}
|
||||
|
||||
float ChipmunkConstraint2D::GetLastImpulse() const
|
||||
{
|
||||
return float(cpConstraintGetImpulse(m_constraint));
|
||||
}
|
||||
|
||||
float ChipmunkConstraint2D::GetMaxBias() const
|
||||
{
|
||||
return float(cpConstraintGetMaxBias(m_constraint));
|
||||
}
|
||||
|
||||
float ChipmunkConstraint2D::GetMaxForce() const
|
||||
{
|
||||
return float(cpConstraintGetMaxForce(m_constraint));
|
||||
}
|
||||
|
||||
ChipmunkPhysWorld2D& ChipmunkConstraint2D::GetWorld()
|
||||
{
|
||||
return *static_cast<ChipmunkPhysWorld2D*>(cpSpaceGetUserData(cpConstraintGetSpace(m_constraint)));
|
||||
}
|
||||
|
||||
const ChipmunkPhysWorld2D& ChipmunkConstraint2D::GetWorld() const
|
||||
{
|
||||
return *static_cast<ChipmunkPhysWorld2D*>(cpSpaceGetUserData(cpConstraintGetSpace(m_constraint)));
|
||||
}
|
||||
|
||||
bool ChipmunkConstraint2D::IsBodyCollisionEnabled() const
|
||||
{
|
||||
return cpConstraintGetCollideBodies(m_constraint) == cpTrue;
|
||||
}
|
||||
|
||||
bool ChipmunkConstraint2D::IsSingleBody() const
|
||||
{
|
||||
return cpConstraintGetBodyB(m_constraint) == cpSpaceGetStaticBody(cpConstraintGetSpace(m_constraint));
|
||||
}
|
||||
|
||||
void ChipmunkConstraint2D::SetErrorBias(float bias)
|
||||
{
|
||||
cpConstraintSetErrorBias(m_constraint, bias);
|
||||
}
|
||||
|
||||
void ChipmunkConstraint2D::SetMaxBias(float bias)
|
||||
{
|
||||
cpConstraintSetMaxBias(m_constraint, bias);
|
||||
}
|
||||
|
||||
void ChipmunkConstraint2D::SetMaxForce(float force)
|
||||
{
|
||||
cpConstraintSetMaxForce(m_constraint, force);
|
||||
}
|
||||
|
||||
ChipmunkConstraint2D& ChipmunkConstraint2D::operator=(ChipmunkConstraint2D&& rhs) noexcept
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_constraint = std::move(rhs.m_constraint);
|
||||
if (m_constraint)
|
||||
cpConstraintSetUserData(m_constraint, this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ChipmunkConstraint2D::Destroy()
|
||||
{
|
||||
if (m_constraint)
|
||||
{
|
||||
cpSpaceRemoveConstraint(cpConstraintGetSpace(m_constraint), m_constraint);
|
||||
cpConstraintDestroy(m_constraint);
|
||||
|
||||
m_constraint = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ChipmunkDampedSpringConstraint2D::ChipmunkDampedSpringConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpDampedSpringNew(first.GetHandle(), second.GetHandle(), ToChipmunk(firstAnchor), ToChipmunk(secondAnchor), restLength, stiffness, damping))
|
||||
{
|
||||
}
|
||||
|
||||
float ChipmunkDampedSpringConstraint2D::GetDamping() const
|
||||
{
|
||||
return float(cpDampedSpringGetDamping(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkDampedSpringConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpDampedSpringGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float ChipmunkDampedSpringConstraint2D::GetRestLength() const
|
||||
{
|
||||
return float(cpDampedSpringGetRestLength(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkDampedSpringConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpDampedSpringGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float ChipmunkDampedSpringConstraint2D::GetStiffness() const
|
||||
{
|
||||
return float(cpDampedSpringGetStiffness(m_constraint));
|
||||
}
|
||||
|
||||
void ChipmunkDampedSpringConstraint2D::SetDamping(float newDamping)
|
||||
{
|
||||
cpDampedSpringSetDamping(m_constraint, newDamping);
|
||||
}
|
||||
|
||||
void ChipmunkDampedSpringConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpDampedSpringSetAnchorA(m_constraint, ToChipmunk(firstAnchor));
|
||||
}
|
||||
|
||||
void ChipmunkDampedSpringConstraint2D::SetRestLength(float newLength)
|
||||
{
|
||||
cpDampedSpringSetRestLength(m_constraint, newLength);
|
||||
}
|
||||
|
||||
void ChipmunkDampedSpringConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpDampedSpringSetAnchorB(m_constraint, ToChipmunk(firstAnchor));
|
||||
}
|
||||
|
||||
void ChipmunkDampedSpringConstraint2D::SetStiffness(float newStiffness)
|
||||
{
|
||||
cpDampedSpringSetStiffness(m_constraint, newStiffness);
|
||||
}
|
||||
|
||||
|
||||
ChipmunkDampedRotarySpringConstraint2D::ChipmunkDampedRotarySpringConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const RadianAnglef& restAngle, float stiffness, float damping) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle.value, stiffness, damping))
|
||||
{
|
||||
}
|
||||
|
||||
float ChipmunkDampedRotarySpringConstraint2D::GetDamping() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetDamping(m_constraint));
|
||||
}
|
||||
|
||||
RadianAnglef ChipmunkDampedRotarySpringConstraint2D::GetRestAngle() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetRestAngle(m_constraint));
|
||||
}
|
||||
|
||||
float ChipmunkDampedRotarySpringConstraint2D::GetStiffness() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetStiffness(m_constraint));
|
||||
}
|
||||
|
||||
void ChipmunkDampedRotarySpringConstraint2D::SetDamping(float newDamping)
|
||||
{
|
||||
cpDampedSpringSetDamping(m_constraint, newDamping);
|
||||
}
|
||||
|
||||
void ChipmunkDampedRotarySpringConstraint2D::SetRestAngle(const RadianAnglef& newAngle)
|
||||
{
|
||||
cpDampedRotarySpringSetRestAngle(m_constraint, newAngle.value);
|
||||
}
|
||||
|
||||
void ChipmunkDampedRotarySpringConstraint2D::SetStiffness(float newStiffness)
|
||||
{
|
||||
cpDampedRotarySpringSetStiffness(m_constraint, newStiffness);
|
||||
}
|
||||
|
||||
|
||||
ChipmunkGearConstraint2D::ChipmunkGearConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, float phase, float ratio) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpGearJointNew(first.GetHandle(), second.GetHandle(), phase, ratio))
|
||||
{
|
||||
}
|
||||
|
||||
float ChipmunkGearConstraint2D::GetPhase() const
|
||||
{
|
||||
return float(cpGearJointGetPhase(m_constraint));
|
||||
}
|
||||
|
||||
float ChipmunkGearConstraint2D::GetRatio() const
|
||||
{
|
||||
return float(cpGearJointGetRatio(m_constraint));
|
||||
}
|
||||
|
||||
void ChipmunkGearConstraint2D::SetPhase(float phase)
|
||||
{
|
||||
cpGearJointSetPhase(m_constraint, phase);
|
||||
}
|
||||
|
||||
void ChipmunkGearConstraint2D::SetRatio(float ratio)
|
||||
{
|
||||
cpGearJointSetRatio(m_constraint, ratio);
|
||||
}
|
||||
|
||||
|
||||
ChipmunkMotorConstraint2D::ChipmunkMotorConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, float rate) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpSimpleMotorNew(first.GetHandle(), second.GetHandle(), rate))
|
||||
{
|
||||
}
|
||||
|
||||
float ChipmunkMotorConstraint2D::GetRate() const
|
||||
{
|
||||
return float(cpSimpleMotorGetRate(m_constraint));
|
||||
}
|
||||
|
||||
void ChipmunkMotorConstraint2D::SetRate(float rate)
|
||||
{
|
||||
cpSimpleMotorSetRate(m_constraint, rate);
|
||||
}
|
||||
|
||||
|
||||
ChipmunkPinConstraint2D::ChipmunkPinConstraint2D(ChipmunkRigidBody2D& body, const Vector2f& anchor) :
|
||||
ChipmunkConstraint2D(body.GetWorld(), cpPinJointNew(body.GetHandle(), cpSpaceGetStaticBody(body.GetWorld()->GetHandle()), ToChipmunk(body.ToLocal(anchor)), ToChipmunk(body.ToLocal(anchor))))
|
||||
{
|
||||
}
|
||||
|
||||
ChipmunkPinConstraint2D::ChipmunkPinConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpPinJointNew(first.GetHandle(), second.GetHandle(), ToChipmunk(firstAnchor), ToChipmunk(secondAnchor)))
|
||||
{
|
||||
}
|
||||
|
||||
float ChipmunkPinConstraint2D::GetDistance() const
|
||||
{
|
||||
return float(cpPinJointGetDist(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkPinConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
return FromChipmunk(cpBodyLocalToWorld(cpConstraintGetBodyA(m_constraint), cpPinJointGetAnchorA(m_constraint)));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkPinConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
return FromChipmunk(cpBodyLocalToWorld(cpConstraintGetBodyB(m_constraint), cpPinJointGetAnchorB(m_constraint)));
|
||||
}
|
||||
|
||||
void ChipmunkPinConstraint2D::SetDistance(float newDistance)
|
||||
{
|
||||
cpPinJointSetDist(m_constraint, newDistance);
|
||||
}
|
||||
|
||||
void ChipmunkPinConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPinJointSetAnchorA(m_constraint, cpBodyWorldToLocal(cpConstraintGetBodyA(m_constraint), ToChipmunk(firstAnchor)));
|
||||
}
|
||||
|
||||
void ChipmunkPinConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPinJointSetAnchorB(m_constraint, cpBodyWorldToLocal(cpConstraintGetBodyB(m_constraint), ToChipmunk(firstAnchor)));
|
||||
}
|
||||
|
||||
|
||||
ChipmunkPivotConstraint2D::ChipmunkPivotConstraint2D(ChipmunkRigidBody2D& body, const Vector2f& anchor) :
|
||||
ChipmunkConstraint2D(body.GetWorld(), cpPivotJointNew(cpSpaceGetStaticBody(body.GetWorld()->GetHandle()), body.GetHandle(), ToChipmunk(anchor)))
|
||||
{
|
||||
}
|
||||
|
||||
ChipmunkPivotConstraint2D::ChipmunkPivotConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& anchor) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpPivotJointNew(first.GetHandle(), second.GetHandle(), ToChipmunk(anchor)))
|
||||
{
|
||||
}
|
||||
|
||||
ChipmunkPivotConstraint2D::ChipmunkPivotConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpPivotJointNew2(first.GetHandle(), second.GetHandle(), ToChipmunk(firstAnchor), ToChipmunk(secondAnchor)))
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f ChipmunkPivotConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
return FromChipmunk(cpBodyLocalToWorld(cpConstraintGetBodyA(m_constraint), cpPivotJointGetAnchorA(m_constraint)));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkPivotConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
return FromChipmunk(cpBodyLocalToWorld(cpConstraintGetBodyB(m_constraint), cpPivotJointGetAnchorB(m_constraint)));
|
||||
}
|
||||
|
||||
void ChipmunkPivotConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPivotJointSetAnchorA(m_constraint, cpBodyWorldToLocal(cpConstraintGetBodyA(m_constraint), ToChipmunk(firstAnchor)));
|
||||
}
|
||||
|
||||
void ChipmunkPivotConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPivotJointSetAnchorB(m_constraint, cpBodyWorldToLocal(cpConstraintGetBodyB(m_constraint), ToChipmunk(firstAnchor)));
|
||||
}
|
||||
|
||||
|
||||
ChipmunkRatchetConstraint2D::ChipmunkRatchetConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, float phase, float ratchet) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpRatchetJointNew(first.GetHandle(), second.GetHandle(), phase, ratchet))
|
||||
{
|
||||
}
|
||||
|
||||
RadianAnglef ChipmunkRatchetConstraint2D::GetAngle() const
|
||||
{
|
||||
return float(cpRatchetJointGetAngle(m_constraint));
|
||||
}
|
||||
|
||||
float ChipmunkRatchetConstraint2D::GetPhase() const
|
||||
{
|
||||
return float(cpRatchetJointGetPhase(m_constraint));
|
||||
}
|
||||
|
||||
float ChipmunkRatchetConstraint2D::GetRatchet() const
|
||||
{
|
||||
return float(cpRatchetJointGetRatchet(m_constraint));
|
||||
}
|
||||
|
||||
void ChipmunkRatchetConstraint2D::SetAngle(const RadianAnglef& angle)
|
||||
{
|
||||
cpRatchetJointSetAngle(m_constraint, angle.value);
|
||||
}
|
||||
|
||||
void ChipmunkRatchetConstraint2D::SetPhase(float phase)
|
||||
{
|
||||
cpRatchetJointSetPhase(m_constraint, phase);
|
||||
}
|
||||
|
||||
void ChipmunkRatchetConstraint2D::SetRatchet(float ratchet)
|
||||
{
|
||||
cpRatchetJointSetRatchet(m_constraint, ratchet);
|
||||
}
|
||||
|
||||
|
||||
ChipmunkRotaryLimitConstraint2D::ChipmunkRotaryLimitConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const RadianAnglef& minAngle, const RadianAnglef& maxAngle) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle.value, maxAngle.value))
|
||||
{
|
||||
}
|
||||
|
||||
RadianAnglef ChipmunkRotaryLimitConstraint2D::GetMaxAngle() const
|
||||
{
|
||||
return float(cpRotaryLimitJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
RadianAnglef ChipmunkRotaryLimitConstraint2D::GetMinAngle() const
|
||||
{
|
||||
return float(cpRotaryLimitJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
void ChipmunkRotaryLimitConstraint2D::SetMaxAngle(const RadianAnglef& maxAngle)
|
||||
{
|
||||
cpRotaryLimitJointSetMax(m_constraint, maxAngle.value);
|
||||
}
|
||||
|
||||
void ChipmunkRotaryLimitConstraint2D::SetMinAngle(const RadianAnglef& minAngle)
|
||||
{
|
||||
cpRotaryLimitJointSetMin(m_constraint, minAngle.value);
|
||||
}
|
||||
|
||||
|
||||
ChipmunkSlideConstraint2D::ChipmunkSlideConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max) :
|
||||
ChipmunkConstraint2D(first.GetWorld(), cpSlideJointNew(first.GetHandle(), second.GetHandle(), ToChipmunk(firstAnchor), ToChipmunk(secondAnchor), min, max))
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f ChipmunkSlideConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpSlideJointGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float ChipmunkSlideConstraint2D::GetMaxDistance() const
|
||||
{
|
||||
return float(cpSlideJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
float ChipmunkSlideConstraint2D::GetMinDistance() const
|
||||
{
|
||||
return float(cpSlideJointGetMin(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkSlideConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpSlideJointGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
void ChipmunkSlideConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpSlideJointSetAnchorA(m_constraint, ToChipmunk(firstAnchor));
|
||||
}
|
||||
|
||||
void ChipmunkSlideConstraint2D::SetMaxDistance(float newMaxDistance)
|
||||
{
|
||||
cpSlideJointSetMax(m_constraint, newMaxDistance);
|
||||
}
|
||||
|
||||
void ChipmunkSlideConstraint2D::SetMinDistance(float newMinDistance)
|
||||
{
|
||||
cpSlideJointSetMin(m_constraint, newMinDistance);
|
||||
}
|
||||
|
||||
void ChipmunkSlideConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpSlideJointSetAnchorB(m_constraint, ToChipmunk(firstAnchor));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysics2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
ChipmunkPhysics2D::ChipmunkPhysics2D(Config /*config*/) :
|
||||
ModuleBase("ChipmunkPhysics2D", this)
|
||||
{
|
||||
}
|
||||
|
||||
ChipmunkPhysics2D* ChipmunkPhysics2D::s_instance = nullptr;
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltAbstractBody.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
JoltAbstractBody::~JoltAbstractBody() = default;
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysicsStepListener.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
JoltPhysicsStepListener::~JoltPhysicsStepListener() = default;
|
||||
|
||||
void JoltPhysicsStepListener::PostSimulate(float /*elapsedTime*/)
|
||||
{
|
||||
}
|
||||
|
||||
void JoltPhysicsStepListener::PreSimulate(float /*elapsedTime*/)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKHELPER_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKHELPER_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_CHIPMUNKHELPER_HPP
|
||||
#define NAZARA_PHYSICS2D_CHIPMUNKHELPER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
|
@ -17,6 +17,6 @@ namespace Nz
|
|||
inline cpVect ToChipmunk(const Vector2f& vec);
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkHelper.inl>
|
||||
#include <Nazara/Physics2D/ChipmunkHelper.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKHELPER_HPP
|
||||
#endif // NAZARA_PHYSICS2D_CHIPMUNKHELPER_HPP
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -17,4 +17,4 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkHelper.hpp>
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
#include <Nazara/Physics2D/ChipmunkHelper.hpp>
|
||||
#include <NazaraUtils/CallOnExit.hpp>
|
||||
#include <NazaraUtils/StackArray.hpp>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include <chipmunk/chipmunk_structs.h>
|
||||
#include <array>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -18,9 +18,9 @@ namespace Nz
|
|||
constexpr cpSpaceDebugColor s_chipmunkWhite = { 1.f, 1.f, 1.f, 1.f };
|
||||
}
|
||||
|
||||
ChipmunkCollider2D::~ChipmunkCollider2D() = default;
|
||||
Collider2D::~Collider2D() = default;
|
||||
|
||||
void ChipmunkCollider2D::ForEachPolygon(const FunctionRef<void(const Vector2f* vertices, std::size_t vertexCount)>& callback) const
|
||||
void Collider2D::ForEachPolygon(const FunctionRef<void(const Vector2f* vertices, std::size_t vertexCount)>& callback) const
|
||||
{
|
||||
// Currently, the only way to get only the polygons of a shape is to create a temporary cpSpace containing only this shape
|
||||
// A better way to do this would be to reimplement this function in every subclass type in the very same way chipmunk does
|
||||
|
|
@ -126,7 +126,7 @@ namespace Nz
|
|||
cpSpaceDebugDraw(space, &drawOptions);
|
||||
}
|
||||
|
||||
std::size_t ChipmunkCollider2D::GenerateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
std::size_t Collider2D::GenerateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
{
|
||||
std::size_t shapeCount = CreateShapes(body, shapes);
|
||||
|
||||
|
|
@ -148,33 +148,33 @@ namespace Nz
|
|||
|
||||
/******************************** BoxCollider2D *********************************/
|
||||
|
||||
ChipmunkBoxCollider2D::ChipmunkBoxCollider2D(const Vector2f& size, float radius) :
|
||||
ChipmunkBoxCollider2D(Rectf(-size.x / 2.f, -size.y / 2.f, size.x, size.y), radius)
|
||||
BoxCollider2D::BoxCollider2D(const Vector2f& size, float radius) :
|
||||
BoxCollider2D(Rectf(-size.x / 2.f, -size.y / 2.f, size.x, size.y), radius)
|
||||
{
|
||||
}
|
||||
|
||||
ChipmunkBoxCollider2D::ChipmunkBoxCollider2D(const Rectf& rect, float radius) :
|
||||
BoxCollider2D::BoxCollider2D(const Rectf& rect, float radius) :
|
||||
m_rect(rect),
|
||||
m_radius(radius)
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f ChipmunkBoxCollider2D::ComputeCenterOfMass() const
|
||||
Vector2f BoxCollider2D::ComputeCenterOfMass() const
|
||||
{
|
||||
return m_rect.GetCenter();
|
||||
}
|
||||
|
||||
float ChipmunkBoxCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
float BoxCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
{
|
||||
return SafeCast<float>(cpMomentForBox2(mass, cpBBNew(m_rect.x, m_rect.y, m_rect.x + m_rect.width, m_rect.y + m_rect.height)));
|
||||
}
|
||||
|
||||
ChipmunkColliderType2D ChipmunkBoxCollider2D::GetType() const
|
||||
ColliderType2D BoxCollider2D::GetType() const
|
||||
{
|
||||
return ChipmunkColliderType2D::Box;
|
||||
return ColliderType2D::Box;
|
||||
}
|
||||
|
||||
std::size_t ChipmunkBoxCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
std::size_t BoxCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
{
|
||||
shapes->push_back(cpBoxShapeNew2(body, cpBBNew(m_rect.x, m_rect.y, m_rect.x + m_rect.width, m_rect.y + m_rect.height), m_radius));
|
||||
return 1;
|
||||
|
|
@ -182,28 +182,28 @@ namespace Nz
|
|||
|
||||
/******************************** CircleCollider2D *********************************/
|
||||
|
||||
ChipmunkCircleCollider2D::ChipmunkCircleCollider2D(float radius, const Vector2f& offset) :
|
||||
CircleCollider2D::CircleCollider2D(float radius, const Vector2f& offset) :
|
||||
m_offset(offset),
|
||||
m_radius(radius)
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f ChipmunkCircleCollider2D::ComputeCenterOfMass() const
|
||||
Vector2f CircleCollider2D::ComputeCenterOfMass() const
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
float ChipmunkCircleCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
float CircleCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
{
|
||||
return SafeCast<float>(cpMomentForCircle(mass, 0.f, m_radius, cpv(m_offset.x, m_offset.y)));
|
||||
}
|
||||
|
||||
ChipmunkColliderType2D ChipmunkCircleCollider2D::GetType() const
|
||||
ColliderType2D CircleCollider2D::GetType() const
|
||||
{
|
||||
return ChipmunkColliderType2D::Circle;
|
||||
return ColliderType2D::Circle;
|
||||
}
|
||||
|
||||
std::size_t ChipmunkCircleCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
std::size_t CircleCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
{
|
||||
shapes->push_back(cpCircleShapeNew(body, m_radius, cpv(m_offset.x, m_offset.y)));
|
||||
return 1;
|
||||
|
|
@ -211,13 +211,13 @@ namespace Nz
|
|||
|
||||
/******************************** CompoundCollider2D *********************************/
|
||||
|
||||
ChipmunkCompoundCollider2D::ChipmunkCompoundCollider2D(std::vector<std::shared_ptr<ChipmunkCollider2D>> geoms) :
|
||||
CompoundCollider2D::CompoundCollider2D(std::vector<std::shared_ptr<Collider2D>> geoms) :
|
||||
m_geoms(std::move(geoms)),
|
||||
m_doesOverrideCollisionProperties(true)
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f ChipmunkCompoundCollider2D::ComputeCenterOfMass() const
|
||||
Vector2f CompoundCollider2D::ComputeCenterOfMass() const
|
||||
{
|
||||
Vector2f centerOfMass = Vector2f::Zero();
|
||||
for (const auto& geom : m_geoms)
|
||||
|
|
@ -226,7 +226,7 @@ namespace Nz
|
|||
return centerOfMass / float(m_geoms.size());
|
||||
}
|
||||
|
||||
float ChipmunkCompoundCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
float CompoundCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
{
|
||||
///TODO: Correctly compute moment using parallel axis theorem:
|
||||
/// https://chipmunk-physics.net/forum/viewtopic.php?t=1056
|
||||
|
|
@ -237,12 +237,12 @@ namespace Nz
|
|||
return momentOfInertia;
|
||||
}
|
||||
|
||||
ChipmunkColliderType2D ChipmunkCompoundCollider2D::GetType() const
|
||||
ColliderType2D CompoundCollider2D::GetType() const
|
||||
{
|
||||
return ChipmunkColliderType2D::Compound;
|
||||
return ColliderType2D::Compound;
|
||||
}
|
||||
|
||||
std::size_t ChipmunkCompoundCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
std::size_t CompoundCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
{
|
||||
// Since C++ does not allow protected call from other objects, we have to be a friend of Collider2D, yay
|
||||
|
||||
|
|
@ -253,11 +253,11 @@ namespace Nz
|
|||
return shapeCount;
|
||||
}
|
||||
|
||||
std::size_t ChipmunkCompoundCollider2D::GenerateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
std::size_t CompoundCollider2D::GenerateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
{
|
||||
// This is our parent's default behavior
|
||||
if (m_doesOverrideCollisionProperties)
|
||||
return ChipmunkCollider2D::GenerateShapes(body, shapes);
|
||||
return Collider2D::GenerateShapes(body, shapes);
|
||||
else
|
||||
{
|
||||
std::size_t shapeCount = 0;
|
||||
|
|
@ -270,7 +270,7 @@ namespace Nz
|
|||
|
||||
/******************************** ConvexCollider2D *********************************/
|
||||
|
||||
ChipmunkConvexCollider2D::ChipmunkConvexCollider2D(SparsePtr<const Vector2f> vertices, std::size_t vertexCount, float radius) :
|
||||
ConvexCollider2D::ConvexCollider2D(SparsePtr<const Vector2f> vertices, std::size_t vertexCount, float radius) :
|
||||
m_radius(radius)
|
||||
{
|
||||
m_vertices.resize(vertexCount);
|
||||
|
|
@ -278,7 +278,7 @@ namespace Nz
|
|||
m_vertices[i] = Vector2<cpFloat>(*vertices++);
|
||||
}
|
||||
|
||||
Vector2f ChipmunkConvexCollider2D::ComputeCenterOfMass() const
|
||||
Vector2f ConvexCollider2D::ComputeCenterOfMass() const
|
||||
{
|
||||
static_assert(sizeof(cpVect) == sizeof(Vector2d), "Chipmunk vector is not equivalent to Vector2d");
|
||||
|
||||
|
|
@ -287,19 +287,19 @@ namespace Nz
|
|||
return Vector2f(float(center.x), float(center.y));
|
||||
}
|
||||
|
||||
float ChipmunkConvexCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
float ConvexCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
{
|
||||
static_assert(sizeof(cpVect) == sizeof(Vector2d), "Chipmunk vector is not equivalent to Vector2d");
|
||||
|
||||
return SafeCast<float>(cpMomentForPoly(mass, int(m_vertices.size()), reinterpret_cast<const cpVect*>(m_vertices.data()), cpv(0.0, 0.0), m_radius));
|
||||
}
|
||||
|
||||
ChipmunkColliderType2D ChipmunkConvexCollider2D::GetType() const
|
||||
ColliderType2D ConvexCollider2D::GetType() const
|
||||
{
|
||||
return ChipmunkColliderType2D::Convex;
|
||||
return ColliderType2D::Convex;
|
||||
}
|
||||
|
||||
std::size_t ChipmunkConvexCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
std::size_t ConvexCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
{
|
||||
shapes->push_back(cpPolyShapeNew(body, int(m_vertices.size()), reinterpret_cast<const cpVect*>(m_vertices.data()), cpTransformIdentity, m_radius));
|
||||
return 1;
|
||||
|
|
@ -307,44 +307,44 @@ namespace Nz
|
|||
|
||||
/********************************* NullCollider2D **********************************/
|
||||
|
||||
ChipmunkColliderType2D ChipmunkNullCollider2D::GetType() const
|
||||
ColliderType2D NullCollider2D::GetType() const
|
||||
{
|
||||
return ChipmunkColliderType2D::Null;
|
||||
return ColliderType2D::Null;
|
||||
}
|
||||
|
||||
Vector2f ChipmunkNullCollider2D::ComputeCenterOfMass() const
|
||||
Vector2f NullCollider2D::ComputeCenterOfMass() const
|
||||
{
|
||||
return Vector2f::Zero();
|
||||
}
|
||||
|
||||
float ChipmunkNullCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
float NullCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
{
|
||||
return (mass > 0.f) ? 1.f : 0.f; //< Null inertia is only possible for static/kinematic objects
|
||||
}
|
||||
|
||||
std::size_t ChipmunkNullCollider2D::CreateShapes(cpBody* /*body*/, std::vector<cpShape*>* /*shapes*/) const
|
||||
std::size_t NullCollider2D::CreateShapes(cpBody* /*body*/, std::vector<cpShape*>* /*shapes*/) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************** SegmentCollider2D *********************************/
|
||||
|
||||
Vector2f ChipmunkSegmentCollider2D::ComputeCenterOfMass() const
|
||||
Vector2f SegmentCollider2D::ComputeCenterOfMass() const
|
||||
{
|
||||
return (m_first + m_second) / 2.f;
|
||||
}
|
||||
|
||||
float ChipmunkSegmentCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
float SegmentCollider2D::ComputeMomentOfInertia(float mass) const
|
||||
{
|
||||
return SafeCast<float>(cpMomentForSegment(mass, cpv(m_first.x, m_first.y), cpv(m_second.x, m_second.y), m_thickness));
|
||||
}
|
||||
|
||||
ChipmunkColliderType2D ChipmunkSegmentCollider2D::GetType() const
|
||||
ColliderType2D SegmentCollider2D::GetType() const
|
||||
{
|
||||
return ChipmunkColliderType2D::Segment;
|
||||
return ColliderType2D::Segment;
|
||||
}
|
||||
|
||||
std::size_t ChipmunkSegmentCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
std::size_t SegmentCollider2D::CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const
|
||||
{
|
||||
cpShape* segment = cpSegmentShapeNew(body, cpv(m_first.x, m_first.y), cpv(m_second.x, m_second.y), m_thickness);
|
||||
cpSegmentShapeSetNeighbors(segment, cpv(m_firstNeighbor.x, m_firstNeighbor.y), cpv(m_secondNeighbor.x, m_secondNeighbor.y));
|
||||
|
|
@ -1,101 +1,101 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.hpp>
|
||||
#include <Nazara/Physics2D/PhysArbiter2D.hpp>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
float ChipmunkArbiter2D::ComputeTotalKinematicEnergy() const
|
||||
float PhysArbiter2D::ComputeTotalKinematicEnergy() const
|
||||
{
|
||||
return float(cpArbiterTotalKE(m_arbiter));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkArbiter2D::ComputeTotalImpulse() const
|
||||
Vector2f PhysArbiter2D::ComputeTotalImpulse() const
|
||||
{
|
||||
cpVect impulse = cpArbiterTotalImpulse(m_arbiter);
|
||||
return Vector2f(Vector2<cpFloat>(impulse.x, impulse.y));
|
||||
}
|
||||
|
||||
std::pair<ChipmunkRigidBody2D*, ChipmunkRigidBody2D*> ChipmunkArbiter2D::GetBodies() const
|
||||
std::pair<RigidBody2D*, RigidBody2D*> PhysArbiter2D::GetBodies() const
|
||||
{
|
||||
std::pair<ChipmunkRigidBody2D*, ChipmunkRigidBody2D*> bodies;
|
||||
std::pair<RigidBody2D*, RigidBody2D*> bodies;
|
||||
cpBody* firstBody;
|
||||
cpBody* secondBody;
|
||||
cpArbiterGetBodies(m_arbiter, &firstBody, &secondBody);
|
||||
|
||||
bodies.first = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
bodies.second = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
bodies.first = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
bodies.second = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
return bodies;
|
||||
}
|
||||
|
||||
std::size_t ChipmunkArbiter2D::GetContactCount() const
|
||||
std::size_t PhysArbiter2D::GetContactCount() const
|
||||
{
|
||||
return cpArbiterGetCount(m_arbiter);
|
||||
}
|
||||
|
||||
float ChipmunkArbiter2D::GetContactDepth(std::size_t i) const
|
||||
float PhysArbiter2D::GetContactDepth(std::size_t i) const
|
||||
{
|
||||
return float(cpArbiterGetDepth(m_arbiter, int(i)));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkArbiter2D::GetContactPointA(std::size_t i) const
|
||||
Vector2f PhysArbiter2D::GetContactPointA(std::size_t i) const
|
||||
{
|
||||
cpVect point = cpArbiterGetPointA(m_arbiter, int(i));
|
||||
return Vector2f(Vector2<cpFloat>(point.x, point.y));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkArbiter2D::GetContactPointB(std::size_t i) const
|
||||
Vector2f PhysArbiter2D::GetContactPointB(std::size_t i) const
|
||||
{
|
||||
cpVect point = cpArbiterGetPointB(m_arbiter, int(i));
|
||||
return Vector2f(Vector2<cpFloat>(point.x, point.y));
|
||||
}
|
||||
|
||||
float ChipmunkArbiter2D::GetElasticity() const
|
||||
float PhysArbiter2D::GetElasticity() const
|
||||
{
|
||||
return float(cpArbiterGetRestitution(m_arbiter));
|
||||
}
|
||||
float ChipmunkArbiter2D::GetFriction() const
|
||||
float PhysArbiter2D::GetFriction() const
|
||||
{
|
||||
return float(cpArbiterGetFriction(m_arbiter));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkArbiter2D::GetNormal() const
|
||||
Vector2f PhysArbiter2D::GetNormal() const
|
||||
{
|
||||
cpVect normal = cpArbiterGetNormal(m_arbiter);
|
||||
return Vector2f(Vector2<cpFloat>(normal.x, normal.y));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkArbiter2D::GetSurfaceVelocity() const
|
||||
Vector2f PhysArbiter2D::GetSurfaceVelocity() const
|
||||
{
|
||||
cpVect velocity = cpArbiterGetNormal(m_arbiter);
|
||||
return Vector2f(Vector2<cpFloat>(velocity.x, velocity.y));
|
||||
}
|
||||
|
||||
bool ChipmunkArbiter2D::IsFirstContact() const
|
||||
bool PhysArbiter2D::IsFirstContact() const
|
||||
{
|
||||
return cpArbiterIsFirstContact(m_arbiter) == cpTrue;
|
||||
}
|
||||
|
||||
bool ChipmunkArbiter2D::IsRemoval() const
|
||||
bool PhysArbiter2D::IsRemoval() const
|
||||
{
|
||||
return cpArbiterIsRemoval(m_arbiter) == cpTrue;
|
||||
}
|
||||
|
||||
void ChipmunkArbiter2D::SetElasticity(float elasticity)
|
||||
void PhysArbiter2D::SetElasticity(float elasticity)
|
||||
{
|
||||
cpArbiterSetRestitution(m_arbiter, elasticity);
|
||||
}
|
||||
|
||||
void ChipmunkArbiter2D::SetFriction(float friction)
|
||||
void PhysArbiter2D::SetFriction(float friction)
|
||||
{
|
||||
cpArbiterSetFriction(m_arbiter, friction);
|
||||
}
|
||||
|
||||
void ChipmunkArbiter2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||
void PhysArbiter2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||
{
|
||||
cpArbiterSetSurfaceVelocity(m_arbiter, cpv(surfaceVelocity.x, surfaceVelocity.y));
|
||||
}
|
||||
|
|
@ -0,0 +1,457 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics2D/PhysConstraint2D.hpp>
|
||||
#include <Nazara/Physics2D/ChipmunkHelper.hpp>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
PhysConstraint2D::PhysConstraint2D(PhysWorld2D* world, cpConstraint* constraint) :
|
||||
m_constraint(constraint)
|
||||
{
|
||||
cpConstraintSetUserData(m_constraint, this);
|
||||
cpSpaceAddConstraint(world->GetHandle(), m_constraint);
|
||||
}
|
||||
|
||||
PhysConstraint2D::PhysConstraint2D(PhysConstraint2D&& constraint) noexcept :
|
||||
m_constraint(std::move(constraint.m_constraint))
|
||||
{
|
||||
if (m_constraint)
|
||||
cpConstraintSetUserData(m_constraint, this);
|
||||
}
|
||||
|
||||
PhysConstraint2D::~PhysConstraint2D()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void PhysConstraint2D::EnableBodyCollision(bool enable)
|
||||
{
|
||||
cpConstraintSetCollideBodies(m_constraint, (enable) ? cpTrue : cpFalse);
|
||||
}
|
||||
|
||||
RigidBody2D& PhysConstraint2D::GetBodyA()
|
||||
{
|
||||
return *static_cast<RigidBody2D*>(cpBodyGetUserData(cpConstraintGetBodyA(m_constraint)));
|
||||
}
|
||||
|
||||
const RigidBody2D& PhysConstraint2D::GetBodyA() const
|
||||
{
|
||||
return *static_cast<RigidBody2D*>(cpBodyGetUserData(cpConstraintGetBodyA(m_constraint)));
|
||||
}
|
||||
|
||||
RigidBody2D& PhysConstraint2D::GetBodyB()
|
||||
{
|
||||
NazaraAssert(!IsSingleBody(), "constraint is not attached to a second body");
|
||||
return *static_cast<RigidBody2D*>(cpBodyGetUserData(cpConstraintGetBodyB(m_constraint)));
|
||||
}
|
||||
|
||||
const RigidBody2D& PhysConstraint2D::GetBodyB() const
|
||||
{
|
||||
NazaraAssert(!IsSingleBody(), "constraint is not attached to a second body");
|
||||
return *static_cast<RigidBody2D*>(cpBodyGetUserData(cpConstraintGetBodyB(m_constraint)));
|
||||
}
|
||||
|
||||
float PhysConstraint2D::GetErrorBias() const
|
||||
{
|
||||
return float(cpConstraintGetErrorBias(m_constraint));
|
||||
}
|
||||
|
||||
float PhysConstraint2D::GetLastImpulse() const
|
||||
{
|
||||
return float(cpConstraintGetImpulse(m_constraint));
|
||||
}
|
||||
|
||||
float PhysConstraint2D::GetMaxBias() const
|
||||
{
|
||||
return float(cpConstraintGetMaxBias(m_constraint));
|
||||
}
|
||||
|
||||
float PhysConstraint2D::GetMaxForce() const
|
||||
{
|
||||
return float(cpConstraintGetMaxForce(m_constraint));
|
||||
}
|
||||
|
||||
PhysWorld2D& PhysConstraint2D::GetWorld()
|
||||
{
|
||||
return *static_cast<PhysWorld2D*>(cpSpaceGetUserData(cpConstraintGetSpace(m_constraint)));
|
||||
}
|
||||
|
||||
const PhysWorld2D& PhysConstraint2D::GetWorld() const
|
||||
{
|
||||
return *static_cast<PhysWorld2D*>(cpSpaceGetUserData(cpConstraintGetSpace(m_constraint)));
|
||||
}
|
||||
|
||||
bool PhysConstraint2D::IsBodyCollisionEnabled() const
|
||||
{
|
||||
return cpConstraintGetCollideBodies(m_constraint) == cpTrue;
|
||||
}
|
||||
|
||||
bool PhysConstraint2D::IsSingleBody() const
|
||||
{
|
||||
return cpConstraintGetBodyB(m_constraint) == cpSpaceGetStaticBody(cpConstraintGetSpace(m_constraint));
|
||||
}
|
||||
|
||||
void PhysConstraint2D::SetErrorBias(float bias)
|
||||
{
|
||||
cpConstraintSetErrorBias(m_constraint, bias);
|
||||
}
|
||||
|
||||
void PhysConstraint2D::SetMaxBias(float bias)
|
||||
{
|
||||
cpConstraintSetMaxBias(m_constraint, bias);
|
||||
}
|
||||
|
||||
void PhysConstraint2D::SetMaxForce(float force)
|
||||
{
|
||||
cpConstraintSetMaxForce(m_constraint, force);
|
||||
}
|
||||
|
||||
PhysConstraint2D& PhysConstraint2D::operator=(PhysConstraint2D&& rhs) noexcept
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_constraint = std::move(rhs.m_constraint);
|
||||
if (m_constraint)
|
||||
cpConstraintSetUserData(m_constraint, this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void PhysConstraint2D::Destroy()
|
||||
{
|
||||
if (m_constraint)
|
||||
{
|
||||
cpSpaceRemoveConstraint(cpConstraintGetSpace(m_constraint), m_constraint);
|
||||
cpConstraintDestroy(m_constraint);
|
||||
|
||||
m_constraint = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PhysDampedSpringConstraint2D::PhysDampedSpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping) :
|
||||
PhysConstraint2D(first.GetWorld(), cpDampedSpringNew(first.GetHandle(), second.GetHandle(), ToChipmunk(firstAnchor), ToChipmunk(secondAnchor), restLength, stiffness, damping))
|
||||
{
|
||||
}
|
||||
|
||||
float PhysDampedSpringConstraint2D::GetDamping() const
|
||||
{
|
||||
return float(cpDampedSpringGetDamping(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f PhysDampedSpringConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpDampedSpringGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float PhysDampedSpringConstraint2D::GetRestLength() const
|
||||
{
|
||||
return float(cpDampedSpringGetRestLength(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f PhysDampedSpringConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpDampedSpringGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float PhysDampedSpringConstraint2D::GetStiffness() const
|
||||
{
|
||||
return float(cpDampedSpringGetStiffness(m_constraint));
|
||||
}
|
||||
|
||||
void PhysDampedSpringConstraint2D::SetDamping(float newDamping)
|
||||
{
|
||||
cpDampedSpringSetDamping(m_constraint, newDamping);
|
||||
}
|
||||
|
||||
void PhysDampedSpringConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpDampedSpringSetAnchorA(m_constraint, ToChipmunk(firstAnchor));
|
||||
}
|
||||
|
||||
void PhysDampedSpringConstraint2D::SetRestLength(float newLength)
|
||||
{
|
||||
cpDampedSpringSetRestLength(m_constraint, newLength);
|
||||
}
|
||||
|
||||
void PhysDampedSpringConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpDampedSpringSetAnchorB(m_constraint, ToChipmunk(firstAnchor));
|
||||
}
|
||||
|
||||
void PhysDampedSpringConstraint2D::SetStiffness(float newStiffness)
|
||||
{
|
||||
cpDampedSpringSetStiffness(m_constraint, newStiffness);
|
||||
}
|
||||
|
||||
|
||||
PhysDampedRotarySpringConstraint2D::PhysDampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& restAngle, float stiffness, float damping) :
|
||||
PhysConstraint2D(first.GetWorld(), cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle.value, stiffness, damping))
|
||||
{
|
||||
}
|
||||
|
||||
float PhysDampedRotarySpringConstraint2D::GetDamping() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetDamping(m_constraint));
|
||||
}
|
||||
|
||||
RadianAnglef PhysDampedRotarySpringConstraint2D::GetRestAngle() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetRestAngle(m_constraint));
|
||||
}
|
||||
|
||||
float PhysDampedRotarySpringConstraint2D::GetStiffness() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetStiffness(m_constraint));
|
||||
}
|
||||
|
||||
void PhysDampedRotarySpringConstraint2D::SetDamping(float newDamping)
|
||||
{
|
||||
cpDampedSpringSetDamping(m_constraint, newDamping);
|
||||
}
|
||||
|
||||
void PhysDampedRotarySpringConstraint2D::SetRestAngle(const RadianAnglef& newAngle)
|
||||
{
|
||||
cpDampedRotarySpringSetRestAngle(m_constraint, newAngle.value);
|
||||
}
|
||||
|
||||
void PhysDampedRotarySpringConstraint2D::SetStiffness(float newStiffness)
|
||||
{
|
||||
cpDampedRotarySpringSetStiffness(m_constraint, newStiffness);
|
||||
}
|
||||
|
||||
|
||||
PhysGearConstraint2D::PhysGearConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratio) :
|
||||
PhysConstraint2D(first.GetWorld(), cpGearJointNew(first.GetHandle(), second.GetHandle(), phase, ratio))
|
||||
{
|
||||
}
|
||||
|
||||
float PhysGearConstraint2D::GetPhase() const
|
||||
{
|
||||
return float(cpGearJointGetPhase(m_constraint));
|
||||
}
|
||||
|
||||
float PhysGearConstraint2D::GetRatio() const
|
||||
{
|
||||
return float(cpGearJointGetRatio(m_constraint));
|
||||
}
|
||||
|
||||
void PhysGearConstraint2D::SetPhase(float phase)
|
||||
{
|
||||
cpGearJointSetPhase(m_constraint, phase);
|
||||
}
|
||||
|
||||
void PhysGearConstraint2D::SetRatio(float ratio)
|
||||
{
|
||||
cpGearJointSetRatio(m_constraint, ratio);
|
||||
}
|
||||
|
||||
|
||||
PhysMotorConstraint2D::PhysMotorConstraint2D(RigidBody2D& first, RigidBody2D& second, float rate) :
|
||||
PhysConstraint2D(first.GetWorld(), cpSimpleMotorNew(first.GetHandle(), second.GetHandle(), rate))
|
||||
{
|
||||
}
|
||||
|
||||
float PhysMotorConstraint2D::GetRate() const
|
||||
{
|
||||
return float(cpSimpleMotorGetRate(m_constraint));
|
||||
}
|
||||
|
||||
void PhysMotorConstraint2D::SetRate(float rate)
|
||||
{
|
||||
cpSimpleMotorSetRate(m_constraint, rate);
|
||||
}
|
||||
|
||||
|
||||
PhysPinConstraint2D::PhysPinConstraint2D(RigidBody2D& body, const Vector2f& anchor) :
|
||||
PhysConstraint2D(body.GetWorld(), cpPinJointNew(body.GetHandle(), cpSpaceGetStaticBody(body.GetWorld()->GetHandle()), ToChipmunk(body.ToLocal(anchor)), ToChipmunk(body.ToLocal(anchor))))
|
||||
{
|
||||
}
|
||||
|
||||
PhysPinConstraint2D::PhysPinConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
|
||||
PhysConstraint2D(first.GetWorld(), cpPinJointNew(first.GetHandle(), second.GetHandle(), ToChipmunk(firstAnchor), ToChipmunk(secondAnchor)))
|
||||
{
|
||||
}
|
||||
|
||||
float PhysPinConstraint2D::GetDistance() const
|
||||
{
|
||||
return float(cpPinJointGetDist(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f PhysPinConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
return FromChipmunk(cpBodyLocalToWorld(cpConstraintGetBodyA(m_constraint), cpPinJointGetAnchorA(m_constraint)));
|
||||
}
|
||||
|
||||
Vector2f PhysPinConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
return FromChipmunk(cpBodyLocalToWorld(cpConstraintGetBodyB(m_constraint), cpPinJointGetAnchorB(m_constraint)));
|
||||
}
|
||||
|
||||
void PhysPinConstraint2D::SetDistance(float newDistance)
|
||||
{
|
||||
cpPinJointSetDist(m_constraint, newDistance);
|
||||
}
|
||||
|
||||
void PhysPinConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPinJointSetAnchorA(m_constraint, cpBodyWorldToLocal(cpConstraintGetBodyA(m_constraint), ToChipmunk(firstAnchor)));
|
||||
}
|
||||
|
||||
void PhysPinConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPinJointSetAnchorB(m_constraint, cpBodyWorldToLocal(cpConstraintGetBodyB(m_constraint), ToChipmunk(firstAnchor)));
|
||||
}
|
||||
|
||||
|
||||
PhysPivotConstraint2D::PhysPivotConstraint2D(RigidBody2D& body, const Vector2f& anchor) :
|
||||
PhysConstraint2D(body.GetWorld(), cpPivotJointNew(cpSpaceGetStaticBody(body.GetWorld()->GetHandle()), body.GetHandle(), ToChipmunk(anchor)))
|
||||
{
|
||||
}
|
||||
|
||||
PhysPivotConstraint2D::PhysPivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor) :
|
||||
PhysConstraint2D(first.GetWorld(), cpPivotJointNew(first.GetHandle(), second.GetHandle(), ToChipmunk(anchor)))
|
||||
{
|
||||
}
|
||||
|
||||
PhysPivotConstraint2D::PhysPivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
|
||||
PhysConstraint2D(first.GetWorld(), cpPivotJointNew2(first.GetHandle(), second.GetHandle(), ToChipmunk(firstAnchor), ToChipmunk(secondAnchor)))
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f PhysPivotConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
return FromChipmunk(cpBodyLocalToWorld(cpConstraintGetBodyA(m_constraint), cpPivotJointGetAnchorA(m_constraint)));
|
||||
}
|
||||
|
||||
Vector2f PhysPivotConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
return FromChipmunk(cpBodyLocalToWorld(cpConstraintGetBodyB(m_constraint), cpPivotJointGetAnchorB(m_constraint)));
|
||||
}
|
||||
|
||||
void PhysPivotConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPivotJointSetAnchorA(m_constraint, cpBodyWorldToLocal(cpConstraintGetBodyA(m_constraint), ToChipmunk(firstAnchor)));
|
||||
}
|
||||
|
||||
void PhysPivotConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPivotJointSetAnchorB(m_constraint, cpBodyWorldToLocal(cpConstraintGetBodyB(m_constraint), ToChipmunk(firstAnchor)));
|
||||
}
|
||||
|
||||
|
||||
PhysRatchetConstraint2D::PhysRatchetConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratchet) :
|
||||
PhysConstraint2D(first.GetWorld(), cpRatchetJointNew(first.GetHandle(), second.GetHandle(), phase, ratchet))
|
||||
{
|
||||
}
|
||||
|
||||
RadianAnglef PhysRatchetConstraint2D::GetAngle() const
|
||||
{
|
||||
return float(cpRatchetJointGetAngle(m_constraint));
|
||||
}
|
||||
|
||||
float PhysRatchetConstraint2D::GetPhase() const
|
||||
{
|
||||
return float(cpRatchetJointGetPhase(m_constraint));
|
||||
}
|
||||
|
||||
float PhysRatchetConstraint2D::GetRatchet() const
|
||||
{
|
||||
return float(cpRatchetJointGetRatchet(m_constraint));
|
||||
}
|
||||
|
||||
void PhysRatchetConstraint2D::SetAngle(const RadianAnglef& angle)
|
||||
{
|
||||
cpRatchetJointSetAngle(m_constraint, angle.value);
|
||||
}
|
||||
|
||||
void PhysRatchetConstraint2D::SetPhase(float phase)
|
||||
{
|
||||
cpRatchetJointSetPhase(m_constraint, phase);
|
||||
}
|
||||
|
||||
void PhysRatchetConstraint2D::SetRatchet(float ratchet)
|
||||
{
|
||||
cpRatchetJointSetRatchet(m_constraint, ratchet);
|
||||
}
|
||||
|
||||
|
||||
PhysRotaryLimitConstraint2D::PhysRotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& minAngle, const RadianAnglef& maxAngle) :
|
||||
PhysConstraint2D(first.GetWorld(), cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle.value, maxAngle.value))
|
||||
{
|
||||
}
|
||||
|
||||
RadianAnglef PhysRotaryLimitConstraint2D::GetMaxAngle() const
|
||||
{
|
||||
return float(cpRotaryLimitJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
RadianAnglef PhysRotaryLimitConstraint2D::GetMinAngle() const
|
||||
{
|
||||
return float(cpRotaryLimitJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
void PhysRotaryLimitConstraint2D::SetMaxAngle(const RadianAnglef& maxAngle)
|
||||
{
|
||||
cpRotaryLimitJointSetMax(m_constraint, maxAngle.value);
|
||||
}
|
||||
|
||||
void PhysRotaryLimitConstraint2D::SetMinAngle(const RadianAnglef& minAngle)
|
||||
{
|
||||
cpRotaryLimitJointSetMin(m_constraint, minAngle.value);
|
||||
}
|
||||
|
||||
|
||||
PhysSlideConstraint2D::PhysSlideConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max) :
|
||||
PhysConstraint2D(first.GetWorld(), cpSlideJointNew(first.GetHandle(), second.GetHandle(), ToChipmunk(firstAnchor), ToChipmunk(secondAnchor), min, max))
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f PhysSlideConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpSlideJointGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float PhysSlideConstraint2D::GetMaxDistance() const
|
||||
{
|
||||
return float(cpSlideJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
float PhysSlideConstraint2D::GetMinDistance() const
|
||||
{
|
||||
return float(cpSlideJointGetMin(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f PhysSlideConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpSlideJointGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
void PhysSlideConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpSlideJointSetAnchorA(m_constraint, ToChipmunk(firstAnchor));
|
||||
}
|
||||
|
||||
void PhysSlideConstraint2D::SetMaxDistance(float newMaxDistance)
|
||||
{
|
||||
cpSlideJointSetMax(m_constraint, newMaxDistance);
|
||||
}
|
||||
|
||||
void PhysSlideConstraint2D::SetMinDistance(float newMinDistance)
|
||||
{
|
||||
cpSlideJointSetMin(m_constraint, newMinDistance);
|
||||
}
|
||||
|
||||
void PhysSlideConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpSlideJointSetAnchorB(m_constraint, ToChipmunk(firstAnchor));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/PhysArbiter2D.hpp>
|
||||
#include <NazaraUtils/StackArray.hpp>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -24,21 +24,21 @@ namespace Nz
|
|||
|
||||
void CpCircleCallback(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
|
||||
{
|
||||
auto drawOptions = static_cast<ChipmunkPhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
if (drawOptions->circleCallback)
|
||||
drawOptions->circleCallback(Vector2f(float(pos.x), float(pos.y)), RadianAnglef(float(angle)), float(radius), CpDebugColorToColor(outlineColor), CpDebugColorToColor(fillColor), drawOptions->userdata);
|
||||
}
|
||||
|
||||
void CpDotCallback(cpFloat size, cpVect pos, cpSpaceDebugColor color, cpDataPointer userdata)
|
||||
{
|
||||
auto drawOptions = static_cast<ChipmunkPhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
if (drawOptions->dotCallback)
|
||||
drawOptions->dotCallback(Vector2f(float(pos.x), float(pos.y)), float(size), CpDebugColorToColor(color), drawOptions->userdata);
|
||||
}
|
||||
|
||||
void CpPolygonCallback(int vertexCount, const cpVect* vertices, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
|
||||
{
|
||||
auto drawOptions = static_cast<ChipmunkPhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
if (drawOptions->polygonCallback)
|
||||
{
|
||||
if constexpr (sizeof(cpVect) == sizeof(Vector2f))
|
||||
|
|
@ -56,24 +56,24 @@ namespace Nz
|
|||
|
||||
void CpSegmentCallback(cpVect a, cpVect b, cpSpaceDebugColor color, cpDataPointer userdata)
|
||||
{
|
||||
auto drawOptions = static_cast<ChipmunkPhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
if (drawOptions->segmentCallback)
|
||||
drawOptions->segmentCallback(Vector2f(float(a.x), float(a.y)), Vector2f(float(b.x), float(b.y)), CpDebugColorToColor(color), drawOptions->userdata);
|
||||
}
|
||||
|
||||
void CpThickSegmentCallback(cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
|
||||
{
|
||||
auto drawOptions = static_cast<ChipmunkPhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
if (drawOptions->thickSegmentCallback)
|
||||
drawOptions->thickSegmentCallback(Vector2f(float(a.x), float(a.y)), Vector2f(float(b.x), float(b.y)), float(radius), CpDebugColorToColor(outlineColor), CpDebugColorToColor(fillColor), drawOptions->userdata);
|
||||
}
|
||||
|
||||
cpSpaceDebugColor CpShapeColorCallback(cpShape* shape, cpDataPointer userdata)
|
||||
{
|
||||
auto drawOptions = static_cast<ChipmunkPhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
|
||||
if (drawOptions->colorCallback)
|
||||
{
|
||||
ChipmunkRigidBody2D& rigidBody = *static_cast<ChipmunkRigidBody2D*>(cpShapeGetUserData(shape));
|
||||
RigidBody2D& rigidBody = *static_cast<RigidBody2D*>(cpShapeGetUserData(shape));
|
||||
return ColorToCpDebugColor(drawOptions->colorCallback(rigidBody, rigidBody.GetShapeIndex(shape), drawOptions->userdata));
|
||||
}
|
||||
else
|
||||
|
|
@ -81,7 +81,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
ChipmunkPhysWorld2D::ChipmunkPhysWorld2D() :
|
||||
PhysWorld2D::PhysWorld2D() :
|
||||
m_maxStepCount(50),
|
||||
m_stepSize(Time::TickDuration(120)),
|
||||
m_timestepAccumulator(Time::Zero())
|
||||
|
|
@ -90,12 +90,12 @@ namespace Nz
|
|||
cpSpaceSetUserData(m_handle, this);
|
||||
}
|
||||
|
||||
ChipmunkPhysWorld2D::~ChipmunkPhysWorld2D()
|
||||
PhysWorld2D::~PhysWorld2D()
|
||||
{
|
||||
cpSpaceFree(m_handle);
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::DebugDraw(const DebugDrawOptions& options, bool drawShapes, bool drawConstraints, bool drawCollisions) const
|
||||
void PhysWorld2D::DebugDraw(const DebugDrawOptions& options, bool drawShapes, bool drawConstraints, bool drawCollisions) const
|
||||
{
|
||||
auto ColorToCpDebugColor = [](Color c) -> cpSpaceDebugColor
|
||||
{
|
||||
|
|
@ -131,45 +131,45 @@ namespace Nz
|
|||
cpSpaceDebugDraw(m_handle, &drawOptions);
|
||||
}
|
||||
|
||||
float ChipmunkPhysWorld2D::GetDamping() const
|
||||
float PhysWorld2D::GetDamping() const
|
||||
{
|
||||
return float(cpSpaceGetDamping(m_handle));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkPhysWorld2D::GetGravity() const
|
||||
Vector2f PhysWorld2D::GetGravity() const
|
||||
{
|
||||
cpVect gravity = cpSpaceGetGravity(m_handle);
|
||||
return Vector2f(Vector2<cpFloat>(gravity.x, gravity.y));
|
||||
}
|
||||
|
||||
cpSpace* ChipmunkPhysWorld2D::GetHandle() const
|
||||
cpSpace* PhysWorld2D::GetHandle() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
std::size_t ChipmunkPhysWorld2D::GetIterationCount() const
|
||||
std::size_t PhysWorld2D::GetIterationCount() const
|
||||
{
|
||||
return cpSpaceGetIterations(m_handle);
|
||||
}
|
||||
|
||||
std::size_t ChipmunkPhysWorld2D::GetMaxStepCount() const
|
||||
std::size_t PhysWorld2D::GetMaxStepCount() const
|
||||
{
|
||||
return m_maxStepCount;
|
||||
}
|
||||
|
||||
Time ChipmunkPhysWorld2D::GetStepSize() const
|
||||
Time PhysWorld2D::GetStepSize() const
|
||||
{
|
||||
return m_stepSize;
|
||||
}
|
||||
|
||||
bool ChipmunkPhysWorld2D::NearestBodyQuery(const Vector2f & from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, ChipmunkRigidBody2D** nearestBody)
|
||||
bool PhysWorld2D::NearestBodyQuery(const Vector2f & from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RigidBody2D** nearestBody)
|
||||
{
|
||||
cpShapeFilter filter = cpShapeFilterNew(collisionGroup, categoryMask, collisionMask);
|
||||
|
||||
if (cpShape* shape = cpSpacePointQueryNearest(m_handle, {from.x, from.y}, maxDistance, filter, nullptr))
|
||||
{
|
||||
if (nearestBody)
|
||||
*nearestBody = static_cast<ChipmunkRigidBody2D*>(cpShapeGetUserData(shape));
|
||||
*nearestBody = static_cast<RigidBody2D*>(cpShapeGetUserData(shape));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -177,7 +177,7 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ChipmunkPhysWorld2D::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, NearestQueryResult* result)
|
||||
bool PhysWorld2D::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, NearestQueryResult* result)
|
||||
{
|
||||
cpShapeFilter filter = cpShapeFilterNew(collisionGroup, categoryMask, collisionMask);
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ namespace Nz
|
|||
result->closestPoint = Vector2f(Vector2<cpFloat>(queryInfo.point.x, queryInfo.point.y));
|
||||
result->distance = float(queryInfo.distance);
|
||||
result->fraction = Vector2f(Vector2<cpFloat>(queryInfo.gradient.x, queryInfo.gradient.y));
|
||||
result->nearestBody = static_cast<ChipmunkRigidBody2D*>(cpShapeGetUserData(queryInfo.shape));
|
||||
result->nearestBody = static_cast<RigidBody2D*>(cpShapeGetUserData(queryInfo.shape));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -206,7 +206,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(const RaycastHit&)>& callback)
|
||||
void PhysWorld2D::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(const RaycastHit&)>& callback)
|
||||
{
|
||||
using CallbackType = std::remove_reference_t<decltype(callback)>;
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ namespace Nz
|
|||
hitInfo.fraction = float(alpha);
|
||||
hitInfo.hitNormal = Vector2f(Vector2<cpFloat>(normal.x, normal.y));
|
||||
hitInfo.hitPos = Vector2f(Vector2<cpFloat>(point.x, point.y));
|
||||
hitInfo.nearestBody = static_cast<ChipmunkRigidBody2D*>(cpShapeGetUserData(shape));
|
||||
hitInfo.nearestBody = static_cast<RigidBody2D*>(cpShapeGetUserData(shape));
|
||||
|
||||
callback(hitInfo);
|
||||
};
|
||||
|
|
@ -227,7 +227,7 @@ namespace Nz
|
|||
cpSpaceSegmentQuery(m_handle, { from.x, from.y }, { to.x, to.y }, radius, filter, cpCallback, const_cast<void*>(static_cast<const void*>(&callback)));
|
||||
}
|
||||
|
||||
bool ChipmunkPhysWorld2D::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RaycastHit>* hitInfos)
|
||||
bool PhysWorld2D::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RaycastHit>* hitInfos)
|
||||
{
|
||||
using ResultType = decltype(hitInfos);
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ namespace Nz
|
|||
hitInfo.fraction = float(alpha);
|
||||
hitInfo.hitNormal = Vector2f(Vector2<cpFloat>(normal.x, normal.y));
|
||||
hitInfo.hitPos = Vector2f(Vector2<cpFloat>(point.x, point.y));
|
||||
hitInfo.nearestBody = static_cast<ChipmunkRigidBody2D*>(cpShapeGetUserData(shape));
|
||||
hitInfo.nearestBody = static_cast<RigidBody2D*>(cpShapeGetUserData(shape));
|
||||
|
||||
results->emplace_back(std::move(hitInfo));
|
||||
};
|
||||
|
|
@ -252,7 +252,7 @@ namespace Nz
|
|||
return hitInfos->size() != previousSize;
|
||||
}
|
||||
|
||||
bool ChipmunkPhysWorld2D::RaycastQueryFirst(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RaycastHit* hitInfo)
|
||||
bool PhysWorld2D::RaycastQueryFirst(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RaycastHit* hitInfo)
|
||||
{
|
||||
cpShapeFilter filter = cpShapeFilterNew(collisionGroup, categoryMask, collisionMask);
|
||||
|
||||
|
|
@ -265,7 +265,7 @@ namespace Nz
|
|||
hitInfo->fraction = float(queryInfo.alpha);
|
||||
hitInfo->hitNormal = Vector2f(Vector2<cpFloat>(queryInfo.normal.x, queryInfo.normal.y));
|
||||
hitInfo->hitPos = Vector2f(Vector2<cpFloat>(queryInfo.point.x, queryInfo.point.y));
|
||||
hitInfo->nearestBody = static_cast<ChipmunkRigidBody2D*>(cpShapeGetUserData(queryInfo.shape));
|
||||
hitInfo->nearestBody = static_cast<RigidBody2D*>(cpShapeGetUserData(queryInfo.shape));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -281,65 +281,65 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(ChipmunkRigidBody2D*)>& callback)
|
||||
void PhysWorld2D::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(RigidBody2D*)>& callback)
|
||||
{
|
||||
using CallbackType = std::remove_reference_t<decltype(callback)>;
|
||||
|
||||
auto cpCallback = [](cpShape* shape, void* data)
|
||||
{
|
||||
CallbackType& callback = *static_cast<CallbackType*>(data);
|
||||
callback(static_cast<ChipmunkRigidBody2D*>(cpShapeGetUserData(shape)));
|
||||
callback(static_cast<RigidBody2D*>(cpShapeGetUserData(shape)));
|
||||
};
|
||||
|
||||
cpShapeFilter filter = cpShapeFilterNew(collisionGroup, categoryMask, collisionMask);
|
||||
cpSpaceBBQuery(m_handle, cpBBNew(boundingBox.x, boundingBox.y, boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height), filter, cpCallback, const_cast<void*>(static_cast<const void*>(&callback)));
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<ChipmunkRigidBody2D*>* bodies)
|
||||
void PhysWorld2D::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RigidBody2D*>* bodies)
|
||||
{
|
||||
using ResultType = decltype(bodies);
|
||||
|
||||
auto callback = [] (cpShape* shape, void* data)
|
||||
{
|
||||
ResultType results = static_cast<ResultType>(data);
|
||||
results->push_back(static_cast<ChipmunkRigidBody2D*>(cpShapeGetUserData(shape)));
|
||||
results->push_back(static_cast<RigidBody2D*>(cpShapeGetUserData(shape)));
|
||||
};
|
||||
|
||||
cpShapeFilter filter = cpShapeFilterNew(collisionGroup, categoryMask, collisionMask);
|
||||
cpSpaceBBQuery(m_handle, cpBBNew(boundingBox.x, boundingBox.y, boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height), filter, callback, bodies);
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::RegisterCallbacks(unsigned int collisionId, ContactCallbacks callbacks)
|
||||
void PhysWorld2D::RegisterCallbacks(unsigned int collisionId, ContactCallbacks callbacks)
|
||||
{
|
||||
InitCallbacks(cpSpaceAddWildcardHandler(m_handle, collisionId), std::move(callbacks));
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, ContactCallbacks callbacks)
|
||||
void PhysWorld2D::RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, ContactCallbacks callbacks)
|
||||
{
|
||||
InitCallbacks(cpSpaceAddCollisionHandler(m_handle, collisionIdA, collisionIdB), std::move(callbacks));
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::SetDamping(float dampingValue)
|
||||
void PhysWorld2D::SetDamping(float dampingValue)
|
||||
{
|
||||
cpSpaceSetDamping(m_handle, dampingValue);
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::SetGravity(const Vector2f& gravity)
|
||||
void PhysWorld2D::SetGravity(const Vector2f& gravity)
|
||||
{
|
||||
cpSpaceSetGravity(m_handle, cpv(gravity.x, gravity.y));
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::SetIterationCount(std::size_t iterationCount)
|
||||
void PhysWorld2D::SetIterationCount(std::size_t iterationCount)
|
||||
{
|
||||
cpSpaceSetIterations(m_handle, SafeCast<int>(iterationCount));
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::SetMaxStepCount(std::size_t maxStepCount)
|
||||
void PhysWorld2D::SetMaxStepCount(std::size_t maxStepCount)
|
||||
{
|
||||
m_maxStepCount = maxStepCount;
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::SetSleepTime(Time sleepTime)
|
||||
void PhysWorld2D::SetSleepTime(Time sleepTime)
|
||||
{
|
||||
if (sleepTime > Time::Zero())
|
||||
cpSpaceSetSleepTimeThreshold(m_handle, sleepTime.AsSeconds<cpFloat>());
|
||||
|
|
@ -347,12 +347,12 @@ namespace Nz
|
|||
cpSpaceSetSleepTimeThreshold(m_handle, std::numeric_limits<cpFloat>::infinity());
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::SetStepSize(Time stepSize)
|
||||
void PhysWorld2D::SetStepSize(Time stepSize)
|
||||
{
|
||||
m_stepSize = stepSize;
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::Step(Time timestep)
|
||||
void PhysWorld2D::Step(Time timestep)
|
||||
{
|
||||
m_timestepAccumulator += timestep;
|
||||
|
||||
|
|
@ -371,7 +371,7 @@ namespace Nz
|
|||
{
|
||||
for (auto&& [bodyIndex, callbackVec] : m_rigidBodyPostSteps)
|
||||
{
|
||||
ChipmunkRigidBody2D* rigidBody = m_bodies[bodyIndex];
|
||||
RigidBody2D* rigidBody = m_bodies[bodyIndex];
|
||||
assert(rigidBody);
|
||||
|
||||
for (const auto& step : callbackVec)
|
||||
|
|
@ -385,12 +385,12 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::UseSpatialHash(float cellSize, std::size_t entityCount)
|
||||
void PhysWorld2D::UseSpatialHash(float cellSize, std::size_t entityCount)
|
||||
{
|
||||
cpSpaceUseSpatialHash(m_handle, cpFloat(cellSize), int(entityCount));
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::InitCallbacks(cpCollisionHandler* handler, ContactCallbacks callbacks)
|
||||
void PhysWorld2D::InitCallbacks(cpCollisionHandler* handler, ContactCallbacks callbacks)
|
||||
{
|
||||
auto it = m_callbacks.find(handler);
|
||||
if (it == m_callbacks.end())
|
||||
|
|
@ -409,11 +409,11 @@ namespace Nz
|
|||
cpBody* secondBody;
|
||||
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||
|
||||
ChipmunkPhysWorld2D* world = static_cast<ChipmunkPhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
ChipmunkRigidBody2D* firstRigidBody = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
ChipmunkRigidBody2D* secondRigidBody = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
ChipmunkArbiter2D arbiter(arb);
|
||||
PhysArbiter2D arbiter(arb);
|
||||
|
||||
const ContactCallbacks* customCallbacks = static_cast<const ContactCallbacks*>(data);
|
||||
if (customCallbacks->startCallback(*world, arbiter, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||
|
|
@ -438,11 +438,11 @@ namespace Nz
|
|||
cpBody* secondBody;
|
||||
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||
|
||||
ChipmunkPhysWorld2D* world = static_cast<ChipmunkPhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
ChipmunkRigidBody2D* firstRigidBody = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
ChipmunkRigidBody2D* secondRigidBody = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
ChipmunkArbiter2D arbiter(arb);
|
||||
PhysArbiter2D arbiter(arb);
|
||||
|
||||
const ContactCallbacks* customCallbacks = static_cast<const ContactCallbacks*>(data);
|
||||
customCallbacks->endCallback(*world, arbiter, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||
|
|
@ -463,11 +463,11 @@ namespace Nz
|
|||
cpBody* secondBody;
|
||||
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||
|
||||
ChipmunkPhysWorld2D* world = static_cast<ChipmunkPhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
ChipmunkRigidBody2D* firstRigidBody = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
ChipmunkRigidBody2D* secondRigidBody = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
ChipmunkArbiter2D arbiter(arb);
|
||||
PhysArbiter2D arbiter(arb);
|
||||
|
||||
const ContactCallbacks* customCallbacks = static_cast<const ContactCallbacks*>(data);
|
||||
if (customCallbacks->preSolveCallback(*world, arbiter, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||
|
|
@ -492,11 +492,11 @@ namespace Nz
|
|||
cpBody* secondBody;
|
||||
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||
|
||||
ChipmunkPhysWorld2D* world = static_cast<ChipmunkPhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
ChipmunkRigidBody2D* firstRigidBody = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
ChipmunkRigidBody2D* secondRigidBody = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
ChipmunkArbiter2D arbiter(arb);
|
||||
PhysArbiter2D arbiter(arb);
|
||||
|
||||
const ContactCallbacks* customCallbacks = static_cast<const ContactCallbacks*>(data);
|
||||
customCallbacks->postSolveCallback(*world, arbiter, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||
|
|
@ -510,7 +510,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkPhysWorld2D::DeferBodyAction(ChipmunkRigidBody2D& rigidBody, PostStep&& func)
|
||||
void PhysWorld2D::DeferBodyAction(RigidBody2D& rigidBody, PostStep&& func)
|
||||
{
|
||||
// If space isn't locked, no need to wait
|
||||
if (!cpSpaceIsLocked(m_handle))
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics2D/Physics2D.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Physics2D::Physics2D(Config /*config*/) :
|
||||
ModuleBase("Physics2D", this)
|
||||
{
|
||||
}
|
||||
|
||||
Physics2D* Physics2D::s_instance = nullptr;
|
||||
}
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkHelper.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <Nazara/Physics2D/ChipmunkHelper.hpp>
|
||||
#include <Nazara/Physics2D/PhysArbiter2D.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include <chipmunk/chipmunk_private.h>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
ChipmunkRigidBody2D::ChipmunkRigidBody2D(const ChipmunkRigidBody2D& object) :
|
||||
RigidBody2D::RigidBody2D(const RigidBody2D& object) :
|
||||
m_geom(object.m_geom),
|
||||
m_world(object.m_world),
|
||||
m_positionOffset(object.m_positionOffset),
|
||||
|
|
@ -43,7 +43,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
ChipmunkRigidBody2D::ChipmunkRigidBody2D(ChipmunkRigidBody2D&& object) noexcept :
|
||||
RigidBody2D::RigidBody2D(RigidBody2D&& object) noexcept :
|
||||
m_shapes(std::move(object.m_shapes)),
|
||||
m_geom(std::move(object.m_geom)),
|
||||
m_handle(object.m_handle),
|
||||
|
|
@ -69,7 +69,7 @@ namespace Nz
|
|||
object.m_handle = nullptr;
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys)
|
||||
void RigidBody2D::AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys)
|
||||
{
|
||||
switch (coordSys)
|
||||
{
|
||||
|
|
@ -83,7 +83,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::AddImpulse(const Vector2f& impulse, const Vector2f& point, CoordSys coordSys)
|
||||
void RigidBody2D::AddImpulse(const Vector2f& impulse, const Vector2f& point, CoordSys coordSys)
|
||||
{
|
||||
switch (coordSys)
|
||||
{
|
||||
|
|
@ -97,12 +97,12 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::AddTorque(const RadianAnglef& torque)
|
||||
void RigidBody2D::AddTorque(const RadianAnglef& torque)
|
||||
{
|
||||
cpBodySetTorque(m_handle, cpBodyGetTorque(m_handle) + torque.value);
|
||||
}
|
||||
|
||||
bool ChipmunkRigidBody2D::ClosestPointQuery(const Vector2f& position, Vector2f* closestPoint, float* closestDistance) const
|
||||
bool RigidBody2D::ClosestPointQuery(const Vector2f& position, Vector2f* closestPoint, float* closestDistance) const
|
||||
{
|
||||
cpVect pos = cpv(cpFloat(position.x), cpFloat(position.y));
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::EnableSimulation(bool simulation)
|
||||
void RigidBody2D::EnableSimulation(bool simulation)
|
||||
{
|
||||
if (m_isSimulationEnabled != simulation)
|
||||
{
|
||||
|
|
@ -146,7 +146,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::ForEachArbiter(const FunctionRef<void(ChipmunkArbiter2D&)>& callback)
|
||||
void RigidBody2D::ForEachArbiter(const FunctionRef<void(PhysArbiter2D&)>& callback)
|
||||
{
|
||||
using CallbackType = std::remove_reference_t<decltype(callback)>;
|
||||
|
||||
|
|
@ -154,23 +154,23 @@ namespace Nz
|
|||
{
|
||||
CallbackType& cb = *static_cast<CallbackType*>(data);
|
||||
|
||||
ChipmunkArbiter2D wrappedArbiter(arbiter);
|
||||
PhysArbiter2D wrappedArbiter(arbiter);
|
||||
cb(wrappedArbiter);
|
||||
};
|
||||
|
||||
cpBodyEachArbiter(m_handle, Trampoline, const_cast<void*>(static_cast<const void*>(&callback)));
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::ForceSleep()
|
||||
void RigidBody2D::ForceSleep()
|
||||
{
|
||||
m_world->DeferBodyAction(*this, [](ChipmunkRigidBody2D* body)
|
||||
m_world->DeferBodyAction(*this, [](RigidBody2D* body)
|
||||
{
|
||||
if (cpBodyGetType(body->GetHandle()) == CP_BODY_TYPE_DYNAMIC)
|
||||
cpBodySleep(body->GetHandle());
|
||||
});
|
||||
}
|
||||
|
||||
Rectf ChipmunkRigidBody2D::GetAABB() const
|
||||
Rectf RigidBody2D::GetAABB() const
|
||||
{
|
||||
if (m_shapes.empty())
|
||||
return Rectf::Zero();
|
||||
|
|
@ -183,24 +183,24 @@ namespace Nz
|
|||
return Rectf(Rect<cpFloat>(bb.l, bb.b, bb.r - bb.l, bb.t - bb.b));
|
||||
}
|
||||
|
||||
RadianAnglef ChipmunkRigidBody2D::GetAngularVelocity() const
|
||||
RadianAnglef RigidBody2D::GetAngularVelocity() const
|
||||
{
|
||||
return float(cpBodyGetAngularVelocity(m_handle));
|
||||
}
|
||||
|
||||
float ChipmunkRigidBody2D::GetElasticity(std::size_t shapeIndex) const
|
||||
float RigidBody2D::GetElasticity(std::size_t shapeIndex) const
|
||||
{
|
||||
assert(shapeIndex < m_shapes.size());
|
||||
return float(cpShapeGetElasticity(m_shapes[shapeIndex]));
|
||||
}
|
||||
|
||||
float ChipmunkRigidBody2D::GetFriction(std::size_t shapeIndex) const
|
||||
float RigidBody2D::GetFriction(std::size_t shapeIndex) const
|
||||
{
|
||||
assert(shapeIndex < m_shapes.size());
|
||||
return float(cpShapeGetFriction(m_shapes[shapeIndex]));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkRigidBody2D::GetMassCenter(CoordSys coordSys) const
|
||||
Vector2f RigidBody2D::GetMassCenter(CoordSys coordSys) const
|
||||
{
|
||||
cpVect massCenter = cpBodyGetCenterOfGravity(m_handle);
|
||||
|
||||
|
|
@ -217,77 +217,77 @@ namespace Nz
|
|||
return Vector2f(static_cast<float>(massCenter.x), static_cast<float>(massCenter.y));
|
||||
}
|
||||
|
||||
float ChipmunkRigidBody2D::GetMomentOfInertia() const
|
||||
float RigidBody2D::GetMomentOfInertia() const
|
||||
{
|
||||
return float(cpBodyGetMoment(m_handle));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkRigidBody2D::GetPosition() const
|
||||
Vector2f RigidBody2D::GetPosition() const
|
||||
{
|
||||
cpVect pos = cpBodyLocalToWorld(m_handle, cpv(-m_positionOffset.x, -m_positionOffset.y));
|
||||
return Vector2f(static_cast<float>(pos.x), static_cast<float>(pos.y));
|
||||
}
|
||||
|
||||
RadianAnglef ChipmunkRigidBody2D::GetRotation() const
|
||||
RadianAnglef RigidBody2D::GetRotation() const
|
||||
{
|
||||
return float(cpBodyGetAngle(m_handle));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkRigidBody2D::GetSurfaceVelocity(std::size_t shapeIndex) const
|
||||
Vector2f RigidBody2D::GetSurfaceVelocity(std::size_t shapeIndex) const
|
||||
{
|
||||
assert(shapeIndex < m_shapes.size());
|
||||
cpVect vel = cpShapeGetSurfaceVelocity(m_shapes[shapeIndex]);
|
||||
return Vector2f(static_cast<float>(vel.x), static_cast<float>(vel.y));
|
||||
}
|
||||
|
||||
Vector2f ChipmunkRigidBody2D::GetVelocity() const
|
||||
Vector2f RigidBody2D::GetVelocity() const
|
||||
{
|
||||
cpVect vel = cpBodyGetVelocity(m_handle);
|
||||
return Vector2f(static_cast<float>(vel.x), static_cast<float>(vel.y));
|
||||
}
|
||||
|
||||
bool ChipmunkRigidBody2D::IsSleeping() const
|
||||
bool RigidBody2D::IsSleeping() const
|
||||
{
|
||||
return cpBodyIsSleeping(m_handle) != 0;
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::ResetVelocityFunction()
|
||||
void RigidBody2D::ResetVelocityFunction()
|
||||
{
|
||||
m_handle->velocity_func = cpBodyUpdateVelocity;
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetAngularVelocity(const RadianAnglef& angularVelocity)
|
||||
void RigidBody2D::SetAngularVelocity(const RadianAnglef& angularVelocity)
|
||||
{
|
||||
cpBodySetAngularVelocity(m_handle, angularVelocity.value);
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetElasticity(float friction)
|
||||
void RigidBody2D::SetElasticity(float friction)
|
||||
{
|
||||
cpFloat frict(friction);
|
||||
for (cpShape* shape : m_shapes)
|
||||
cpShapeSetElasticity(shape, frict);
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetElasticity(std::size_t shapeIndex, float friction)
|
||||
void RigidBody2D::SetElasticity(std::size_t shapeIndex, float friction)
|
||||
{
|
||||
assert(shapeIndex < m_shapes.size());
|
||||
cpShapeSetElasticity(m_shapes[shapeIndex], cpFloat(friction));
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetFriction(float friction)
|
||||
void RigidBody2D::SetFriction(float friction)
|
||||
{
|
||||
cpFloat frict(friction);
|
||||
for (cpShape* shape : m_shapes)
|
||||
cpShapeSetFriction(shape, frict);
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetFriction(std::size_t shapeIndex, float friction)
|
||||
void RigidBody2D::SetFriction(std::size_t shapeIndex, float friction)
|
||||
{
|
||||
assert(shapeIndex < m_shapes.size());
|
||||
cpShapeSetFriction(m_shapes[shapeIndex], cpFloat(friction));
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetGeom(std::shared_ptr<ChipmunkCollider2D> geom, bool recomputeMoment, bool recomputeMassCenter)
|
||||
void RigidBody2D::SetGeom(std::shared_ptr<Collider2D> geom, bool recomputeMoment, bool recomputeMassCenter)
|
||||
{
|
||||
// We have no public way of getting rid of an existing geom without removing the whole body
|
||||
// So let's save some attributes of the body, destroy it and rebuild it
|
||||
|
|
@ -315,7 +315,7 @@ namespace Nz
|
|||
if (geom)
|
||||
m_geom = std::move(geom);
|
||||
else
|
||||
m_geom = std::make_shared<ChipmunkNullCollider2D>();
|
||||
m_geom = std::make_shared<NullCollider2D>();
|
||||
|
||||
m_geom->GenerateShapes(m_handle, &m_shapes);
|
||||
|
||||
|
|
@ -335,13 +335,13 @@ namespace Nz
|
|||
SetMassCenter(m_geom->ComputeCenterOfMass());
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetMass(float mass, bool recomputeMoment)
|
||||
void RigidBody2D::SetMass(float mass, bool recomputeMoment)
|
||||
{
|
||||
if (m_mass > 0.f)
|
||||
{
|
||||
if (mass > 0.f)
|
||||
{
|
||||
m_world->DeferBodyAction(*this, [mass, recomputeMoment](ChipmunkRigidBody2D* body)
|
||||
m_world->DeferBodyAction(*this, [mass, recomputeMoment](RigidBody2D* body)
|
||||
{
|
||||
cpBodySetMass(body->GetHandle(), mass);
|
||||
|
||||
|
|
@ -350,11 +350,11 @@ namespace Nz
|
|||
});
|
||||
}
|
||||
else
|
||||
m_world->DeferBodyAction(*this, [](ChipmunkRigidBody2D* body) { cpBodySetType(body->GetHandle(), (body->IsStatic()) ? CP_BODY_TYPE_STATIC : CP_BODY_TYPE_KINEMATIC); } );
|
||||
m_world->DeferBodyAction(*this, [](RigidBody2D* body) { cpBodySetType(body->GetHandle(), (body->IsStatic()) ? CP_BODY_TYPE_STATIC : CP_BODY_TYPE_KINEMATIC); } );
|
||||
}
|
||||
else if (mass > 0.f)
|
||||
{
|
||||
m_world->DeferBodyAction(*this, [mass, recomputeMoment](ChipmunkRigidBody2D* body)
|
||||
m_world->DeferBodyAction(*this, [mass, recomputeMoment](RigidBody2D* body)
|
||||
{
|
||||
if (cpBodyGetType(body->GetHandle()) != CP_BODY_TYPE_DYNAMIC)
|
||||
{
|
||||
|
|
@ -370,7 +370,7 @@ namespace Nz
|
|||
m_mass = mass;
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetMassCenter(const Vector2f& center, CoordSys coordSys)
|
||||
void RigidBody2D::SetMassCenter(const Vector2f& center, CoordSys coordSys)
|
||||
{
|
||||
cpVect massCenter = ToChipmunk(center);
|
||||
|
||||
|
|
@ -387,64 +387,64 @@ namespace Nz
|
|||
cpBodySetCenterOfGravity(m_handle, massCenter);
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetMomentOfInertia(float moment)
|
||||
void RigidBody2D::SetMomentOfInertia(float moment)
|
||||
{
|
||||
// Even though Chipmunk allows us to change this anytime, we need to do it in a post-step to prevent other post-steps to override this
|
||||
m_world->DeferBodyAction(*this, [moment] (ChipmunkRigidBody2D* body)
|
||||
m_world->DeferBodyAction(*this, [moment] (RigidBody2D* body)
|
||||
{
|
||||
cpBodySetMoment(body->GetHandle(), moment);
|
||||
});
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetPosition(const Vector2f& position)
|
||||
void RigidBody2D::SetPosition(const Vector2f& position)
|
||||
{
|
||||
// Use cpTransformVect to rotate/scale the position offset
|
||||
cpBodySetPosition(m_handle, cpvadd(ToChipmunk(position), cpTransformVect(m_handle->transform, ToChipmunk(m_positionOffset))));
|
||||
if (m_isStatic)
|
||||
{
|
||||
m_world->DeferBodyAction(*this, [](ChipmunkRigidBody2D* body)
|
||||
m_world->DeferBodyAction(*this, [](RigidBody2D* body)
|
||||
{
|
||||
cpSpaceReindexShapesForBody(body->GetWorld()->GetHandle(), body->GetHandle());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetPositionOffset(const Vector2f& offset)
|
||||
void RigidBody2D::SetPositionOffset(const Vector2f& offset)
|
||||
{
|
||||
Vector2f position = GetPosition();
|
||||
m_positionOffset = offset;
|
||||
SetPosition(position);
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetRotation(const RadianAnglef& rotation)
|
||||
void RigidBody2D::SetRotation(const RadianAnglef& rotation)
|
||||
{
|
||||
cpBodySetAngle(m_handle, rotation.value);
|
||||
if (m_isStatic)
|
||||
{
|
||||
m_world->DeferBodyAction(*this, [](ChipmunkRigidBody2D* body)
|
||||
m_world->DeferBodyAction(*this, [](RigidBody2D* body)
|
||||
{
|
||||
cpSpaceReindexShapesForBody(body->GetWorld()->GetHandle(), body->GetHandle());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||
void RigidBody2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||
{
|
||||
Vector2<cpFloat> velocity(surfaceVelocity.x, surfaceVelocity.y);
|
||||
for (cpShape* shape : m_shapes)
|
||||
cpShapeSetSurfaceVelocity(shape, cpv(velocity.x, velocity.y));
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetSurfaceVelocity(std::size_t shapeIndex, const Vector2f& surfaceVelocity)
|
||||
void RigidBody2D::SetSurfaceVelocity(std::size_t shapeIndex, const Vector2f& surfaceVelocity)
|
||||
{
|
||||
assert(shapeIndex < m_shapes.size());
|
||||
cpShapeSetSurfaceVelocity(m_shapes[shapeIndex], cpv(cpFloat(surfaceVelocity.x), cpFloat(surfaceVelocity.y)));
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetStatic(bool setStaticBody)
|
||||
void RigidBody2D::SetStatic(bool setStaticBody)
|
||||
{
|
||||
m_isStatic = setStaticBody;
|
||||
m_world->DeferBodyAction(*this, [](ChipmunkRigidBody2D* body)
|
||||
m_world->DeferBodyAction(*this, [](RigidBody2D* body)
|
||||
{
|
||||
if (body->IsStatic())
|
||||
{
|
||||
|
|
@ -458,12 +458,12 @@ namespace Nz
|
|||
});
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetVelocity(const Vector2f& velocity)
|
||||
void RigidBody2D::SetVelocity(const Vector2f& velocity)
|
||||
{
|
||||
cpBodySetVelocity(m_handle, ToChipmunk(velocity));
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::SetVelocityFunction(VelocityFunc velocityFunc)
|
||||
void RigidBody2D::SetVelocityFunction(VelocityFunc velocityFunc)
|
||||
{
|
||||
m_velocityFunc = std::move(velocityFunc);
|
||||
|
||||
|
|
@ -471,7 +471,7 @@ namespace Nz
|
|||
{
|
||||
m_handle->velocity_func = [](cpBody* body, cpVect gravity, cpFloat damping, cpFloat dt)
|
||||
{
|
||||
ChipmunkRigidBody2D* rigidBody = static_cast<ChipmunkRigidBody2D*>(cpBodyGetUserData(body));
|
||||
RigidBody2D* rigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(body));
|
||||
const auto& callback = rigidBody->GetVelocityFunction();
|
||||
assert(callback);
|
||||
|
||||
|
|
@ -482,48 +482,48 @@ namespace Nz
|
|||
m_handle->velocity_func = cpBodyUpdateVelocity;
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::TeleportTo(const Vector2f& position, const RadianAnglef& rotation)
|
||||
void RigidBody2D::TeleportTo(const Vector2f& position, const RadianAnglef& rotation)
|
||||
{
|
||||
// Use cpTransformVect to rotate/scale the position offset
|
||||
cpBodySetPosition(m_handle, cpvadd(ToChipmunk(position), cpTransformVect(m_handle->transform, ToChipmunk(m_positionOffset))));
|
||||
cpBodySetAngle(m_handle, rotation.value);
|
||||
if (m_isStatic)
|
||||
{
|
||||
m_world->DeferBodyAction(*this, [](ChipmunkRigidBody2D* body)
|
||||
m_world->DeferBodyAction(*this, [](RigidBody2D* body)
|
||||
{
|
||||
cpSpaceReindexShapesForBody(body->GetWorld()->GetHandle(), body->GetHandle());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
RadianAnglef ChipmunkRigidBody2D::ToLocal(const RadianAnglef& worldRotation)
|
||||
RadianAnglef RigidBody2D::ToLocal(const RadianAnglef& worldRotation)
|
||||
{
|
||||
return worldRotation - GetRotation();
|
||||
}
|
||||
|
||||
Vector2f ChipmunkRigidBody2D::ToLocal(const Vector2f& worldPosition)
|
||||
Vector2f RigidBody2D::ToLocal(const Vector2f& worldPosition)
|
||||
{
|
||||
return FromChipmunk(cpBodyWorldToLocal(m_handle, ToChipmunk(worldPosition)));
|
||||
}
|
||||
|
||||
RadianAnglef ChipmunkRigidBody2D::ToWorld(const RadianAnglef& localRotation)
|
||||
RadianAnglef RigidBody2D::ToWorld(const RadianAnglef& localRotation)
|
||||
{
|
||||
return GetRotation() + localRotation;
|
||||
}
|
||||
|
||||
Vector2f ChipmunkRigidBody2D::ToWorld(const Vector2f& localPosition)
|
||||
Vector2f RigidBody2D::ToWorld(const Vector2f& localPosition)
|
||||
{
|
||||
return FromChipmunk(cpBodyLocalToWorld(m_handle, ToChipmunk(localPosition)));
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::UpdateVelocity(const Vector2f& gravity, float damping, float deltaTime)
|
||||
void RigidBody2D::UpdateVelocity(const Vector2f& gravity, float damping, float deltaTime)
|
||||
{
|
||||
cpBodyUpdateVelocity(m_handle, ToChipmunk(gravity), damping, deltaTime);
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::Wakeup()
|
||||
void RigidBody2D::Wakeup()
|
||||
{
|
||||
m_world->DeferBodyAction(*this, [](ChipmunkRigidBody2D* body)
|
||||
m_world->DeferBodyAction(*this, [](RigidBody2D* body)
|
||||
{
|
||||
if (cpBodyGetType(body->GetHandle()) != CP_BODY_TYPE_STATIC)
|
||||
cpBodyActivate(body->GetHandle());
|
||||
|
|
@ -532,12 +532,12 @@ namespace Nz
|
|||
});
|
||||
}
|
||||
|
||||
ChipmunkRigidBody2D& ChipmunkRigidBody2D::operator=(const ChipmunkRigidBody2D& object)
|
||||
RigidBody2D& RigidBody2D::operator=(const RigidBody2D& object)
|
||||
{
|
||||
return operator=(ChipmunkRigidBody2D(object));
|
||||
return operator=(RigidBody2D(object));
|
||||
}
|
||||
|
||||
ChipmunkRigidBody2D& ChipmunkRigidBody2D::operator=(ChipmunkRigidBody2D&& object) noexcept
|
||||
RigidBody2D& RigidBody2D::operator=(RigidBody2D&& object) noexcept
|
||||
{
|
||||
Destroy();
|
||||
|
||||
|
|
@ -569,7 +569,7 @@ namespace Nz
|
|||
return *this;
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::Create(ChipmunkPhysWorld2D& world, const DynamicSettings& settings)
|
||||
void RigidBody2D::Create(PhysWorld2D& world, const DynamicSettings& settings)
|
||||
{
|
||||
m_isRegistered = false;
|
||||
m_isSimulationEnabled = settings.isSimulationEnabled;
|
||||
|
|
@ -591,7 +591,7 @@ namespace Nz
|
|||
SetVelocity(settings.linearVelocity);
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::Create(ChipmunkPhysWorld2D& world, const StaticSettings& settings)
|
||||
void RigidBody2D::Create(PhysWorld2D& world, const StaticSettings& settings)
|
||||
{
|
||||
m_gravityFactor = 1.f;
|
||||
m_isRegistered = false;
|
||||
|
|
@ -611,7 +611,7 @@ namespace Nz
|
|||
SetRotation(settings.rotation);
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::Destroy()
|
||||
void RigidBody2D::Destroy()
|
||||
{
|
||||
if (m_bodyIndex != InvalidBodyIndex)
|
||||
{
|
||||
|
|
@ -622,7 +622,7 @@ namespace Nz
|
|||
DestroyBody();
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::DestroyBody()
|
||||
void RigidBody2D::DestroyBody()
|
||||
{
|
||||
UnregisterFromSpace();
|
||||
|
||||
|
|
@ -638,7 +638,7 @@ namespace Nz
|
|||
m_shapes.clear();
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::RegisterToSpace()
|
||||
void RigidBody2D::RegisterToSpace()
|
||||
{
|
||||
if (!m_isRegistered)
|
||||
{
|
||||
|
|
@ -653,7 +653,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::UnregisterFromSpace()
|
||||
void RigidBody2D::UnregisterFromSpace()
|
||||
{
|
||||
if (m_isRegistered)
|
||||
{
|
||||
|
|
@ -668,7 +668,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::CopyBodyData(cpBody* from, cpBody* to)
|
||||
void RigidBody2D::CopyBodyData(cpBody* from, cpBody* to)
|
||||
{
|
||||
cpBodySetType(to, cpBodyGetType(from));
|
||||
|
||||
|
|
@ -684,7 +684,7 @@ namespace Nz
|
|||
to->velocity_func = from->velocity_func;
|
||||
}
|
||||
|
||||
void ChipmunkRigidBody2D::CopyShapeData(cpShape* from, cpShape* to)
|
||||
void RigidBody2D::CopyShapeData(cpShape* from, cpShape* to)
|
||||
{
|
||||
cpShapeSetElasticity(to, cpShapeGetElasticity(from));
|
||||
cpShapeSetFriction(to, cpShapeGetFriction(from));
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.hpp>
|
||||
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||
#include <Nazara/Physics2D/Systems/Physics2DSystem.hpp>
|
||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -20,30 +20,30 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
ChipmunkPhysics2DSystem::ChipmunkPhysics2DSystem(entt::registry& registry) :
|
||||
Physics2DSystem::Physics2DSystem(entt::registry& registry) :
|
||||
m_registry(registry),
|
||||
m_physicsConstructObserver(m_registry, entt::collector.group<ChipmunkRigidBody2DComponent, NodeComponent>())
|
||||
m_physicsConstructObserver(m_registry, entt::collector.group<RigidBody2DComponent, NodeComponent>())
|
||||
{
|
||||
m_bodyConstructConnection = registry.on_construct<ChipmunkRigidBody2DComponent>().connect<&ChipmunkPhysics2DSystem::OnBodyConstruct>(this);
|
||||
m_bodyDestructConnection = registry.on_destroy<ChipmunkRigidBody2DComponent>().connect<&ChipmunkPhysics2DSystem::OnBodyDestruct>(this);
|
||||
m_bodyConstructConnection = registry.on_construct<RigidBody2DComponent>().connect<&Physics2DSystem::OnBodyConstruct>(this);
|
||||
m_bodyDestructConnection = registry.on_destroy<RigidBody2DComponent>().connect<&Physics2DSystem::OnBodyDestruct>(this);
|
||||
}
|
||||
|
||||
ChipmunkPhysics2DSystem::~ChipmunkPhysics2DSystem()
|
||||
Physics2DSystem::~Physics2DSystem()
|
||||
{
|
||||
m_physicsConstructObserver.disconnect();
|
||||
|
||||
// Ensure every body is destroyed before world is
|
||||
auto rigidBodyView = m_registry.view<ChipmunkRigidBody2DComponent>();
|
||||
auto rigidBodyView = m_registry.view<RigidBody2DComponent>();
|
||||
for (auto [entity, rigidBodyComponent] : rigidBodyView.each())
|
||||
rigidBodyComponent.Destroy();
|
||||
}
|
||||
|
||||
void ChipmunkPhysics2DSystem::Update(Time elapsedTime)
|
||||
void Physics2DSystem::Update(Time elapsedTime)
|
||||
{
|
||||
// Move newly-created physics entities to their node position/rotation
|
||||
m_physicsConstructObserver.each([&](entt::entity entity)
|
||||
{
|
||||
ChipmunkRigidBody2DComponent& entityPhysics = m_registry.get<ChipmunkRigidBody2DComponent>(entity);
|
||||
RigidBody2DComponent& entityPhysics = m_registry.get<RigidBody2DComponent>(entity);
|
||||
NodeComponent& entityNode = m_registry.get<NodeComponent>(entity);
|
||||
|
||||
entityPhysics.TeleportTo(Vector2f(entityNode.GetPosition()), AngleFromQuaternion(entityNode.GetRotation()));
|
||||
|
|
@ -52,7 +52,7 @@ namespace Nz
|
|||
m_physWorld.Step(elapsedTime);
|
||||
|
||||
// Replicate rigid body position to their node components
|
||||
auto view = m_registry.view<NodeComponent, const ChipmunkRigidBody2DComponent>(entt::exclude<DisabledComponent>);
|
||||
auto view = m_registry.view<NodeComponent, const RigidBody2DComponent>(entt::exclude<DisabledComponent>);
|
||||
for (auto [entity, nodeComponent, rigidBodyComponent] : view.each())
|
||||
{
|
||||
if (rigidBodyComponent.IsSleeping())
|
||||
|
|
@ -62,14 +62,14 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
ChipmunkPhysWorld2D::ContactCallbacks ChipmunkPhysics2DSystem::SetupContactCallbacks(ContactCallbacks callbacks)
|
||||
PhysWorld2D::ContactCallbacks Physics2DSystem::SetupContactCallbacks(ContactCallbacks callbacks)
|
||||
{
|
||||
ChipmunkPhysWorld2D::ContactCallbacks trampolineCallbacks;
|
||||
PhysWorld2D::ContactCallbacks trampolineCallbacks;
|
||||
trampolineCallbacks.userdata = callbacks.userdata;
|
||||
|
||||
if (callbacks.endCallback)
|
||||
{
|
||||
trampolineCallbacks.endCallback = [this, cb = std::move(callbacks.endCallback)](ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)
|
||||
trampolineCallbacks.endCallback = [this, cb = std::move(callbacks.endCallback)](PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)
|
||||
{
|
||||
return cb(world, arbiter, GetRigidBodyEntity(bodyA.GetBodyIndex()), GetRigidBodyEntity(bodyB.GetBodyIndex()), userdata);
|
||||
};
|
||||
|
|
@ -77,7 +77,7 @@ namespace Nz
|
|||
|
||||
if (callbacks.preSolveCallback)
|
||||
{
|
||||
trampolineCallbacks.preSolveCallback = [this, cb = std::move(callbacks.preSolveCallback)](ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)
|
||||
trampolineCallbacks.preSolveCallback = [this, cb = std::move(callbacks.preSolveCallback)](PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)
|
||||
{
|
||||
return cb(world, arbiter, GetRigidBodyEntity(bodyA.GetBodyIndex()), GetRigidBodyEntity(bodyB.GetBodyIndex()), userdata);
|
||||
};
|
||||
|
|
@ -85,7 +85,7 @@ namespace Nz
|
|||
|
||||
if (callbacks.postSolveCallback)
|
||||
{
|
||||
trampolineCallbacks.postSolveCallback = [this, cb = std::move(callbacks.postSolveCallback)](ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)
|
||||
trampolineCallbacks.postSolveCallback = [this, cb = std::move(callbacks.postSolveCallback)](PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)
|
||||
{
|
||||
return cb(world, arbiter, GetRigidBodyEntity(bodyA.GetBodyIndex()), GetRigidBodyEntity(bodyB.GetBodyIndex()), userdata);
|
||||
};
|
||||
|
|
@ -93,7 +93,7 @@ namespace Nz
|
|||
|
||||
if (callbacks.startCallback)
|
||||
{
|
||||
trampolineCallbacks.startCallback = [this, cb = std::move(callbacks.startCallback)](ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)
|
||||
trampolineCallbacks.startCallback = [this, cb = std::move(callbacks.startCallback)](PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)
|
||||
{
|
||||
return cb(world, arbiter, GetRigidBodyEntity(bodyA.GetBodyIndex()), GetRigidBodyEntity(bodyB.GetBodyIndex()), userdata);
|
||||
};
|
||||
|
|
@ -102,9 +102,9 @@ namespace Nz
|
|||
return trampolineCallbacks;
|
||||
}
|
||||
|
||||
void ChipmunkPhysics2DSystem::OnBodyConstruct(entt::registry& registry, entt::entity entity)
|
||||
void Physics2DSystem::OnBodyConstruct(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
ChipmunkRigidBody2DComponent& rigidBody = registry.get<ChipmunkRigidBody2DComponent>(entity);
|
||||
RigidBody2DComponent& rigidBody = registry.get<RigidBody2DComponent>(entity);
|
||||
rigidBody.Construct(m_physWorld);
|
||||
|
||||
UInt32 uniqueIndex = rigidBody.GetBodyIndex();
|
||||
|
|
@ -114,10 +114,10 @@ namespace Nz
|
|||
m_bodyIndicesToEntity[uniqueIndex] = entity;
|
||||
}
|
||||
|
||||
void ChipmunkPhysics2DSystem::OnBodyDestruct(entt::registry& registry, entt::entity entity)
|
||||
void Physics2DSystem::OnBodyDestruct(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
// Unregister owning entity
|
||||
ChipmunkRigidBody2DComponent& rigidBody = registry.get<ChipmunkRigidBody2DComponent>(entity);
|
||||
RigidBody2DComponent& rigidBody = registry.get<RigidBody2DComponent>(entity);
|
||||
UInt32 uniqueIndex = rigidBody.GetBodyIndex();
|
||||
assert(uniqueIndex <= m_bodyIndicesToEntity.size());
|
||||
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltCollider3D.hpp>
|
||||
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||
#include <Nazara/Core/PrimitiveList.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltHelper.hpp>
|
||||
#include <Nazara/Physics3D/JoltHelper.hpp>
|
||||
#include <Nazara/Utility/Algorithm.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/SoftwareBuffer.hpp>
|
||||
|
|
@ -21,14 +21,14 @@
|
|||
#include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
JoltCollider3D::JoltCollider3D() = default;
|
||||
JoltCollider3D::~JoltCollider3D() = default;
|
||||
Collider3D::Collider3D() = default;
|
||||
Collider3D::~Collider3D() = default;
|
||||
|
||||
std::shared_ptr<StaticMesh> JoltCollider3D::GenerateDebugMesh() const
|
||||
std::shared_ptr<StaticMesh> Collider3D::GenerateDebugMesh() const
|
||||
{
|
||||
std::vector<Vector3f> colliderVertices;
|
||||
std::vector<UInt16> colliderIndices;
|
||||
|
|
@ -44,12 +44,12 @@ namespace Nz
|
|||
return colliderSubMesh;
|
||||
}
|
||||
|
||||
std::shared_ptr<JoltCollider3D> JoltCollider3D::Build(const PrimitiveList& list)
|
||||
std::shared_ptr<Collider3D> Collider3D::Build(const PrimitiveList& list)
|
||||
{
|
||||
std::size_t primitiveCount = list.GetSize();
|
||||
if (primitiveCount > 1)
|
||||
{
|
||||
std::vector<JoltCompoundCollider3D::ChildCollider> childColliders(primitiveCount);
|
||||
std::vector<CompoundCollider3D::ChildCollider> childColliders(primitiveCount);
|
||||
|
||||
for (unsigned int i = 0; i < primitiveCount; ++i)
|
||||
{
|
||||
|
|
@ -59,7 +59,7 @@ namespace Nz
|
|||
childColliders[i].rotation = primitive.matrix.GetRotation();
|
||||
}
|
||||
|
||||
return std::make_shared<JoltCompoundCollider3D>(std::move(childColliders));
|
||||
return std::make_shared<CompoundCollider3D>(std::move(childColliders));
|
||||
}
|
||||
else if (primitiveCount > 0)
|
||||
return CreateGeomFromPrimitive(list.GetPrimitive(0));
|
||||
|
|
@ -67,12 +67,12 @@ namespace Nz
|
|||
return nullptr;// std::make_shared<NullCollider3D>(); //< TODO
|
||||
}
|
||||
|
||||
void JoltCollider3D::ResetShapeSettings()
|
||||
void Collider3D::ResetShapeSettings()
|
||||
{
|
||||
m_shapeSettings.reset();
|
||||
}
|
||||
|
||||
void JoltCollider3D::SetupShapeSettings(std::unique_ptr<JPH::ShapeSettings>&& shapeSettings)
|
||||
void Collider3D::SetupShapeSettings(std::unique_ptr<JPH::ShapeSettings>&& shapeSettings)
|
||||
{
|
||||
assert(!m_shapeSettings);
|
||||
m_shapeSettings = std::move(shapeSettings);
|
||||
|
|
@ -82,37 +82,37 @@ namespace Nz
|
|||
throw std::runtime_error(std::string("shape creation failed: ") + result.GetError().c_str());
|
||||
}
|
||||
|
||||
std::shared_ptr<JoltCollider3D> JoltCollider3D::CreateGeomFromPrimitive(const Primitive& primitive)
|
||||
std::shared_ptr<Collider3D> Collider3D::CreateGeomFromPrimitive(const Primitive& primitive)
|
||||
{
|
||||
switch (primitive.type)
|
||||
{
|
||||
case PrimitiveType::Box:
|
||||
return std::make_shared<JoltBoxCollider3D>(primitive.box.lengths);
|
||||
return std::make_shared<BoxCollider3D>(primitive.box.lengths);
|
||||
|
||||
case PrimitiveType::Cone:
|
||||
return nullptr; //< TODO
|
||||
//return std::make_shared<ConeCollider3D>(primitive.cone.length, primitive.cone.radius);
|
||||
|
||||
case PrimitiveType::Plane:
|
||||
return std::make_shared<JoltBoxCollider3D>(Vector3f(primitive.plane.size.x, 0.01f, primitive.plane.size.y));
|
||||
return std::make_shared<BoxCollider3D>(Vector3f(primitive.plane.size.x, 0.01f, primitive.plane.size.y));
|
||||
///TODO: PlaneGeom?
|
||||
|
||||
case PrimitiveType::Sphere:
|
||||
return std::make_shared<JoltSphereCollider3D>(primitive.sphere.size);
|
||||
return std::make_shared<SphereCollider3D>(primitive.sphere.size);
|
||||
}
|
||||
|
||||
NazaraErrorFmt("Primitive type not handled ({0:#x})", UnderlyingCast(primitive.type));
|
||||
return std::shared_ptr<JoltCollider3D>();
|
||||
return std::shared_ptr<Collider3D>();
|
||||
}
|
||||
|
||||
/********************************** JoltBoxCollider3D **********************************/
|
||||
/********************************** BoxCollider3D **********************************/
|
||||
|
||||
JoltBoxCollider3D::JoltBoxCollider3D(const Vector3f& lengths, float convexRadius)
|
||||
BoxCollider3D::BoxCollider3D(const Vector3f& lengths, float convexRadius)
|
||||
{
|
||||
SetupShapeSettings(std::make_unique<JPH::BoxShapeSettings>(ToJolt(lengths * 0.5f), convexRadius));
|
||||
}
|
||||
|
||||
void JoltBoxCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
void BoxCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
{
|
||||
auto InsertVertex = [&](float x, float y, float z) -> UInt16
|
||||
{
|
||||
|
|
@ -154,24 +154,24 @@ namespace Nz
|
|||
InsertEdge(v3, v7);
|
||||
}
|
||||
|
||||
Vector3f JoltBoxCollider3D::GetLengths() const
|
||||
Vector3f BoxCollider3D::GetLengths() const
|
||||
{
|
||||
return FromJolt(GetShapeSettingsAs<JPH::BoxShapeSettings>()->mHalfExtent) * 2.f;
|
||||
}
|
||||
|
||||
JoltColliderType3D JoltBoxCollider3D::GetType() const
|
||||
ColliderType3D BoxCollider3D::GetType() const
|
||||
{
|
||||
return JoltColliderType3D::Box;
|
||||
return ColliderType3D::Box;
|
||||
}
|
||||
|
||||
/********************************** JoltCapsuleCollider3D **********************************/
|
||||
/********************************** CapsuleCollider3D **********************************/
|
||||
|
||||
JoltCapsuleCollider3D::JoltCapsuleCollider3D(float height, float radius)
|
||||
CapsuleCollider3D::CapsuleCollider3D(float height, float radius)
|
||||
{
|
||||
SetupShapeSettings(std::make_unique<JPH::CapsuleShapeSettings>(height * 0.5f, radius));
|
||||
}
|
||||
|
||||
void JoltCapsuleCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
void CapsuleCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
{
|
||||
constexpr unsigned int cornerStepCount = 10;
|
||||
constexpr unsigned int sliceCount = 4;
|
||||
|
|
@ -237,24 +237,24 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
float JoltCapsuleCollider3D::GetHeight() const
|
||||
float CapsuleCollider3D::GetHeight() const
|
||||
{
|
||||
return GetShapeSettingsAs<JPH::CapsuleShapeSettings>()->mHalfHeightOfCylinder * 2.0f;
|
||||
}
|
||||
|
||||
float JoltCapsuleCollider3D::GetRadius() const
|
||||
float CapsuleCollider3D::GetRadius() const
|
||||
{
|
||||
return GetShapeSettingsAs<JPH::CapsuleShapeSettings>()->mRadius;
|
||||
}
|
||||
|
||||
JoltColliderType3D JoltCapsuleCollider3D::GetType() const
|
||||
ColliderType3D CapsuleCollider3D::GetType() const
|
||||
{
|
||||
return JoltColliderType3D::Capsule;
|
||||
return ColliderType3D::Capsule;
|
||||
}
|
||||
|
||||
/******************************* JoltCompoundCollider3D ********************************/
|
||||
/******************************* CompoundCollider3D ********************************/
|
||||
|
||||
JoltCompoundCollider3D::JoltCompoundCollider3D(std::vector<ChildCollider> childs) :
|
||||
CompoundCollider3D::CompoundCollider3D(std::vector<ChildCollider> childs) :
|
||||
m_childs(std::move(childs))
|
||||
{
|
||||
auto shapeSettings = std::make_unique<JPH::StaticCompoundShapeSettings>();
|
||||
|
|
@ -264,31 +264,31 @@ namespace Nz
|
|||
SetupShapeSettings(std::move(shapeSettings));
|
||||
}
|
||||
|
||||
JoltCompoundCollider3D::~JoltCompoundCollider3D()
|
||||
CompoundCollider3D::~CompoundCollider3D()
|
||||
{
|
||||
// We have to destroy shape settings first as it carries references on the inner colliders
|
||||
ResetShapeSettings();
|
||||
}
|
||||
|
||||
void JoltCompoundCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
void CompoundCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
{
|
||||
for (const auto& child : m_childs)
|
||||
child.collider->BuildDebugMesh(vertices, indices, offsetMatrix * Matrix4f::Transform(child.offset, child.rotation));
|
||||
}
|
||||
|
||||
auto JoltCompoundCollider3D::GetGeoms() const -> const std::vector<ChildCollider>&
|
||||
auto CompoundCollider3D::GetGeoms() const -> const std::vector<ChildCollider>&
|
||||
{
|
||||
return m_childs;
|
||||
}
|
||||
|
||||
JoltColliderType3D JoltCompoundCollider3D::GetType() const
|
||||
ColliderType3D CompoundCollider3D::GetType() const
|
||||
{
|
||||
return JoltColliderType3D::Compound;
|
||||
return ColliderType3D::Compound;
|
||||
}
|
||||
|
||||
/******************************** JoltConvexHullCollider3D *********************************/
|
||||
/******************************** ConvexHullCollider3D *********************************/
|
||||
|
||||
JoltConvexHullCollider3D::JoltConvexHullCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, float hullTolerance, float convexRadius, float maxErrorConvexRadius)
|
||||
ConvexHullCollider3D::ConvexHullCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, float hullTolerance, float convexRadius, float maxErrorConvexRadius)
|
||||
{
|
||||
std::unique_ptr<JPH::ConvexHullShapeSettings> settings = std::make_unique<JPH::ConvexHullShapeSettings>();
|
||||
settings->mHullTolerance = hullTolerance;
|
||||
|
|
@ -302,7 +302,7 @@ namespace Nz
|
|||
SetupShapeSettings(std::move(settings));
|
||||
}
|
||||
|
||||
void JoltConvexHullCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
void ConvexHullCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
{
|
||||
const JPH::ConvexHullShapeSettings* settings = GetShapeSettingsAs<JPH::ConvexHullShapeSettings>();
|
||||
const JPH::ConvexHullShape* shape = SafeCast<const JPH::ConvexHullShape*>(settings->Create().Get().GetPtr());
|
||||
|
|
@ -348,14 +348,14 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
JoltColliderType3D JoltConvexHullCollider3D::GetType() const
|
||||
ColliderType3D ConvexHullCollider3D::GetType() const
|
||||
{
|
||||
return JoltColliderType3D::Convex;
|
||||
return ColliderType3D::Convex;
|
||||
}
|
||||
|
||||
/******************************** JoltMeshCollider3D *********************************/
|
||||
/******************************** MeshCollider3D *********************************/
|
||||
|
||||
JoltMeshCollider3D::JoltMeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt16> indices, std::size_t indexCount)
|
||||
MeshCollider3D::MeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt16> indices, std::size_t indexCount)
|
||||
{
|
||||
std::unique_ptr<JPH::MeshShapeSettings> settings = std::make_unique<JPH::MeshShapeSettings>();
|
||||
settings->mTriangleVertices.resize(vertexCount);
|
||||
|
|
@ -380,7 +380,7 @@ namespace Nz
|
|||
SetupShapeSettings(std::move(settings));
|
||||
}
|
||||
|
||||
JoltMeshCollider3D::JoltMeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt32> indices, std::size_t indexCount)
|
||||
MeshCollider3D::MeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt32> indices, std::size_t indexCount)
|
||||
{
|
||||
std::unique_ptr<JPH::MeshShapeSettings> settings = std::make_unique<JPH::MeshShapeSettings>();
|
||||
settings->mTriangleVertices.resize(vertexCount);
|
||||
|
|
@ -405,59 +405,59 @@ namespace Nz
|
|||
SetupShapeSettings(std::move(settings));
|
||||
}
|
||||
|
||||
void JoltMeshCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
void MeshCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
{
|
||||
}
|
||||
|
||||
JoltColliderType3D JoltMeshCollider3D::GetType() const
|
||||
ColliderType3D MeshCollider3D::GetType() const
|
||||
{
|
||||
return JoltColliderType3D::Mesh;
|
||||
return ColliderType3D::Mesh;
|
||||
}
|
||||
|
||||
/******************************** JoltSphereCollider3D *********************************/
|
||||
/******************************** SphereCollider3D *********************************/
|
||||
|
||||
JoltSphereCollider3D::JoltSphereCollider3D(float radius)
|
||||
SphereCollider3D::SphereCollider3D(float radius)
|
||||
{
|
||||
SetupShapeSettings(std::make_unique<JPH::SphereShapeSettings>(radius));
|
||||
}
|
||||
|
||||
void JoltSphereCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
void SphereCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
{
|
||||
}
|
||||
|
||||
float JoltSphereCollider3D::GetRadius() const
|
||||
float SphereCollider3D::GetRadius() const
|
||||
{
|
||||
return GetShapeSettingsAs<JPH::SphereShapeSettings>()->mRadius;
|
||||
}
|
||||
|
||||
JoltColliderType3D JoltSphereCollider3D::GetType() const
|
||||
ColliderType3D SphereCollider3D::GetType() const
|
||||
{
|
||||
return JoltColliderType3D::Sphere;
|
||||
return ColliderType3D::Sphere;
|
||||
}
|
||||
|
||||
/******************************** JoltTranslatedRotatedCollider3D *********************************/
|
||||
/******************************** TranslatedRotatedCollider3D *********************************/
|
||||
|
||||
JoltTranslatedRotatedCollider3D::JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Vector3f& translation, const Quaternionf& rotation) :
|
||||
TranslatedRotatedCollider3D::TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Vector3f& translation, const Quaternionf& rotation) :
|
||||
m_collider(std::move(collider))
|
||||
{
|
||||
SetupShapeSettings(std::make_unique<JPH::RotatedTranslatedShapeSettings>(ToJolt(translation), ToJolt(rotation), m_collider->GetShapeSettings()));
|
||||
}
|
||||
|
||||
JoltTranslatedRotatedCollider3D::~JoltTranslatedRotatedCollider3D()
|
||||
TranslatedRotatedCollider3D::~TranslatedRotatedCollider3D()
|
||||
{
|
||||
// We have to destroy shape settings first as it carries references on the inner collider
|
||||
ResetShapeSettings();
|
||||
}
|
||||
|
||||
void JoltTranslatedRotatedCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
void TranslatedRotatedCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
|
||||
{
|
||||
const JPH::RotatedTranslatedShapeSettings* settings = GetShapeSettingsAs<JPH::RotatedTranslatedShapeSettings>();
|
||||
|
||||
m_collider->BuildDebugMesh(vertices, indices, offsetMatrix * Matrix4f::Transform(FromJolt(settings->mPosition), FromJolt(settings->mRotation)));
|
||||
}
|
||||
|
||||
JoltColliderType3D JoltTranslatedRotatedCollider3D::GetType() const
|
||||
ColliderType3D TranslatedRotatedCollider3D::GetType() const
|
||||
{
|
||||
return JoltColliderType3D::TranslatedRotatedDecoration;
|
||||
return ColliderType3D::TranslatedRotatedDecoration;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTHELPER_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTHELPER_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_JOLTHELPER_HPP
|
||||
#define NAZARA_PHYSICS3D_JOLTHELPER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
|
|
@ -25,6 +25,6 @@ namespace Nz
|
|||
inline JPH::Vec4 ToJolt(const Vector4f& vec);
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltHelper.inl>
|
||||
#include <Nazara/Physics3D/JoltHelper.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTHELPER_HPP
|
||||
#endif // NAZARA_PHYSICS3D_JOLTHELPER_HPP
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue