changeset 589:f674ca0fb76d

add viwer.cc
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 30 Oct 2009 18:39:12 +0900
parents 6c1a627303b2
children c81018fbf51e
files Renderer/Engine/viewer.h Renderer/Test/Makefile.cell Renderer/Test/untitled.cc Renderer/Test/viewer.cc Renderer/Test/viewer.h
diffstat 5 files changed, 200 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/viewer.h	Sat Oct 24 16:11:08 2009 +0900
+++ b/Renderer/Engine/viewer.h	Fri Oct 30 18:39:12 2009 +0900
@@ -104,6 +104,12 @@
 	sgroot->setSceneData(g);
     }
 
+    int getLast()
+    {
+	return sgroot->getLast();
+    }
+
+
 
 
 private:
--- a/Renderer/Test/Makefile.cell	Sat Oct 24 16:11:08 2009 +0900
+++ b/Renderer/Test/Makefile.cell	Fri Oct 30 18:39:12 2009 +0900
@@ -11,7 +11,7 @@
 .cc.o:
 	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
 
-ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic
+ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer
 all: $(ALL)
 
 speobject:
@@ -72,6 +72,10 @@
 dynamic : $(DYNAMIC_OBJ) 
 	$(CC) -o $@ $?    $(LIBS)
 
+VIEWER_OBJ = viewer.o 
+viewer : $(VIEWER_OBJ) 
+	$(CC) -o $@ $?    $(LIBS)
+
 debug: $(TARGET)
 	sudo ppu-gdb ./$(TARGET) 
 
--- a/Renderer/Test/untitled.cc	Sat Oct 24 16:11:08 2009 +0900
+++ b/Renderer/Test/untitled.cc	Fri Oct 30 18:39:12 2009 +0900
@@ -65,7 +65,7 @@
 	node->stack_xyz[1] = -node->stack_xyz[1];
     }
 
-    node->xyz[2] = 1000;
+    node->xyz[2] = 100 ;
     //node->xyz[2] += node->stack_xyz[2];
     //if ((int)node->xyz[2] > screen_h || (int)node->xyz[2] < 100) {
     //node->stack_xyz[2] = -node->stack_xyz[2];
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/viewer.cc	Fri Oct 30 18:39:12 2009 +0900
@@ -0,0 +1,177 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "MainLoop.h"
+#include "viewer.h"
+
+
+// prototype
+static void ball_move(SceneGraphPtr node, int screen_w, int screen_h);
+static void ball_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree);
+static void ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree);
+
+
+static float vy = 0.0f; // y 方向速度
+static float dt = 1.0/1.0f; // frame rate 
+
+static float e = -0.8f;  // 反発係数
+static float g = 9.8f;  // 重力加速度
+//static float v0 = 0.0f; // 初速は 0
+
+static float h0; // 初期高さ
+static float ball_radius = 100.0f;
+
+static float speed = 10.0f;
+
+static void
+ball_move_idle2(SceneGraphPtr node, int screen_w, int screen_h)
+{
+    Pad *pad = sgroot->getController();
+
+    if (pad->circle.isHold()) {
+		if (pad->left.isHold()) {
+			node->xyz[0] -= speed;
+			if(node->xyz[0] < ball_radius)
+				node->xyz[0] = ball_radius;
+		} else if (pad->right.isHold()) {
+			node->xyz[0] += speed;
+			if(node->xyz[0] > screen_w  - ball_radius)
+				node->xyz[0] = screen_w - ball_radius;
+		}
+
+		if (pad->up.isHold()) {
+			node->xyz[1] -= speed;
+		} else if (pad->down.isHold()) {
+			node->xyz[1] += speed;
+            if(node->xyz[1] > screen_h - ball_radius)
+				node->xyz[1] = screen_h - ball_radius;
+		}
+    } else {
+		node->set_move_collision(ball_move, ball_collision);
+    }
+}
+
+static int time = 0;
+
+static void
+ball_move_idle(SceneGraphPtr node, int screen_w, int screen_h)
+{
+    Pad *pad = sgroot->getController();
+
+    if (pad->circle.isPush()) {
+		node->set_move_collision(ball_move_idle2, ball_collision_idle);
+		time = 0;
+    }
+
+    time++;
+
+    if (time > 90) {
+		float w = (float)random();
+      
+		w = fmodf(w, screen_w - ball_radius*2);
+		node->xyz[0] = w + ball_radius;
+		node->xyz[1] = h0;
+		node->set_move_collision(ball_move, ball_collision);
+		time = 0;
+    }
+}
+
+static void
+ball_move(SceneGraphPtr node, int screen_w, int screen_h)
+{
+    vy += g * dt;
+    node->xyz[1] += vy * dt;
+    //    node->xyz[0] += 10.0f;
+}
+
+static void
+ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree)
+{
+}
+
+static void
+ball_collision(SceneGraphPtr node, int screen_w, int screen_h,
+			   SceneGraphPtr tree)
+{
+    if (node->xyz[1] > screen_h - ball_radius) {
+		node->xyz[1] = screen_h - ball_radius;
+
+		vy *= e;
+		if (vy > -g && vy < 0) {
+			vy = 0.0;
+			node->set_move_collision(ball_move_idle, ball_collision_idle);
+		}
+    }
+}
+
+char *xmlfile;
+#define MAX_ROOT 100
+char *parts[MAX_ROOT ];
+int parts_cnt;
+
+MainLoopPtr 
+viewer::init(Viewer *sgroot, int screen_w, int screen_h)
+{
+    SceneGraphPtr ball;
+
+    // 固定した値で srandom すると、毎回同じ、random() 列が生成される
+    // random な値が欲しいなら、man random に方法が書いてあります。
+    srandom(100);
+
+    sgroot->createFromXMLfile(xmlfile);
+
+    ball = sgroot->createSceneGraph();
+    ball->set_move_collision(ball_move, ball_collision);
+
+    h0 = screen_h/2;
+    h0 = -1000;
+
+    ball->xyz[0] = screen_w/2;
+    //ball->xyz[0] = 0.0f;
+    ball->xyz[1] = h0;
+    ball->xyz[2] = 30.0f;
+
+    for(int i=0;i<parts_cnt; i++) {
+        ball->addChild(sgroot->createSceneGraph(parts[i]));
+    }
+    sgroot->setSceneData(ball);
+
+    return sgroot;
+}
+
+extern Application *
+application() {
+    return new viewer();
+}
+
+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);
+
+    for(int i=0;i<argc;i++) {
+        if (strcmp(argv[i],"-sg") == 0 && i+1<=argc) {
+            xmlfile = argv[i+1];
+        } else if (strcmp(argv[i],"-name") == 0 && i+1<=argc) {
+           parts[parts_cnt++] = argv[i+1];
+        }
+    }
+    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/viewer.h	Fri Oct 30 18:39:12 2009 +0900
@@ -0,0 +1,11 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "Application.h"
+#include "MainLoop.h"
+
+class viewer : public Application {
+
+    MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h);
+
+};