|
@@ -0,0 +1,80 @@
|
|
|
+#include "LaunchCircle.h"
|
|
|
+#include <cmath>
|
|
|
+
|
|
|
+LaunchCircle::LaunchCircle(int const rayon, Uint32 const couleur, int const stock)
|
|
|
+:m_rayon(rayon),m_epaisseur(40),m_stock(stock)
|
|
|
+{
|
|
|
+ m_pixel = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, 1, 16,0,0,0,0);
|
|
|
+ SDL_FillRect(m_pixel,NULL,couleur);
|
|
|
+}
|
|
|
+
|
|
|
+LaunchCircle::LaunchCircle(int const rayon, Uint32 const couleur, int const stock, int const epaisseur)
|
|
|
+:m_rayon(rayon),m_epaisseur(epaisseur),m_stock(stock)
|
|
|
+{
|
|
|
+ m_pixel = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, 1, 16,0,0,0,0);
|
|
|
+ SDL_FillRect(m_pixel,NULL,couleur);
|
|
|
+}
|
|
|
+
|
|
|
+LaunchCircle::~LaunchCircle()
|
|
|
+{
|
|
|
+ SDL_FreeSurface(m_pixel);
|
|
|
+}
|
|
|
+
|
|
|
+void LaunchCircle::afficher(int const x, int const y, int const valeur, SDL_Surface *screen)
|
|
|
+{
|
|
|
+ // [1] Création du % puis transformation en radians
|
|
|
+ double radian((double)valeur/m_stock*2*M_PI);//Entre 0 et 2PI
|
|
|
+ radian -= M_PI_2;//Entre -PI/2 et 3PI/2
|
|
|
+
|
|
|
+ // [2] Création de l'équation de droite
|
|
|
+ double m(0);
|
|
|
+ double p(0);
|
|
|
+
|
|
|
+ m = (sin(radian))/(cos(radian));//En gros c'est ça
|
|
|
+ p = -(m*x)+y;//ça c'est fait
|
|
|
+
|
|
|
+ // [3] Trace
|
|
|
+ SDL_Rect position;
|
|
|
+ for (int i(x-m_rayon); i<=x+m_rayon; i++)
|
|
|
+ {
|
|
|
+ for (int j(y-m_rayon); j<=y+m_rayon; j++)
|
|
|
+ {
|
|
|
+
|
|
|
+ if ((i-x)*(i-x)+(j-y)*(j-y)<m_rayon*m_rayon &&
|
|
|
+ (i-x)*(i-x)+(j-y)*(j-y)>m_rayon*m_rayon-m_epaisseur*m_epaisseur)
|
|
|
+ {
|
|
|
+ position.x=i;
|
|
|
+ position.y=j;
|
|
|
+ if (radian <=-M_PI_2)
|
|
|
+ {}
|
|
|
+ else if (radian >= 3*M_PI_2)//Cercle entier
|
|
|
+ {
|
|
|
+ SDL_BlitSurface(m_pixel, 0, screen, &position);
|
|
|
+ }
|
|
|
+ else if (radian == M_PI_2)//Demi cercle
|
|
|
+ {
|
|
|
+ if (i<=x)
|
|
|
+ SDL_BlitSurface(m_pixel, 0, screen, &position);
|
|
|
+ }
|
|
|
+ else if (radian < M_PI_2)//Moins d'une moitié
|
|
|
+ {
|
|
|
+ if (i<=x && j>m*i+p)
|
|
|
+ {
|
|
|
+ SDL_BlitSurface(m_pixel, 0, screen, &position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (radian > M_PI_2)//Plus d'une moitié
|
|
|
+ {
|
|
|
+ if (i<=x)
|
|
|
+ {
|
|
|
+ SDL_BlitSurface(m_pixel, 0, screen, &position);
|
|
|
+ }
|
|
|
+ else if (j<m*i+p)
|
|
|
+ {
|
|
|
+ SDL_BlitSurface(m_pixel, 0, screen, &position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|