Mercurial > hg > Game > Cerium
annotate Renderer/Test/chain.cc @ 558:00428ba0ba03 draft
boss1_action
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 22 Oct 2009 18:38:07 +0900 |
parents | 764772be1e3c |
children | f40558ec00a8 |
rev | line source |
---|---|
539 | 1 #include <iostream> |
2 #include <math.h> | |
3 #include "SceneGraphRoot.h" | |
4 #include "SceneGraph.h" | |
5 #include "SGList.h" | |
6 #include "TaskManager.h" | |
7 #include "Func.h" | |
8 #include "Chain.h" | |
9 #define FALSE 0 | |
10 #define TRUE !FALSE | |
11 #define CHAIN_LEN 50 | |
12 | |
13 static double chain_width = 10; | |
14 | |
15 | |
16 /* SceneGraph の property */ | |
17 ChainPropertyPtr properties[2]; | |
18 ChainPropertyPtr property; | |
19 | |
20 | |
21 //void createSceneGraphFromProperty(ChainPropertyPtr p) ; | |
22 void createSceneGraphFromProperty(void* p) ; | |
23 | |
24 void | |
25 Chain::init_chain_vars(ChainPropertyPtr cv) { | |
26 cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0; | |
27 cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0; | |
28 cv->can_move = TRUE; | |
29 } | |
30 | |
31 void | |
32 set_vector(ChainPropertyPtr p, SceneGraphPtr sg) { | |
33 sg->xyz[0] = p->next_x; | |
34 sg->xyz[1] = p->next_y; | |
35 sg->xyz[2] = 0.0f; | |
36 sg->angle[0] = p->angle[0]; | |
37 sg->angle[1] = p->angle[1]; | |
38 sg->angle[2] = p->angle[2]; | |
39 } | |
40 | |
41 #if 0 | |
42 static void | |
43 chain_move_ope(SceneGraphPtr node, int screen_w, int screen_h) | |
44 { | |
45 Pad *pad = sgroot->getController(); | |
46 | |
47 if (pad->circle.isHold()) { | |
48 property[CHAIN_LEN-1].can_move = FALSE; | |
49 if (pad->left.isHold()) { | |
50 property[CHAIN_LEN-1].x += -5.0; | |
51 } else if (pad->right.isHold()) { | |
52 property[CHAIN_LEN-1].x += 5.0; | |
53 } | |
54 | |
55 if (pad->up.isHold()) { | |
56 property[CHAIN_LEN-1].y += -5.0; | |
57 } else if (pad->down.isHold()) { | |
58 property[CHAIN_LEN-1].y += 5.0; | |
59 } | |
60 } else { | |
61 property[CHAIN_LEN-1].can_move = TRUE; | |
62 } | |
63 } | |
64 #endif | |
65 | |
66 void | |
67 Chain::chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h) | |
68 { | |
69 int id = sg->id; | |
70 //ChainPropertyPtr p = (ChainPropertyPtr)sg->propertyptr; | |
71 HTaskPtr chain_cal; | |
72 ChainPropertyPtr output; | |
73 | |
74 // SceneGraph の切り替えもここでやる | |
75 if (property == properties[0]) { | |
76 property = properties[1]; | |
77 output = properties[0]; | |
78 }else{ | |
79 property = properties[0]; | |
80 output = properties[1]; | |
81 } | |
82 chain_cal = manager->create_task(CHAINCAL_TASK); | |
83 chain_cal->add_inData(property, sizeof(ChainProperty)*CHAIN_LEN); | |
84 chain_cal->add_param(id); | |
85 chain_cal->add_outData(output, sizeof(ChainProperty)*CHAIN_LEN); | |
86 chain_cal->set_post(createSceneGraphFromProperty, (void*)id); | |
87 chain_cal->spawn(); | |
88 | |
89 } | |
90 | |
91 void | |
92 Chain::chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg) | |
93 { | |
94 | |
95 } | |
96 | |
97 void | |
98 createSceneGraphFromProperty(void* p) | |
99 { | |
100 ChainPropertyPtr chain_p = (ChainPropertyPtr)p; | |
101 SceneGraphPtr chain_copy = sgroot->createSceneGraph(CHAIN); | |
102 chain_copy->propertyptr = (void*)chain_p; | |
103 chain_copy->property_size = sizeof(ChainProperty); | |
104 set_vector(chain_p, chain_copy); | |
105 chain_p->parent->addChild(chain_copy); | |
106 } | |
107 | |
108 void | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
109 Chain::init(Viewer *sgroot, int w, int h) |
539 | 110 { |
111 SceneGraphPtr root_chain, chain; | |
112 ChainPropertyPtr rcv; | |
113 ChainProperty r; | |
114 HTaskPtr chain_init; | |
115 | |
116 rcv = &r; | |
117 | |
118 sgroot->createFromXMLfile(manager, "xml_file/chain.xml"); | |
119 | |
120 /* SPE に送る property の配列の領域確保 */ | |
121 properties[0] = (ChainPropertyPtr)manager->allocate(sizeof(ChainProperty)*CHAIN_LEN); | |
122 properties[1] = (ChainPropertyPtr)manager->allocate(sizeof(ChainProperty)*CHAIN_LEN); | |
123 property = properties[0]; | |
124 | |
125 root_chain = sgroot->createSceneGraph(CHAIN); | |
126 // set_move_collision()ではだめ | |
127 // root_chain->set_move_collision(chain_move_ope, chain_collision); | |
128 init_chain_vars(rcv); | |
129 rcv->next_x = w / 2; | |
130 rcv->next_y = 0.0; | |
131 rcv->angle[0] = 0; | |
132 rcv->angle[1] = 0; | |
133 rcv->angle[2] = 0; | |
134 | |
135 set_vector(rcv, root_chain); | |
136 | |
137 for(int i = 0; i < CHAIN_LEN; i++) { | |
138 chain = sgroot->createSceneGraph(CHAIN); | |
139 property[i].id = i; | |
140 init_chain_vars(&property[i]); | |
141 property[i].x = 0; | |
142 property[i].y = chain_width * i; | |
143 set_vector(&property[i], chain); | |
144 property->angle[1] = -90 * (i % 2); | |
145 //chain->set_move_collision(chain_move, chain_collision); | |
146 chain->propertyptr = &property[i]; | |
147 chain->property_size = sizeof(ChainProperty); | |
148 root_chain->addChild(chain); | |
149 property[i].parent = root_chain; | |
150 } | |
151 property[0].can_move = FALSE; | |
152 | |
153 // property を SPU の共有領域へコピーする | |
154 chain_init = manager->create_task(CHAININIT_TASK); | |
155 chain_init->add_inData(property, sizeof(ChainProperty)*CHAIN_LEN); | |
156 chain_init->add_param(CHAIN_LEN); | |
157 chain_init->set_cpu(SPE_0); | |
158 chain_init->set_post(createSceneGraphFromProperty, (void*)property); | |
159 chain_init->spawn(); | |
160 | |
161 sgroot->setSceneData(root_chain); | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
162 return sgroot; |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
163 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
164 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
165 extern Application * |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
166 application() { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
167 return new Chain(); |
539 | 168 } |
169 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
170 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
171 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
172 extern int init(TaskManager *manager, int argc, char *argv[]); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
173 extern void task_initialize(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
174 static void TMend(TaskManager *manager); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
175 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
176 int |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
177 TMmain(TaskManager *manager, int argc, char *argv[]) |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
178 { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
179 task_initialize(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
180 manager->set_TMend(TMend); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
181 return init(manager, argc, argv); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
182 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
183 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
184 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
185 void |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
186 TMend(TaskManager *manager) |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
187 { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
188 printf("test_nogl end\n"); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
189 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
190 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
191 |