- Cambiar todos los literales float de minúscula a mayúscula (1.0f → 1.0F)
- 657 correcciones aplicadas automáticamente con clang-tidy
- Check 1/N completado
🤖 Generated with Claude Code
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
// primitives.cpp - Implementació de funcions geomètriques
|
||
// © 1999 Visente i Sergi (versió Pascal)
|
||
// © 2025 Port a C++20 amb SDL3
|
||
//
|
||
// ==============================================================================
|
||
// DEPRECATED: Use Shape system instead (.shp files + ShapeLoader)
|
||
// ==============================================================================
|
||
|
||
#include "primitives.hpp"
|
||
|
||
#include <cmath>
|
||
|
||
#include "core/defaults.hpp"
|
||
|
||
float modul(const Punt& p) {
|
||
// Càlcul de la magnitud d'un vector: sqrt(x² + y²)
|
||
return std::sqrt(p.x * p.x + p.y * p.y);
|
||
}
|
||
|
||
void diferencia(const Punt& o, const Punt& d, Punt& p) {
|
||
// Resta de vectors (origen - destí)
|
||
p.x = o.x - d.x;
|
||
p.y = o.y - d.y;
|
||
}
|
||
|
||
int distancia(const Punt& o, const Punt& d) {
|
||
// Distància entre dos punts
|
||
Punt p;
|
||
diferencia(o, d, p);
|
||
return static_cast<int>(std::round(modul(p)));
|
||
}
|
||
|
||
float angle_punt(const Punt& p) {
|
||
// Càlcul de l'angle d'un punt (arctan)
|
||
if (p.y != 0) {
|
||
return std::atan(p.x / p.y);
|
||
}
|
||
return 0.0F;
|
||
}
|
||
|
||
void crear_poligon_regular(Poligon& pol, uint8_t n, float r) {
|
||
// Crear un polígon regular amb n costats i radi r
|
||
// Distribueix els punts uniformement al voltant d'un cercle
|
||
|
||
float interval = 2.0F * Defaults::Math::PI / n;
|
||
float act = 0.0F;
|
||
|
||
for (uint8_t i = 0; i < n; i++) {
|
||
pol.ipuntx[i].r = r;
|
||
pol.ipuntx[i].angle = act;
|
||
act += interval;
|
||
}
|
||
|
||
// Inicialitzar propietats del polígon
|
||
pol.centre.x = 320.0F;
|
||
pol.centre.y = 200.0F;
|
||
pol.angle = 0.0F;
|
||
// Convertir velocitat de px/frame a px/s: 2 px/frame × 20 FPS = 40 px/s
|
||
pol.velocitat = Defaults::Physics::ENEMY_SPEED * 20.0F;
|
||
pol.n = n;
|
||
// Convertir rotació de rad/frame a rad/s: 0.0785 rad/frame × 20 FPS = 1.57
|
||
// rad/s (~90°/s)
|
||
pol.drotacio = 0.078539816F * 20.0F;
|
||
pol.rotacio = 0.0F;
|
||
pol.esta = true;
|
||
}
|