Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Universal Mouse Movement Transformer (Natural Acceleration)
#1
MOUSE_DIMENSION.h
Code:
#pragma once

#define MOUSE_PI 3.14159265358979323846264338327950f

class MOUSE_DIMENSION
{
private:
    unsigned long long m_CALLS_PER_INSTANCE;
    unsigned long long m_INSTANCES_PER_LOSS;

    long long m_TOTAL_ANGLE;

    //TODO: Change to double
    //unsigned long long m_INFLATION_FACTOR;
    double m_INFLATION_FACTOR;

    float m_RESOLUTION;
    float m_FOV;
    float m_SENSITIVITY;

    float m_CIRCUMFERENCE;
    float m_RADIUS;

    float RESOLUTION_AND_FOV_TO_RADIUS(float RESOLUTION, float FOV);
public:
    MOUSE_DIMENSION(float RESOLUTION, float FOV, float SENSITIVITY, unsigned long long CALLS_PER_INSTANCE, unsigned long long INSTANCES_PER_LOSS, int MAXIMUM_SENSITIVITY, int STATIC_SENSITIVITY_INCREMENT_SIZE);

    void UPDATE_RESOLUTION(float RESOLUTION);
    void UPDATE_FOV(float FOV);
    void UPDATE_SENSITIVITY(float SENSITIVITY);

    long INPUT(float INPUT);
};

MOUSE_DIMENSION.cpp
Code:
#include "MOUSE_DIMENSION.h"

float MOUSE_DIMENSION::RESOLUTION_AND_FOV_TO_RADIUS(float RESOLUTION, float FOV)
{
    //TODO: return RADIUS from FOV in PIXELS instead of DEGREES
    return (RESOLUTION / sin(MOUSE_PI / (360 / FOV))) / 2;
}

MOUSE_DIMENSION::MOUSE_DIMENSION(float RESOLUTION = 800, float FOV = 90, float SENSITIVITY = 1, unsigned long long CALLS_PER_INSTANCE = 1, unsigned long long INSTANCES_PER_LOSS = 360000, int MAXIMUM_SENSITIVTY = 10, int INCREMENTS_PER_UNIT_OF_SENSITIVITY = 5)
{
    this->m_RESOLUTION = RESOLUTION;

    this->m_RADIUS = this->RESOLUTION_AND_FOV_TO_RADIUS(RESOLUTION, FOV);
    this->m_CIRCUMFERENCE = this->m_RADIUS * MOUSE_PI * 2;

    this->m_FOV = FOV;
    this->m_SENSITIVITY = SENSITIVITY;

    this->m_CALLS_PER_INSTANCE = CALLS_PER_INSTANCE;
    this->m_INSTANCES_PER_LOSS = INSTANCES_PER_LOSS;

    // this accounts for maximum transduced input of PI radians (THE RESULT OF TRANSDUCTION IS ALWAYS BETWEEN -PI AND PI RADIANS)
    this->m_INFLATION_FACTOR = m_CALLS_PER_INSTANCE * m_INSTANCES_PER_LOSS * (MOUSE_PI * 1);

    this->m_TOTAL_ANGLE = 0;
}
void MOUSE_DIMENSION::UPDATE_RESOLUTION(float RESOLUTION)
{
    m_TOTAL_ANGLE = (m_TOTAL_ANGLE / (m_RESOLUTION / (m_RESOLUTION = RESOLUTION)));
    m_RADIUS = this->RESOLUTION_AND_FOV_TO_RADIUS(RESOLUTION, this->m_FOV);
    m_CIRCUMFERENCE = m_RADIUS * MOUSE_PI * 2;

}
void MOUSE_DIMENSION::UPDATE_FOV(float FOV)
{
    m_RADIUS = this->RESOLUTION_AND_FOV_TO_RADIUS(m_RESOLUTION, m_FOV);
    m_CIRCUMFERENCE = m_RADIUS * MOUSE_PI * 2;
    //TODO: UPDATE CIRCUMFERENCE, INFLATION_FACTOR, and TOTAL_ANGLE
}
void MOUSE_DIMENSION::UPDATE_SENSITIVITY(float SENSITIVITY)
{
    this->m_SENSITIVITY = SENSITIVITY;
}
float ABSN(float INPUT)
{
    return sqrt(INPUT * INPUT);
}
float ATANN(float INPUT)
{
    return INPUT / ABSN(INPUT);
}
inline float MODULO(float x, float y)
{
    return fmod(x, y);
}
inline float INTEGERIZE(float input)
{
    return input - MODULO(input, 1);
}
inline float CLAMP(float rotations_in_n_units, float half_n_unit)
{
    return MODULO(INTEGERIZE(rotations_in_n_units / half_n_unit), 2) * -1 * half_n_unit + MODULO(rotations_in_n_units, half_n_unit);
}
float TRANSDUCE(float INPUT, float SENSITIVITY)
{
    return ATANN(INPUT) * 2 * asinf(ABSN(CLAMP(INPUT * SENSITIVITY, 2)) / 2);
}
float FORMAT_INPUT(float INPUT, float SENSITIVITY)
{
    return TRANSDUCE(INPUT, SENSITIVITY);
}
long MOUSE_DIMENSION::INPUT(float INPUT)
{
    long TOTAL_ANGLE = this->m_TOTAL_ANGLE;
    m_TOTAL_ANGLE = static_cast<long long>(fmod(m_TOTAL_ANGLE + (FORMAT_INPUT(INPUT, this->m_SENSITIVITY) * this->m_RADIUS * this->m_INFLATION_FACTOR ),m_CIRCUMFERENCE * m_INFLATION_FACTOR));

    std::cout << "m_RESOLUTION: " << m_RESOLUTION << ", m_INFLATION_FACTOR: " << m_INFLATION_FACTOR << ", NEW_TOTAL: " << TOTAL_ANGLE << "\n";

    return static_cast<long long>(TOTAL_ANGLE / m_INFLATION_FACTOR);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)