Skip to content

Commit 43828eb

Browse files
authored
Merge pull request godotengine#459 from Silver1063/master
Added some missing Vector3 functions and Fixed Vector3 slide
2 parents 1ec4526 + 96ae052 commit 43828eb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

include/core/Vector3.hpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ struct Vector3 {
165165
z + (p_t * (p_b.z - z)));
166166
}
167167

168+
inline Vector3 slerp(const Vector3 &p_b, real_t p_t) const {
169+
real_t theta = angle_to(p_b);
170+
return rotated(cross(p_b).normalized(), theta * p_t);
171+
}
172+
168173
Vector3 cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const Vector3 &post_b, const real_t t) const;
169174

170175
Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const {
@@ -206,6 +211,10 @@ struct Vector3 {
206211
return x * b.x + y * b.y + z * b.z;
207212
}
208213

214+
inline Vector3 project(const Vector3 &p_b) const {
215+
return p_b * (dot(p_b) / p_b.length_squared());
216+
}
217+
209218
inline real_t angle_to(const Vector3 &b) const {
210219
return std::atan2(cross(b).length(), dot(b));
211220
}
@@ -264,7 +273,7 @@ struct Vector3 {
264273
void rotate(const Vector3 &p_axis, real_t p_phi);
265274

266275
inline Vector3 slide(const Vector3 &by) const {
267-
return by - *this * this->dot(by);
276+
return *this - by * this->dot(by);
268277
}
269278

270279
void snap(real_t p_val);

0 commit comments

Comments
 (0)