fix: LineGoalMarker now uses extents instead of left-right extent separate
This commit is contained in:
parent
36d681252b
commit
febfa76bb3
|
@ -38,8 +38,7 @@ float GoalMarker::get_radius() const {
|
|||
|
||||
void LineGoalMarker::_bind_methods() {
|
||||
#define CLASSNAME LineGoalMarker
|
||||
GDPROPERTY(left, Variant::FLOAT);
|
||||
GDPROPERTY(right, Variant::FLOAT);
|
||||
GDPROPERTY(extent, Variant::FLOAT);
|
||||
}
|
||||
|
||||
bool LineGoalMarker::is_point_on(Vector3 point) {
|
||||
|
@ -48,25 +47,17 @@ bool LineGoalMarker::is_point_on(Vector3 point) {
|
|||
|
||||
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);
|
||||
Vector3 const left_unit{basis.get_column(0).normalized()};
|
||||
Vector3 const right_vec{this->get_global_position() + left_unit * -extent};
|
||||
float const length{extent * 2.f};
|
||||
return right_vec + left_unit * Math::clamp(left_unit.dot(point - right_vec), 0.f, length);
|
||||
}
|
||||
|
||||
void LineGoalMarker::set_left(float left) {
|
||||
this->left = left;
|
||||
void LineGoalMarker::set_extent(float extent) {
|
||||
this->extent = extent;
|
||||
}
|
||||
|
||||
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;
|
||||
float LineGoalMarker::get_extent() const {
|
||||
return this->extent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,18 +27,16 @@ protected:
|
|||
};
|
||||
|
||||
class LineGoalMarker : public GoalMarker {
|
||||
GDCLASS(LineGoalMarker, Area3D);
|
||||
GDCLASS(LineGoalMarker, GoalMarker);
|
||||
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;
|
||||
void set_extent(float left);
|
||||
float get_extent() const;
|
||||
private:
|
||||
float left{0.5f}, right{0.5f};
|
||||
float extent{0.5f};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue