Cleanage.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 04_RayTracing / moo / device / Sphere.h
1 #ifndef SPHERE_H
2 #define SPHERE_H
3
4 #include "cudaTools.h"
5 #include "MathTools.h"
6
7 class Sphere
8 {
9 public:
10 __host__
11 Sphere(float3 centre, float r, float hue) :
12 centre(centre),
13 hueInitial(hue)
14 {
15 this->setR(r);
16 }
17
18 __host__
19 Sphere()
20 {
21 }
22
23 __host__
24 void setCentre(const float3& centre)
25 {
26 this->centre = centre;
27 }
28
29 __host__
30 void setR(float r)
31 {
32 this->r = r;
33 this->rCarre = r*r;
34 }
35
36 __host__
37 void setHueInitial(float hue)
38 {
39 this->hueInitial = hue;
40 }
41
42 __device__
43 float hCarre(float2 xySol)
44 {
45 float a = (centre.x - xySol.x);
46 float b = (centre.y - xySol.y);
47 return a * a + b * b;
48 }
49
50 __device__
51 bool isEnDessous(float hCarre)
52 {
53 return hCarre < rCarre;
54 }
55
56 __device__
57 float dz(float hCarre)
58 {
59 return sqrtf(rCarre - hCarre);
60 }
61
62 __device__
63 float brightness(float dz)
64 {
65 return dz / r;
66 }
67
68 __device__
69 float distance(float dz)
70 {
71 return centre.z - dz;
72 }
73
74 __device__
75 float getHueInitial()
76 {
77 return this->hueInitial;
78 }
79
80 __device__
81 float hue(float t) // usefull for animation
82 {
83 return 0.5 + 0.5 * sin(t + T + 3 * PI / 2);
84 }
85
86 private:
87 float r;
88 float3 centre;
89 float hueInitial;
90 float rCarre;
91
92 float T; // Utilisé pour l'animation.
93 };
94 #endif