X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=WCudaMSE%2FStudent_Cuda_Image%2Fsrc%2Fcpp%2Fcore%2F04_RayTracing%2Fmoo%2Fdevice%2FSphere.h;h=a4c49e913227148908bcc18ee24a2c79e10ead1c;hb=1c4b2276e7157acde9a3014b68d5d1667a7d6a44;hp=566b4ab78ea8df10b24a99976f4fa8160e5a57db;hpb=ebdad7dc732d4742d09fd72d312175cb07d27a59;p=GPU.git diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/04_RayTracing/moo/device/Sphere.h b/WCudaMSE/Student_Cuda_Image/src/cpp/core/04_RayTracing/moo/device/Sphere.h index 566b4ab..a4c49e9 100644 --- a/WCudaMSE/Student_Cuda_Image/src/cpp/core/04_RayTracing/moo/device/Sphere.h +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/04_RayTracing/moo/device/Sphere.h @@ -2,28 +2,19 @@ #define SPHERE_H #include "cudaTools.h" -#include "cudaType_CPU.h" -#include "mathTools.h" +#include "MathTools.h" -#endif class Sphere { public: __host__ - Sphere(float3 centre, float r, float hue) : - centre(centre), - hueInitial(hue) - { - this->setR(r); - } - - __host__ + __device__ Sphere() { } __host__ - void setCentre(float3 centre) + void setCentre(const float3& centre) { this->centre = centre; } @@ -32,65 +23,74 @@ class Sphere 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(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; - 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