feat: add Cross2D for Kreuzprodukt vector calculation

This commit is contained in:
huaqo-games
2026-06-29 18:13:31 +02:00
parent 59b51c2beb
commit c27ada5352
2 changed files with 137 additions and 133 deletions
+15 -16
View File
@@ -1,27 +1,26 @@
#include "engine.h"
bool IsVectorZero(Vector2 v) {
float epsilon = 0.01f;
return (fabs(v.x) < epsilon && fabs(v.y) < epsilon);
float epsilon = 0.01f;
return (fabs(v.x) < epsilon && fabs(v.y) < epsilon);
}
Vector2 GetRandomVector(const Rectangle bounds) {
return (Vector2){
bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width,
bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height
};
return (Vector2){
bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width,
bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height};
}
Vector2 RotationToVector2(float rotation)
{
float rad = rotation * (PI / 180.0f);
Vector2 vec = { cosf(rad), sinf(rad) };
return vec;
Vector2 RotationToVector2(float rotation) {
float rad = rotation * (PI / 180.0f);
Vector2 vec = {cosf(rad), sinf(rad)};
return vec;
}
float Vector2ToRotation(Vector2 vec)
{
float rad = atan2f(vec.y, vec.x);
float deg = rad * (180.0f / PI);
return deg;
float Vector2ToRotation(Vector2 vec) {
float rad = atan2f(vec.y, vec.x);
float deg = rad * (180.0f / PI);
return deg;
}
float Cross2D(Vector2 a, Vector2 b) { return a.x * b.y - a.y * b.x; }