mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-11-22 00:48:09 +01:00
Added set_look_at helper method to Basis.
This commit is contained in:
parent
6f53257e05
commit
422314a8fd
@ -242,6 +242,22 @@ Basis Basis::create_from_scale(const Vector3 &p_scale) {
|
|||||||
Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up) {
|
Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up) {
|
||||||
return Basis::create_looking_at(p_target, p_up);
|
return Basis::create_looking_at(p_target, p_up);
|
||||||
}
|
}
|
||||||
|
void Basis::set_look_at(const Vector3 &p_target, const Vector3 &p_up) {
|
||||||
|
#ifdef MATH_CHECKS
|
||||||
|
ERR_FAIL_COND_MSG(p_target.is_equal_approx(Vector3()), "The target vector can't be zero.");
|
||||||
|
ERR_FAIL_COND_MSG(p_up.is_equal_approx(Vector3()), "The up vector can't be zero.");
|
||||||
|
#endif
|
||||||
|
Vector3 v_z = -p_target.normalized();
|
||||||
|
Vector3 v_x = p_up.cross(v_z);
|
||||||
|
#ifdef MATH_CHECKS
|
||||||
|
ERR_FAIL_COND_MSG(v_x.is_equal_approx(Vector3()), "The target vector and up vector can't be parallel to each other.");
|
||||||
|
#endif
|
||||||
|
v_x.normalize();
|
||||||
|
Vector3 v_y = v_z.cross(v_x);
|
||||||
|
|
||||||
|
set_columns(v_x, v_y, v_z);
|
||||||
|
}
|
||||||
|
|
||||||
Basis Basis::from_scale(const Vector3 &p_scale) {
|
Basis Basis::from_scale(const Vector3 &p_scale) {
|
||||||
return Basis::create_from_scale(p_scale);
|
return Basis::create_from_scale(p_scale);
|
||||||
}
|
}
|
||||||
|
@ -290,6 +290,8 @@ struct _NO_DISCARD_CLASS_ Basis {
|
|||||||
static Basis create_from_scale(const Vector3 &p_scale);
|
static Basis create_from_scale(const Vector3 &p_scale);
|
||||||
|
|
||||||
Basis looking_at(const Vector3 &p_target, const Vector3 &p_up = Vector3(0, 1, 0));
|
Basis looking_at(const Vector3 &p_target, const Vector3 &p_up = Vector3(0, 1, 0));
|
||||||
|
void set_look_at(const Vector3 &p_target, const Vector3 &p_up = Vector3(0, 1, 0));
|
||||||
|
|
||||||
Basis from_scale(const Vector3 &p_scale);
|
Basis from_scale(const Vector3 &p_scale);
|
||||||
|
|
||||||
operator Quaternion() const { return get_quaternion(); }
|
operator Quaternion() const { return get_quaternion(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user