mirror of
https://github.com/RawAccelOfficial/rawaccel.git
synced 2025-05-10 18:06:38 +02:00
refactor vec2/math
This commit is contained in:
parent
5b659e1cfb
commit
6a9272d3af
11 changed files with 44 additions and 52 deletions
|
@ -3,7 +3,6 @@
|
|||
#include "rawaccel-base.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
namespace rawaccel {
|
||||
|
|
|
@ -2,12 +2,10 @@
|
|||
|
||||
#include "rawaccel-base.hpp"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
struct jump_base {
|
||||
static constexpr double smooth_scale = 2 * PI;
|
||||
static constexpr double smooth_scale = 2 * M_PI;
|
||||
|
||||
vec2d step;
|
||||
double smooth_rate;
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#include "rawaccel-base.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
// represents the range [2^start, 2^stop], with num - 1
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
#include "accel-lookup.hpp"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
template <bool Gain> struct loglog_sigmoid;
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
#include "rawaccel-base.hpp"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
/// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "rawaccel-base.hpp"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
namespace rawaccel {
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-version.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)utility-install.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)vec2.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)math-vec2.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)utility.hpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
36
common/math-vec2.hpp
Normal file
36
common/math-vec2.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
template <typename T>
|
||||
struct vec2 {
|
||||
T x;
|
||||
T y;
|
||||
};
|
||||
|
||||
using vec2d = vec2<double>;
|
||||
|
||||
inline vec2d direction(double degrees)
|
||||
{
|
||||
double radians = degrees * M_PI / 180;
|
||||
return { cos(radians), sin(radians) };
|
||||
}
|
||||
|
||||
constexpr vec2d rotate(const vec2d& v, const vec2d& direction)
|
||||
{
|
||||
return {
|
||||
v.x * direction.x - v.y * direction.y,
|
||||
v.x * direction.y + v.y * direction.x
|
||||
};
|
||||
}
|
||||
|
||||
inline double magnitude(const vec2d& v)
|
||||
{
|
||||
return sqrt(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
inline double lp_distance(const vec2d& v, double p)
|
||||
{
|
||||
return pow(pow(v.x, p) + pow(v.y, p), 1 / p);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "vec2.h"
|
||||
#include "math-vec2.hpp"
|
||||
|
||||
namespace rawaccel {
|
||||
using milliseconds = double;
|
||||
|
@ -22,7 +22,6 @@ namespace rawaccel {
|
|||
inline constexpr size_t LUT_POINTS_CAPACITY = LUT_RAW_DATA_CAPACITY / 2;
|
||||
|
||||
inline constexpr double MAX_NORM = 16;
|
||||
inline constexpr double PI = 3.14159265358979323846;
|
||||
|
||||
inline constexpr bool LEGACY = 0;
|
||||
inline constexpr bool GAIN = 1;
|
||||
|
|
|
@ -4,30 +4,6 @@
|
|||
|
||||
namespace rawaccel {
|
||||
|
||||
inline vec2d direction(double degrees)
|
||||
{
|
||||
double radians = degrees * PI / 180;
|
||||
return { cos(radians), sin(radians) };
|
||||
}
|
||||
|
||||
constexpr vec2d rotate(const vec2d& v, const vec2d& direction)
|
||||
{
|
||||
return {
|
||||
v.x * direction.x - v.y * direction.y,
|
||||
v.x * direction.y + v.y * direction.x
|
||||
};
|
||||
}
|
||||
|
||||
inline double magnitude(const vec2d& v)
|
||||
{
|
||||
return sqrt(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
inline double lp_distance(const vec2d& v, double p)
|
||||
{
|
||||
return pow(pow(v.x, p) + pow(v.y, p), 1 / p);
|
||||
}
|
||||
|
||||
struct time_clamp {
|
||||
milliseconds min = DEFAULT_TIME_MIN;
|
||||
milliseconds max = DEFAULT_TIME_MAX;
|
||||
|
@ -100,16 +76,16 @@ namespace rawaccel {
|
|||
|
||||
if (compute_ref_angle && in.y != 0) {
|
||||
if (in.x == 0) {
|
||||
reference_angle = PI / 2;
|
||||
reference_angle = M_PI / 2;
|
||||
}
|
||||
else {
|
||||
reference_angle = atan(fabs(in.y / in.x));
|
||||
|
||||
if (apply_snap) {
|
||||
double snap = args.degrees_snap * PI / 180;
|
||||
double snap = args.degrees_snap * M_PI / 180;
|
||||
|
||||
if (reference_angle > PI / 2 - snap) {
|
||||
reference_angle = PI / 2;
|
||||
if (reference_angle > M_PI / 2 - snap) {
|
||||
reference_angle = M_PI / 2;
|
||||
in = { 0, _copysign(magnitude(in), in.y) };
|
||||
}
|
||||
else if (reference_angle < snap) {
|
||||
|
@ -153,7 +129,7 @@ namespace rawaccel {
|
|||
|
||||
if (apply_directional_weight) {
|
||||
double diff = args.range_weights.y - args.range_weights.x;
|
||||
weight += 2 / PI * reference_angle * diff;
|
||||
weight += 2 / M_PI * reference_angle * diff;
|
||||
}
|
||||
|
||||
double scale = (*cb_x)(data.accel_x, args.accel_x, speed, weight);
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
template <typename T>
|
||||
struct vec2 {
|
||||
T x;
|
||||
T y;
|
||||
};
|
||||
|
||||
using vec2d = vec2<double>;
|
Loading…
Add table
Add a link
Reference in a new issue