comparison Renderer/Test/cube.cc @ 653:7a311860a76e draft

remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
author hiroki@henri.cr.ie.u-ryukyu.ac.jp
date Wed, 25 Nov 2009 21:56:14 +0900
parents 338ad9c856fc
children
comparison
equal deleted inserted replaced
646:9f9390b45f78 653:7a311860a76e
2 #include "SceneGraphRoot.h" 2 #include "SceneGraphRoot.h"
3 #include "vacuum.h" 3 #include "vacuum.h"
4 #define SELECT 2 4 #define SELECT 2
5 5
6 void 6 void
7 cube_collision(SceneGraphPtr node, int screen_w, int screen_h, 7 cube_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
8 SceneGraphPtr tree) 8 SceneGraphPtr tree)
9 { 9 {
10 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
10 if (node->frame > 120) { 11 if (node->frame > 120) {
11 cube_split(node,tree); 12 cube_split(node,tree, sgroot);
12 } 13 }
13 } 14 }
14 15
15 void 16 void
16 cube_move_left(SceneGraphPtr node, int screen_w, int screen_h) 17 cube_move_left(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
17 { 18 {
18 node->xyz[0] -= node->stack_xyz[0]; 19 node->xyz[0] -= node->stack_xyz[0];
19 node->xyz[1] += node->stack_xyz[1]; 20 node->xyz[1] += node->stack_xyz[1];
20 21
21 if (node->xyz[0] < 0) { 22 if (node->xyz[0] < 0) {
34 node->angle[1] += 2.0f; 35 node->angle[1] += 2.0f;
35 node->angle[2] += 2.0f; 36 node->angle[2] += 2.0f;
36 } 37 }
37 38
38 void 39 void
39 cube_move_right(SceneGraphPtr node, int screen_w, int screen_h) 40 cube_move_right(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
40 { 41 {
41 node->xyz[0] += node->stack_xyz[0]; 42 node->xyz[0] += node->stack_xyz[0];
42 node->xyz[1] += node->stack_xyz[1]; 43 node->xyz[1] += node->stack_xyz[1];
43 44
44 if (node->xyz[0] > screen_w) { 45 if (node->xyz[0] > screen_w) {
53 54
54 extern int redcube ; 55 extern int redcube ;
55 extern int enemy ; 56 extern int enemy ;
56 57
57 void 58 void
58 cube_split(SceneGraphPtr root,SceneGraphPtr tree) 59 cube_split(SceneGraphPtr root,SceneGraphPtr tree, SceneGraphRoot *sgroot
60 )
59 { 61 {
60 62
61 SceneGraphPtr p; 63 SceneGraphPtr p;
62 // SceneGraphPtr common_move = sgroot->createSceneGraph(); 64 // SceneGraphPtr common_move = sgroot->createSceneGraph();
63 // SceneGraphPtr root_common_move = root->parent; 65 // SceneGraphPtr root_common_move = root->parent;
132 } 134 }
133 } 135 }
134 } 136 }
135 137
136 void 138 void
137 collision_purple(SceneGraphIteratorPtr it,SceneGraphPtr node,int w,int h) 139 collision_purple(SceneGraphIteratorPtr it,SceneGraphPtr node,int w,int h, SceneGraphRoot *sgroot)
138 { 140 {
139 float dx, dy,ddx,ddy, r; 141 float dx, dy,ddx,ddy, r;
140 float q = 0; 142 float q = 0;
141 143
142 for (; it->hasNext(enemy);) { 144 for (; it->hasNext(enemy);) {
147 dy = node->xyz[1] - mcube->xyz[1]; 149 dy = node->xyz[1] - mcube->xyz[1];
148 ddx = dx*dx; 150 ddx = dx*dx;
149 ddy = dy*dy; 151 ddy = dy*dy;
150 152
151 if(sqrt(ddx) < 10 && sqrt(ddy) < 10) { 153 if(sqrt(ddx) < 10 && sqrt(ddy) < 10) {
152 gameover_scene(w,h,mcube); 154 gameover_scene(w,h,mcube, sgroot);
153 node->remove(); 155 node->remove();
154 break; 156 break;
155 } 157 }
156 r = sqrt(ddx + ddy); 158 r = sqrt(ddx + ddy);
157 if (r >= 1) q = 200/r; 159 if (r >= 1) q = 200/r;