changeset 727:aaaa0baeab89

fix SgChange.cc, SgRootChange.cc
author aaa
date Sat, 19 Dec 2009 17:11:43 +0900
parents 9136cf9186b6
children 4f77768d7a7f
files Renderer/Engine/SgChange.cc Renderer/Test/SgRootChange.cc TaskManager/kernel/ppe/DmaBuffer.cc
diffstat 3 files changed, 101 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SgChange.cc	Sat Dec 19 16:37:49 2009 +0900
+++ b/Renderer/Engine/SgChange.cc	Sat Dec 19 17:11:43 2009 +0900
@@ -255,7 +255,7 @@
 {
     SgChange *viewer = (SgChange *)viewer_;
     HTaskPtr task_next = viewer->manager->create_task(Dummy);
-    viewer->run_draw(task_next);
+    viewer->rendering(task_next);
 
 }
 
--- a/Renderer/Test/SgRootChange.cc	Sat Dec 19 16:37:49 2009 +0900
+++ b/Renderer/Test/SgRootChange.cc	Sat Dec 19 17:11:43 2009 +0900
@@ -4,17 +4,104 @@
 #include "MainLoop.h"
 #include "SgRootChange.h"
 
+static void ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+static void ball_collision_idle(SceneGraphPtr, void *sgroot_, 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, void *sgroot_, int screen_w, int screen_h)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    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, void *sgroot_, int screen_w, int screen_h)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    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, void *sgroot_, int screen_w, int screen_h)
 {
-    printf("test\n");
+    vy += g * dt;
+    node->xyz[1] += vy * dt;
+    //    node->xyz[0] += 10.0f;
+}
+
+static void
+ball_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree)
+{
 }
 
 static void
 ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
 			   SceneGraphPtr tree)
 {
-    printf("collision\n");
+    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);
+		}
+    }
 }
 
 // prototype
@@ -28,9 +115,19 @@
 SgRootChange::init_only_sg(SgChange *sgroot, int screen_w, int screen_h)
 {
     SceneGraphPtr ball;
+    srandom(100);
+
     sgroot->createFromXMLfile("xml_file/Ball.xml");
     ball = sgroot->createSceneGraph("Ball");
     ball->set_move_collision(ball_move, ball_collision);
+
+    h0 = screen_h/2;
+    h0 = -1000;
+
+    ball->xyz[0] = screen_w/2;
+    ball->xyz[1] = h0;
+    ball->xyz[2] = 30.0f;
+
     sgroot->setSceneData(ball);
 
     return sgroot;
--- a/TaskManager/kernel/ppe/DmaBuffer.cc	Sat Dec 19 16:37:49 2009 +0900
+++ b/TaskManager/kernel/ppe/DmaBuffer.cc	Sat Dec 19 17:11:43 2009 +0900
@@ -9,7 +9,7 @@
 
 DmaBuffer::DmaBuffer(int size)
 {
-#ifdef NO_POSIX_MEMALIGN
+#ifndef HAS_POSIX_MEMALIGN
     buffer[0] = malloc(size);
     buffer[1] = malloc(size);
 #else