changeset 766:984e6aa17174

task/DrawSpan fix
author yutaka@henri.cr.ie.u-ryukyu.ac.jp
date Wed, 10 Feb 2010 19:43:57 +0900
parents dc26593f8c40
children 719573b2e569
files Renderer/Engine/task/DrawSpan.cc
diffstat 1 files changed, 41 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/task/DrawSpan.cc	Wed Feb 10 19:33:27 2010 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Wed Feb 10 19:43:57 2010 +0900
@@ -387,13 +387,17 @@
 		    int world_x, int world_y, float world_z)
 
 {
+
+
     unsigned char rgb[4];
     int light_rgb;
     int flag;
     float normal_vector[4] = {normal_x,normal_y,normal_z,0};
-    // 光のベクトル,きめうちしちゃった。どうにかする
-    float light_vector[4] = {0,0,-1,0};
+    float light_vector[4];
     float inner_product;
+    float *light_xyz = (float*)smanager->global_get(Light);
+
+    normalize(normal_vector, normal_vector);
 
     // 引数で受け取った color の rgb 情報の抜き出し
 #if LITTLEENDIAN
@@ -408,15 +412,41 @@
     rgb[0] = (color & 0x000000ff);
 #endif
 
-    // 法線ベクトルと光源ベクトルとの内積をとる
-    inner_product = innerProduct1(normal_vector,light_vector);
-    // 内積がマイナスの場合は色がない。
-    flag = (inner_product > 0);
+    int tmp_rgb[3] = {0,0,0};
+    int light_num = 4;
+    for (int i = 0; i < light_num; i++) {
+
+      light_vector[0] = world_x - light_xyz[i*4];
+      light_vector[1] = world_y - light_xyz[i*4+1];
+      light_vector[2] = light_xyz[i*4+2] - world_z;
+      light_vector[3] = light_xyz[i*4+3];
+
+      normalize(light_vector, light_vector);
+
+      // 法線ベクトルと光源ベクトルとの内積をとる
+      inner_product = innerProduct1(normal_vector,light_vector);
+
+      //printf("inner_product %f\n",inner_product);
 
-    // 内積を rgb にかけていく
-    rgb[0] = (unsigned char)(rgb[0]*inner_product*flag);
-    rgb[1] = (unsigned char)(rgb[1]*inner_product*flag);
-    rgb[2] = (unsigned char)(rgb[2]*inner_product*flag);
+      // 内積がマイナスの場合は色がない。
+      flag = (inner_product > 0);
+
+      // 内積を rgb にかけていく
+      tmp_rgb[0] += (unsigned char)(rgb[0]*inner_product*flag);
+      tmp_rgb[1] += (unsigned char)(rgb[1]*inner_product*flag);
+      tmp_rgb[2] += (unsigned char)(rgb[2]*inner_product*flag);
+
+    }
+
+    int rgb_flag[3];
+    for (int i = 0; i < 3; i++) {
+      rgb_flag[i] = (tmp_rgb[i] > 255);
+    }
+
+    rgb[0] = tmp_rgb[0]*(1 - rgb_flag[0]) + 255*(rgb_flag[0]);
+    rgb[1] = tmp_rgb[1]*(1 - rgb_flag[1]) + 255*(rgb_flag[1]);
+    rgb[2] = tmp_rgb[2]*(1 - rgb_flag[2]) + 255*(rgb_flag[2]);
+
 
     //計算した rgb を light_rgb にまとめる。
 #if LITTLEENDIAN
@@ -426,6 +456,7 @@
 #endif
 
     return light_rgb;
+
 }