projects
/
GPU.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Missing parameters file.
[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
index
a437dab
..
a4c49e9
100644
(file)
--- 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
@@
-8,14
+8,7
@@
class Sphere
{
public:
__host__
{
public:
__host__
- Sphere(float3 centre, float r, float hue) :
- centre(centre),
- hueInitial(hue)
- {
- this->setR(r);
- }
-
- __host__
+ __device__
Sphere()
{
}
Sphere()
{
}
@@
-30,65
+23,74
@@
class Sphere
void setR(float r)
{
this->r = r;
void setR(float r)
{
this->r = r;
- this->rCarre = r
*
r;
+ this->rCarre = r
*
r;
}
__host__
void setHueInitial(float hue)
{
}
__host__
void setHueInitial(float hue)
{
- this->
hueInitial = hue
;
+ this->
T = asinf(2 * hue - 1) - 3 * PI / 2
;
}
}
+ /*
+ * Calcul de h².
+ */
__device__
__device__
- float h
Carre(float2 xySol)
+ float h
Square(float2 xySol) const
{
{
-
float a = (
centre.x - xySol.x);
-
float b = (
centre.y - xySol.y);
+
const float a = (this->
centre.x - xySol.x);
+
const float b = (this->
centre.y - xySol.y);
return a * a + b * b;
}
return a * a + b * b;
}
+ /*
+ * Est-ce que la sphre se trouve en dessous d'un point (x, y) en fonction de h².
+ * Voir la méthode 'hCarre(..)'.
+ */
__device__
__device__
- bool is
EnDessous(float hCarre)
+ bool is
Below(float hCarre) const
{
{
- return hCarre < rCarre;
+ return hCarre <
this->
rCarre;
}
}
+ /*
+ * Hauteur du point de collision du rayon par rapport au centre de la sphère.
+ */
__device__
__device__
- float dz(float hCarre)
+ float dz(float hCarre)
const
{
return sqrtf(rCarre - hCarre);
}
__device__
{
return sqrtf(rCarre - hCarre);
}
__device__
- float
brightness(float dz)
+ float
distance(float dz) const
{
{
- return
dz / r
;
+ return
this->centre.z - dz
;
}
}
+ /**
+ * Renvoie la le B de HSB compris entre 0 et 1 dépendant du paramètre 'dz'
+ * lui même compris entre 0 et le rayon 'r'.
+ */
__device__
__device__
- float
distance(float dz)
+ float
brightness(float dz) const
{
{
- return
centre.z - dz
;
+ return
dz / this->r
;
}
}
+ /*
+ * La couleur
+ */
__device__
__device__
- float
getHueInitial()
+ float
hue(float t) const
{
{
- return this->hueInitial;
- }
-
- __device__
- float hue(float t) // usefull for animation
- {
- return 0.5 + 0.5 * sin(t + T + 3 * PI / 2);
+ return 0.5 + 0.5 * sinf(t + this->T + 3 * PI / 2);
}
private:
}
private:
- float r;
- float3 centre;
- float hueInitial;
- float rCarre;
-
+ float r; // Rayon.
+ float3 centre; // Position.
+ float rCarre; // Précalul de r².
float T; // Utilisé pour l'animation.
};
#endif
float T; // Utilisé pour l'animation.
};
#endif