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
|
|
109 Chain::init(TaskManager *manager, int w, int h)
|
|
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);
|
|
162 }
|
|
163
|