changeset 738:510424e175ae

light
author yutaka@localhost.localdomain
date Thu, 31 Dec 2009 04:07:18 +0900
parents 50220f219341
children 050f92cd3628
files Renderer/Engine/Camera.cc Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/polygon.h Renderer/Engine/spe/DrawSpan.cc Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Renderer/Engine/task/DrawSpan.cc
diffstat 6 files changed, 73 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/Camera.cc	Sun Dec 27 20:49:38 2009 +0900
+++ b/Renderer/Engine/Camera.cc	Thu Dec 31 04:07:18 2009 +0900
@@ -145,6 +145,15 @@
     m_screen = new float[16];
     
     this->set_move_collision(camera_move, camera_collision, (void *)sgroot);
+
+    for(int i = 0; i < 16; i++) {
+      real_matrix[i] = 0;
+      if (i % 5 == 0) {
+        real_matrix[i] = 1;
+      }
+    }
+
+
 }
 
 Camera::~Camera(void)
--- a/Renderer/Engine/SceneGraphRoot.cc	Sun Dec 27 20:49:38 2009 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Thu Dec 31 04:07:18 2009 +0900
@@ -439,6 +439,8 @@
 			c->frame = t->frame;
             /*親の回転、座標から、子の回転、座標を算出*/
             get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix);
+	    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
+            get_matrix(c->real_matrix, c->angle, c->xyz, cur_parent->real_matrix);
         } 
 
 		if (t->children != NULL && c != NULL) {
--- a/Renderer/Engine/polygon.h	Sun Dec 27 20:49:38 2009 +0900
+++ b/Renderer/Engine/polygon.h	Thu Dec 31 04:07:18 2009 +0900
@@ -21,6 +21,7 @@
     float angle[4];   // angle
     float c_xyz[4];   // center of rotation
     float matrix[16];
+    float real_matrix[16];
     float *anim;
     int texture_id; //texture id number
     struct texture_list texture_info;
--- a/Renderer/Engine/spe/DrawSpan.cc	Sun Dec 27 20:49:38 2009 +0900
+++ b/Renderer/Engine/spe/DrawSpan.cc	Thu Dec 31 04:07:18 2009 +0900
@@ -44,15 +44,16 @@
                             int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z,
 			    TilePtr tile, int world_x, int world_y, float world_z,SchedTask *smanager);
 
-
-
 // static    void reboot(SpanPackPtr spack, int cur_span_x);
 
 static    int drawDot1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag);
 //static    void drawDot2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag);
 static    int drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag);
 // static    void drawLine2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag);
-static    int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z);
+
+static    int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z,
+                                  SchedTask *smanager,int x, int y, float z, int world_x, int world_y, float world_z);
+
 
 static float
 innerProduct1(float *v0, float *v1)
@@ -182,7 +183,7 @@
  * @param tex_addr テクスチャのアドレス(MainMemory)
  */
 static void
-updateBuffer(Gptr g, float zpos, int rangex, int x, int y, int tex_x, int tex_y,
+updateBuffer(Gptr g, float zpos, int rangex, int localx, int localy, int tex_x, int tex_y,
 	     float normal_x, float normal_y, float normal_z, TilePtr tile,
 	     int world_x, int world_y, float world_z, SchedTask *smanager)
 {
@@ -197,12 +198,16 @@
     /*完全に透けているか判断*/
     int flag = (alpha != 0);
 
-    color = infinity_light_calc(color,normal_x,normal_y,normal_z);
+    color = infinity_light_calc(color,normal_x,normal_y,normal_z,
+                                smanager,localx,localy,zpos,
+                                world_x,world_y,world_z);
 
-    g->zRow[x + (rangex*y)] = zpos*flag + g->zRow[x + (rangex*y)]*(1-flag);
-    int *point = &g->linebuf[y][x] ;
+    g->zRow[localx + (rangex*localy)] = zpos*flag + g->zRow[localx + (rangex*localy)]*(1-flag);
+    int *point = &g->linebuf[localy][localx] ;
     *point =  color*flag + *point *(1-flag);
 
+
+
 }
 
 /**
@@ -377,7 +382,10 @@
 }
 
 static int
-infinity_light_calc(int color,float normal_x, float normal_y, float normal_z)
+infinity_light_calc(int color,float normal_x, float normal_y,
+		    float normal_z, SchedTask *smanager, int x, int y, float z,
+		    int world_x, int world_y, float world_z)
+
 {
     unsigned char rgb[4];
     int light_rgb;
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Sun Dec 27 20:49:38 2009 +0900
+++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Thu Dec 31 04:07:18 2009 +0900
@@ -74,12 +74,6 @@
 run(SchedTask *smanager, void *rbuf, void *wbuf)
 {
     float xyz1[4], xyz2[4], xyz3[4];
-    /*
-     *頂点毎に法線ベクトルがある
-     *面毎じゃない
-     *なにかに使うのかな?わからないから、一応とっておく。
-     *by yutaka
-     */
     float normal1[4],normal2[4],normal3[4];
 
     SceneGraphPtr sg_top = (SceneGraphPtr)smanager->get_param(0);
@@ -171,7 +165,6 @@
 		triangle->ver3.tex_x = sg->coord_tex[(i+2)*3];
 		triangle->ver3.tex_y = sg->coord_tex[(i+2)*3+1];
 
-
                 normal1[0] = sg->normal[(i+0)*3];
                 normal1[1] = sg->normal[(i+0)*3+1];
                 normal1[2] = sg->normal[(i+0)*3+2]*-1.0f;
@@ -187,7 +180,18 @@
                 normal3[2] = sg->normal[(i+2)*3+2]*-1.0f;
                 normal3[3] = 1.0f;
 
-                ApplyNormalMatrix(normal1,sg->matrix);
+                ApplyNormalMatrix(normal1,sg->real_matrix);
+                ApplyNormalMatrix(normal2,sg->real_matrix);
+                ApplyNormalMatrix(normal3,sg->real_matrix);
+
+                normal1[0] /= normal1[2];
+                normal1[1] /= normal1[2];
+
+                normal2[0] /= normal2[2];
+                normal2[1] /= normal2[2];
+
+                normal3[0] /= normal3[2];
+                normal3[1] /= normal3[2];
 
                 //ここでpolygonに法線ベクトルの情報がわたった
 
@@ -203,8 +207,6 @@
                 triangle->normal3.y = normal3[1];
                 triangle->normal3.z = normal3[2];
 
-
-	
 		triangle->tex_info.addr   = sg->texture_info.pixels;
 		triangle->tex_info.width  = sg->texture_info.t_w;
 		triangle->tex_info.height = sg->texture_info.t_h;
--- a/Renderer/Engine/task/DrawSpan.cc	Sun Dec 27 20:49:38 2009 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Thu Dec 31 04:07:18 2009 +0900
@@ -39,9 +39,10 @@
 // static    TilePtr isAvailableTile(memaddr addr);
 static    memaddr getTile(int tx, int ty, int tw, memaddr tex_addr_top);
 static    int getTexBlock(int tx, int ty, int twidth);
-static    void updateBuffer(Gptr g, float zpos, int rangex, int x, int y,
-                      int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z, TilePtr tile);
 
+static    void updateBuffer(Gptr g, float zpos, int rangex, int loaclx, int localy,
+                            int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z,
+			    TilePtr tile, int world_x, int world_y, float world_z,SchedTask *smanager);
 
 // static    void reboot(SpanPackPtr spack, int cur_span_x);
 
@@ -49,7 +50,10 @@
 //static    void drawDot2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag);
 static    int drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag);
 // static    void drawLine2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag);
-static    int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z);
+
+static    int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z,
+                                  SchedTask *smanager,int x, int y, float z, int world_x, int world_y, float world_z);
+
 
 static float
 innerProduct1(float *v0, float *v1)
@@ -179,8 +183,9 @@
  * @param tex_addr テクスチャのアドレス(MainMemory)
  */
 static void
-updateBuffer(Gptr g, float zpos, int rangex, int x, int y, int tex_x, int tex_y,
-                       float normal_x, float normal_y, float normal_z, TilePtr tile)
+updateBuffer(Gptr g, float zpos, int rangex, int localx, int localy, int tex_x, int tex_y,
+	     float normal_x, float normal_y, float normal_z, TilePtr tile,
+	     int world_x, int world_y, float world_z, SchedTask *smanager)
 {
 
     int color = get_rgb(tex_x, tex_y, tile);
@@ -193,12 +198,16 @@
     /*完全に透けているか判断*/
     int flag = (alpha != 0);
 
-    color = infinity_light_calc(color,normal_x,normal_y,normal_z);
+    color = infinity_light_calc(color,normal_x,normal_y,normal_z,
+                                smanager,localx,localy,zpos,
+                                world_x,world_y,world_z);
 
-    g->zRow[x + (rangex*y)] = zpos*flag + g->zRow[x + (rangex*y)]*(1-flag);
-    int *point = &g->linebuf[y][x] ;
+    g->zRow[localx + (rangex*localy)] = zpos*flag + g->zRow[localx + (rangex*localy)]*(1-flag);
+    int *point = &g->linebuf[localy][localx] ;
     *point =  color*flag + *point *(1-flag);
 
+
+
 }
 
 /**
@@ -258,7 +267,8 @@
 
         updateBuffer(g, zpos, rangex, localx, localy,
                      tex_localx, tex_localy,
-                     normal_x,normal_y,normal_z,tile);
+                     normal_x,normal_y,normal_z,tile,
+		     span->x, span->y, zpos, smanager);
     }
 
     return -1;
@@ -319,6 +329,10 @@
     float zpos1 = span->start_z;
     float zpos2 = span->end_z;
 
+    //spanを右から左に見ていくうちに、zが下がるのか、上がっていくのか。
+    float z_inclination = (zpos1 - zpos2) / x_len;
+    float world_z = zpos2;
+
     // Tile 内での座標
     int localx, localy = getLocalY(span->y-1);
 
@@ -328,6 +342,8 @@
     for (int j = je; j >= js; j--) {
         float tex_x, tex_y, tex_z;
 
+	world_z += z_inclination;
+
         localx = getLocalX(x-1+j);
 
         tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1);
@@ -357,7 +373,8 @@
 
             updateBuffer(g, tex_z, rangex, localx, localy,
                          tex_localx, tex_localy,
-                         normal_x, normal_y, normal_z, tile);
+                         normal_x, normal_y, normal_z, tile,
+			 span->x+j, span->y, world_z, smanager);
         }
     }
 
@@ -365,7 +382,10 @@
 }
 
 static int
-infinity_light_calc(int color,float normal_x, float normal_y, float normal_z)
+infinity_light_calc(int color,float normal_x, float normal_y,
+		    float normal_z, SchedTask *smanager, int x, int y, float z,
+		    int world_x, int world_y, float world_z)
+
 {
     unsigned char rgb[4];
     int light_rgb;
@@ -423,8 +443,8 @@
     Span nop_span;
     nop_span.length_x = 1;
 
-    // uint32 display   = smanager->get_param(0);
-    // int screen_width = smanager->get_param(1);
+    // uint32 display   = (long)smanager->get_param(0);
+    // int screen_width = (long)smanager->get_param(1);
     int rangex_start = (long)smanager->get_param(2);
     int rangex_end   = (long)smanager->get_param(3);
 
@@ -456,11 +476,9 @@
         }
 
         SpanPtr resume_span = &nop_span;
-        int resume_span_x = 0;
 
         for (int t = 0; t < spack->info.size; t++) {
             SpanPtr next_span;
-            int next_span_x;
 
             span = &spack->span[t];
 
@@ -476,7 +494,6 @@
             next_span = span;
 
             resume_span = next_span;
-            resume_span_x = next_span_x;
 
             tl_tag_flg1 ^= 1;
             tl_tag_flg2 ^= 1;