From b5293e8baeba927e1e1d8b15b078ce91e0a87c67 Mon Sep 17 00:00:00 2001 From: Sara Date: Thu, 16 May 2024 09:11:14 +0200 Subject: [PATCH] feat: added variables and properties --- src/car_physics.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/car_physics.hpp | 18 ++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/car_physics.cpp b/src/car_physics.cpp index 410c7c0..c764d7c 100644 --- a/src/car_physics.cpp +++ b/src/car_physics.cpp @@ -1,12 +1,56 @@ #include "car_physics.hpp" +#include namespace godot { void CarPhysics::_bind_methods() { #define CLASSNAME CarPhysics + GDPROPERTY_HINTED(oversteer_curve, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Curve"); + GDPROPERTY_HINTED(understeer_curve, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Curve"); +} + void CarPhysics::_enter_tree() { this->set_use_custom_integrator(true); } void CarPhysics::_integrate_forces(PhysicsDirectBodyState3D *state) { + +void CarPhysics::set_target_speed(float target) { + this->target_speed = target; +} + +float CarPhysics::get_target_speed() const { + return this->target_speed; +} + +void CarPhysics::set_current_steering(float steering) { + this->current_steering = steering; +} + +float CarPhysics::get_current_steering() const { + return this->current_steering; +} + +void CarPhysics::set_brake(bool brake) { + this->brake = brake; +} + +bool CarPhysics::get_brake() const { + return this->brake; +} + +void CarPhysics::set_oversteer_curve(Ref curve) { + this->oversteer_curve = curve; +} + +Ref CarPhysics::get_oversteer_curve() const { + return this->oversteer_curve; +} + +void CarPhysics::set_understeer_curve(Ref curve) { + this->understeer_curve = curve; +} + +Ref CarPhysics::get_understeer_curve() const { + return this->understeer_curve; } const float CarPhysics::ACCELERATION{20.f}; diff --git a/src/car_physics.hpp b/src/car_physics.hpp index 814c54e..9e935c8 100644 --- a/src/car_physics.hpp +++ b/src/car_physics.hpp @@ -8,7 +8,25 @@ class CarPhysics : public RigidBody3D { public: virtual void _enter_tree() override; virtual void _integrate_forces(PhysicsDirectBodyState3D *state) override; + void set_target_speed(float target); + float get_target_speed() const; + void set_current_steering(float steering); + float get_current_steering() const; + void set_brake(bool value); + bool get_brake() const; + void set_oversteer_curve(Ref curve); + Ref get_oversteer_curve() const; + void set_understeer_curve(Ref curve); + Ref get_understeer_curve() const; private: + float target_speed{0.f}; + float current_steering{0.f}; + Vector3 local_velocity{}; + float gravity_velocity{-1.f}; + bool brake{false}; + Ref oversteer_curve{}; + Ref understeer_curve{}; + static const float ACCELERATION; static const float BRAKE_FORCE; static const float UNDERSTEER_SPEED_MUL;