feat: added LineGoalMarker
This commit is contained in:
parent
15f9451b92
commit
028aa48c3a
|
@ -1,7 +1,8 @@
|
||||||
#include "goal_marker.hpp"
|
#include "goal_marker.hpp"
|
||||||
#include "godot_cpp/classes/global_constants.hpp"
|
#include "godot_cpp/core/math.hpp"
|
||||||
#include "planner.hpp"
|
#include "planner.hpp"
|
||||||
#include "utils/godot_macros.h"
|
#include "utils/godot_macros.h"
|
||||||
|
#include <godot_cpp/classes/global_constants.hpp>
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
void GoalMarker::_bind_methods() {
|
void GoalMarker::_bind_methods() {
|
||||||
|
@ -9,11 +10,63 @@ void GoalMarker::_bind_methods() {
|
||||||
GDPROPERTY_HINTED(goal, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Goal");
|
GDPROPERTY_HINTED(goal, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Goal");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<goap::Goal> GoalMarker::get_goal() const {
|
bool GoalMarker::is_point_on(Vector3 point) {
|
||||||
return this->goal;
|
return point.distance_squared_to(this->get_global_position()) <= .5f * .5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 GoalMarker::nearest_point_on(Vector3 nearest_to) {
|
||||||
|
return this->get_global_position();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalMarker::set_goal(Ref<goap::Goal> goal) {
|
void GoalMarker::set_goal(Ref<goap::Goal> goal) {
|
||||||
this->goal = goal;
|
this->goal = goal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ref<goap::Goal> GoalMarker::get_goal() const {
|
||||||
|
return this->goal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GoalMarker::set_radius(float radius) {
|
||||||
|
this->radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GoalMarker::get_radius() const {
|
||||||
|
return this->radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef CLASSNAME
|
||||||
|
|
||||||
|
void LineGoalMarker::_bind_methods() {
|
||||||
|
#define CLASSNAME LineGoalMarker
|
||||||
|
GDPROPERTY(left, Variant::FLOAT);
|
||||||
|
GDPROPERTY(right, Variant::FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LineGoalMarker::is_point_on(Vector3 point) {
|
||||||
|
return this->nearest_point_on(point).distance_to(point) < this->radius * this->radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 LineGoalMarker::nearest_point_on(Vector3 point) {
|
||||||
|
Basis const &basis{this->get_global_basis()};
|
||||||
|
Vector3 const right_unit{basis.get_column(0).normalized()};
|
||||||
|
Vector3 const leftvec{(right_unit * -left) + this->get_global_position()};
|
||||||
|
float const length{Math::abs(right - left)};
|
||||||
|
return leftvec + right_unit * Math::clamp(right_unit.dot(point - leftvec), 0.f, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineGoalMarker::set_left(float left) {
|
||||||
|
this->left = left;
|
||||||
|
}
|
||||||
|
|
||||||
|
float LineGoalMarker::get_left() const {
|
||||||
|
return this->left;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineGoalMarker::set_right(float right) {
|
||||||
|
this->right = right;
|
||||||
|
}
|
||||||
|
|
||||||
|
float LineGoalMarker::get_right() const {
|
||||||
|
return this->right;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,31 @@ class GoalMarker : public Area3D {
|
||||||
GDCLASS(GoalMarker, Area3D);
|
GDCLASS(GoalMarker, Area3D);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
Ref<goap::Goal> get_goal() const;
|
virtual bool is_point_on(Vector3 point);
|
||||||
|
virtual Vector3 nearest_point_on(Vector3 near_to);
|
||||||
|
|
||||||
void set_goal(Ref<goap::Goal> goal);
|
void set_goal(Ref<goap::Goal> goal);
|
||||||
private:
|
Ref<goap::Goal> get_goal() const;
|
||||||
|
void set_radius(float radius);
|
||||||
|
float get_radius() const;
|
||||||
|
protected:
|
||||||
Ref<goap::Goal> goal{nullptr};
|
Ref<goap::Goal> goal{nullptr};
|
||||||
|
float radius{0.2f};
|
||||||
|
};
|
||||||
|
|
||||||
|
class LineGoalMarker : public GoalMarker {
|
||||||
|
GDCLASS(LineGoalMarker, Area3D);
|
||||||
|
static void _bind_methods();
|
||||||
|
public:
|
||||||
|
virtual bool is_point_on(Vector3 point) override;
|
||||||
|
virtual Vector3 nearest_point_on(Vector3 near_to) override;
|
||||||
|
|
||||||
|
void set_left(float left);
|
||||||
|
float get_left() const;
|
||||||
|
void set_right(float right);
|
||||||
|
float get_right() const;
|
||||||
|
private:
|
||||||
|
float left{0.5f}, right{0.5f};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level)
|
||||||
ClassDB::register_class<goap::Goal>();
|
ClassDB::register_class<goap::Goal>();
|
||||||
ClassDB::register_class<goap::Planner>();
|
ClassDB::register_class<goap::Planner>();
|
||||||
ClassDB::register_class<GoalMarker>();
|
ClassDB::register_class<GoalMarker>();
|
||||||
|
ClassDB::register_class<LineGoalMarker>();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
|
|
Loading…
Reference in a new issue