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