mirror of
https://github.com/RawAccelOfficial/rawaccel.git
synced 2025-05-11 10:26:58 +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 "rawaccel-base.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
namespace rawaccel {
|
namespace rawaccel {
|
||||||
|
|
|
@ -2,12 +2,10 @@
|
||||||
|
|
||||||
#include "rawaccel-base.hpp"
|
#include "rawaccel-base.hpp"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace rawaccel {
|
namespace rawaccel {
|
||||||
|
|
||||||
struct jump_base {
|
struct jump_base {
|
||||||
static constexpr double smooth_scale = 2 * PI;
|
static constexpr double smooth_scale = 2 * M_PI;
|
||||||
|
|
||||||
vec2d step;
|
vec2d step;
|
||||||
double smooth_rate;
|
double smooth_rate;
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
#include "rawaccel-base.hpp"
|
#include "rawaccel-base.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace rawaccel {
|
namespace rawaccel {
|
||||||
|
|
||||||
// represents the range [2^start, 2^stop], with num - 1
|
// represents the range [2^start, 2^stop], with num - 1
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
#include "accel-lookup.hpp"
|
#include "accel-lookup.hpp"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace rawaccel {
|
namespace rawaccel {
|
||||||
|
|
||||||
template <bool Gain> struct loglog_sigmoid;
|
template <bool Gain> struct loglog_sigmoid;
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
#include "rawaccel-base.hpp"
|
#include "rawaccel-base.hpp"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace rawaccel {
|
namespace rawaccel {
|
||||||
|
|
||||||
/// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary>
|
/// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary>
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include "rawaccel-base.hpp"
|
#include "rawaccel-base.hpp"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|
||||||
namespace rawaccel {
|
namespace rawaccel {
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-version.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-version.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)utility-install.hpp" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)utility-install.hpp" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)vec2.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)math-vec2.hpp" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)utility.hpp" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)utility.hpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</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
|
#pragma once
|
||||||
|
|
||||||
#include "vec2.h"
|
#include "math-vec2.hpp"
|
||||||
|
|
||||||
namespace rawaccel {
|
namespace rawaccel {
|
||||||
using milliseconds = double;
|
using milliseconds = double;
|
||||||
|
@ -22,7 +22,6 @@ namespace rawaccel {
|
||||||
inline constexpr size_t LUT_POINTS_CAPACITY = LUT_RAW_DATA_CAPACITY / 2;
|
inline constexpr size_t LUT_POINTS_CAPACITY = LUT_RAW_DATA_CAPACITY / 2;
|
||||||
|
|
||||||
inline constexpr double MAX_NORM = 16;
|
inline constexpr double MAX_NORM = 16;
|
||||||
inline constexpr double PI = 3.14159265358979323846;
|
|
||||||
|
|
||||||
inline constexpr bool LEGACY = 0;
|
inline constexpr bool LEGACY = 0;
|
||||||
inline constexpr bool GAIN = 1;
|
inline constexpr bool GAIN = 1;
|
||||||
|
|
|
@ -4,30 +4,6 @@
|
||||||
|
|
||||||
namespace rawaccel {
|
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 {
|
struct time_clamp {
|
||||||
milliseconds min = DEFAULT_TIME_MIN;
|
milliseconds min = DEFAULT_TIME_MIN;
|
||||||
milliseconds max = DEFAULT_TIME_MAX;
|
milliseconds max = DEFAULT_TIME_MAX;
|
||||||
|
@ -100,16 +76,16 @@ namespace rawaccel {
|
||||||
|
|
||||||
if (compute_ref_angle && in.y != 0) {
|
if (compute_ref_angle && in.y != 0) {
|
||||||
if (in.x == 0) {
|
if (in.x == 0) {
|
||||||
reference_angle = PI / 2;
|
reference_angle = M_PI / 2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reference_angle = atan(fabs(in.y / in.x));
|
reference_angle = atan(fabs(in.y / in.x));
|
||||||
|
|
||||||
if (apply_snap) {
|
if (apply_snap) {
|
||||||
double snap = args.degrees_snap * PI / 180;
|
double snap = args.degrees_snap * M_PI / 180;
|
||||||
|
|
||||||
if (reference_angle > PI / 2 - snap) {
|
if (reference_angle > M_PI / 2 - snap) {
|
||||||
reference_angle = PI / 2;
|
reference_angle = M_PI / 2;
|
||||||
in = { 0, _copysign(magnitude(in), in.y) };
|
in = { 0, _copysign(magnitude(in), in.y) };
|
||||||
}
|
}
|
||||||
else if (reference_angle < snap) {
|
else if (reference_angle < snap) {
|
||||||
|
@ -153,7 +129,7 @@ namespace rawaccel {
|
||||||
|
|
||||||
if (apply_directional_weight) {
|
if (apply_directional_weight) {
|
||||||
double diff = args.range_weights.y - args.range_weights.x;
|
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);
|
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