changeset 767:e4d635b1f018

add spe/univers_move
author hiroki@henri.cr.ie.u-ryukyu.ac.jp
date Sat, 13 Feb 2010 17:33:38 +0900
parents 987d4cced279
children 719573b2e569
files Renderer/Engine/SceneGraph.h Renderer/Engine/spe/spe-main.cc Renderer/Engine/spe/univers_move.cc Renderer/Engine/spe/univers_move.h Renderer/Test/property_universe.cc Renderer/Test/property_universe.h
diffstat 6 files changed, 282 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraph.h	Sun Feb 07 17:52:52 2010 +0900
+++ b/Renderer/Engine/SceneGraph.h	Sat Feb 13 17:33:38 2010 +0900
@@ -36,7 +36,8 @@
 	
     int property_size;
     void *propertyptr;
-    void *property;
+    //void *property;
+    memaddr property;
     void *update_property;
 
     // xml ファイルから生成した時のオブジェクトリスト
--- a/Renderer/Engine/spe/spe-main.cc	Sun Feb 07 17:52:52 2010 +0900
+++ b/Renderer/Engine/spe/spe-main.cc	Sat Feb 13 17:33:38 2010 +0900
@@ -22,6 +22,7 @@
 SchedExternTask(UpdateKey);
 
 SchedExternTask(PropertyTask);
+SchedExternTask(UniversTask);
 
 void
 task_init(Scheduler *s)
@@ -42,7 +43,9 @@
 
     SchedRegister( ShowTime);
 
-    SchedRegister( PropertyTask);
     SchedRegister( InitKey);
     SchedRegister( UpdateKey);
+
+    SchedRegister( PropertyTask);
+    SchedRegister( UniversTask);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/univers_move.cc	Sat Feb 13 17:33:38 2010 +0900
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "universe_move.h"
+#include "Func.h"
+#include "types.h"
+
+/* これは必須 */
+SchedDefineTask(UniversTask);
+
+typedef struct {
+    float xyz[3];
+    float angle[3];
+    float stack_xyz[3];
+    SceneGraphPtr parent;
+    SceneGraphPtr children;
+    int property_index;
+    int parent_index;
+    SceneGraphPtr sg;
+    const char *name;
+} *PropertyPtr, Property;
+
+static int
+run(SchedTask *s,void *rbuf, void *wbuf)
+{
+    PropertyPtr	property	= (PropertyPtr)s->get_input(rbuf, 0);
+    PropertyPtr	update_property = (PropertyPtr)s->get_output(wbuf, 0);
+
+    property[0]->angle[1] += 1.0f;
+    if (property[0]->angle[1] > 360.0f) {
+	property[0]->angle[1] = 0.0f;
+    }
+
+    property[0]->xyz[0] += property[0]->stack_xyz[0];
+    if ((int)property[0]->xyz[0] > screen_w || (int)property[0]->xyz[0] < 0) {
+	property[0]->stack_xyz[0] = -property[0]->stack_xyz[0];
+    }
+
+    property[0]->xyz[1] += property[0]->stack_xyz[1];
+    if ((int)property[0]->xyz[1] > screen_h || (int)property[0]->xyz[1] < 0) {
+	property[0]->stack_xyz[1] = -property[0]->stack_xyz[1];
+    }
+
+    memcpy((void*)update_property, (void*)property, sizeof(Property)*2);
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/univers_move.h	Sat Feb 13 17:33:38 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_UNIVERS
+#define INCLUDED_TASK_UNIVERSY
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/property_universe.cc	Sat Feb 13 17:33:38 2010 +0900
@@ -0,0 +1,195 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "MainLoop.h"
+#include "property_universe.h"
+#include "types.h"
+#include "Func.h"
+#include "sys.h"
+#include "SgChange.h"
+
+#define PROPERTY_LENGTH 2;
+
+Property *property, *update_property;
+
+// prototype
+static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+static void move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void createSceneGraphFromProperty(SchedTask *s, void *sgroot, void *arg1);
+static void set_property(Property *p, SceneGraphPtr sg);
+static void apply_property(SceneGraphPtr sg, Property *p);
+static void regist_task(SceneGraphRoot *sgroot);
+static void set_relation(SceneGraphPtr parent, SceneGraphPtr child);
+
+static void
+move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    HTaskPtr property_task = sgroot->move_exec_task;
+
+    property_task->add_inData(property, sizeof(Property));
+    property_task->add_outData(update_property, sizeof(Property));
+    property_task->set_cpu(SPE_ANY);    
+    property_task->set_post(createSceneGraphFromProperty, (void *)sgroot, 0);
+    property_task->spawn();
+}
+
+static void
+collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
+	  SceneGraphPtr tree)
+{
+}
+
+static void
+createSceneGraphFromProperty(SchedTask *s, void *sgroot_, void *arg1)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    SceneGraphPtr camera = sgroot->camera;
+    SceneGraphPtr p_node;
+    int p_length = sgroot->;
+
+    // ここが allExecute の tree をたどって clone して行くところに相当する
+    //Property *t = update_property;
+    Property *p;
+
+    for (int i = 0; i < PROPERTY_LENGTH; i++) {
+	p = &update_property[i];
+	SceneGraphPtr node = sgroot->createSceneGraph(t->name);
+	node->set_move_collision(t->move_func, t->collision_func);
+	apply_property(node, t);	    
+    }
+	
+    for (int j = 0; j < PROPERTY_LENGTH; j++) {
+	p = &update_property[j];
+	p_node = p->node;
+	if (t->have_parent) {
+	    SceneGraphPtr parent = update_property[t->parent_index]->node;
+	    parent->addChilde(p_node);
+	    get_matrix(p_node->matrix, p_node->angle, p_node->xyz, parent->matrix);
+	    get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, parent->real_matrix);
+	} else {
+	    get_matrix(p_node->matrix, p_node->angle, p_node->xyz, camera->matrix);
+	    get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, camera->real_matrix);
+	}
+    }
+
+    sgroot->setSceneData(update_property[0]->node);
+
+    Property *tmp = property;
+    property = update_property;
+    update_property = tmp;
+
+    sgroot->move_finish();
+}
+
+static void
+apply_property(SceneGraphPtr node, Property *p)
+{
+    for (int i = 0; i < 3; i++) {
+	node->xyz[i] = p->xyz[i];
+	node->angle[i] = p->angle[i];
+	node->stack_xyz[i] = p->stack_xyz[i];
+    }
+    p->node = node;
+    node->property = (memaddr)p;
+}
+
+/*
+  ここで必要な値をプロパティに格納
+ */
+static void
+set_property(Property *p, SceneGraphPtr node, int index)
+{
+    for (int i = 0; i < 3; i++) {
+	p->xyz[i] = node->xyz[i];
+	p->angle[i] = node->angle[i];
+	p->stack_xyz[i] = node->stack_xyz[i];
+    }
+    p->parent = node->parent;
+    p->children = node->children;
+    p->name = node->name;
+    p->property_index = index;    
+    
+    p->node = node;
+    node->property = (memaddr)p;
+}
+
+static void
+regist_task(SceneGraphRoot *sgroot)
+{
+    TaskManager *manager = sgroot->tmanager;
+    HTaskPtr task = manager->create_task(PropertyUniverseTask);
+    // sgroot->setExecTask(task); とやるべき?
+    sgroot->move_exec_task = task;
+}
+
+static void
+set_relation(SceneGraphPtr parent, SceneGraphPtr child)
+{
+    child->property->parent_index = parent->property->property_index;
+    child->property->have_parent = 1;
+}
+
+MainLoopPtr 
+property_universe::init(Viewer *viewer, int screen_w, int screen_h)
+{
+    // SgChange を使うための2行
+    SgChange *sgroot = new SgChange(viewer);
+    sgroot->run_init();
+    // 上で書いた regist_task() を登録
+    // 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);
+
+    SceneGraphPtr earth;
+    sgroot->createFromXMLfile("xml_file/universe.xml");
+    earth = sgroot->createSceneGraph("Earth");
+    earth->set_move_collision(earth_move, earth_collision);
+    earth->xyz[0] = screen_w / 2;
+    earth->xyz[1] = screen_h / 2;
+
+    SceneGraphPtr moon;
+    moon = sgroot->createSceneGraph("Moon");
+    moon->set_move_collision(moon_move, moon_collision);
+
+    earth->addChild(moon);
+
+    set_property(property[root_obj_index], earth, 0);
+    set_property(property[1], moon, 1);
+    set_relation(earth, moon);
+    
+    sgroot->setSceneData(earth);
+
+    return sgroot;
+}
+
+extern Application *
+application() {
+    return new create_task();
+}
+
+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/property_universe.h	Sat Feb 13 17:33:38 2010 +0900
@@ -0,0 +1,25 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "Application.h"
+#include "MainLoop.h"
+#include "viewer.h"
+
+typedef struct {
+    float xyz[3];  // 12 byte
+    float angle[3];
+    float stack_xyz[3];
+    SceneGraphPtr parent;
+    SceneGraphPtr children;
+    int property_index;
+    int parent_index;
+    int have_parent;
+    SceneGraphPtr node;
+    const char *name;
+} *PropertyPtr, Property;
+
+class property_universe : public Application {
+
+    MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h);
+
+};