Ray tracing (pas termine).
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 04_RayTracing / moo / device / Sphere.h
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 (file)
index 0000000..566b4ab
--- /dev/null
@@ -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