Merge pull request #1625 from Flarkk/looking_at
Add `p_use_model_front` to `Basis::looking_at()`pull/1594/head
commit
96675a814b
|
@ -224,7 +224,7 @@ struct _NO_DISCARD_ Basis {
|
||||||
|
|
||||||
operator Quaternion() const { return get_quaternion(); }
|
operator Quaternion() const { return get_quaternion(); }
|
||||||
|
|
||||||
static Basis looking_at(const Vector3 &p_target, const Vector3 &p_up = Vector3(0, 1, 0));
|
static Basis looking_at(const Vector3 &p_target, const Vector3 &p_up = Vector3(0, 1, 0), bool p_use_model_front = false);
|
||||||
|
|
||||||
Basis(const Quaternion &p_quaternion) { set_quaternion(p_quaternion); }
|
Basis(const Quaternion &p_quaternion) { set_quaternion(p_quaternion); }
|
||||||
Basis(const Quaternion &p_quaternion, const Vector3 &p_scale) { set_quaternion_scale(p_quaternion, p_scale); }
|
Basis(const Quaternion &p_quaternion, const Vector3 &p_scale) { set_quaternion_scale(p_quaternion, p_scale); }
|
||||||
|
|
|
@ -1037,12 +1037,15 @@ void Basis::rotate_sh(real_t *p_values) {
|
||||||
p_values[8] = d4 * s_scale_dst4;
|
p_values[8] = d4 * s_scale_dst4;
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up) {
|
Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up, bool p_use_model_front) {
|
||||||
#ifdef MATH_CHECKS
|
#ifdef MATH_CHECKS
|
||||||
ERR_FAIL_COND_V_MSG(p_target.is_zero_approx(), Basis(), "The target vector can't be zero.");
|
ERR_FAIL_COND_V_MSG(p_target.is_zero_approx(), Basis(), "The target vector can't be zero.");
|
||||||
ERR_FAIL_COND_V_MSG(p_up.is_zero_approx(), Basis(), "The up vector can't be zero.");
|
ERR_FAIL_COND_V_MSG(p_up.is_zero_approx(), Basis(), "The up vector can't be zero.");
|
||||||
#endif
|
#endif
|
||||||
Vector3 v_z = -p_target.normalized();
|
Vector3 v_z = p_target.normalized();
|
||||||
|
if (!p_use_model_front) {
|
||||||
|
v_z = -v_z;
|
||||||
|
}
|
||||||
Vector3 v_x = p_up.cross(v_z);
|
Vector3 v_x = p_up.cross(v_z);
|
||||||
#ifdef MATH_CHECKS
|
#ifdef MATH_CHECKS
|
||||||
ERR_FAIL_COND_V_MSG(v_x.is_zero_approx(), Basis(), "The target vector and up vector can't be parallel to each other.");
|
ERR_FAIL_COND_V_MSG(v_x.is_zero_approx(), Basis(), "The target vector and up vector can't be parallel to each other.");
|
||||||
|
|
Loading…
Reference in New Issue