Files
SDL3CPlusPlus/src/script/physics_bridge.hpp
johndoe6345789 5a4dd23df2 Implement PhysicsBridge and ScriptEngine for enhanced physics and scripting capabilities
- Added PhysicsBridge class to manage physics interactions using Bullet Physics.
- Introduced ScriptEngine class to handle Lua scripting, including loading scene objects and managing audio commands.
- Updated test_cube_script to utilize ScriptEngine instead of CubeScript, ensuring compatibility with new architecture.
- Implemented methods for loading meshes, creating physics objects, and handling audio playback within the ScriptEngine.
- Enhanced error handling and input management for Lua scripts.
2026-01-03 23:44:01 +00:00

57 lines
1.7 KiB
C++

#ifndef SDL3CPP_SCRIPT_PHYSICS_BRIDGE_HPP
#define SDL3CPP_SCRIPT_PHYSICS_BRIDGE_HPP
#include <memory>
#include <string>
#include <unordered_map>
class btVector3;
class btTransform;
class btCollisionShape;
class btMotionState;
class btRigidBody;
class btDefaultCollisionConfiguration;
class btCollisionDispatcher;
class btBroadphaseInterface;
class btSequentialImpulseConstraintSolver;
class btDiscreteDynamicsWorld;
namespace sdl3cpp::script {
class PhysicsBridge {
public:
PhysicsBridge();
~PhysicsBridge();
PhysicsBridge(const PhysicsBridge&) = delete;
PhysicsBridge& operator=(const PhysicsBridge&) = delete;
bool addBoxRigidBody(const std::string& name,
const btVector3& halfExtents,
float mass,
const btTransform& transform,
std::string& error);
int stepSimulation(float deltaTime);
bool getRigidBodyTransform(const std::string& name,
btTransform& outTransform,
std::string& error) const;
private:
struct BodyRecord {
std::unique_ptr<btCollisionShape> shape;
std::unique_ptr<btMotionState> motionState;
std::unique_ptr<btRigidBody> body;
};
std::unique_ptr<btDefaultCollisionConfiguration> collisionConfig_;
std::unique_ptr<btCollisionDispatcher> dispatcher_;
std::unique_ptr<btBroadphaseInterface> broadphase_;
std::unique_ptr<btSequentialImpulseConstraintSolver> solver_;
std::unique_ptr<btDiscreteDynamicsWorld> world_;
std::unordered_map<std::string, BodyRecord> bodies_;
};
} // namespace sdl3cpp::script
#endif // SDL3CPP_SCRIPT_PHYSICS_BRIDGE_HPP