Physics3D: Add PivotConstraint3D
This commit is contained in:
committed by
Jérôme Leclercq
parent
522315dbca
commit
5cbc435e1a
74
include/Nazara/Physics3D/Constraint3D.hpp
Normal file
74
include/Nazara/Physics3D/Constraint3D.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" 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_CONSTRAINT3D_HPP
|
||||
#define NAZARA_PHYSICS3D_CONSTRAINT3D_HPP
|
||||
|
||||
#include <Nazara/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>
|
||||
|
||||
class btTypedConstraint;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Constraint3D;
|
||||
|
||||
using Constraint3DHandle = ObjectHandle<Constraint3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API Constraint3D : public HandledObject<Constraint3D>
|
||||
{
|
||||
public:
|
||||
Constraint3D(const Constraint3D&) = delete;
|
||||
Constraint3D(Constraint3D&& constraint) noexcept;
|
||||
virtual ~Constraint3D();
|
||||
|
||||
RigidBody3D& GetBodyA();
|
||||
const RigidBody3D& GetBodyA() const;
|
||||
RigidBody3D& GetBodyB();
|
||||
const RigidBody3D& GetBodyB() const;
|
||||
PhysWorld3D& GetWorld();
|
||||
const PhysWorld3D& GetWorld() const;
|
||||
|
||||
inline bool IsBodyCollisionEnabled() const;
|
||||
bool IsSingleBody() const;
|
||||
|
||||
Constraint3D& operator=(const Constraint3D&) = delete;
|
||||
Constraint3D& operator=(Constraint3D&& constraint) noexcept;
|
||||
|
||||
protected:
|
||||
Constraint3D(std::unique_ptr<btTypedConstraint> constraint, bool disableCollisions = false);
|
||||
|
||||
template<typename T> T* GetConstraint();
|
||||
template<typename T> const T* GetConstraint() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<btTypedConstraint> m_constraint;
|
||||
bool m_bodyCollisionEnabled;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API PivotConstraint3D : public Constraint3D
|
||||
{
|
||||
public:
|
||||
PivotConstraint3D(RigidBody3D& first, const Vector3f& pivot);
|
||||
PivotConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& pivot, bool disableCollisions = false);
|
||||
PivotConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor, bool disableCollisions = false);
|
||||
~PivotConstraint3D() = default;
|
||||
|
||||
Vector3f GetFirstAnchor() const;
|
||||
Vector3f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector3f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector3f& secondAnchor);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Constraint3D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_CONSTRAINT3D_HPP
|
||||
29
include/Nazara/Physics3D/Constraint3D.inl
Normal file
29
include/Nazara/Physics3D/Constraint3D.inl
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" 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/Constraint3D.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline bool Constraint3D::IsBodyCollisionEnabled() const
|
||||
{
|
||||
return m_bodyCollisionEnabled;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* Constraint3D::GetConstraint()
|
||||
{
|
||||
return SafeCast<T*>(m_constraint.get());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* Constraint3D::GetConstraint() const
|
||||
{
|
||||
return SafeCast<const T*>(m_constraint.get());
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
@@ -43,16 +43,17 @@ namespace Nz
|
||||
Boxf GetAABB() const;
|
||||
float GetAngularDamping() const;
|
||||
Vector3f GetAngularVelocity() const;
|
||||
const std::shared_ptr<Collider3D>& GetGeom() const;
|
||||
inline const std::shared_ptr<Collider3D>& GetGeom() const;
|
||||
float GetLinearDamping() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
float GetMass() const;
|
||||
Vector3f GetMassCenter(CoordSys coordSys = CoordSys::Local) const;
|
||||
Matrix4f GetMatrix() const;
|
||||
Vector3f GetPosition() const;
|
||||
btRigidBody* GetRigidBody() const;
|
||||
inline btRigidBody* GetRigidBody() const;
|
||||
Quaternionf GetRotation() const;
|
||||
PhysWorld3D* GetWorld() const;
|
||||
inline std::size_t GetUniqueIndex() const;
|
||||
inline PhysWorld3D* GetWorld() const;
|
||||
|
||||
bool IsSimulationEnabled() const;
|
||||
bool IsSleeping() const;
|
||||
@@ -68,6 +69,11 @@ namespace Nz
|
||||
void SetPosition(const Vector3f& position);
|
||||
void SetRotation(const Quaternionf& rotation);
|
||||
|
||||
Quaternionf ToLocal(const Quaternionf& worldRotation);
|
||||
Vector3f ToLocal(const Vector3f& worldPosition);
|
||||
Quaternionf ToWorld(const Quaternionf& localRotation);
|
||||
Vector3f ToWorld(const Vector3f& localPosition);
|
||||
|
||||
void WakeUp();
|
||||
|
||||
RigidBody3D& operator=(const RigidBody3D& object) = delete;
|
||||
|
||||
@@ -10,6 +10,25 @@ namespace Nz
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Collider3D>& RigidBody3D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline btRigidBody* RigidBody3D::GetRigidBody() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
inline std::size_t RigidBody3D::GetUniqueIndex() const
|
||||
{
|
||||
return m_bodyPoolIndex;
|
||||
}
|
||||
|
||||
inline PhysWorld3D* RigidBody3D::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user