Merge branch 'intolerantape-Minor-Changes'
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "Double2.h"
|
||||
#include "Double3.h"
|
||||
@@ -107,3 +107,11 @@ double Double2::TriangleArea(const Double2& v0, const Double2& v1, const Double2
|
||||
{
|
||||
return Math::Abs((v0.X * (v1.Y - v2.Y) + v1.X * (v2.Y - v0.Y) + v2.X * (v0.Y - v1.Y)) / 2.);
|
||||
}
|
||||
|
||||
double Double2::Angle(const Double2& from, const Double2& to)
|
||||
{
|
||||
const double dot = Math::Clamp(Dot(Normalize(from), Normalize(to)), -1.0, 1.0);
|
||||
if (Math::Abs(dot) > (1.0 - ZeroTolerance))
|
||||
return dot > 0.0 ? 0.0 : PI;
|
||||
return Math::Acos(dot);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -625,6 +625,15 @@ public:
|
||||
/// <param name="v2">The third triangle vertex.</param>
|
||||
/// <returns>The triangle area.</returns>
|
||||
static double TriangleArea(const Double2& v0, const Double2& v1, const Double2& v2);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the angle (in radians) between from and to. This is always the smallest value.
|
||||
/// </summary>
|
||||
/// <param name="from">The first vector.</param>
|
||||
/// <param name="to">The second vector.</param>
|
||||
/// <returns>The angle (in radians).</returns>
|
||||
static double Angle(const Double2& from, const Double2& to);
|
||||
|
||||
};
|
||||
|
||||
inline Double2 operator+(double a, const Double2& b)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "Double2.h"
|
||||
#include "Double3.h"
|
||||
@@ -45,6 +45,20 @@ Double3::Double3(const Vector2& xy)
|
||||
{
|
||||
}
|
||||
|
||||
Double3::Double3(const Vector3& xyz)
|
||||
: X(xyz.X)
|
||||
, Y(xyz.Y)
|
||||
, Z(xyz.Z)
|
||||
{
|
||||
}
|
||||
|
||||
Double3::Double3(const Vector4& xyzw)
|
||||
: X(xyzw.X)
|
||||
, Y(xyzw.Y)
|
||||
, Z(xyzw.Z)
|
||||
{
|
||||
}
|
||||
|
||||
Double3::Double3(const Int2& xy, double z)
|
||||
: X(static_cast<double>(xy.X))
|
||||
, Y(static_cast<double>(xy.Y))
|
||||
@@ -66,13 +80,6 @@ Double3::Double3(const Int4& xyzw)
|
||||
{
|
||||
}
|
||||
|
||||
Double3::Double3(const Vector4& xyzw)
|
||||
: X(xyzw.X)
|
||||
, Y(xyzw.Y)
|
||||
, Z(xyzw.Z)
|
||||
{
|
||||
}
|
||||
|
||||
Double3::Double3(const Double2& xy)
|
||||
: X(xy.X)
|
||||
, Y(xy.Y)
|
||||
@@ -383,3 +390,11 @@ double Double3::TriangleArea(const Double3& v0, const Double3& v1, const Double3
|
||||
{
|
||||
return (v2 - v0 ^ v1 - v0).Length() * 0.5;
|
||||
}
|
||||
|
||||
double Double3::Angle(const Double3& from, const Double3& to)
|
||||
{
|
||||
const double dot = Math::Clamp(Dot(Normalize(from), Normalize(to)), -1.0, 1.0);
|
||||
if (Math::Abs(dot) > (1.0 - ZeroTolerance))
|
||||
return dot > 0.0 ? 0.0 : PI;
|
||||
return Math::Acos(dot);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -143,11 +143,19 @@ public:
|
||||
// Init
|
||||
// @param xy Vector2 value
|
||||
explicit Double3(const Vector2& xy);
|
||||
|
||||
// Init
|
||||
// @param xyz Vector3 value
|
||||
explicit Double3(const Vector3& xyz);
|
||||
|
||||
// Init
|
||||
// @param xy Int22 with X and Y components values
|
||||
// @param xyz Vector4 value
|
||||
explicit Double3(const Vector4& xyzw);
|
||||
|
||||
// Init
|
||||
// @param xy Int2 with X and Y components values
|
||||
// @param z Z component value
|
||||
explicit Double3(const Int2& xy, double z);
|
||||
explicit Double3(const Int2& xy, double z);
|
||||
|
||||
// Init
|
||||
// @param xyz Int3 value
|
||||
@@ -155,22 +163,17 @@ public:
|
||||
|
||||
// Init
|
||||
// @param xyzw Int4 value
|
||||
explicit Double3(const Int4& xyzw);
|
||||
|
||||
// Init
|
||||
// @param xyz Vector4 value
|
||||
explicit Double3(const Vector4& xyzw);
|
||||
explicit Double3(const Int4& xyzw);
|
||||
|
||||
// Init
|
||||
// @param xy Double2 value
|
||||
Double3(const Double2& xy);
|
||||
explicit Double3(const Double2& xy);
|
||||
|
||||
// Init
|
||||
// @param xy Double2 value
|
||||
// @param z Z component value
|
||||
explicit Double3(const Double2& xy, double z);
|
||||
|
||||
|
||||
// Init
|
||||
// @param xyzw Double4 value
|
||||
explicit Double3(const Double4& xyzw);
|
||||
@@ -931,6 +934,14 @@ public:
|
||||
/// <returns>The triangle area.</returns>
|
||||
static double TriangleArea(const Double3& v0, const Double3& v1, const Double3& v2);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the angle (in radians) between from and to. This is always the smallest value.
|
||||
/// </summary>
|
||||
/// <param name="from">The first vector.</param>
|
||||
/// <param name="to">The second vector.</param>
|
||||
/// <returns>The angle (in radians).</returns>
|
||||
static double Angle(const Double3& from, const Double3& to);
|
||||
|
||||
};
|
||||
|
||||
inline Double3 operator+(double a, const Double3& b)
|
||||
|
||||
@@ -54,6 +54,14 @@ Double4::Double4(const Vector3& xyz, double w)
|
||||
{
|
||||
}
|
||||
|
||||
Double4::Double4(const Vector4& xyzw)
|
||||
: X(xyzw.X)
|
||||
, Y(xyzw.Y)
|
||||
, Z(xyzw.Z)
|
||||
, W(xyzw.W)
|
||||
{
|
||||
}
|
||||
|
||||
Double4::Double4(const Int2& xy, double z, double w)
|
||||
: X(static_cast<double>(xy.X))
|
||||
, Y(static_cast<double>(xy.Y))
|
||||
|
||||
@@ -131,14 +131,16 @@ public:
|
||||
// Init
|
||||
// @param xy X and Y values in the vector
|
||||
// @param zw Z and W values in the vector
|
||||
// @param z Z component value
|
||||
// @param w W component value
|
||||
explicit Double4(const Vector2& xy, const Vector2& zw);
|
||||
|
||||
// Init
|
||||
// @param xyz X, Y and Z values in the vector
|
||||
// @param w W component value
|
||||
explicit Double4(const Vector3& xyz, double w);
|
||||
|
||||
// Init
|
||||
// @param xyzw Vector4 value
|
||||
explicit Double4(const Vector4& xyzw);
|
||||
|
||||
// Init
|
||||
// @param xy X and Y values in the vector
|
||||
@@ -152,7 +154,7 @@ public:
|
||||
explicit Double4(const Int3& xyz, double w);
|
||||
|
||||
// Init
|
||||
// @param color Int4 value
|
||||
// @param xyzw Int4 value
|
||||
explicit Double4(const Int4& xyzw);
|
||||
|
||||
// Init
|
||||
|
||||
@@ -411,6 +411,15 @@ namespace Math
|
||||
return (T)(a * (1.0f - alpha) + b * alpha);
|
||||
}
|
||||
|
||||
// Calculates the linear parameter t that produces the interpolation value within the range [a, b].
|
||||
template<class T, class U>
|
||||
static T InverseLerp(const T& a, const T& b, const U& value)
|
||||
{
|
||||
if (a == b)
|
||||
return (T)0;
|
||||
return Saturate((value - a) / (b - a));
|
||||
}
|
||||
|
||||
// Performs smooth (cubic Hermite) interpolation between 0 and 1
|
||||
// @param amount Value between 0 and 1 indicating interpolation amount
|
||||
static float SmoothStep(float amount)
|
||||
|
||||
@@ -312,6 +312,16 @@ public:
|
||||
{
|
||||
return Vector3::Transform(Vector3::Down, Orientation);
|
||||
}
|
||||
|
||||
FORCE_INLINE Vector3 GetForward() const
|
||||
{
|
||||
return Vector3::Transform(Vector3::Forward, Orientation);
|
||||
}
|
||||
|
||||
FORCE_INLINE Vector3 GetBackward() const
|
||||
{
|
||||
return Vector3::Transform(Vector3::Backward, Orientation);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -107,3 +107,11 @@ float Vector2::TriangleArea(const Vector2& v0, const Vector2& v1, const Vector2&
|
||||
{
|
||||
return Math::Abs((v0.X * (v1.Y - v2.Y) + v1.X * (v2.Y - v0.Y) + v2.X * (v0.Y - v1.Y)) / 2);
|
||||
}
|
||||
|
||||
float Vector2::Angle(const Vector2& from, const Vector2& to)
|
||||
{
|
||||
const float dot = Math::Clamp(Dot(Normalize(from), Normalize(to)), -1.0f, 1.0f);
|
||||
if (Math::Abs(dot) > (1.0f - ZeroTolerance))
|
||||
return dot > 0.0f ? 0.0f : PI;
|
||||
return Math::Acos(dot);
|
||||
}
|
||||
|
||||
@@ -621,13 +621,8 @@ public:
|
||||
/// <param name="from">The first vector.</param>
|
||||
/// <param name="to">The second vector.</param>
|
||||
/// <returns>The angle (in radians).</returns>
|
||||
static float Angle(const Vector2& from, const Vector2& to)
|
||||
{
|
||||
const float dot = Math::Clamp(Dot(Normalize(from), Normalize(to)), -1.0f, 1.0f);
|
||||
if (Math::Abs(dot) > (1.0f - ZeroTolerance))
|
||||
return dot > 0.0f ? 0.0f : PI;
|
||||
return Math::Acos(dot);
|
||||
}
|
||||
static float Angle(const Vector2& from, const Vector2& to);
|
||||
|
||||
};
|
||||
|
||||
inline Vector2 operator+(float a, const Vector2& b)
|
||||
|
||||
@@ -383,3 +383,11 @@ float Vector3::TriangleArea(const Vector3& v0, const Vector3& v1, const Vector3&
|
||||
{
|
||||
return (v2 - v0 ^ v1 - v0).Length() * 0.5f;
|
||||
}
|
||||
|
||||
float Vector3::Angle(const Vector3& from, const Vector3& to)
|
||||
{
|
||||
const float dot = Math::Clamp(Dot(Normalize(from), Normalize(to)), -1.0f, 1.0f);
|
||||
if (Math::Abs(dot) > (1.0f - ZeroTolerance))
|
||||
return dot > 0.0f ? 0.0f : PI;
|
||||
return Math::Acos(dot);
|
||||
}
|
||||
|
||||
@@ -935,13 +935,8 @@ public:
|
||||
/// <param name="from">The first vector.</param>
|
||||
/// <param name="to">The second vector.</param>
|
||||
/// <returns>The angle (in radians).</returns>
|
||||
static float Angle(const Vector3& from, const Vector3& to)
|
||||
{
|
||||
const float dot = Math::Clamp(Dot(Normalize(from), Normalize(to)), -1.0f, 1.0f);
|
||||
if (Math::Abs(dot) > (1.0f - ZeroTolerance))
|
||||
return dot > 0.0f ? 0.0f : PI;
|
||||
return Math::Acos(dot);
|
||||
}
|
||||
static float Angle(const Vector3& from, const Vector3& to);
|
||||
|
||||
};
|
||||
|
||||
inline Vector3 operator+(float a, const Vector3& b)
|
||||
|
||||
@@ -125,19 +125,19 @@ public:
|
||||
// @param xy X and Y values in the vector
|
||||
// @param z Z component value
|
||||
// @param w W component value
|
||||
Vector4(const Vector2& xy, float z, float w);
|
||||
explicit Vector4(const Vector2& xy, float z, float w);
|
||||
|
||||
// Init
|
||||
// @param xy X and Y values in the vector
|
||||
// @param zw Z and W values in the vector
|
||||
// @param z Z component value
|
||||
// @param w W component value
|
||||
Vector4(const Vector2& xy, const Vector2& zw);
|
||||
explicit Vector4(const Vector2& xy, const Vector2& zw);
|
||||
|
||||
// Init
|
||||
// @param xyz X, Y and Z values in the vector
|
||||
// @param w W component value
|
||||
Vector4(const Vector3& xyz, float w);
|
||||
explicit Vector4(const Vector3& xyz, float w);
|
||||
|
||||
// Init
|
||||
// @param xy X and Y values in the vector
|
||||
|
||||
Reference in New Issue
Block a user