Rippling CUDA Warmup et Smart.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 01_Rippling / moo / device / math / RipplingMath.h
index 74c4dfc..655fa09 100755 (executable)
@@ -22,14 +22,8 @@ class RipplingMath
 \r
        __device__\r
        RipplingMath(int w, int h)\r
+           : dim2(w / 2.0)\r
            {\r
-           // TODO\r
-           }\r
-\r
-       __device__\r
-       RipplingMath(const RipplingMath& source)\r
-           {\r
-           // TODO\r
            }\r
 \r
        /*--------------------------------------*\\r
@@ -45,35 +39,35 @@ class RipplingMath
        __device__\r
        void color(int i, int j, float t, uchar4& color)\r
            {\r
-           // Debug (a mettre en commentaire)\r
-               {\r
-               unsigned char levelGris = 128; //in [0.255]  (debug image)\r
-               color.x = levelGris;\r
-               color.y = levelGris;\r
-               color.z = levelGris;\r
-               }\r
-\r
-           // Vrai problem\r
-               {\r
-               // TODO\r
-               }\r
-\r
-           //color.w = 255; // opaque\r
+           const double dxy10 = dxy(j, i) / 10.0;\r
+           const double grayLevelFloat = 128.0 + 127.0 * cos(dxy10 - t / 7.0 / 10.0) / (dxy10 + 1);\r
+           const uchar grayLevel = (uchar)(long(grayLevelFloat) % 256);\r
+\r
+           color.x = grayLevel;\r
+           color.y = grayLevel;\r
+           color.z = grayLevel;\r
            }\r
 \r
     private:\r
+       __device__\r
+       double dxy(int x, int y)\r
+           {\r
+           return sqrt(pow(x - this->dim2, 2.0) + pow(y - this->dim2, 2.0));\r
+           }\r
+\r
 \r
        /*--------------------------------------*\\r
        |*              Attributs               *|\r
         \*-------------------------------------*/\r
 \r
     private:\r
+       const double dim2;\r
 \r
        // Tools\r
 \r
     };\r
 \r
-#endif \r
+#endif\r
 \r
 /*----------------------------------------------------------------------*\\r
  |*                    End                                             *|\r