More refactoring
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Easing.cpp
|
||||
String.cpp
|
||||
Random.cpp
|
||||
)
|
48
src/dawn/util/Easing.cpp
Normal file
48
src/dawn/util/Easing.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Easing.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
float_t Easing::linear(float_t t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
float_t Easing::easeInQuad(float_t t) {
|
||||
return t * t;
|
||||
}
|
||||
|
||||
float_t Easing::easeOutQuad(float_t t) {
|
||||
return t * (2 - t);
|
||||
}
|
||||
|
||||
float_t Easing::easeInOutQuad(float_t t) {
|
||||
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
||||
}
|
||||
|
||||
float_t Easing::easeInCubic(float_t t) {
|
||||
return t * t * t;
|
||||
}
|
||||
|
||||
float_t Easing::easeOutCubic(float_t t) {
|
||||
return (--t) * t * t + 1;
|
||||
}
|
||||
|
||||
float_t Easing::easeInOutCubic(float_t t) {
|
||||
return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
|
||||
}
|
||||
|
||||
float_t Easing::easeInQuart(float_t t) {
|
||||
return t * t * t * t;
|
||||
}
|
||||
|
||||
float_t Easing::easeOutQuart(float_t t) {
|
||||
return 1 - (--t) * t * t * t;
|
||||
}
|
||||
|
||||
float_t Easing::easeInOutQuart(float_t t) {
|
||||
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * (--t) * t * t * t;
|
||||
}
|
92
src/dawn/util/Easing.hpp
Normal file
92
src/dawn/util/Easing.hpp
Normal file
@ -0,0 +1,92 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Easing final {
|
||||
public:
|
||||
/**
|
||||
* Linear easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t linear(float_t t);
|
||||
|
||||
/**
|
||||
* Quadratic easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t easeInQuad(float_t t);
|
||||
|
||||
/**
|
||||
* Quadratic easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t easeOutQuad(float_t t);
|
||||
|
||||
/**
|
||||
* Quadratic easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t easeInOutQuad(float_t t);
|
||||
|
||||
/**
|
||||
* Cubic easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t easeInCubic(float_t t);
|
||||
|
||||
/**
|
||||
* Cubic easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t easeOutCubic(float_t t);
|
||||
|
||||
/**
|
||||
* Cubic easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t easeInOutCubic(float_t t);
|
||||
|
||||
/**
|
||||
* Quartic easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t easeInQuart(float_t t);
|
||||
|
||||
/**
|
||||
* Quartic easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t easeOutQuart(float_t t);
|
||||
|
||||
/**
|
||||
* Quartic easing function.
|
||||
*
|
||||
* @param t Time value between 0 and 1.
|
||||
* @return Eased value.
|
||||
*/
|
||||
static float_t easeInOutQuart(float_t t);
|
||||
};
|
||||
}
|
@ -23,6 +23,16 @@ namespace Dawn {
|
||||
*/
|
||||
static uint64_t next();
|
||||
|
||||
/**
|
||||
* Returns a random number between 0 and RAND_MAX.
|
||||
*
|
||||
* @return Random number between 0 and RAND_MAX.
|
||||
*/
|
||||
template<typename T>
|
||||
static T random() {
|
||||
return (T)next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random number between the provided min and max values.
|
||||
*
|
||||
|
Reference in New Issue
Block a user