comparison Renderer/Test/cube.cc @ 563:338ad9c856fc draft

all exmple on Mac OS X
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 22 Oct 2009 23:05:16 +0900
parents 4c5264373c51
children 7a311860a76e
comparison
equal deleted inserted replaced
562:d65f21b18165 563:338ad9c856fc
1 #include <math.h> 1 #include <math.h>
2 #include "SceneGraphRoot.h" 2 #include "SceneGraphRoot.h"
3 #include "vacuum.h" 3 #include "vacuum.h"
4 #include "SGList.h"
5 #define SELECT 2 4 #define SELECT 2
6 5
7 void 6 void
8 cube_collision(SceneGraphPtr node, int screen_w, int screen_h, 7 cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
9 SceneGraphPtr tree) 8 SceneGraphPtr tree)
50 node->stack_xyz[1] = -node->stack_xyz[1]; 49 node->stack_xyz[1] = -node->stack_xyz[1];
51 } 50 }
52 51
53 } 52 }
54 53
54 extern int redcube ;
55 extern int enemy ;
55 56
56 void 57 void
57 cube_split(SceneGraphPtr root,SceneGraphPtr tree) 58 cube_split(SceneGraphPtr root,SceneGraphPtr tree)
58 { 59 {
59 60
60 SceneGraphPtr p; 61 SceneGraphPtr p;
61 // SceneGraphPtr common_move = sgroot->createSceneGraph(); 62 // SceneGraphPtr common_move = sgroot->createSceneGraph();
62 // SceneGraphPtr root_common_move = root->parent; 63 // SceneGraphPtr root_common_move = root->parent;
63 64
64 if(random()%SELECT) { 65 if(random()%SELECT) {
65 p = sgroot->createSceneGraph(REDCUBE); 66 p = sgroot->createSceneGraph(redcube);
66 } 67 }
67 else { 68 else {
68 p = sgroot->createSceneGraph(ENEMY); 69 p = sgroot->createSceneGraph(enemy);
69 } 70 }
70 71
71 root->set_move_collision(cube_move_right, cube_collision); 72 root->set_move_collision(cube_move_right, cube_collision);
72 p->set_move_collision(cube_move_left, cube_collision); 73 p->set_move_collision(cube_move_left, cube_collision);
73 74
96 collision_red(SceneGraphIteratorPtr it,SceneGraphPtr node) 97 collision_red(SceneGraphIteratorPtr it,SceneGraphPtr node)
97 { 98 {
98 float dx, dy,ddx,ddy, r; 99 float dx, dy,ddx,ddy, r;
99 float q = 0; 100 float q = 0;
100 101
101 for (; it->hasNext(REDCUBE);) { 102 for (; it->hasNext(redcube);) {
102 103
103 it->next(REDCUBE); 104 it->next(redcube);
104 SceneGraphPtr mcube = it->get(); 105 SceneGraphPtr mcube = it->get();
105 dx = node->xyz[0] - mcube->xyz[0]; 106 dx = node->xyz[0] - mcube->xyz[0];
106 dy = node->xyz[1] - mcube->xyz[1]; 107 dy = node->xyz[1] - mcube->xyz[1];
107 108
108 ddx = dx*dx; 109 ddx = dx*dx;
136 collision_purple(SceneGraphIteratorPtr it,SceneGraphPtr node,int w,int h) 137 collision_purple(SceneGraphIteratorPtr it,SceneGraphPtr node,int w,int h)
137 { 138 {
138 float dx, dy,ddx,ddy, r; 139 float dx, dy,ddx,ddy, r;
139 float q = 0; 140 float q = 0;
140 141
141 for (; it->hasNext(ENEMY);) { 142 for (; it->hasNext(enemy);) {
142 it->next(ENEMY); 143 it->next(enemy);
143 SceneGraphPtr mcube = it->get(); 144 SceneGraphPtr mcube = it->get();
144 145
145 dx = node->xyz[0] - mcube->xyz[0]; 146 dx = node->xyz[0] - mcube->xyz[0];
146 dy = node->xyz[1] - mcube->xyz[1]; 147 dy = node->xyz[1] - mcube->xyz[1];
147 ddx = dx*dx; 148 ddx = dx*dx;