diff options
Diffstat (limited to 'include/godot_cpp/variant')
-rw-r--r-- | include/godot_cpp/variant/aabb.hpp | 14 | ||||
-rw-r--r-- | include/godot_cpp/variant/color.hpp | 30 | ||||
-rw-r--r-- | include/godot_cpp/variant/quaternion.hpp | 20 | ||||
-rw-r--r-- | include/godot_cpp/variant/rect2.hpp | 4 | ||||
-rw-r--r-- | include/godot_cpp/variant/vector2.hpp | 8 | ||||
-rw-r--r-- | include/godot_cpp/variant/vector2i.hpp | 12 | ||||
-rw-r--r-- | include/godot_cpp/variant/vector3.hpp | 10 |
7 files changed, 51 insertions, 47 deletions
diff --git a/include/godot_cpp/variant/aabb.hpp b/include/godot_cpp/variant/aabb.hpp index 1d46025..f654aae 100644 --- a/include/godot_cpp/variant/aabb.hpp +++ b/include/godot_cpp/variant/aabb.hpp @@ -336,7 +336,7 @@ inline void AABB::expand_to(const Vector3 &p_vector) { } void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const { - Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5); + Vector3 half_extents(size.x * (real_t)0.5, size.y * (real_t)0.5, size.z * (real_t)0.5); Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z); real_t length = p_plane.normal.abs().dot(half_extents); @@ -374,9 +374,9 @@ inline real_t AABB::get_shortest_axis_size() const { } bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const { - real_t divx = 1.0 / p_dir.x; - real_t divy = 1.0 / p_dir.y; - real_t divz = 1.0 / p_dir.z; + real_t divx = (real_t)1.0 / p_dir.x; + real_t divy = (real_t)1.0 / p_dir.y; + real_t divz = (real_t)1.0 / p_dir.z; Vector3 upbound = position + size; real_t tmin, tmax, tymin, tymax, tzmin, tzmax; @@ -426,9 +426,9 @@ void AABB::grow_by(real_t p_amount) { position.x -= p_amount; position.y -= p_amount; position.z -= p_amount; - size.x += 2.0 * p_amount; - size.y += 2.0 * p_amount; - size.z += 2.0 * p_amount; + size.x += (real_t)2.0 * p_amount; + size.y += (real_t)2.0 * p_amount; + size.z += (real_t)2.0 * p_amount; } void AABB::quantize(real_t p_unit) { diff --git a/include/godot_cpp/variant/color.hpp b/include/godot_cpp/variant/color.hpp index 7fe6294..d8948d1 100644 --- a/include/godot_cpp/variant/color.hpp +++ b/include/godot_cpp/variant/color.hpp @@ -157,7 +157,7 @@ public: inline Color blend(const Color &p_over) const { Color res; - float sa = 1.0 - p_over.a; + float sa = (real_t)1.0 - p_over.a; res.a = a * sa + p_over.a; if (res.a == 0) { return Color(0, 0, 0, 0); @@ -171,16 +171,16 @@ public: inline Color to_linear() const { return Color( - r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4), - g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4), - b < 0.04045 ? b * (1.0 / 12.92) : Math::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4), + r < (real_t)0.04045 ? r * (real_t)(1.0 / 12.92) : Math::pow((r + (real_t)0.055) * (real_t)(1.0 / (1.0 + 0.055)), (real_t)2.4), + g < (real_t)0.04045 ? g * (real_t)(1.0 / 12.92) : Math::pow((g + (real_t)0.055) * (real_t)(1.0 / (1.0 + 0.055)), (real_t)2.4), + b < (real_t)0.04045 ? b * (real_t)(1.0 / 12.92) : Math::pow((b + (real_t)0.055) * (real_t)(1.0 / (1.0 + 0.055)), (real_t)2.4), a); } inline Color to_srgb() const { return Color( - r < 0.0031308 ? 12.92 * r : (1.0 + 0.055) * Math::pow(r, 1.0f / 2.4f) - 0.055, - g < 0.0031308 ? 12.92 * g : (1.0 + 0.055) * Math::pow(g, 1.0f / 2.4f) - 0.055, - b < 0.0031308 ? 12.92 * b : (1.0 + 0.055) * Math::pow(b, 1.0f / 2.4f) - 0.055, a); + r < (real_t)0.0031308 ? (real_t)12.92 * r : (real_t)(1.0 + 0.055) * Math::pow(r, (real_t)(1.0 / 2.4)) - (real_t)0.055, + g < (real_t)0.0031308 ? (real_t)12.92 * g : (real_t)(1.0 + 0.055) * Math::pow(g, (real_t)(1.0 / 2.4)) - (real_t)0.055, + b < (real_t)0.0031308 ? (real_t)12.92 * b : (real_t)(1.0 + 0.055) * Math::pow(b, (real_t)(1.0 / 2.4)) - (real_t)0.055, a); } static Color hex(uint32_t p_hex); @@ -202,14 +202,14 @@ public: operator String() const; // For the binder. - inline void set_r8(int32_t r8) { r = (Math::clamp(r8, 0, 255) / 255.0); } - inline int32_t get_r8() const { return int32_t(Math::clamp(r * 255.0, 0.0, 255.0)); } - inline void set_g8(int32_t g8) { g = (Math::clamp(g8, 0, 255) / 255.0); } - inline int32_t get_g8() const { return int32_t(Math::clamp(g * 255.0, 0.0, 255.0)); } - inline void set_b8(int32_t b8) { b = (Math::clamp(b8, 0, 255) / 255.0); } - inline int32_t get_b8() const { return int32_t(Math::clamp(b * 255.0, 0.0, 255.0)); } - inline void set_a8(int32_t a8) { a = (Math::clamp(a8, 0, 255) / 255.0); } - inline int32_t get_a8() const { return int32_t(Math::clamp(a * 255.0, 0.0, 255.0)); } + inline void set_r8(int32_t r8) { r = (Math::clamp(r8, 0, 255) / (real_t)255.0); } + inline int32_t get_r8() const { return int32_t(Math::clamp(r * (real_t)255.0, (real_t)0.0, (real_t)255.0)); } + inline void set_g8(int32_t g8) { g = (Math::clamp(g8, 0, 255) / (real_t)255.0); } + inline int32_t get_g8() const { return int32_t(Math::clamp(g * (real_t)255.0, (real_t)0.0, (real_t)255.0)); } + inline void set_b8(int32_t b8) { b = (Math::clamp(b8, 0, 255) / (real_t)255.0); } + inline int32_t get_b8() const { return int32_t(Math::clamp(b * (real_t)255.0, (real_t)0.0, (real_t)255.0)); } + inline void set_a8(int32_t a8) { a = (Math::clamp(a8, 0, 255) / (real_t)255.0); } + inline int32_t get_a8() const { return int32_t(Math::clamp(a * (real_t)255.0, (real_t)0.0, (real_t)255.0)); } inline void set_h(float p_h) { set_hsv(p_h, get_s(), get_v()); } inline void set_s(float p_s) { set_hsv(get_h(), p_s, get_v()); } diff --git a/include/godot_cpp/variant/quaternion.hpp b/include/godot_cpp/variant/quaternion.hpp index 012cfd0..e87862c 100644 --- a/include/godot_cpp/variant/quaternion.hpp +++ b/include/godot_cpp/variant/quaternion.hpp @@ -152,19 +152,19 @@ public: Vector3 c = v0.cross(v1); real_t d = v0.dot(v1); - if (d < -1.0 + CMP_EPSILON) { - x = 0; - y = 1; - z = 0; - w = 0; + if (d < (real_t)-1.0 + CMP_EPSILON) { + x = (real_t)0.0; + y = (real_t)1.0; + z = (real_t)0.0; + w = (real_t)0.0; } else { - real_t s = Math::sqrt((1.0 + d) * 2.0); - real_t rs = 1.0 / s; + real_t s = Math::sqrt(((real_t)1.0 + d) * (real_t)2.0); + real_t rs = (real_t)1.0 / s; x = c.x * rs; y = c.y * rs; z = c.z * rs; - w = s * 0.5; + w = s * (real_t)0.5; } } }; @@ -199,7 +199,7 @@ void Quaternion::operator*=(const real_t &s) { } void Quaternion::operator/=(const real_t &s) { - *this *= 1.0 / s; + *this *= (real_t)1.0 / s; } Quaternion Quaternion::operator+(const Quaternion &q2) const { @@ -222,7 +222,7 @@ Quaternion Quaternion::operator*(const real_t &s) const { } Quaternion Quaternion::operator/(const real_t &s) const { - return *this * (1.0 / s); + return *this * ((real_t)1.0 / s); } bool Quaternion::operator==(const Quaternion &p_quat) const { diff --git a/include/godot_cpp/variant/rect2.hpp b/include/godot_cpp/variant/rect2.hpp index a75406e..e5a25ca 100644 --- a/include/godot_cpp/variant/rect2.hpp +++ b/include/godot_cpp/variant/rect2.hpp @@ -37,7 +37,7 @@ namespace godot { -struct Transform2D; +class Transform2D; class Rect2 { public: @@ -290,7 +290,7 @@ public: //check ray box r /= l; - Vector2 ir(1.0 / r.x, 1.0 / r.y); + Vector2 ir((real_t)1.0 / r.x, (real_t)1.0 / r.y); // lb is the corner of AABB with minimal coordinates - left bottom, rt is maximal corner // r.org is origin of ray diff --git a/include/godot_cpp/variant/vector2.hpp b/include/godot_cpp/variant/vector2.hpp index 2c020ef..f7ae8b0 100644 --- a/include/godot_cpp/variant/vector2.hpp +++ b/include/godot_cpp/variant/vector2.hpp @@ -164,19 +164,19 @@ inline Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) const { } inline Vector2 operator*(float p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; + return p_vec * (real_t)p_scalar; } inline Vector2 operator*(double p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; + return p_vec * (real_t)p_scalar; } inline Vector2 operator*(int32_t p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; + return p_vec * (real_t)p_scalar; } inline Vector2 operator*(int64_t p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; + return p_vec * (real_t)p_scalar; } inline Vector2 Vector2::operator+(const Vector2 &p_v) const { diff --git a/include/godot_cpp/variant/vector2i.hpp b/include/godot_cpp/variant/vector2i.hpp index 3726c31..a975812 100644 --- a/include/godot_cpp/variant/vector2i.hpp +++ b/include/godot_cpp/variant/vector2i.hpp @@ -95,7 +95,7 @@ public: operator String() const; - operator Vector2() const { return Vector2(x, y); } + operator Vector2() const { return Vector2((real_t)x, (real_t)y); } inline Vector2i() {} inline Vector2i(const Vector2 &p_vec2) { @@ -113,15 +113,19 @@ inline Vector2i operator*(const int32_t &p_scalar, const Vector2i &p_vector) { } inline Vector2i operator*(const int64_t &p_scalar, const Vector2i &p_vector) { - return p_vector * p_scalar; + return p_vector * (int32_t)p_scalar; } inline Vector2i operator*(const float &p_scalar, const Vector2i &p_vector) { - return p_vector * p_scalar; + float x = (float)p_vector.x * p_scalar; + float y = (float)p_vector.y * p_scalar; + return Vector2i((int32_t)round(x), (int32_t)round(y)); } inline Vector2i operator*(const double &p_scalar, const Vector2i &p_vector) { - return p_vector * p_scalar; + double x = (double)p_vector.x * p_scalar; + double y = (double)p_vector.y * p_scalar; + return Vector2i((int32_t)round(x), (int32_t)round(y)); } typedef Vector2i Size2i; diff --git a/include/godot_cpp/variant/vector3.hpp b/include/godot_cpp/variant/vector3.hpp index 8420066..e435fb6 100644 --- a/include/godot_cpp/variant/vector3.hpp +++ b/include/godot_cpp/variant/vector3.hpp @@ -385,8 +385,8 @@ real_t Vector3::length_squared() const { void Vector3::normalize() { real_t lengthsq = length_squared(); - if (lengthsq == 0) { - x = y = z = 0; + if (lengthsq == (real_t)0.0) { + x = y = z = (real_t)0.0; } else { real_t length = Math::sqrt(lengthsq); x /= length; @@ -403,15 +403,15 @@ Vector3 Vector3::normalized() const { bool Vector3::is_normalized() const { // use length_squared() instead of length() to avoid sqrt(), makes it more stringent. - return Math::is_equal_approx(length_squared(), 1.0, UNIT_EPSILON); + return Math::is_equal_approx(length_squared(), (real_t)1.0, (real_t)UNIT_EPSILON); } Vector3 Vector3::inverse() const { - return Vector3(1.0 / x, 1.0 / y, 1.0 / z); + return Vector3((real_t)1.0 / x, (real_t)1.0 / y, (real_t)1.0 / z); } void Vector3::zero() { - x = y = z = 0; + x = y = z = (real_t)0.0; } // slide returns the component of the vector along the given plane, specified by its normal vector. |