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