changeset 419:9348e49f63cf

merge
author Hiroki NAKASONE <hiroki@cr.ie.u-ryukyu.ac.jp>
date Wed, 23 Sep 2009 21:24:38 +0900
parents 475a01e217cd (current diff) 5e09f0fdab88 (diff)
children 90d677a9c00b
files TaskManager/Test/test_render/Makefile TaskManager/Test/test_render/task/task_init.cc TaskManager/Test/test_render/viewer.cc
diffstat 7 files changed, 251 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/Application/chain_old.cc	Wed Sep 23 21:24:38 2009 +0900
@@ -0,0 +1,159 @@
+#include <iostream.h>
+#include <math.h>
+#include "SceneGraphRoot.h"
+#include "SGList.h"
+#include "SceneGraph.h"
+#include "TaskManager.h"
+#include "Func.h"
+
+
+#define FALSE 0
+#define TRUE !FALSE
+#define CHAIN_LEN 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 {
+    double x, y, next_x, next_y;
+    double vx, vy, next_vx, next_vy;
+    int can_move;
+} CHAIN_VARS;
+
+CHAIN_VARS cv[CHAIN_LEN];
+
+void
+init_chainold_vars(CHAIN_VARS *cv) {
+    cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0;
+    cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0;
+    cv->can_move = TRUE;
+}
+
+void
+set_old_vector(CHAIN_VARS *cv, SceneGraphPtr sg) {
+    sg->xyz[0] = (float)cv->next_x;
+    sg->xyz[1] = (float)cv->next_y;
+    sg->xyz[2] = 0.0f;
+}
+
+
+static void
+chain_old_move_ope(SceneGraphPtr node, int screen_w, int screen_h)
+{
+    Pad *pad = sgroot->getController();
+
+    if (pad->circle.isHold()) {
+        cv[CHAIN_LEN-1].can_move = FALSE;
+        if (pad->left.isHold()) {
+            cv[CHAIN_LEN-1].x += -5.0;
+        } else if (pad->right.isHold()) {
+            cv[CHAIN_LEN-1].x += 5.0;
+        }
+
+        if (pad->up.isHold()) {
+            cv[CHAIN_LEN-1].y += -5.0;
+        } else if (pad->down.isHold()) {
+            cv[CHAIN_LEN-1].y += 5.0;
+        }
+    } else {
+        cv[CHAIN_LEN-1].can_move = TRUE;
+    }
+}
+
+void
+chain_old_move(SceneGraphPtr sg, int w, int h)
+{
+    int id = sg->id;
+    if(id == 0) {
+        for(int cnt = 0; cnt < 600; cnt++) {
+            for(int i = 0; i < CHAIN_LEN; i++) {
+                if(cv[i].can_move) {
+                    double dx = cv[i-1].x - cv[i].x;
+                    double dy = cv[i-1].y - cv[i].y;
+                    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 < CHAIN_LEN - 1) {
+                        dx = cv[i+1].x - cv[i].x;
+                        dy = cv[i+1].y - cv[i].y;
+                        l = sqrt(dx * dx + dy * dy);
+                        a = k * (l - chain_width) / m;
+                        ax += a * dx / l;
+                        ay += a * dy / l;
+                    }
+                    ay += g;
+                    cv[i].vx *= safe;
+                    cv[i].vy *= safe;
+                    cv[i].next_vx = cv[i].vx + ax * dt;
+                    cv[i].next_vy = cv[i].vy + ay * dt;
+                    cv[i].next_x = cv[i].x + cv[i].vx * dt;
+                    cv[i].next_y = cv[i].y + cv[i].vy * dt;
+                } else {
+                    cv[i].next_x = cv[i].x;
+                    cv[i].next_y = cv[i].y;
+                }
+            }
+            for(int i = 0; i < CHAIN_LEN; i++) {
+                cv[i].vx = cv[i].next_vx;
+                cv[i].vy = cv[i].next_vy;
+                cv[i].x = cv[i].next_x;
+                cv[i].y = cv[i].next_y;
+            }
+        }
+        //    cout << id << ", " << sg->xyz[1] << endl;
+    }
+    set_old_vector(&cv[id], sg);
+    int p, n;
+    p = n = id;
+    if(p != 0) {
+        p--;
+    }
+    if(n != CHAIN_LEN - 1) {
+        n++;
+    }
+    sg->angle[2-(id%2)*2]
+        = 90 + atan((cv[p].next_y - cv[n].next_y) / (cv[p].next_x - cv[n].next_x)) * 180 / M_PI;
+}
+
+void
+chain_old_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg)
+{
+
+}
+
+void
+chain_old_init(TaskManager *manager, int w, int h)
+{
+    SceneGraphPtr root_old_chain, chain;
+    CHAIN_VARS rcv;
+
+    sgroot->createFromXMLfile(manager,"xml_file/chain.xml");
+
+    root_old_chain = sgroot->createSceneGraph(CHAIN);
+    root_old_chain->set_move_collision(chain_old_move_ope, chain_old_collision);
+    init_chainold_vars(&rcv);
+    rcv.next_x = w / 2;
+    rcv.next_y = 0.0;
+    set_old_vector(&rcv, root_old_chain);
+
+    for(int i = 0; i < CHAIN_LEN; i++) {
+        chain = sgroot->createSceneGraph(CHAIN);
+        chain->id = i;
+        init_chainold_vars(&cv[i]);
+        cv[i].x = 0;
+        cv[i].y = chain_width * i;
+        set_old_vector(&cv[i], chain);
+        chain->angle[1] = -90 * (i % 2);
+        chain->set_move_collision(chain_old_move, chain_old_collision);
+
+        root_old_chain->addChild(chain);
+    }
+    cv[0].can_move = FALSE;
+
+    sgroot->setSceneData(root_old_chain);
+}
--- a/TaskManager/Test/test_render/SceneGraphRoot.h	Wed Sep 23 21:05:24 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraphRoot.h	Wed Sep 23 21:24:38 2009 +0900
@@ -74,4 +74,6 @@
 
 #endif
 
+// 大域変数は無くすこと
 extern SceneGraphRootPtr sgroot;
+extern SceneGraphRootPtr sgroot_2;
--- a/TaskManager/Test/test_render/spe/ChainCal.cpp	Wed Sep 23 21:05:24 2009 +0900
+++ b/TaskManager/Test/test_render/spe/ChainCal.cpp	Wed Sep 23 21:24:38 2009 +0900
@@ -37,54 +37,54 @@
     //CHAIN_VARS* o_property = (CHAIN_VARS*)wbuf;
     
     for(int cnt = 0; cnt < 600; cnt++) {
-	for(int i = 0; i < CHAIN_LEN; i++) {
-	    if(property[i].can_move) {
-		double dx = property[i-1].x - property[i].x;
-		double dy = property[i-1].y - property[i].y;
-		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 < CHAIN_LEN - 1) {
-		    dx = property[i+1].x - property[i].x;
-		    dy = property[i+1].y - property[i].y;
-		    l = sqrt(dx * dx + dy * dy);
-		    a = k * (l - chain_width) / m;
-		    ax += a * dx / l;
-		    ay += a * dy / l;
+		for(int i = 0; i < CHAIN_LEN; i++) {
+			if(property[i].can_move) {
+				double dx = property[i-1].x - property[i].x;
+				double dy = property[i-1].y - property[i].y;
+				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 < CHAIN_LEN - 1) {
+					dx = property[i+1].x - property[i].x;
+					dy = property[i+1].y - property[i].y;
+					l = sqrt(dx * dx + dy * dy);
+					a = k * (l - chain_width) / m;
+					ax += a * dx / l;
+					ay += a * dy / l;
+				}
+				ay += g;
+				property[i].vx *= safe;
+				property[i].vy *= safe;
+				property[i].next_vx = property[i].vx + ax * dt;
+				property[i].next_vy = property[i].vy + ay * dt;
+				property[i].next_x = property[i].x + property[i].vx * dt;
+				property[i].next_y = property[i].y + property[i].vy * dt;
+			} else {
+				property[i].next_x = property[i].x;
+				property[i].next_y = property[i].y;
+			}
 		}
-		ay += g;
-		property[i].vx *= safe;
-		property[i].vy *= safe;
-		property[i].next_vx = property[i].vx + ax * dt;
-		property[i].next_vy = property[i].vy + ay * dt;
-		property[i].next_x = property[i].x + property[i].vx * dt;
-		property[i].next_y = property[i].y + property[i].vy * dt;
-	    } else {
-		property[i].next_x = property[i].x;
-		property[i].next_y = property[i].y;
-	    }
-	}
-	for(int i = 0; i < CHAIN_LEN; i++) {
-	    property[i].vx = property[i].next_vx;
-	    property[i].vy = property[i].next_vy;
-	    property[i].x = property[i].next_x;
-	    property[i].y = property[i].next_y;
-	}
+		for(int i = 0; i < CHAIN_LEN; i++) {
+			property[i].vx = property[i].next_vx;
+			property[i].vy = property[i].next_vy;
+			property[i].x = property[i].next_x;
+			property[i].y = property[i].next_y;
+		}
     }
-
+	
     for (int j = 0; j < CHAIN_LEN; j++) {
-	int p, n;
-	id = property[j].id;
-	p = n = id;
-	if(p != 0) {
-	    p--;
-	}
-	if(n != CHAIN_LEN - 1) {
-	    n++;
-	}
-	property[j].angle[2-(id%2)*2]
-	    = 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI;
+		int p, n;
+		id = property[j].id;
+		p = n = id;
+		if(p != 0) {
+			p--;
+		}
+		if(n != CHAIN_LEN - 1) {
+			n++;
+		}
+		property[j].angle[2-(id%2)*2]
+			= 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI;
     }
     
     return 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/task/Switch.cc	Wed Sep 23 21:24:38 2009 +0900
@@ -0,0 +1,17 @@
+#include <stdlib.h>
+#include <string.h>
+#include "Switch.h"
+#include "viewer_types.h"
+#include "SceneGraphRoot.h"
+
+SchedDefineTask(Switch);
+
+int
+Switch::run(void *rbuf, void *wbuf)
+{
+    SceneGraphRootPtr tmp = sgroot;
+    sgroot = sgroot_2;
+    sgroot_2 = tmp;
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/task/Switch.h	Wed Sep 23 21:24:38 2009 +0900
@@ -0,0 +1,12 @@
+#ifndef INCLUDED_TASK_SWITCH
+#define INCLUDED_TASK_SWITCH
+
+#include "SchedTask.h"
+
+class Switch : public SchedTask {
+public:
+    SchedConstructor(Switch);
+    int run(void *rbuf, void *wbuf);
+};
+
+#endif
--- a/TaskManager/Test/test_render/task/task_init.cc	Wed Sep 23 21:05:24 2009 +0900
+++ b/TaskManager/Test/test_render/task/task_init.cc	Wed Sep 23 21:24:38 2009 +0900
@@ -22,9 +22,14 @@
 SchedExternTask(ShowTime);
 SchedExternTask(ChainMove);
 SchedExternTask(SendKey);
+
 SchedExternTask(UpdateKey);
 SchedExternTask(InitKey);
 
+SchedExternTask(ChainMove);
+SchedExternTask(Switch);
+
+
 /**
  * set_cpu(CPU_PPE) で動作する task
  */
@@ -53,6 +58,7 @@
     SchedRegisterTask(INIT_KEY_TASK, InitKey);
 
     SchedRegisterTask(SHOW_TIME, ShowTime);
+    SchedRegisterTask(TASK_SWITCH, Switch);
 
     // usr
     SchedRegisterTask(CHAIN_MOVE, ChainMove);
--- a/TaskManager/Test/test_render/viewer.cc	Wed Sep 23 21:05:24 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.cc	Wed Sep 23 21:24:38 2009 +0900
@@ -25,7 +25,7 @@
 int frames;
 
 SceneGraphRootPtr sgroot;
-//SceneGraphRootPtr sgroot_2;
+SceneGraphRootPtr sgroot_2;
 
 /* Data Pack sent to Other CPUs (ex. SPE) */
 SceneGraphPack *sgpack;
@@ -100,6 +100,7 @@
 extern void vacuum_init(TaskManager *manager, int w, int h);
 extern void untitled_init(TaskManager *manager);
 extern void chain_init(TaskManager *manager, int w, int h);
+extern void chain_old_init(TaskManager *manager, int w, int h);
 extern void boss1_init(TaskManager *manager, int w, int h);
 extern void init_gaplant(TaskManager *manager, int w, int h);
 extern void vacuum_init2(TaskManager *manager, int w, int h);
@@ -114,7 +115,7 @@
     frames     = 0;
 
     sgroot = new SceneGraphRoot(this->width, this->height);
-    //sgroot_2 = new SceneGraphRoot(this->width, this->height);
+    sgroot_2 = new SceneGraphRoot(this->width, this->height);
     //sgroot->createFromXMLFile(xml);
 
     switch (sg_number) {
@@ -165,6 +166,9 @@
 	speLoop();
 	return;
         break;
+    case 17:
+        chain_old_init(manager, this->width, this-> height);
+	break;
     default:
         node_init(manager);
         break;
@@ -244,9 +248,11 @@
     // TASK_INIT_TEXTURE が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ
 
     /* test */
+   
     HTaskPtr task_switch = manager->create_task(TASK_SWITCH);
     task_switch->wait_for(task_next);
     task_switch->set_post(post2runMoveDrawLoop, (void*)this);
+    task_switch->spawn();
 }
 
 void
@@ -360,8 +366,8 @@
     rendering(task_next);
 
 }
+
 */
-
 void
 Viewer::mainLoop()
 {
@@ -591,6 +597,6 @@
     }
 
     delete sgroot;
-    //delete sgroot_2;
+    delete sgroot_2;
     quit();
 }