26
|
1 createHuman = function(sgroot, w, h){
|
|
2 var walk_man = new sgroot.createSceneGraph3();
|
|
3 walk_man.xyz[0] = 100;
|
|
4 walk_man.xyz[1] = -5;
|
|
5 walk_man.xyz[2] = 100;
|
|
6 position_xyz[0] = walk_man.xyz[0];
|
|
7 position_xyz[1] = walk_man.xyz[1];
|
|
8 position_xyz[2] = walk_man.xyz[2] - 50;
|
|
9 aim_xyz[0] = position_xyz[0];
|
|
10 aim_xyz[1] = position_xyz[1];
|
|
11 aim_xyz[2] = position_xyz[2] + 1;
|
|
12 walk_man.scale = 0.01;
|
|
13 walk_man.set_move_collision(body_move, body_collision)
|
|
14 //walk_man.set_move_collision(plane_move, no_collision_idle);
|
|
15
|
|
16
|
|
17 var head = new sgroot.createSceneGraph1("head");
|
|
18 head.angle[0] = 90;
|
|
19 head.angle[1] = 0;
|
|
20 head.angle[2] = -90;
|
|
21 head.xyz[0] = -sgroot.sg_src["head"].model_x * 100;
|
|
22 head.xyz[1] = -sgroot.sg_src["head"].model_y * 100;
|
|
23 head.xyz[2] = -sgroot.sg_src["head"].model_z * 100;
|
|
24 head.set_move_collision(main_move, no_collision_idle);
|
|
25
|
|
26
|
|
27 var body = new sgroot.createSceneGraph1("body");
|
|
28 body.xyz[0] = -sgroot.sg_src["body"].model_x * 100;
|
|
29 body.xyz[1] = -sgroot.sg_src["body"].model_y * 100;
|
|
30 body.xyz[2] = -sgroot.sg_src["body"].model_z * 100 + 200;
|
|
31 body.set_move_collision(no_move_idle, no_collision_idle);
|
|
32
|
|
33
|
|
34 var joint_rh = new sgroot.createSceneGraph1("Kata");
|
|
35 /*joint_rh.xyz[0] = -sgroot.sg_src["green"].model_x * 7
|
|
36 joint_rh.xyz[1] =- sgroot.sg_src["green"].model_y * 7
|
|
37 joint_rh.xyz[2] = -sgroot.sg_src["green"].model_z * 7
|
|
38 */
|
|
39
|
|
40 joint_rh.scale = 7;
|
|
41 joint_rh.set_move_collision(joint_rh_move, no_collision_idle);
|
|
42
|
|
43
|
|
44 var right_hand = new sgroot.createSceneGraph1("right_hand");
|
|
45 right_hand.xyz[0] = -sgroot.sg_src["right_hand"].model_x * (100/7);
|
|
46 right_hand.xyz[1] = -sgroot.sg_src["right_hand"].model_y * (100/7);
|
|
47 right_hand.xyz[2] = -sgroot.sg_src["right_hand"].model_z * (100/7) - (sgroot.sg_src["right_hand"].w / 2);
|
|
48 right_hand.scale = 1/7;
|
|
49 right_hand.set_move_collision(right_hand_move, no_collision_idle);
|
|
50
|
|
51
|
|
52 var joint_lh = new sgroot.createSceneGraph1("Kata");
|
|
53 joint_lh.scale = 7;
|
|
54 joint_lh.set_move_collision(joint_lh_move, no_collision_idle);
|
|
55
|
|
56
|
|
57 var left_hand = new sgroot.createSceneGraph1("left_hand");
|
|
58 left_hand.xyz[0] = -sgroot.sg_src["left_hand"].model_x * (100/7);
|
|
59 left_hand.xyz[1] = -sgroot.sg_src["left_hand"].model_y * (100/7);
|
|
60 left_hand.xyz[2] = -sgroot.sg_src["left_hand"].model_z * (100/7) - (sgroot.sg_src["left_hand"].w / 2);
|
|
61 left_hand.scale = 1/7;
|
|
62 left_hand.set_move_collision(left_hand_move, no_collision_idle);
|
|
63
|
|
64
|
|
65 var joint_rl = new sgroot.createSceneGraph1("Kata");
|
|
66 joint_rl.scale = 7;
|
|
67 joint_rl.set_move_collision(joint_rl_move, no_collision_idle);
|
|
68
|
|
69 var right_leg = new sgroot.createSceneGraph1("left_leg");
|
|
70 right_leg.xyz[0] = -sgroot.sg_src["left_leg"].model_x * (100/7);
|
|
71 right_leg.xyz[1] = -sgroot.sg_src["left_leg"].model_y * (100/7);
|
|
72 right_leg.xyz[2] = -sgroot.sg_src["left_leg"].model_z * (100/7) - (sgroot.sg_src["left_leg"].w / 10);
|
|
73 right_leg.scale = 1/7;
|
|
74 right_leg.set_move_collision(right_leg_move, no_collision_idle);
|
|
75
|
|
76
|
|
77 var joint_ll = new sgroot.createSceneGraph1("Kata");
|
|
78 joint_ll.scale = 7;
|
|
79 joint_ll.set_move_collision(joint_ll_move, no_collision_idle);
|
|
80
|
|
81
|
|
82 var left_leg = new sgroot.createSceneGraph1("left_leg");
|
|
83 left_leg.xyz[0] = -sgroot.sg_src["left_leg"].model_x * (100/7);
|
|
84 left_leg.xyz[1] = -sgroot.sg_src["left_leg"].model_y * (100/7);
|
|
85 left_leg.xyz[2] = -sgroot.sg_src["left_leg"].model_z * (100/7) - (sgroot.sg_src["left_leg"].w / 10);
|
|
86 left_leg.scale = 1/7;
|
|
87 left_leg.set_move_collision(left_leg_move, no_collision_idle);
|
|
88
|
|
89
|
|
90
|
|
91 walk_man.addChild(head);
|
|
92 head.addChild(body);
|
|
93
|
|
94 body.addChild(joint_rh);
|
|
95 joint_rh.addChild(right_hand);
|
|
96
|
|
97 body.addChild(joint_lh);
|
|
98 joint_lh.addChild(left_hand);
|
|
99
|
|
100 body.addChild(joint_rl);
|
|
101 joint_rl.addChild(right_leg);
|
|
102
|
|
103 body.addChild(joint_ll);
|
|
104 joint_ll.addChild(left_leg);
|
|
105
|
|
106
|
|
107
|
|
108 return walk_man;
|
|
109
|
|
110 }
|
|
111
|
|
112
|
|
113 roteta_body = function(node, sgroot, w, h){
|
|
114 node.angle[2] += 1;
|
|
115 }
|
|
116
|
|
117 head_move = function(node, sgroot, w, h){
|
|
118 var move_eye = 1.0;
|
|
119 var PI = 3.14;
|
|
120 var pad = new sgroot.getController();
|
|
121 var dx = node.parents.xyz[0] - position_xyz[0];
|
|
122 var dz = node.parents.xyz[2] - position_xyz[2];
|
|
123 var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dz,2));
|
|
124
|
|
125
|
|
126 if(pad.left_isHold()){
|
|
127 cameraAngle_xyz[0] -= move_eye;
|
|
128 theta_xz += move_eye;
|
|
129 var radian = ((theta_xz%360) / 360) * 2 * PI;
|
|
130 var x_rate = Math.sin(radian);
|
|
131 var z_rate = Math.cos(radian);
|
|
132 var mv_x = d * Math.cos(radian);
|
|
133 var mv_z = d * Math.sin(radian);
|
|
134
|
|
135 position_xyz[0] = node.parents.xyz[0] - mv_x;
|
|
136 position_xyz[2] = node.parents.xyz[2] - mv_z;
|
|
137 aim_xyz[0] = position_xyz[0] ;
|
|
138 aim_xyz[2] = position_xyz[2] + 1;
|
|
139 node.angle[0] -= move_eye;
|
|
140 angleRate_xyz[0] = x_rate;
|
|
141 angleRate_xyz[2] = z_rate;
|
|
142 }
|
|
143
|
|
144
|
|
145 if(pad.right_isHold()){
|
|
146 cameraAngle_xyz[0] += move_eye;
|
|
147 theta_xz -= move_eye;
|
|
148 var radian = ((theta_xz%360) / 360) * 2 * PI;
|
|
149 var x_rate = Math.sin(radian);
|
|
150 var z_rate = Math.cos(radian);
|
|
151 var mv_x = d * Math.cos(radian)
|
|
152 var mv_z = d * Math.sin(radian);
|
|
153
|
|
154 position_xyz[0] = node.parents.xyz[0] - mv_x;
|
|
155 position_xyz[2] = node.parents.xyz[2] - mv_z;
|
|
156 aim_xyz[0] = position_xyz[0];
|
|
157 aim_xyz[2] = position_xyz[2] + 1;
|
|
158 node.angle[0] += move_eye;
|
|
159 angleRate_xyz[0] = x_rate;
|
|
160 angleRate_xyz[2] = z_rate;
|
|
161 }
|
|
162
|
|
163
|
|
164 if(pad.up_isHold() && cameraAngle_xyz[1] > -90){
|
|
165 //node.angle[2] -= move_eye
|
|
166 cameraAngle_xyz[1] -= move_eye;
|
|
167 }
|
|
168
|
|
169 if(pad.down_isHold() && cameraAngle_xyz[1] < 90){
|
|
170 //node.angle[2] += move_eye
|
|
171 cameraAngle_xyz[1] += move_eye;
|
|
172 }
|
|
173
|
|
174 }
|
|
175
|
|
176
|
|
177
|
|
178 body_move = function(node, sgroot, w, h){
|
|
179 var move_eye = 1.0;
|
|
180 var move_walk = 1.0;
|
|
181 var PI = 3.14;
|
|
182 var pad = new sgroot.getController();
|
|
183 var dx = position_xyz[0] - aim_xyz[0];
|
|
184 var dz = position_xyz[2] - aim_xyz[2];
|
|
185 var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dz,2));
|
|
186
|
|
187 //if(node.xyz[0] >= 0 && node.xyz[2] >= 0){
|
|
188 if(pad.left_move_isHold()){
|
|
189 var radian = (((theta_xz+90)%360) / 360) * 2 * PI;
|
|
190
|
|
191 if(!pad.zoom_in_isHold()){
|
|
192 node.xyz[0] += move_walk * Math.cos(radian);
|
|
193 node.xyz[2] += move_walk * Math.sin(radian);
|
|
194 }
|
|
195
|
|
196 aim_xyz[0] += move_walk * Math.cos(radian);
|
|
197 aim_xyz[2] += move_walk * Math.sin(radian);
|
|
198 position_xyz[0] += move_walk * Math.cos(radian);
|
|
199 position_xyz[2] += move_walk * Math.sin(radian);
|
|
200 }
|
|
201
|
|
202 if(pad.right_move_isHold()){
|
|
203 var radian = (((theta_xz+90)%360) / 360) * 2 * PI;
|
|
204
|
|
205 if(!pad.zoom_in_isHold()){
|
|
206 node.xyz[0] -= move_walk * Math.cos(radian);
|
|
207 node.xyz[2] -= move_walk * Math.sin(radian);
|
|
208 }
|
|
209
|
|
210 aim_xyz[0] -= move_walk * Math.cos(radian);
|
|
211 aim_xyz[2] -= move_walk * Math.sin(radian);
|
|
212 position_xyz[0] -= move_walk * Math.cos(radian);
|
|
213 position_xyz[2] -= move_walk * Math.sin(radian);
|
|
214 }
|
|
215
|
|
216 if(pad.front_move_isHold()){
|
|
217 var radian = ((theta_xz%360) / 360) * 2 * PI;
|
|
218
|
|
219 if(!pad.zoom_in_isHold()){
|
|
220 node.xyz[0] += move_walk * Math.cos(radian);
|
|
221 node.xyz[2] += move_walk * Math.sin(radian);
|
|
222 }
|
|
223
|
|
224 position_xyz[0] += move_walk * Math.cos(radian);
|
|
225 position_xyz[2] += move_walk * Math.sin(radian);
|
|
226 aim_xyz[0] += move_walk * Math.cos(radian);
|
|
227 aim_xyz[2] += move_walk * Math.sin(radian);
|
|
228
|
|
229 move_length++;
|
|
230 }
|
|
231
|
|
232 if(pad.back_move_isHold()){
|
|
233 var radian = ((theta_xz%360) / 360) * 2 * PI;
|
|
234
|
|
235 if(!pad.zoom_in_isHold()){
|
|
236 node.xyz[0] -= move_walk * Math.cos(radian);
|
|
237 node.xyz[2] -= move_walk * Math.sin(radian);
|
|
238 }
|
|
239
|
|
240 position_xyz[0] -= move_walk * Math.cos(radian);
|
|
241 position_xyz[2] -= move_walk * Math.sin(radian);
|
|
242 aim_xyz[0] -= move_walk * Math.cos(radian);
|
|
243 aim_xyz[2] -= move_walk * Math.sin(radian);
|
|
244
|
|
245 move_length--;
|
|
246 }
|
|
247 //}
|
|
248
|
|
249 if(pad.start_isHold()){
|
|
250 var bullet_speed = 2;
|
|
251 var radian_xz = ((theta_xz%360)/360) * 2 * PI;
|
|
252 var radian_yz = ((cameraAngle_xyz[1]%90)/90) * (PI / 2);
|
|
253 var bullet = new sgroot.createSceneGraph1("yellow");
|
|
254 bullet.xyz[0] = position_xyz[0] + Math.cos(radian_xz) * 200;
|
|
255 bullet.xyz[1] = position_xyz[1] + Math.sin(radian_yz) * 200;
|
|
256 bullet.xyz[2] = position_xyz[2] + Math.sin(radian_xz) * 200;
|
|
257 bullet.dx = Math.cos(radian_xz) * bullet_speed;
|
|
258 bullet.dy = Math.sin(radian_yz) * bullet_speed;
|
|
259 bullet.dz = Math.sin(radian_xz) * bullet_speed;
|
|
260 bullet.scale = 0.3;
|
|
261 bullet.set_move_collision(bullet_move, no_collision_idle);
|
|
262 }
|
|
263
|
|
264
|
|
265 if(pad.space_isHold()){
|
|
266 node.xyz[1] -= 0.8;
|
|
267 position_xyz[1] -= 0.8;
|
|
268 aim_xyz[1] -= 0.8;
|
|
269 }else if(pad.space_isRelease() && node.xyz[1] < -5){
|
|
270 node.xyz[1] += 0.4;
|
|
271 position_xyz[1] += 0.4;
|
|
272 aim_xyz[1] += 0.4;
|
|
273 }
|
|
274 }
|
|
275
|
|
276
|
|
277
|
|
278 body_collision = function(node, sgroot, w, h){
|
|
279 var dx = node.xyz[0] - position_xyz[0];
|
|
280 var dz = node.xyz[2] - position_xyz[2];
|
|
281 var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dz,2));
|
|
282 var PI = 3.14;
|
|
283 var radian = ((theta_xz%360) / 360) * 2 * PI;
|
|
284 if(node.xyz[0] < 0){
|
|
285 node.xyz[0] = 0;
|
|
286 position_xyz[0] = -d * Math.cos(radian);
|
|
287 aim_xyz[0] = position_xyz[0];
|
|
288 }
|
|
289
|
|
290 if(node.xyz[0] > 350){
|
|
291 node.xyz[0] = 350;
|
|
292 position_xyz[0] = 350 + (-d * Math.cos(radian));
|
|
293 aim_xyz[0] = position_xyz[0];
|
|
294 }
|
|
295
|
|
296
|
|
297 if(node.xyz[2] < 0){
|
|
298 node.xyz[2] = 0;
|
|
299 position_xyz[2] = -d * Math.sin(radian);
|
|
300 aim_xyz[2] = position_xyz[2] + 1;
|
|
301 }
|
|
302
|
|
303 if(node.xyz[2] > 350){
|
|
304 node.xyz[2] = 350;
|
|
305 position_xyz[2] = 350 + (-d * Math.sin(radian));
|
|
306 aim_xyz[2] = position_xyz[2] + 1;
|
|
307 }
|
|
308 }
|
|
309
|
|
310
|
|
311 right_hand_move = function(node, sgroot, w, h){
|
|
312 var PI = 3.14;
|
|
313 var radian = (((move_length*5)%360) / 360) * 2 * PI;
|
|
314 var range = 90;
|
|
315 node.angle[0] = Math.sin(radian) * range;
|
|
316 }
|
|
317
|
|
318
|
|
319 left_hand_move = function(node, sgroot, w, h){
|
|
320 var PI = 3.14;
|
|
321 var radian = (((move_length*5)%360) / 360) * 2 * PI;
|
|
322 var range = 90;
|
|
323
|
|
324 node.angle[0] = Math.sin(-radian) * range;
|
|
325 }
|
|
326
|
|
327
|
|
328 right_leg_move = function(node, sgroot, w, h){
|
|
329 var PI = 3.14;
|
|
330 var radian = (((move_length*5)%360) / 360) * 2 * PI;
|
|
331 var range = 90;
|
|
332
|
|
333 node.angle[0] = Math.sin(-radian) * range;
|
|
334 }
|
|
335
|
|
336
|
|
337 left_leg_move = function(node, sgroot, w, h){
|
|
338 var PI = 3.14;
|
|
339 var radian = (((move_length*5)%360) / 360) * 2 * PI;
|
|
340 var range = 90;
|
|
341
|
|
342 node.angle[0] = Math.sin(radian) * range;
|
|
343 }
|
|
344
|
|
345
|
|
346 joint_rh_move = function(node, sgroot, w, h){
|
|
347 node.angle[1] = 45;
|
|
348 node.xyz[0] = 0;
|
|
349 node.xyz[1] = 300;
|
|
350 node.xyz[2] = 100;
|
|
351 }
|
|
352
|
|
353 joint_lh_move = function(node, sgroot, w, h){
|
|
354 node.angle[1] = -45;
|
|
355 node.xyz[0] = 0;
|
|
356 node.xyz[1] = -300;
|
|
357 node.xyz[2] = 100;
|
|
358 }
|
|
359
|
|
360
|
|
361 joint_rl_move = function(node, sgroot, w, h){
|
|
362 node.xyz[0] = 0;
|
|
363 node.xyz[1] = -60;
|
|
364 node.xyz[2] = 0;
|
|
365 }
|
|
366
|
|
367
|
|
368
|
|
369
|
|
370 joint_ll_move = function(node, sgroot, w, h){
|
|
371 node.xyz[0] = 0;
|
|
372 node.xyz[1] = 60;
|
|
373 node.xyz[2] = 0;
|
|
374 }
|
|
375
|