rename velocity_to_delta to angle_to_vector, remove endpoint function

This commit is contained in:
ohsqueezy 2023-06-22 21:25:57 -04:00
parent c0852ba04f
commit b02ae013ab
2 changed files with 11 additions and 29 deletions

View File

@ -1,4 +1,4 @@
/* +------------------------------------------------------+
/* +------------------------------------------------------+
____/ \____ /| - Open source game framework licensed to freely use, |
\ / / | copy, modify and sell without restriction |
+--\ ^__^ /--+ | |
@ -10,7 +10,7 @@
#include "math.hpp"
glm::vec2 sb::velocity_to_delta(float angle, float magnitude)
glm::vec2 sb::angle_to_vector(float angle, float magnitude)
{
return {glm::sin(angle) * magnitude, glm::cos(angle) * magnitude};
}
@ -30,11 +30,6 @@ float sb::angle_ratio(float start, float end)
return sb::angle_difference(start, end) / glm::pi<float>();
}
glm::vec2 sb::endpoint(glm::vec2 start, float angle, float magnitude)
{
return start + velocity_to_delta(angle, magnitude);
}
std::vector<glm::vec2> sb::bezier(const std::vector<glm::vec2>& control, int resolution)
{
std::vector<glm::vec2> points;

View File

@ -20,10 +20,10 @@ This test of points on a square and one point below the square should print the
std::cout << glm::degrees(sb::angle_between(a, b)) << " " << glm::degrees(sb::angle_between(b, a)) << " " <<
glm::degrees(sb::angle_between(a, c)) << " " << glm::degrees(sb::angle_between(c, a)) << " " <<
glm::degrees(sb::angle_between(b, e)) << " " << glm::degrees(sb::angle_between(e, b)) << std::endl <<
sb::velocity_to_delta(sb::angle_between(a, b), 4.0f * glm::sqrt(2.0f)) << " " <<
sb::velocity_to_delta(sb::angle_between(b, a), 4.0f * glm::sqrt(2.0f)) << " " <<
sb::velocity_to_delta(sb::angle_between(d, a), 4.0f) << " " <<
sb::velocity_to_delta(sb::angle_between(b, e), 1.0f) << std::endl;
sb::angle_to_vector(sb::angle_between(a, b), 4.0f * glm::sqrt(2.0f)) << " " <<
sb::angle_to_vector(sb::angle_between(b, a), 4.0f * glm::sqrt(2.0f)) << " " <<
sb::angle_to_vector(sb::angle_between(d, a), 4.0f) << " " <<
sb::angle_to_vector(sb::angle_between(b, e), 1.0f) << std::endl;
Should print,
@ -61,14 +61,13 @@ namespace sb
static inline const glm::vec3 ZAXIS {0.0f, 0.0f, 1.0f};
/*!
* Convert a vector described by the given angle and magnitude to an X and Y offset vector.
* Get a 2D vector from an angle and magnitude
*
* @param angle a float representing the angle of velocity in radians, with 0 being up on the screen and increasing
* values going clockwise
* @param magnitude a float representing the speed, or the magnitude of the input vector in the X/Y plane
* @return a glm::vec2 of the change in X and Y for the given velocity vector
* @param angle angle of a vector in radians, with 0 being up on the screen and increasing values going clockwise
* @param magnitude magnitude (length, speed, etc.) of a vector
* @return 2D vector of the change in X and Y for the given angle and magnitude
*/
glm::vec2 velocity_to_delta(float angle, float magnitude);
glm::vec2 angle_to_vector(float angle, float magnitude = 1.0f);
/*!
* Get the angle between two vectors, or the angle the first would rotate to to point toward the second.
@ -100,18 +99,6 @@ namespace sb
*/
float angle_ratio(float start, float end);
/*!
* Get the end point of a move given a start point, angle, and magnitude.
*
* This gives the same result as start + velocity_to_delta(float angle, float magnitude).
*
* @param start a 2D vertex representing the starting point of this step
* @param angle an angle in radians representing the direction of the step
* @param magnitude a float representing the speed or distance to travel in this step
* @return a 2D vertex representing the end point of this step
*/
glm::vec2 endpoint(glm::vec2 start, float angle, float magnitude);
/*!
* Calculate a 2D bezier curve from four 2D control points.
*