changeset 772:e53ae444ac6f

Test/property_chain is work
author hiroki@henri.cr.ie.u-ryukyu.ac.jp
date Mon, 15 Feb 2010 13:33:29 +0900
parents 720720e4e8df
children 8dd9fe36e206
files Renderer/Engine/RenderingTasks.h Renderer/Engine/spe/chain_move.cc Renderer/Engine/spe/spe-main.cc Renderer/Test/Makefile.cell Renderer/Test/property_chain.cc
diffstat 5 files changed, 89 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/RenderingTasks.h	Sun Feb 14 18:56:08 2010 +0900
+++ b/Renderer/Engine/RenderingTasks.h	Mon Feb 15 13:33:29 2010 +0900
@@ -34,6 +34,7 @@
      ChainInit,
      PropertyTask,
      UniverseTask,
+     ChainTask,
 
      RUN_FINISH,
 
--- a/Renderer/Engine/spe/chain_move.cc	Sun Feb 14 18:56:08 2010 +0900
+++ b/Renderer/Engine/spe/chain_move.cc	Mon Feb 15 13:33:29 2010 +0900
@@ -8,7 +8,13 @@
 /* これは必須 */
 SchedDefineTask(ChainTask);
 
-static const int PROPERTY_LENGTH = 51;
+static const int PROPERTY_LENGTH = 50;
+static double m = 100.0;
+static double k = 7000.0;
+static double g = 9.8;
+static double dt = 0.003;
+static double chain_width = 10;
+static double safe = 0.995;
 
 typedef struct {
     float xyz[3];
@@ -16,6 +22,7 @@
     float stack_xyz[3];
     float next_xyz[3];
     float v_xyz[3];
+    float next_v_xyz[3];
     int property_index;
     int parent_index;
     int have_parent;
@@ -23,7 +30,7 @@
     memaddr parent;
     memaddr children;
     memaddr node;
-    const char *name;
+    int sgid;
 } *PropertyPtr, Property;
 
 static int
@@ -32,7 +39,59 @@
     PropertyPtr	property	= (PropertyPtr)s->get_input(rbuf, 0);
     PropertyPtr	update_property = (PropertyPtr)s->get_output(wbuf, 0);
 
-    int id = 0;
+    property[0].can_move = 0;
+
+    for(int cnt = 0; cnt < 600; cnt++) {
+	for(int i = 0; i < PROPERTY_LENGTH; i++) {
+	    if(property[i].can_move) {
+		double dx = property[i-1].xyz[0] - property[i].xyz[0];
+		double dy = property[i-1].xyz[1] - property[i].xyz[1];
+		double l = sqrt(dx * dx + dy * dy);
+		double a = k * (l - chain_width) / m;
+		double ax = a * dx / l;
+		double ay = a * dy / l;
+		if(i < PROPERTY_LENGTH - 1) {
+		    dx = property[i+1].xyz[0] - property[i].xyz[0];
+		    dy = property[i+1].xyz[1] - property[i].xyz[1];
+		    l = sqrt(dx * dx + dy * dy);
+		    a = k * (l - chain_width) / m;
+		    ax += a * dx / l;
+		    ay += a * dy / l;
+		}
+		ay += g;
+		property[i].v_xyz[0] *= safe;
+		property[i].v_xyz[1] *= safe;
+		property[i].next_v_xyz[0] = property[i].v_xyz[0] + ax * dt;
+		property[i].next_v_xyz[1] = property[i].v_xyz[1] + ay * dt;
+		property[i].next_xyz[0] = property[i].xyz[0] + property[i].v_xyz[0] * dt;
+		property[i].next_xyz[1] = property[i].xyz[1] + property[i].v_xyz[1] * dt;
+	    } else {
+		property[i].next_xyz[0] = property[i].xyz[0];
+		property[i].next_xyz[1] = property[i].xyz[1];
+	    }
+	}
+	for(int i = 0; i < PROPERTY_LENGTH; i++) {
+	    property[i].v_xyz[0] = property[i].next_v_xyz[0];
+	    property[i].v_xyz[1] = property[i].next_v_xyz[1];
+	    property[i].xyz[0] = property[i].next_xyz[0];
+	    property[i].xyz[1] = property[i].next_xyz[1];
+	}
+    }
+
+    for(int i = 0; i < PROPERTY_LENGTH; i++) {
+	int id = property[i].property_index;
+	int p, n;	
+	p = n = id;
+	if(p != 0) {
+	    p--;
+	}
+	if(n != PROPERTY_LENGTH - 1) {
+	    n++;
+	}
+	property[i].angle[2-(id%2)*2]
+	    = 90 + atan((property[p].next_xyz[1] - property[n].next_xyz[1])
+			/ (property[p].next_xyz[0] - property[n].next_xyz[0])) * 180 / M_PI;
+    }
 
     memcpy((void*)update_property, (void*)property, sizeof(Property)*PROPERTY_LENGTH);
 
--- a/Renderer/Engine/spe/spe-main.cc	Sun Feb 14 18:56:08 2010 +0900
+++ b/Renderer/Engine/spe/spe-main.cc	Mon Feb 15 13:33:29 2010 +0900
@@ -23,6 +23,7 @@
 
 SchedExternTask(PropertyTask);
 SchedExternTask(UniverseTask);
+SchedExternTask(ChainTask);
 
 void
 task_init(Scheduler *s)
@@ -48,4 +49,5 @@
 
     SchedRegister( PropertyTask);
     SchedRegister( UniverseTask);
+    SchedRegister( ChainTask);
 }
--- a/Renderer/Test/Makefile.cell	Sun Feb 14 18:56:08 2010 +0900
+++ b/Renderer/Test/Makefile.cell	Mon Feb 15 13:33:29 2010 +0900
@@ -11,7 +11,7 @@
 .cc.o:
 	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
 
-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
+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
 all: $(ALL)
 
 speobject:
@@ -95,6 +95,10 @@
 CHAIN_OLD = chain_old.o
 chain_old : $(CHAIN_OLD)
 	$(CC) -o $@ $? $(LIBS)
+
+P_CHAIN_OBJ = property_chain.o
+property_chain : $(P_CHAIN_OBJ)
+	$(CC) -o $@ $? $(LIBS)
 	
 debug: $(TARGET)
 	sudo ppu-gdb ./$(TARGET) 
--- a/Renderer/Test/property_chain.cc	Sun Feb 14 18:56:08 2010 +0900
+++ b/Renderer/Test/property_chain.cc	Mon Feb 15 13:33:29 2010 +0900
@@ -10,19 +10,8 @@
 
 #define FALSE 0
 #define TRUE !FALSE
-static const int PROPERTY_LENGTH = 51;
-static double m = 100.0;
-static double k = 7000.0;
-static double g = 9.8;
-static double dt = 0.003;
+static const int PROPERTY_LENGTH = 50;
 static double chain_width = 10;
-static double safe = 0.995;
-
-typedef struct {
-    double x, y, next_x, next_y;
-    double vx, vy, next_vx, next_vy;
-    int can_move;
-} CHAIN_VARS;
 
 typedef struct {
     float xyz[3];
@@ -30,6 +19,7 @@
     float stack_xyz[3];
     float next_xyz[3];
     float v_xyz[3];
+    float next_v_xyz[3];
     int property_index;
     int parent_index;
     int have_parent;
@@ -37,7 +27,7 @@
     memaddr parent;
     memaddr children;
     memaddr node;
-    const char *name;
+    int sgid;
 } *PropertyPtr, Property;
 
 
@@ -60,6 +50,7 @@
 	p->stack_xyz[i] = 0;
 	p->next_xyz[i] = 0;
 	p->v_xyz[i] = 0;
+	p->next_v_xyz[i] = 0;
     }
 
     p->property_index = 0;
@@ -96,16 +87,14 @@
     SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
     SceneGraphPtr camera = sgroot->camera;
     SceneGraphPtr p_node;
+    SceneGraphPtr root;
     
     // ここが allExecute の tree をたどって clone して行くところに相当する
     Property *p;
     
     for (int i = 0; i < PROPERTY_LENGTH; i++) {
 	p = &update_property[i];
-	SceneGraphPtr node = sgroot->createSceneGraph(p->name);
-	if (strcmp(node->name, "Earth") == 0) {
-	    node->set_move_collision(move, collision);
-	}
+	SceneGraphPtr node = sgroot->createSceneGraph(p->sgid);
 	apply_property(node, p);    
     }
 	
@@ -123,7 +112,9 @@
 	}
     }
 
-    sgroot->setSceneData((SceneGraphPtr)update_property[0].node);
+    root = (SceneGraphPtr)update_property[0].node;
+    root->set_move_collision(move, collision);
+    sgroot->setSceneData(root);
 
     Property *tmp = property;
     property = update_property;
@@ -157,9 +148,8 @@
     }
     p->parent = (memaddr)node->parent;
     p->children = (memaddr)node->children;
-    p->name = node->name;
     p->property_index = index;    
-    
+    p->sgid = node->sgid;
     p->node = (memaddr)node;
     node->property = (memaddr)p;
 }
@@ -168,30 +158,28 @@
 regist_task(SceneGraphRoot *sgroot)
 {
     TaskManager *manager = sgroot->tmanager;
-    HTaskPtr task = manager->create_task(UniverseTask);
+    HTaskPtr task = manager->create_task(ChainTask);
     // sgroot->setExecTask(task); とやるべき?
     sgroot->move_exec_task = task;
 }
 
+/*
+  Property に親子関係を書き込む
+  これも API に入れちゃっていいかな
+ */
 static void
 set_relation(SceneGraphPtr parent, SceneGraphPtr child)
 {
-    /*
-    child->property->parent_index = parent->property->property_index;
-    child->property->have_parent = 1;
-    */
-
     Property *p = (Property *)parent->property;
     Property *c = (Property *)child->property;
     p->children = (memaddr)child;
     c->parent = (memaddr)parent;
     c->parent_index = p->property_index;
     c->have_parent = 1;
-
 }
 
 MainLoopPtr 
-property_universe::init(Viewer *viewer, int screen_w, int screen_h)
+property_chain::init(Viewer *viewer, int screen_w, int screen_h)
 {
     // SgChange を使うための2行
     SgChange *sgroot = new SgChange(viewer);
@@ -200,13 +188,12 @@
     // sgroot->appTaskRegist(regist_task); がいいかな
     sgroot->sgroot_A->appTaskRegist(regist_task);
 
-    int root_obj_index = 0;
     property        = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH);
     update_property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH);
 
     // property の初期化 application ごとに固有
     for(int i = 0; i < PROPERTY_LENGTH; i++) {
-	init_chain(property[i]);
+	init_chain(&property[i]);
     }
 
     SceneGraphPtr root_chain, chain;
@@ -214,7 +201,7 @@
     root_chain = sgroot->createSceneGraph("CHAIN");
     root_chain->xyz[0] = screen_w / 2;
     root_chain->xyz[1] = 0.0f;
-    root_chain->set_move_collision(move, colliison);
+    root_chain->set_move_collision(move, collision);
     set_property(&property[0], root_chain, 0);
     
     for (int i = 1; i < PROPERTY_LENGTH; i++) {
@@ -242,7 +229,7 @@
 
 extern Application *
 application() {
-    return new property_universe();
+    return new property_chain();
 }
 
 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";