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;fp=WCudaMSE%2FStudent_Cuda_Image%2Fsrc%2Fcpp%2Fcore%2F04_RayTracing%2Fmoo%2Fdevice%2FSphere.h;h=566b4ab78ea8df10b24a99976f4fa8160e5a57db;hp=0000000000000000000000000000000000000000;hb=ebdad7dc732d4742d09fd72d312175cb07d27a59;hpb=00dcb50daad8129676832b0b646e675770ee51a0 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 new file mode 100644 index 0000000..566b4ab --- /dev/null +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/04_RayTracing/moo/device/Sphere.h @@ -0,0 +1,96 @@ +#ifndef SPHERE_H +#define SPHERE_H + +#include "cudaTools.h" +#include "cudaType_CPU.h" +#include "mathTools.h" + +#endif +class Sphere + { + public: + __host__ + Sphere(float3 centre, float r, float hue) : + centre(centre), + hueInitial(hue) + { + this->setR(r); + } + + __host__ + Sphere() + { + } + + __host__ + void setCentre(float3 centre) + { + this->centre = centre; + } + + __host__ + void setR(float r) + { + this->r = r; + this->rCarre = r*r; + } + + __host__ + void setHueInitial(float hue) + { + this->hueInitial = hue; + } + + __device__ + float hCarre(float2 xySol) + { + float a = (centre.x - xySol.x); + float b = (centre.y - xySol.y); + return a * a + b * b; + } + + __device__ + bool isEnDessous(float hCarre) + { + return hCarre < rCarre; + } + + __device__ + float dz(float hCarre) + { + return sqrtf(rCarre - hCarre); + } + + __device__ + float brightness(float dz) + { + return dz / r; + } + + __device__ + float distance(float dz) + { + return centre.z - dz; + } + + __device__ + float getHueInitial() + { + return this->hueInitial; + } + + __device__ + float hue(float t) // usefull for animation + { + return 0.5 + 0.5 * sin(t + T + 3 * PI / 2); + } + + private: + float r; + float3 centre; + float hueInitial; + float rCarre; + + float T; // Utilisé pour l'animation. + }; +#endif