changeset 1277:4ba9b622073d draft

merge
author Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Nov 2011 19:40:47 +0900
parents e92f00ed2fc0 (diff) 08d81be1c6e4 (current diff)
children de51d55ea403
files Renderer/Engine/Camera.cc Renderer/Engine/SceneGraph.cc Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/matrix_calc.cc Renderer/Engine/task/DrawSpan.cc example/Eratosthenes/Func.h example/Eratosthenes/Makefile example/Eratosthenes/Makefile.cell example/Eratosthenes/Makefile.def example/Eratosthenes/Makefile.linux example/Eratosthenes/Makefile.macosx example/Eratosthenes/README example/Eratosthenes/bitmap.h example/Eratosthenes/main.cc example/Eratosthenes/ppe/.#Hello.cc example/Eratosthenes/ppe/Prime.cc example/Eratosthenes/ppe/Prime.h example/Eratosthenes/ppe/PrintTask.cc example/Eratosthenes/ppe/PrintTask.h example/Eratosthenes/ppe/SaveTask.cc example/Eratosthenes/ppe/SaveTask.h example/Eratosthenes/ppe/task_init.cc example/Eratosthenes/spe/Makefile example/Eratosthenes/spe/Prime.cc example/Eratosthenes/spe/Prime.h example/Eratosthenes/spe/PrintTask.cc example/Eratosthenes/spe/PrintTask.h example/Eratosthenes/spe/spe-main.cc example/Miller_Rabin/run.sh example/Miller_Rabin/time.sh
diffstat 12 files changed, 287 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/Camera.cc	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Engine/Camera.cc	Tue Nov 22 19:40:47 2011 +0900
@@ -120,7 +120,8 @@
 
     fov  = 60.0f;
     near = 0.0f;
-    far  = 1000.0f;
+    far  = 10.0f;
+
 
     zd[0] =  0.0f;
     zd[1] =  0.0f;
@@ -205,10 +206,14 @@
     tm[14] = 0.0f;
     tm[15] = 1.0f;
 
+    /* transform */
+
     applyMatrix(cz, tm, zd);
     applyMatrix(cy, tm, yd);
     applyMatrix(p, tm, xyz);
 
+    /* define view axis of coordinates */
+
     outerProduct(cx, cy, cz);
     normalize(cx, cx);
     normalize(cz, cz);
@@ -311,6 +316,9 @@
     
     matrix4x4(tmp, this->m_pers, this->m_screen);
     matrix4x4(this->matrix, this->m_view, tmp);
+    /* 法線ベクトル、光源ベクトル に使うビュー座標変換までの行列 */
+    for (int i = 0; i < 16; i++) this->real_matrix[i] = this->m_view[i];
+
 #else
     get_matrix(matrix, angle, xyz, NULL);
 #endif
--- a/Renderer/Engine/SceneGraph.cc	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Engine/SceneGraph.cc	Tue Nov 22 19:40:47 2011 +0900
@@ -1131,6 +1131,7 @@
     for(int i=0;i<4;i++) {
 	for(int j=0;i<3;j++) {
 	    matrix[i*4+j] = matrix[i*4+j]*scale[i]; 
+            /* real_matrix は スケールする必要はないかも */
 	    real_matrix[i*4+j] = real_matrix[i*4+j]*scale[i]; 
         }
     }
--- a/Renderer/Engine/SceneGraphRoot.cc	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Tue Nov 22 19:40:47 2011 +0900
@@ -406,8 +406,8 @@
     int light_num = 4;
     for (int i = 0; i < light_num; i++) {
 
-	get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
-
+        get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->real_matrix);
+      
 	light_vector[i*4] = 0.0f;
 	light_vector[i*4+1] = 0.0f;
 	light_vector[i*4+2] = 0.0f;
--- a/Renderer/Engine/matrix_calc.cc	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Engine/matrix_calc.cc	Tue Nov 22 19:40:47 2011 +0900
@@ -28,7 +28,7 @@
 }
 
 void
-inversMatrix(float *m0, float *m1)
+inverseMatrix(float *m0, float *m1)
 {
     float m[16];
 
--- a/Renderer/Engine/matrix_calc.h	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Engine/matrix_calc.h	Tue Nov 22 19:40:47 2011 +0900
@@ -18,7 +18,7 @@
 void outerProduct(float *v0, float *v1, float *v2);
 float innerProduct(float *v0, float *v1);
 void applyMatrix(float *v0, float *m, float *v1);
-void inversMatrix(float *m0, float *m1);
+void inverseMatrix(float *m0, float *m1);
 void transposeMatrix(float *m0, float *m1);
 void unitMatrix(float *m);
 void transMatrix(float *m0, float *m1, float *v);
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Tue Nov 22 19:40:47 2011 +0900
@@ -46,17 +46,11 @@
     min = val[0];
 
     for (int i = 1; i < num; i++) {
-        
         if (max < val[i]) {
-        
             max = val[i];
-    
         } else if (min > val[i]) {
-
             min = val[i];
-
         }
-
     }
 
     return (max - min);
@@ -64,6 +58,7 @@
 }
 
 
+
 static int 
 createPolygon(SchedTask *smanager, void *rbuf, void *wbuf)
 {
@@ -72,7 +67,6 @@
 
       もっと細かなTaskに分けるぞ!
 
-
      */
 
     float xyz1[4], xyz2[4], xyz3[4];
@@ -81,11 +75,13 @@
     //pp, matrix, real_matrix を受け取る
     PolygonPackPtr in_pp      = (PolygonPackPtr)smanager->get_input(rbuf, 0);
     float *matrix             = (float*)smanager->get_input(rbuf, 1);
-    float real_matrix[16]; //        = (float*)smanager->get_input(rbuf, 2);
 
-    for (int i = 0; i<16; i++) real_matrix[i]=matrix[i];
-    real_matrix[4*0+3]=real_matrix[4*1+3]=real_matrix[4*2+3]=0;
-     
+    //float real_matrix[16]; //        = (float*)smanager->get_input(rbuf, 2);
+    float *real_matrix = (float*)smanager->get_input(rbuf, 2);
+  
+    //for (int i = 0; i<16; i++) real_matrix[i]=matrix[i];
+    //real_matrix[4*0+3]=real_matrix[4*1+3]=real_matrix[4*2+3]=0;
+
     texture_list *tritexinfo  = (texture_list*)smanager->get_input(rbuf, 3);
     
     PolygonPackPtr next = (PolygonPackPtr)smanager->get_param(0);
@@ -118,34 +114,64 @@
       xyz3[2] = tri.ver3.z * -1.0f;
       xyz3[3] = 1.0f;
       
-      // matrix = 回転行列*透視変換行列
+      // matrix = ビュー座標変換行列*射影変換行列*スクリーン変換行列
       ApplyMatrix(xyz1, matrix);
       ApplyMatrix(xyz2, matrix);
       ApplyMatrix(xyz3, matrix);
 
       if (xyz1[2] > 100 && xyz2[2] > 100 && xyz3[2] > 100) {
 
-	xyz1[0] /= xyz1[2];
-	xyz1[1] /= xyz1[2];
-	xyz2[0] /= xyz2[2];
-	xyz2[1] /= xyz2[2];
-	xyz3[0] /= xyz3[2];
-	xyz3[1] /= xyz3[2];
+          /*
+           * 同次座標で除算、同次クリップ空間に変換する
+           *
+           */
+
+          xyz1[0] /= xyz1[2];
+          xyz1[1] /= xyz1[2];
+
+          xyz2[0] /= xyz2[2];
+          xyz2[1] /= xyz2[2];
+
+          xyz3[0] /= xyz3[2];
+          xyz3[1] /= xyz3[2];
+
+
+/*
+
+           * 本当はz座標で除算するんじゃなくて
+           * 同次座標でx,y,z座標を除算するんじゃないのかな
+           * これすると、光源がうまくいかず。多分z座標をどこかで使ってる
+           * 同次座標は、もとのz座標と同じだから、入れ替えてやればいいか。
+           * そしたらこの位置で、視錐台カリングとかもできるはず
+           *
+
+          xyz1[0] /= xyz1[3];
+          xyz1[1] /= xyz1[3];
+          xyz1[2] /= xyz2[3];
+
+          xyz2[0] /= xyz2[3];
+          xyz2[1] /= xyz2[3];
+          xyz2[2] /= xyz2[3];
+
+          xyz3[0] /= xyz3[3];
+          xyz3[1] /= xyz3[3];
+          xyz3[2] /= xyz2[3];
+*/
 
       } else {
-      
-	xyz1[0] = 0; 
-	xyz1[1] = 0;
-	xyz1[2] = 0;
+          
+          xyz1[0] = 0; 
+          xyz1[1] = 0;
+          xyz1[2] = 0;
 
-	xyz2[0] = 0;
-	xyz2[1] = 0; 
-	xyz2[2] = 0;
+          xyz2[0] = 0;
+          xyz2[1] = 0; 
+          xyz2[2] = 0;
 
-	xyz3[0] = 0; 
-	xyz3[1] = 0;
-	xyz3[2] = 0;
-
+          xyz3[0] = 0; 
+          xyz3[1] = 0;
+          xyz3[2] = 0;
+          
       }
    
       TrianglePackPtr triangle = &out_pp->tri[i];
@@ -185,20 +211,46 @@
       normal3[2] = tri.normal3.z * -1.0f;
       //normal3[3] = 1.0f;
       normal3[3] = 0.0f;
-      
+
+      /*
+       * 法線は回転、平行移動、ビュー座標変換までの段階でよい
+       * Camera が持っている matrix は 射影変換とスクリーン変換が入っている 
+       * 
+       * Matrix をバラバラに持つ必要がある 
+       * 今はreal_matrixがビュー座標変換行列までを演算した行列になっている
+       *
+       */
+
+      /*
+       * real_matrix = ビュー座標変換行列
+       * スケーリングが入ると、演算が終わった normal vector を正規化する必要がある
+       * 今は DrawSpan で normalize している
+       *
+       * normal vector の同次座標は 0 なので、real_matrix の平行移動部分を除く必要はない
+       *
+       */
+
       ApplyMatrix(normal1,real_matrix);
       ApplyMatrix(normal2,real_matrix);
       ApplyMatrix(normal3,real_matrix);
-      
-      normal1[0] /= normal1[2];
-      normal1[1] /= normal1[2];
+
+/*
+
+     * 法線ベクトルは透視変換しなくていい
+  
+      normal1[0] /= normal1[3];
+      normal1[1] /= normal1[3];
+      normal1[2] /= normal1[3];
       
-      normal2[0] /= normal2[2];
-      normal2[1] /= normal2[2];
+      normal2[0] /= normal2[3];
+      normal2[1] /= normal2[3];
+      normal2[2] /= normal2[3];
       
-      normal3[0] /= normal3[2];
-      normal3[1] /= normal3[2];
-      
+      normal3[0] /= normal3[3];
+      normal3[1] /= normal3[3];
+      normal3[2] /= normal3[3];
+*/
+
       triangle->normal1.x = normal1[0];
       triangle->normal1.y = normal1[1];
       triangle->normal1.z = normal1[2];
--- a/Renderer/Engine/task/DrawSpan.cc	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Tue Nov 22 19:40:47 2011 +0900
@@ -550,7 +550,7 @@
     float light_vector[4];
     float *light_xyz = (float*)smanager->global_get(Light);
 
-    normalize(normal_vector, normal_vector);
+    //normalize(normal_vector, normal_vector);
 
     // 引数で受け取った color の rgb 情報の抜き出し
 #if LITTLEENDIAN
@@ -567,7 +567,8 @@
 
     int tmp_rgb[3] = {0,0,0};
     int light_num = 4;
-    float inner_product = 0.2; // 0.2 は環境光ってことにしてみた。
+    //float inner_product = 0.2; // 0.2 は環境光ってことにしてみた。
+    float inner_product = 0; // 0.2 は環境光ってことにしてみた。
     for (int i = 0; i < light_num; i++) {
 
       light_vector[0] = world_x - light_xyz[i*4];
--- a/Renderer/Test/Makefile.cell	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Test/Makefile.cell	Tue Nov 22 19:40:47 2011 +0900
@@ -15,7 +15,7 @@
 %.pb.cc: $(PROTODIR)/%.proto
 	$(PROTO) $(PROTOFLAGS) $<
 
-ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange property_test create_task property_universe chain_old property_chain aquarium network init_aquarium viewer_2
+ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange property_test create_task property_universe chain_old property_chain aquarium network init_aquarium viewer_2 light_test
 
 all: $(ALL)
 
@@ -121,6 +121,11 @@
 viewer_2 : $(VIEWER_OBJ2) 
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
 
+LIGHT_TEST = light_test.o
+light_test : $(LIGHT_TEST) 
+	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
+
+
 
 debug: $(TARGET)
 	sudo ppu-gdb ./$(TARGET) 
--- a/Renderer/Test/Makefile.macosx	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Test/Makefile.macosx	Tue Nov 22 19:40:47 2011 +0900
@@ -13,7 +13,7 @@
 %.pb.cc: $(PROTODIR)/%.proto
 	$(PROTO) $(PROTOFLAGS) $<
 
-ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange viewer aquarium network init_aquarium test_linda viewer_2
+ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange viewer viewer_2 light_test aquarium network init_aquarium test_linda
 
 all: $(ALL)
 
@@ -85,10 +85,22 @@
 SgRootChange : $(SGCHANGE_OBJ) 
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
 
-VIEWER_OBJ = viewer_2.o
+VIEWER_OBJ = viewer.o
 viewer : $(VIEWER_OBJ) 
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
 
+
+LIGHT_TEST_OBJ = light_test.o
+light_test : $(LIGHT_TEST_OBJ) 
+	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
+
+
+VIEWER_OBJ2 = viewer_2.o
+viewer_2 : $(VIEWER_OBJ2) 
+	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
+
+
+
 AQUARIUM_OBJ = aquarium.pb.o aquarium.o
 aquarium : $(AQUARIUM_OBJ)
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS) $(PROTOLIBS)
@@ -97,6 +109,7 @@
 network : $(NETWORK_OBJ)
 	$(CC) $(CFLAGS) -o $@ $?    $(LIBS) $(PROTOLIBS)
 
+
 INIT_AQUARIUM_OBJ = aquarium.pb.o init_aquarium.o
 init_aquarium : $(INIT_AQUARIUM_OBJ)
 	$(CC) $(CFLAGS) -o $@ $? $(LIBS) $(PROTOLIBS)
@@ -105,9 +118,6 @@
 test_linda : $(TEST_LINDA_OBJ)
 	$(CC) $(CFLAGS) -o $@ $? $(LIBS) $(PROTOLIBS)
 
-VIEWER_OBJ2 = viewer_2.o
-viewer_2 : $(VIEWER_OBJ2) 
-	$(CC) $(CFLAGS) -o $@ $?    $(LIBS)
 
 run: $(TARGET)
 	sudo ./$(TARGET) -width 576 -height 384 -bpp 32
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/light_test.cc	Tue Nov 22 19:40:47 2011 +0900
@@ -0,0 +1,147 @@
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "light_test.h"
+
+
+// prototype
+static void light_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void light_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void light_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+
+static void object_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+
+static void
+object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
+	       SceneGraphPtr tree)
+{
+}
+
+static void
+object_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+}
+
+static void
+light_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    Pad *pad = sgroot->getController();
+
+    if (pad->circle.isPush()) {
+	node->set_move_collision(light_move_rotation, light_collision);
+    }
+
+    if (pad->left.isHold()) {
+        node->xyz[0] -= 10;
+    } else if (pad->right.isHold()) {
+        node->xyz[0] += 10;
+    }
+    if (pad->up.isHold()) {
+        node->xyz[1] -= 10;
+    } else if (pad->down.isHold()) {
+        node->xyz[1] += 10;
+    }
+
+
+}
+
+static void
+light_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    Pad *pad = sgroot->getController();
+    if (pad->circle.isPush()) {
+	node->set_move_collision(light_move_translation, light_collision);
+    }
+
+    if (pad->up.isHold()) {
+        node->xyz[2] += 10;
+    } else if (pad->down.isHold()) {
+        node->xyz[2] -= 10;
+    }
+
+    if (pad->up.isHold()) {
+        node->angle[0] += 10;
+    } else if (pad->down.isHold()) {
+        node->angle[0] -= 10;
+    }
+
+
+}
+
+
+static void
+light_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
+	       SceneGraphPtr tree)
+{
+
+}
+
+
+MainLoopPtr
+light_test::init(Viewer *sgroot, int screen_w, int screen_h)
+{
+
+    sgroot->createFromXMLfile( "xml_file/universe.xml");
+    sgroot->createFromXMLfile( "xml_file/cube.xml");
+    sgroot->OnLightSysSwitch();
+    SceneGraphPtr light = sgroot->getLight(0); 
+    //光源のスイッチON
+    sgroot->OnLightSwitch(1);
+
+    // SceneGraph ID から SceneGraph を生成する
+    SceneGraphPtr light_object = sgroot->createSceneGraph("Cube");
+    light_object->set_move_collision(light_move_translation, light_collision);
+    light_object->xyz[0] = screen_w / 2;
+    light_object->xyz[1] = screen_h / 2;
+   
+
+    SceneGraphPtr moon = sgroot->createSceneGraph("Moon");
+    moon->set_move_collision(object_move, object_collision);
+    moon->xyz[0] = screen_w / 2;
+    moon->xyz[1] = screen_h / 2;
+
+    
+    // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon)
+    SceneGraphPtr root = sgroot->createSceneGraph();
+
+    root->addChild(light_object);
+    light_object->addChild(light);
+    root->addChild(moon);
+
+    // SceneGraphRoot に、使用する SceneGraph を設定する
+    // このとき、ユーザーは SceneGraph の root を渡す。
+    sgroot->setSceneData(root);
+    return sgroot;
+}
+
+extern Application *
+application() {
+    return new light_test();
+}
+
+const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
+
+extern int init(TaskManager *manager, int argc, char *argv[]);
+extern void task_initialize();
+static void TMend(TaskManager *manager);
+
+int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+    task_initialize();
+    manager->set_TMend(TMend);
+    return init(manager, argc, argv);
+
+}
+
+void
+TMend(TaskManager *manager)
+{
+    printf("test_nogl end\n");
+}
+
+/* end */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/light_test.h	Tue Nov 22 19:40:47 2011 +0900
@@ -0,0 +1,11 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "Application.h"
+#include "MainLoop.h"
+
+class light_test : public Application {
+
+    MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h);
+};
+
--- a/Renderer/Test/viewer.cc	Sun Nov 20 12:05:35 2011 +0900
+++ b/Renderer/Test/viewer.cc	Tue Nov 22 19:40:47 2011 +0900
@@ -75,15 +75,7 @@
 object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, 
 	       int screen_h,  SceneGraphPtr tree)
 {
-//     if (node->xyz[1] > screen_h - object_radius) {
-// 		node->xyz[1] = screen_h - object_radius;
 
-// 		vy *= e;
-// 		if (vy > -g && vy < 0) {
-// 			vy = 0.0;
-// 			node->set_move_collision(object_move_idle, object_collision_idle);
-// 		}
-//     }
 }
 
 char *xmlfile;
@@ -105,6 +97,7 @@
 	light->xyz[0] = screen_w / 2;
 	light->xyz[1] = screen_h / 2;
 	light->xyz[2] = -100;
+
     }