Redid PR 190 for master now that nativescript 1.1 has been merged

pull/202/head
Bastiaan Olij 2018-11-22 22:14:28 +11:00
parent 8ffda12b83
commit d7982cfac3
2 changed files with 29 additions and 1 deletions

View File

@ -7,6 +7,7 @@
namespace godot { namespace godot {
class Basis;
struct Vector3 { struct Vector3 {
@ -79,6 +80,8 @@ struct Vector3 {
Vector3 cubic_interpolate(const Vector3& b, const Vector3& pre_a, const Vector3& post_b, const real_t t) const; Vector3 cubic_interpolate(const Vector3& b, const Vector3& pre_a, const Vector3& post_b, const real_t t) const;
Vector3 bounce(const Vector3& p_normal) const;
real_t length() const; real_t length() const;
real_t length_squared() const; real_t length_squared() const;
@ -89,10 +92,15 @@ struct Vector3 {
real_t dot(const Vector3& b) const; real_t dot(const Vector3& b) const;
real_t angle_to(const Vector3& b) const;
Vector3 floor() const; Vector3 floor() const;
Vector3 inverse() const; Vector3 inverse() const;
bool is_normalized() const;
Basis outer(const Vector3& b) const;

View File

@ -10,7 +10,6 @@
namespace godot { namespace godot {
Vector3::Vector3(real_t x, real_t y, real_t z) Vector3::Vector3(real_t x, real_t y, real_t z)
{ {
this->x = x; this->x = x;
@ -209,6 +208,11 @@ Vector3 Vector3::cubic_interpolate(const Vector3& b, const Vector3& pre_a, const
return out; return out;
} }
Vector3 Vector3::bounce(const Vector3& p_normal) const
{
return -reflect(p_normal);
}
real_t Vector3::length() const real_t Vector3::length() const
{ {
real_t x2=x*x; real_t x2=x*x;
@ -242,6 +246,11 @@ real_t Vector3::dot(const Vector3& b) const
return x*b.x + y*b.y + z*b.z; return x*b.x + y*b.y + z*b.z;
} }
real_t Vector3::angle_to(const Vector3& b) const
{
return std::atan2(cross(b).length(), dot(b));
}
Vector3 Vector3::floor() const Vector3 Vector3::floor() const
{ {
return Vector3(::floor(x), ::floor(y), ::floor(z)); return Vector3(::floor(x), ::floor(y), ::floor(z));
@ -252,7 +261,18 @@ Vector3 Vector3::inverse() const
return Vector3( 1.0/x, 1.0/y, 1.0/z ); return Vector3( 1.0/x, 1.0/y, 1.0/z );
} }
bool Vector3::is_normalized() const
{
return std::abs(length_squared() - 1.0) < 0.00001;
}
Basis Vector3::outer(const Vector3& b) const
{
Vector3 row0(x * b.x, x * b.y, x * b.z);
Vector3 row1(y * b.x, y * b.y, y * b.z);
Vector3 row2(z * b.x, z * b.y, z * b.z);
return Basis(row0, row1, row2);
}
int Vector3::max_axis() const int Vector3::max_axis() const