Mercurial > hg > Game > Cerium
annotate Renderer/Test/cube.cc @ 1245:a97b4dd4574c draft
Added tag real_matrix for changeset cd50c48f45e7
author | Kakeru TAMASIRO <e095736@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 11 Nov 2011 17:04:13 +0900 |
parents | 7a311860a76e |
children |
rev | line source |
---|---|
539 | 1 #include <math.h> |
2 #include "SceneGraphRoot.h" | |
3 #include "vacuum.h" | |
4 #define SELECT 2 | |
5 | |
6 void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
7 cube_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
539 | 8 SceneGraphPtr tree) |
9 { | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
10 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
539 | 11 if (node->frame > 120) { |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
12 cube_split(node,tree, sgroot); |
539 | 13 } |
14 } | |
15 | |
16 void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
17 cube_move_left(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
539 | 18 { |
19 node->xyz[0] -= node->stack_xyz[0]; | |
20 node->xyz[1] += node->stack_xyz[1]; | |
21 | |
22 if (node->xyz[0] < 0) { | |
23 node->set_move_collision(cube_move_right, cube_collision); | |
24 } | |
25 | |
26 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { | |
27 node->stack_xyz[1] = -node->stack_xyz[1]; | |
28 } | |
29 } | |
30 | |
31 void | |
32 cube_rotate(SceneGraphPtr node, int w, int h) | |
33 { | |
34 node->angle[0] += 2.0f; | |
35 node->angle[1] += 2.0f; | |
36 node->angle[2] += 2.0f; | |
37 } | |
38 | |
39 void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
40 cube_move_right(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
539 | 41 { |
42 node->xyz[0] += node->stack_xyz[0]; | |
43 node->xyz[1] += node->stack_xyz[1]; | |
44 | |
45 if (node->xyz[0] > screen_w) { | |
46 node->set_move_collision(cube_move_left, cube_collision); | |
47 } | |
48 | |
49 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { | |
50 node->stack_xyz[1] = -node->stack_xyz[1]; | |
51 } | |
52 | |
53 } | |
54 | |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
55 extern int redcube ; |
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
56 extern int enemy ; |
539 | 57 |
58 void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
59 cube_split(SceneGraphPtr root,SceneGraphPtr tree, SceneGraphRoot *sgroot |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
60 ) |
539 | 61 { |
62 | |
63 SceneGraphPtr p; | |
64 // SceneGraphPtr common_move = sgroot->createSceneGraph(); | |
65 // SceneGraphPtr root_common_move = root->parent; | |
66 | |
67 if(random()%SELECT) { | |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
68 p = sgroot->createSceneGraph(redcube); |
539 | 69 } |
70 else { | |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
71 p = sgroot->createSceneGraph(enemy); |
539 | 72 } |
73 | |
74 root->set_move_collision(cube_move_right, cube_collision); | |
75 p->set_move_collision(cube_move_left, cube_collision); | |
76 | |
77 root->frame = 0; | |
78 p->frame = 0; | |
79 | |
80 p->xyz[0] = root->xyz[0] + 2; | |
81 p->xyz[1] = root->xyz[1]; | |
82 p->xyz[2] = root->xyz[2]; | |
83 | |
84 p->stack_xyz[0] = 2.0f; | |
85 p->stack_xyz[1] = random()%3-1; | |
86 p->stack_xyz[2] = 0.0f; | |
87 | |
88 root->xyz[0] -= 2; | |
89 root->stack_xyz[0] = 2.0f; | |
90 root->stack_xyz[1] = random()%3-1; | |
91 | |
92 //common_move->addChild(p); | |
93 root->addBrother(p); | |
94 | |
95 } | |
96 | |
97 | |
98 void | |
99 collision_red(SceneGraphIteratorPtr it,SceneGraphPtr node) | |
100 { | |
101 float dx, dy,ddx,ddy, r; | |
102 float q = 0; | |
103 | |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
104 for (; it->hasNext(redcube);) { |
539 | 105 |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
106 it->next(redcube); |
539 | 107 SceneGraphPtr mcube = it->get(); |
108 dx = node->xyz[0] - mcube->xyz[0]; | |
109 dy = node->xyz[1] - mcube->xyz[1]; | |
110 | |
111 ddx = dx*dx; | |
112 ddy = dy*dy; | |
113 | |
114 if(sqrt(ddx) < 10 && sqrt(ddy) < 10) { | |
115 mcube->remove(); | |
116 continue; | |
117 } | |
118 r = sqrt(ddx + ddy); | |
119 if (r >= 1) q = 200/r; | |
120 if (dx == 0) { | |
121 if(mcube->xyz[1] > node->xyz[1]) { | |
122 mcube->stack_xyz[1] -= q; | |
123 } else if(mcube->xyz[1] < node->xyz[1]) { | |
124 mcube->stack_xyz[1] += q; | |
125 } | |
126 } else { | |
127 if(mcube->xyz[0] > node->xyz[0]) { | |
128 mcube->xyz[0] -= q*cos(atan(dy/dx)); | |
129 mcube->xyz[1] -= q*sin(atan(dy/dx)); | |
130 } else if(mcube->xyz[0] < node->xyz[0]) { | |
131 mcube->xyz[0] += q*cos(atan(dy/dx)); | |
132 mcube->xyz[1] += q*sin(atan(dy/dx)); | |
133 } | |
134 } | |
135 } | |
136 } | |
137 | |
138 void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
139 collision_purple(SceneGraphIteratorPtr it,SceneGraphPtr node,int w,int h, SceneGraphRoot *sgroot) |
539 | 140 { |
141 float dx, dy,ddx,ddy, r; | |
142 float q = 0; | |
143 | |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
144 for (; it->hasNext(enemy);) { |
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
145 it->next(enemy); |
539 | 146 SceneGraphPtr mcube = it->get(); |
147 | |
148 dx = node->xyz[0] - mcube->xyz[0]; | |
149 dy = node->xyz[1] - mcube->xyz[1]; | |
150 ddx = dx*dx; | |
151 ddy = dy*dy; | |
152 | |
153 if(sqrt(ddx) < 10 && sqrt(ddy) < 10) { | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
154 gameover_scene(w,h,mcube, sgroot); |
539 | 155 node->remove(); |
156 break; | |
157 } | |
158 r = sqrt(ddx + ddy); | |
159 if (r >= 1) q = 200/r; | |
160 if (dx == 0) { | |
161 if(mcube->xyz[1] > node->xyz[1]) { | |
162 mcube->stack_xyz[1] -= q; | |
163 } else if(mcube->xyz[1] < node->xyz[1]) { | |
164 mcube->stack_xyz[1] += q; | |
165 } | |
166 } else { | |
167 | |
168 if(mcube->xyz[0] > node->xyz[0]) { | |
169 mcube->xyz[0] -= q*cos(atan(dy/dx)); | |
170 mcube->xyz[1] -= q*sin(atan(dy/dx)); | |
171 } else if(mcube->xyz[0] < node->xyz[0]) { | |
172 mcube->xyz[0] += q*cos(atan(dy/dx)); | |
173 mcube->xyz[1] += q*sin(atan(dy/dx)); | |
174 } | |
175 } | |
176 } | |
177 } |