#define SPHERE_H
#include "cudaTools.h"
-#include "cudaType_CPU.h"
#include "MathTools.h"
class Sphere
{
public:
__host__
- Sphere(cpu::float3 centre, float r, float hue) :
- centre(centre),
- hueInitial(hue)
- {
- this->setR(r);
- }
-
- __host__
+ __device__
Sphere()
{
}
__host__
- void setCentre(const cpu::float3& centre)
+ void setCentre(const float3& centre)
{
this->centre = centre;
}
void setR(float r)
{
this->r = r;
- this->rCarre = r*r;
+ this->rCarre = r * r;
}
__host__
void setHueInitial(float hue)
{
- this->hueInitial = hue;
+ this->T = asinf(2 * hue - 1) - 3 * PI / 2;
}
+ /*
+ * Calcul de h².
+ */
__device__
- float hCarre(cpu::float2 xySol)
+ float hSquare(float2 xySol) const
{
- float a = (centre.x - xySol.x);
- float b = (centre.y - xySol.y);
+ const float a = (this->centre.x - xySol.x);
+ const float b = (this->centre.y - xySol.y);
return a * a + b * b;
}
+ /*
+ * Est-ce que la sphre se trouve en dessous d'un point (x, y) en fonction de h².
+ * Voir la méthode 'hCarre(..)'.
+ */
__device__
- bool isEnDessous(float hCarre)
+ bool isBelow(float hCarre) const
{
- return hCarre < rCarre;
+ return hCarre < this->rCarre;
}
+ /*
+ * Hauteur du point de collision du rayon par rapport au centre de la sphère.
+ */
__device__
- float dz(float hCarre)
+ float dz(float hCarre) const
{
return sqrtf(rCarre - hCarre);
}
__device__
- float brightness(float dz)
+ float distance(float dz) const
{
- return dz / r;
+ return this->centre.z - dz;
}
+ /**
+ * Renvoie la le B de HSB compris entre 0 et 1 dépendant du paramètre 'dz'
+ * lui même compris entre 0 et le rayon 'r'.
+ */
__device__
- float distance(float dz)
+ float brightness(float dz) const
{
- return centre.z - dz;
+ return dz / this->r;
}
+ /*
+ * La couleur
+ */
__device__
- float getHueInitial()
+ float hue(float t) const
{
- return this->hueInitial;
- }
-
- __device__
- float hue(float t) // usefull for animation
- {
- return 0.5 + 0.5 * sin(t + T + 3 * PI / 2);
+ return 0.5 + 0.5 * sinf(t + this->T + 3 * PI / 2);
}
private:
- float r;
- cpu::float3 centre;
- float hueInitial;
- float rCarre;
-
+ float r; // Rayon.
+ float3 centre; // Position.
+ float rCarre; // Précalul de r².
float T; // Utilisé pour l'animation.
};
#endif