X-Git-Url: http://git.euphorik.ch/?p=GPU.git;a=blobdiff_plain;f=WCudaMSE%2FStudent_Cuda_Image%2Fsrc%2Fcpp%2Fcore%2F04_RayTracing%2Fmoo%2Fdevice%2FSphere.h;h=3c8df6e6a83ba8d490a33c8a05fef23a8c39922a;hp=a437daba76a7ec4a7c7767a0facc1682358146e5;hb=f8259dce248a4411c3bc64cecb9fc268c4fd81d6;hpb=d720146850389c8bbe75cb86e69d7e26629ff97f 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 a437dab..3c8df6e 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 @@ -7,19 +7,28 @@ class Sphere { public: - __host__ + /*__host__ Sphere(float3 centre, float r, float hue) : centre(centre), hueInitial(hue) { this->setR(r); - } + }*/ __host__ + __device__ Sphere() { } + /*Sphere(const Sphere& other) : + r(other.r), + centre(other.centre), + rCarre(other.rCarre), + T(other.T) + { + }*/ + __host__ void setCentre(const float3& centre) { @@ -30,64 +39,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. + */ __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. };